forked from kdomanski/iso9660
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iso9660_datatypes_test.go
64 lines (50 loc) · 1.74 KB
/
iso9660_datatypes_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//go:build !integration
// +build !integration
package iso9660
import (
"io"
"testing"
"github.com/stretchr/testify/assert"
)
func TestStringPadding(t *testing.T) {
out := MarshalString("foobar", 16)
assert.Equal(t, []byte("foobar "), out)
out = MarshalString("foobar", 4)
assert.Equal(t, []byte("foob"), out)
}
func TestUnmarshallInt32LSBMSB(t *testing.T) {
// data OK
number, err := UnmarshalInt32LSBMSB([]byte{0x00, 0x2D, 0x31, 0x01, 0x01, 0x31, 0x2D, 0x00})
assert.NoError(t, err)
assert.Equal(t, int32(20000000), number)
// data too short
_, err = UnmarshalInt32LSBMSB([]byte{0x01, 0x31, 0x2D, 0x00, 0x00, 0x2D, 0x31})
assert.Equal(t, io.ErrUnexpectedEOF, err)
// endian versions mismatch
_, err = UnmarshalInt32LSBMSB([]byte{0x01, 0x31, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00})
assert.Error(t, err)
}
func TestUnmarshallUint32LSBMSB(t *testing.T) {
// data OK
number, err := UnmarshalUint32LSBMSB([]byte{0x00, 0x5E, 0xD0, 0xB2, 0xB2, 0xD0, 0x5E, 0x00})
assert.NoError(t, err)
assert.Equal(t, uint32(3000000000), number)
// data too short
_, err = UnmarshalUint32LSBMSB([]byte{0x00, 0x5E, 0xD0, 0xB2, 0xB2, 0xD0, 0x5E})
assert.Equal(t, io.ErrUnexpectedEOF, err)
// endian versions mismatch
_, err = UnmarshalUint32LSBMSB([]byte{0x00, 0x5E, 0xD0, 0xB2, 0x00, 0x00, 0x00, 0x00})
assert.Error(t, err)
}
func TestUnmarshallInt16LSBMSB(t *testing.T) {
// data OK
number, err := UnmarshalInt16LSBMSB([]byte{0x20, 0x4E, 0x4E, 0x20})
assert.NoError(t, err)
assert.Equal(t, int16(20000), number)
// data too short
_, err = UnmarshalInt16LSBMSB([]byte{0x20, 0x4E, 0x4E})
assert.Equal(t, io.ErrUnexpectedEOF, err)
// endian versions mismatch
_, err = UnmarshalInt16LSBMSB([]byte{0x20, 0x4E, 0x00, 0x00})
assert.Error(t, err)
}