45 lines
958 B
Go
45 lines
958 B
Go
// Copyright 2021, Henrik Sölver henrik.solver@gmail.com
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
package ipp
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestUnMarshalSinglePositiveInteger(T *testing.T) {
|
|
testdata := []byte{
|
|
0x00, 0x04,
|
|
0x66, 0x6c, 0x6f, 0x70, //flop
|
|
0x00, 0x04,
|
|
0x00, 0x0, 0x0, 0x4,
|
|
}
|
|
|
|
buf := bytes.NewBuffer(testdata)
|
|
bufbuf := bufio.NewReader(buf)
|
|
|
|
var i Integer
|
|
i.unmarshal(bufbuf)
|
|
assert.Equal(T, "flop", i.name, "Should be equal")
|
|
assert.Equal(T, int32(4), i.values[0], "Should be equal")
|
|
}
|
|
|
|
func TestUnMarshalSingleNegativeInteger(T *testing.T) {
|
|
testdata := []byte{
|
|
0x00, 0x04,
|
|
0x66, 0x6c, 0x6f, 0x70, //flop
|
|
0x00, 0x04,
|
|
0xff, 0xff, 0xff, 0xfc,
|
|
}
|
|
buf := bytes.NewBuffer(testdata)
|
|
bufbuf := bufio.NewReader(buf)
|
|
|
|
var i Integer
|
|
i.unmarshal(bufbuf)
|
|
assert.Equal(T, "flop", i.name, "Should be equal")
|
|
assert.Equal(T, int32(-4), i.values[0], "Should be equal")
|
|
}
|