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

Function TestWriteOn64bitArch

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

Source from the content-addressed store, hash-verified

101}
102
103func TestWriteOn64bitArch(t *testing.T) {
104 arch := device.Big64
105 values := []interface{}{
106 uint8(0x12), int8(0x12),
107 uint16(0x1234), int16(0x1234),
108 uint32(0x12345678), int32(0x12345678),
109 BytePtr(0x87654321),
110 []uint8{0x10, 0x20, 0x30},
111 BytePtr(0x1234567890abcdef),
112 "hello",
113 uint64(0xfedcba0987654321), // Mock size_t type
114 }
115
116 buf := &bytes.Buffer{}
117 e := NewEncoder(endian.Writer(buf, arch.GetEndian()), arch)
118 Write(e, values)
119
120 got := buf.Bytes()
121 expected := []byte{
122 0x12, 0x12, // uint8(0x12), int8(0x12),
123 0x12, 0x34, 0x12, 0x34, // uint16(0x1234), int16(0x1234),
124 0x00, 0x00, // padding
125 0x12, 0x34, 0x56, 0x78, // uint32(0x12345678),
126 0x12, 0x34, 0x56, 0x78, // int32(0x12345678),
127 0x00, 0x00, 0x00, 0x00, 0x87, 0x65, 0x43, 0x21, // Pointer(0x87654321),
128 0x10, 0x20, 0x30, // []uint8{0x10, 0x20, 0x30},
129 0x00, 0x00, 0x00, 0x00, 0x00, // padding
130 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, // Pointer(0x1234567890abcdef),
131 'h', 'e', 'l', 'l', 'o', 0, // "hello"
132 0x00, 0x00, // padding
133 0xfe, 0xdc, 0xba, 0x09, 0x87, 0x65, 0x43, 0x21, // uint64(0xfedbca0987654321),
134 }
135
136 if !bytes.Equal(got, expected) {
137 t.Errorf("Bytes were not as expected.\nExpected: % x\nGot: % x", expected, got)
138 }
139}
140
141func TestWriteStructOn64bitArch(t *testing.T) {
142 arch := device.Big64

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