| 79 | } |
| 80 | |
| 81 | static void test_writes() |
| 82 | { |
| 83 | Bytes b; |
| 84 | ByteWriter bw(b); |
| 85 | |
| 86 | bw.seek(0); |
| 87 | bw.write_8(1); |
| 88 | assert((b == Bytes{1})); |
| 89 | bw.write_be32(0x02020202); |
| 90 | assert((b == Bytes{1, 2, 2, 2, 2})); |
| 91 | |
| 92 | auto reset = [&]() |
| 93 | { |
| 94 | b.resize(0); |
| 95 | bw.seek(0); |
| 96 | }; |
| 97 | |
| 98 | // clang-format off |
| 99 | reset(); bw.write_le16(0x0102); assert((b == Bytes{2, 1})); |
| 100 | reset(); bw.write_be16(0x0102); assert((b == Bytes{1, 2})); |
| 101 | reset(); bw.write_le24(0x010203); assert((b == Bytes{3, 2, 1})); |
| 102 | reset(); bw.write_be24(0x010203); assert((b == Bytes{1, 2, 3})); |
| 103 | reset(); bw.write_le32(0x01020304); assert((b == Bytes{4, 3, 2, 1})); |
| 104 | reset(); bw.write_be32(0x01020304); assert((b == Bytes{1, 2, 3, 4})); |
| 105 | // clang-format on |
| 106 | |
| 107 | reset(); |
| 108 | bw += {1, 2, 3, 4, 5}; |
| 109 | assert((b == Bytes{1, 2, 3, 4, 5})); |
| 110 | } |
| 111 | |
| 112 | static void test_slice() |
| 113 | { |