MCPcopy Create free account
hub / github.com/google/gapid / TestWriteOn32bitArch

Function TestWriteOn32bitArch

gapis/memory/write_test.go:25–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestWriteOn32bitArch(t *testing.T) {
26 arch := device.Big32
27 values := []interface{}{
28 uint8(0x12), int8(0x12),
29 uint16(0x1234), int16(0x1234),
30 uint32(0x12345678), int32(0x12345678),
31 BytePtr(0x87654321),
32 []uint8{0x10, 0x20, 0x30},
33 []uint16{0x10, 0x20, 0x30},
34 []uint32{0x10, 0x20, 0x30},
35 "hello",
36 }
37
38 buf := &bytes.Buffer{}
39 e := NewEncoder(endian.Writer(buf, arch.GetEndian()), arch)
40 Write(e, values)
41
42 got := buf.Bytes()
43 expected := []byte{
44 0x12, 0x12, // uint8(0x12), int8(0x12),
45 0x12, 0x34, 0x12, 0x34, // uint16(0x1234), int16(0x1234),
46 0x00, 0x00, // padding
47 0x12, 0x34, 0x56, 0x78, // uint32(0x12345678),
48 0x12, 0x34, 0x56, 0x78, // int32(0x12345678),
49 0x87, 0x65, 0x43, 0x21, // Pointer(0x87654321),
50 0x10, 0x20, 0x30, // []uint8{0x10, 0x20, 0x30},
51 0x00, // padding
52 0x00, 0x10, 0x00, 0x20, 0x00, 0x30, // []uint16{0x10, 0x20, 0x30},
53 0x00, 0x00, // padding
54 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x30, // []uint32{0x10, 0x20, 0x30},
55 'h', 'e', 'l', 'l', 'o', 0, // "hello"
56 }
57
58 if !bytes.Equal(got, expected) {
59 t.Errorf("Bytes were not as expected.\nExpected: % x\nGot: % x", expected, got)
60 }
61}
62
63type encodableStruct struct {
64 X uint8

Callers

nothing calls this directly

Calls 5

BytePtrFunction · 0.85
NewEncoderFunction · 0.85
WriterMethod · 0.80
WriteFunction · 0.70
EqualMethod · 0.45

Tested by

no test coverage detected