(t *testing.T)
| 101 | } |
| 102 | |
| 103 | func 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 | |
| 141 | func TestWriteStructOn64bitArch(t *testing.T) { |
| 142 | arch := device.Big64 |
nothing calls this directly
no test coverage detected