github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/binary/be_test.go (about) 1 package binary 2 3 import "testing" 4 5 func TestBigEndian_Uint16(t *testing.T) { 6 var expected uint16 = 0x0a0b 7 if got := BigEndian.Uint16([]byte{0x0a, 0x0b}); got != expected { 8 t.Errorf("BigEndian.Uint16(): got %x, want %x", got, expected) 9 } 10 } 11 12 func TestBigEndian_Uint32(t *testing.T) { 13 var expected uint32 = 0x0a0b0c0d 14 if got := BigEndian.Uint32([]byte{0x0a, 0x0b, 0x0c, 0x0d}); got != expected { 15 t.Errorf("BigEndian.Uint32(): got %x, want %x", got, expected) 16 } 17 } 18 19 func TestBigEndian_Uint64(t *testing.T) { 20 var expected uint64 = 0x08090a0b0c0d0e0f 21 if got := BigEndian.Uint64([]byte{0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}); got != expected { 22 t.Errorf("BigEndian.Uint64(): got %x, want %x", got, expected) 23 } 24 } 25 26 func TestBigEndian_PutUint16(t *testing.T) { 27 var got [2]byte 28 var expected = [2]byte{0x0a, 0x0b} 29 if BigEndian.PutUint16(got[:], 0x0a0b); got != expected { 30 t.Errorf("BigEndian.PutUint16(): got %x, want %x", got, expected) 31 } 32 } 33 34 func TestBigEndian_PutUint32(t *testing.T) { 35 var got [4]byte 36 var expected = [4]byte{0x0a, 0x0b, 0x0c, 0x0d} 37 if BigEndian.PutUint32(got[:], 0x0a0b0c0d); got != expected { 38 t.Errorf("BigEndian.PutUint32(): got %x, want %x", got, expected) 39 } 40 } 41 42 func TestBigEndian_PutUint64(t *testing.T) { 43 var got [8]byte 44 var expected = [8]byte{0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f} 45 if BigEndian.PutUint64(got[:], 0x08090a0b0c0d0e0f); got != expected { 46 t.Errorf("BigEndian.PutUint64(): got %x, want %x", got, expected) 47 } 48 }