xref: /llvm-project/lldb/unittests/Utility/DataEncoderTest.cpp (revision 220854a47bdc0c281dbaafb54411ec65e76212b3)
1244258e3SGreg Clayton //===-- DataEncoderTest.cpp -----------------------------------------------===//
2244258e3SGreg Clayton //
3244258e3SGreg Clayton // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4244258e3SGreg Clayton // See https://llvm.org/LICENSE.txt for license information.
5244258e3SGreg Clayton // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6244258e3SGreg Clayton //
7244258e3SGreg Clayton //===----------------------------------------------------------------------===//
8244258e3SGreg Clayton 
9244258e3SGreg Clayton #include "gtest/gtest.h"
10244258e3SGreg Clayton 
11244258e3SGreg Clayton #include "lldb/Utility/DataEncoder.h"
12244258e3SGreg Clayton #include "llvm/ADT/ArrayRef.h"
13244258e3SGreg Clayton #include <vector>
14244258e3SGreg Clayton using namespace lldb_private;
15244258e3SGreg Clayton using namespace llvm;
16244258e3SGreg Clayton 
TEST(DataEncoderTest,PutU8)17244258e3SGreg Clayton TEST(DataEncoderTest, PutU8) {
18*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
19244258e3SGreg Clayton   const uint32_t addr_size = 4;
20244258e3SGreg Clayton 
21244258e3SGreg Clayton   uint32_t offset = 0;
22244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderLittle,
23244258e3SGreg Clayton                       addr_size);
24244258e3SGreg Clayton   offset = encoder.PutU8(offset, 11);
25244258e3SGreg Clayton   ASSERT_EQ(offset, 1U);
26244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 2, 3, 4, 5, 6, 7, 8}));
27244258e3SGreg Clayton   offset = encoder.PutU8(offset, 12);
28244258e3SGreg Clayton   ASSERT_EQ(offset, 2U);
29244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 12, 3, 4, 5, 6, 7, 8}));
30244258e3SGreg Clayton   offset = encoder.PutU8(offset, 13);
31244258e3SGreg Clayton   ASSERT_EQ(offset, 3U);
32244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 12, 13, 4, 5, 6, 7, 8}));
33244258e3SGreg Clayton   offset = encoder.PutU8(offset, 14);
34244258e3SGreg Clayton   ASSERT_EQ(offset, 4U);
35244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 12, 13, 14, 5, 6, 7, 8}));
36244258e3SGreg Clayton   // Check that putting a number to an invalid offset doesn't work and returns
37244258e3SGreg Clayton   // an error offset and doesn't modify the buffer.
38244258e3SGreg Clayton   ASSERT_EQ(encoder.PutU8(init.size(), 15), UINT32_MAX);
39244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 12, 13, 14, 5, 6, 7, 8}));
40244258e3SGreg Clayton }
41244258e3SGreg Clayton 
TEST(DataEncoderTest,AppendUnsignedLittle)42244258e3SGreg Clayton TEST(DataEncoderTest, AppendUnsignedLittle) {
43244258e3SGreg Clayton   const uint32_t addr_size = 4;
44244258e3SGreg Clayton   std::vector<uint8_t> expected;
45244258e3SGreg Clayton   DataEncoder encoder(lldb::eByteOrderLittle, addr_size);
46244258e3SGreg Clayton   encoder.AppendU8(0x11);
47244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0x11}));
48244258e3SGreg Clayton   encoder.AppendU16(0x2233);
49244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0x11, 0x33, 0x22}));
50244258e3SGreg Clayton   encoder.AppendU32(0x44556677);
51244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
52244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x33, 0x22, 0x77, 0x66, 0x55, 0x44}));
53244258e3SGreg Clayton   encoder.AppendU64(0x8899AABBCCDDEEFF);
54244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
55244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x33, 0x22, 0x77, 0x66, 0x55, 0x44,
56244258e3SGreg Clayton                                0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88}));
57244258e3SGreg Clayton   encoder.AppendU64(0x8899AABBCCDDEEFF);
58244258e3SGreg Clayton }
59244258e3SGreg Clayton 
TEST(DataEncoderTest,AppendUnsignedBig)60244258e3SGreg Clayton TEST(DataEncoderTest, AppendUnsignedBig) {
61244258e3SGreg Clayton   const uint32_t addr_size = 4;
62244258e3SGreg Clayton   std::vector<uint8_t> expected;
63244258e3SGreg Clayton   DataEncoder encoder(lldb::eByteOrderBig, addr_size);
64244258e3SGreg Clayton   encoder.AppendU8(0x11);
65244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0x11}));
66244258e3SGreg Clayton   encoder.AppendU16(0x2233);
67244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0x11, 0x22, 0x33}));
68244258e3SGreg Clayton   encoder.AppendU32(0x44556677);
69244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
70244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}));
71244258e3SGreg Clayton   encoder.AppendU64(0x8899AABBCCDDEEFF);
72244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
73244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
74244258e3SGreg Clayton                                0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}));
75244258e3SGreg Clayton }
76244258e3SGreg Clayton 
TEST(DataEncoderTest,AppendAddress4Little)77244258e3SGreg Clayton TEST(DataEncoderTest, AppendAddress4Little) {
78244258e3SGreg Clayton   const uint32_t addr_size = 4;
79244258e3SGreg Clayton   std::vector<uint8_t> expected;
80244258e3SGreg Clayton   DataEncoder encoder(lldb::eByteOrderLittle, addr_size);
81244258e3SGreg Clayton   encoder.AppendAddress(0x11223344);
82244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11}));
83244258e3SGreg Clayton   encoder.AppendAddress(0x55);
84244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
85244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x55, 0x00, 0x00, 0x00}));
86244258e3SGreg Clayton }
87244258e3SGreg Clayton 
TEST(DataEncoderTest,AppendAddress4Big)88244258e3SGreg Clayton TEST(DataEncoderTest, AppendAddress4Big) {
89244258e3SGreg Clayton   const uint32_t addr_size = 4;
90244258e3SGreg Clayton   std::vector<uint8_t> expected;
91244258e3SGreg Clayton   DataEncoder encoder(lldb::eByteOrderBig, addr_size);
92244258e3SGreg Clayton   encoder.AppendAddress(0x11223344);
93244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44}));
94244258e3SGreg Clayton   encoder.AppendAddress(0x55);
95244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
96244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x00, 0x00, 0x00, 0x55}));
97244258e3SGreg Clayton }
98244258e3SGreg Clayton 
TEST(DataEncoderTest,AppendAddress8Little)99244258e3SGreg Clayton TEST(DataEncoderTest, AppendAddress8Little) {
100244258e3SGreg Clayton   const uint32_t addr_size = 8;
101244258e3SGreg Clayton   std::vector<uint8_t> expected;
102244258e3SGreg Clayton   DataEncoder encoder(lldb::eByteOrderLittle, addr_size);
103244258e3SGreg Clayton   encoder.AppendAddress(0x11223344);
104244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
105244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00}));
106244258e3SGreg Clayton   encoder.AppendAddress(0x5566778899AABBCC);
107244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
108244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00,
109244258e3SGreg Clayton                                0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55}));
110244258e3SGreg Clayton }
111244258e3SGreg Clayton 
TEST(DataEncoderTest,AppendAddress8Big)112244258e3SGreg Clayton TEST(DataEncoderTest, AppendAddress8Big) {
113244258e3SGreg Clayton   const uint32_t addr_size = 8;
114244258e3SGreg Clayton   std::vector<uint8_t> expected;
115244258e3SGreg Clayton   DataEncoder encoder(lldb::eByteOrderBig, addr_size);
116244258e3SGreg Clayton   encoder.AppendAddress(0x11223344);
117244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
118244258e3SGreg Clayton             ArrayRef<uint8_t>({0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44}));
119244258e3SGreg Clayton   encoder.AppendAddress(0x5566778899AABBCC);
120244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
121244258e3SGreg Clayton             ArrayRef<uint8_t>({0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44,
122244258e3SGreg Clayton                                0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC}));
123244258e3SGreg Clayton }
124244258e3SGreg Clayton 
TEST(DataEncoderTest,AppendData)125244258e3SGreg Clayton TEST(DataEncoderTest, AppendData) {
126244258e3SGreg Clayton   const uint32_t addr_size = 4;
127244258e3SGreg Clayton   std::vector<uint8_t> expected;
128244258e3SGreg Clayton   DataEncoder encoder(lldb::eByteOrderBig, addr_size);
129244258e3SGreg Clayton   // Make sure default constructed StringRef appends nothing
130244258e3SGreg Clayton   encoder.AppendData(StringRef());
131244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({}));
132244258e3SGreg Clayton   // Make sure empty StringRef appends nothing
133244258e3SGreg Clayton   encoder.AppendData(StringRef(""));
134244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({}));
135244258e3SGreg Clayton   // Append some bytes that contains a NULL character
136244258e3SGreg Clayton   encoder.AppendData(StringRef("\x11\x00\x22", 3));
137244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0x11, 0x00, 0x22}));
138244258e3SGreg Clayton }
139244258e3SGreg Clayton 
TEST(DataEncoderTest,AppendCString)140244258e3SGreg Clayton TEST(DataEncoderTest, AppendCString) {
141244258e3SGreg Clayton   const uint32_t addr_size = 4;
142244258e3SGreg Clayton   std::vector<uint8_t> expected;
143244258e3SGreg Clayton   DataEncoder encoder(lldb::eByteOrderBig, addr_size);
144244258e3SGreg Clayton   // Make sure default constructed StringRef appends nothing
145244258e3SGreg Clayton   encoder.AppendCString(StringRef());
146244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({}));
147244258e3SGreg Clayton   // Make sure empty StringRef appends a NULL character since the StringRef
148244258e3SGreg Clayton   // doesn't contain a NULL in the referenced string.
149244258e3SGreg Clayton   encoder.AppendCString(StringRef(""));
150244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0x00}));
151244258e3SGreg Clayton   // Make sure empty StringRef appends only one NULL character if StringRef
152244258e3SGreg Clayton   // does contain a NULL in the referenced string.
153244258e3SGreg Clayton   encoder.AppendCString(StringRef("\0", 1));
154244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0x00, 0x00}));
155244258e3SGreg Clayton   // Append a string where the StringRef doesn't contain a NULL termination
156244258e3SGreg Clayton   // and verify the NULL terminate gets added
157244258e3SGreg Clayton   encoder.AppendCString(StringRef("hello"));
158244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
159244258e3SGreg Clayton             ArrayRef<uint8_t>({0x00, 0x00, 'h', 'e', 'l', 'l', 'o', 0x00}));
160244258e3SGreg Clayton   // Append a string where the StringRef does contain a NULL termination and
161244258e3SGreg Clayton   // verify only one NULL is added
162244258e3SGreg Clayton   encoder.AppendCString(StringRef("world", 6));
163244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
164244258e3SGreg Clayton             ArrayRef<uint8_t>({0x00, 0x00, 'h', 'e', 'l', 'l', 'o', 0x00,
165244258e3SGreg Clayton                                'w', 'o', 'r', 'l', 'd', '\0'}));
166244258e3SGreg Clayton }
167244258e3SGreg Clayton 
TEST(DataEncoderTest,PutU16Little)168244258e3SGreg Clayton TEST(DataEncoderTest, PutU16Little) {
169*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
170244258e3SGreg Clayton   const uint32_t addr_size = 4;
171244258e3SGreg Clayton   uint32_t offset = 0;
172244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderLittle,
173244258e3SGreg Clayton                       addr_size);
174244258e3SGreg Clayton   offset = encoder.PutU16(offset, 11);
175244258e3SGreg Clayton   ASSERT_EQ(offset, 2U);
176244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 0, 3, 4, 5, 6, 7, 8}));
177244258e3SGreg Clayton   offset = encoder.PutU16(offset, 12);
178244258e3SGreg Clayton   ASSERT_EQ(offset, 4U);
179244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 0, 12, 0, 5, 6, 7, 8}));
180244258e3SGreg Clayton   offset = encoder.PutU16(offset, 13);
181244258e3SGreg Clayton   ASSERT_EQ(offset, 6U);
182244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 0, 12, 0, 13, 0, 7, 8}));
183244258e3SGreg Clayton   offset = encoder.PutU16(offset, 14);
184244258e3SGreg Clayton   ASSERT_EQ(offset, 8U);
185244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 0, 12, 0, 13, 0, 14, 0}));
186244258e3SGreg Clayton   // Check that putting a number to an invalid offset doesn't work and returns
187244258e3SGreg Clayton   // an error offset and doesn't modify the buffer.
188244258e3SGreg Clayton   ASSERT_EQ(encoder.PutU16(init.size(), 15), UINT32_MAX);
189244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 0, 12, 0, 13, 0, 14, 0}));
190244258e3SGreg Clayton }
191244258e3SGreg Clayton 
TEST(DataEncoderTest,PutU16Big)192244258e3SGreg Clayton TEST(DataEncoderTest, PutU16Big) {
193*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
194244258e3SGreg Clayton   const uint32_t addr_size = 4;
195244258e3SGreg Clayton   uint32_t offset = 0;
196244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderBig,
197244258e3SGreg Clayton                       addr_size);
198244258e3SGreg Clayton   offset = encoder.PutU16(offset, 11);
199244258e3SGreg Clayton   ASSERT_EQ(offset, 2U);
200244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0, 11, 3, 4, 5, 6, 7, 8}));
201244258e3SGreg Clayton   offset = encoder.PutU16(offset, 12);
202244258e3SGreg Clayton   ASSERT_EQ(offset, 4U);
203244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0, 11, 0, 12, 5, 6, 7, 8}));
204244258e3SGreg Clayton   offset = encoder.PutU16(offset, 13);
205244258e3SGreg Clayton   ASSERT_EQ(offset, 6U);
206244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0, 11, 0, 12, 0, 13, 7, 8}));
207244258e3SGreg Clayton   offset = encoder.PutU16(offset, 14);
208244258e3SGreg Clayton   ASSERT_EQ(offset, 8U);
209244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0, 11, 0, 12, 0, 13, 0, 14}));
210244258e3SGreg Clayton   // Check that putting a number to an invalid offset doesn't work and returns
211244258e3SGreg Clayton   // an error offset and doesn't modify the buffer.
212244258e3SGreg Clayton   ASSERT_EQ(encoder.PutU16(init.size(), 15), UINT32_MAX);
213244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0, 11, 0, 12, 0, 13, 0, 14}));
214244258e3SGreg Clayton }
215244258e3SGreg Clayton 
TEST(DataEncoderTest,PutU32Little)216244258e3SGreg Clayton TEST(DataEncoderTest, PutU32Little) {
217*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
218244258e3SGreg Clayton   const uint32_t addr_size = 4;
219244258e3SGreg Clayton 
220244258e3SGreg Clayton   uint32_t offset = 0;
221244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderLittle,
222244258e3SGreg Clayton                       addr_size);
223244258e3SGreg Clayton   offset = encoder.PutU32(offset, 11);
224244258e3SGreg Clayton   ASSERT_EQ(offset, 4U);
225244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 0, 0, 0, 5, 6, 7, 8}));
226244258e3SGreg Clayton   offset = encoder.PutU32(offset, 12);
227244258e3SGreg Clayton   ASSERT_EQ(offset, 8u);
228244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 0, 0, 0, 12, 0, 0, 0}));
229244258e3SGreg Clayton   // Check that putting a number to an invalid offset doesn't work and returns
230244258e3SGreg Clayton   // an error offset and doesn't modify the buffer.
231244258e3SGreg Clayton   ASSERT_EQ(encoder.PutU32(init.size(), 15), UINT32_MAX);
232244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 0, 0, 0, 12, 0, 0, 0}));
233244258e3SGreg Clayton }
234244258e3SGreg Clayton 
TEST(DataEncoderTest,PutU32Big)235244258e3SGreg Clayton TEST(DataEncoderTest, PutU32Big) {
236*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
237244258e3SGreg Clayton   const uint32_t addr_size = 4;
238244258e3SGreg Clayton 
239244258e3SGreg Clayton   uint32_t offset = 0;
240244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderBig,
241244258e3SGreg Clayton                       addr_size);
242244258e3SGreg Clayton   offset = encoder.PutU32(offset, 11);
243244258e3SGreg Clayton   ASSERT_EQ(offset, 4U);
244244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0, 0, 0, 11, 5, 6, 7, 8}));
245244258e3SGreg Clayton   offset = encoder.PutU32(offset, 12);
246244258e3SGreg Clayton   ASSERT_EQ(offset, 8U);
247244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0, 0, 0, 11, 0, 0, 0, 12}));
248244258e3SGreg Clayton   // Check that putting a number to an invalid offset doesn't work and returns
249244258e3SGreg Clayton   // an error offset and doesn't modify the buffer.
250244258e3SGreg Clayton   ASSERT_EQ(encoder.PutU32(init.size(), 15), UINT32_MAX);
251244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0, 0, 0, 11, 0, 0, 0, 12}));
252244258e3SGreg Clayton }
253244258e3SGreg Clayton 
TEST(DataEncoderTest,PutU64Little)254244258e3SGreg Clayton TEST(DataEncoderTest, PutU64Little) {
255*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
256244258e3SGreg Clayton   const uint32_t addr_size = 4;
257244258e3SGreg Clayton   uint32_t offset = 0;
258244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderLittle,
259244258e3SGreg Clayton                       addr_size);
260244258e3SGreg Clayton   offset = encoder.PutU64(offset, 11);
261244258e3SGreg Clayton   ASSERT_EQ(offset, 8U);
262244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 0, 0, 0, 0, 0, 0, 0}));
263244258e3SGreg Clayton   // Check that putting a number to an invalid offset doesn't work and returns
264244258e3SGreg Clayton   // an error offset and doesn't modify the buffer.
265244258e3SGreg Clayton   ASSERT_EQ(encoder.PutU64(init.size(), 15), UINT32_MAX);
266244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 0, 0, 0, 0, 0, 0, 0}));
267244258e3SGreg Clayton }
268244258e3SGreg Clayton 
TEST(DataEncoderTest,PutU64Big)269244258e3SGreg Clayton TEST(DataEncoderTest, PutU64Big) {
270*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
271244258e3SGreg Clayton   const uint32_t addr_size = 4;
272244258e3SGreg Clayton   uint32_t offset = 0;
273244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderBig,
274244258e3SGreg Clayton                       addr_size);
275244258e3SGreg Clayton   offset = encoder.PutU64(offset, 11);
276244258e3SGreg Clayton   ASSERT_EQ(offset, 8U);
277244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0, 0, 0, 0, 0, 0, 0, 11}));
278244258e3SGreg Clayton   // Check that putting a number to an invalid offset doesn't work and returns
279244258e3SGreg Clayton   // an error offset and doesn't modify the buffer.
280244258e3SGreg Clayton   ASSERT_EQ(encoder.PutU64(init.size(), 15), UINT32_MAX);
281244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0, 0, 0, 0, 0, 0, 0, 11}));
282244258e3SGreg Clayton }
283244258e3SGreg Clayton 
TEST(DataEncoderTest,PutUnsignedLittle)284244258e3SGreg Clayton TEST(DataEncoderTest, PutUnsignedLittle) {
285*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
286244258e3SGreg Clayton   const uint32_t addr_size = 4;
287244258e3SGreg Clayton   uint32_t offset = 0;
288244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderLittle,
289244258e3SGreg Clayton                       addr_size);
290244258e3SGreg Clayton   // Put only the least significant byte from the uint64_t into the encoder
291244258e3SGreg Clayton   offset = encoder.PutUnsigned(0, 1, 0x1122334455667788ULL);
292244258e3SGreg Clayton   ASSERT_EQ(offset, 1U);
293244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({0x88, 2, 3, 4, 5, 6, 7, 8}));
294244258e3SGreg Clayton 
295244258e3SGreg Clayton   // Put only the least significant 2 byte2 from the uint64_t into the encoder
296244258e3SGreg Clayton   offset = encoder.PutUnsigned(0, 2, 0x1122334455667788ULL);
297244258e3SGreg Clayton   ASSERT_EQ(offset, 2U);
298244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
299244258e3SGreg Clayton             ArrayRef<uint8_t>({0x88, 0x77, 3, 4, 5, 6, 7, 8}));
300244258e3SGreg Clayton 
301244258e3SGreg Clayton   // Put only the least significant 4 bytes from the uint64_t into the encoder
302244258e3SGreg Clayton   offset = encoder.PutUnsigned(0, 4, 0x1122334455667788ULL);
303244258e3SGreg Clayton   ASSERT_EQ(offset, 4U);
304244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
305244258e3SGreg Clayton             ArrayRef<uint8_t>({0x88, 0x77, 0x66, 0x55, 5, 6, 7, 8}));
306244258e3SGreg Clayton 
307244258e3SGreg Clayton   // Put the full uint64_t value into the encoder
308244258e3SGreg Clayton   offset = encoder.PutUnsigned(0, 8, 0x1122334455667788ULL);
309244258e3SGreg Clayton   ASSERT_EQ(offset, 8U);
310244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
311244258e3SGreg Clayton             ArrayRef<uint8_t>({0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11}));
312244258e3SGreg Clayton }
313244258e3SGreg Clayton 
TEST(DataEncoderTest,PutUnsignedBig)314244258e3SGreg Clayton TEST(DataEncoderTest, PutUnsignedBig) {
315*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
316244258e3SGreg Clayton   const uint32_t addr_size = 4;
317244258e3SGreg Clayton   uint32_t offset = 0;
318244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderBig,
319244258e3SGreg Clayton                       addr_size);
320244258e3SGreg Clayton   // Put only the least significant byte from the uint64_t into the encoder
321244258e3SGreg Clayton   offset = encoder.PutUnsigned(0, 1, 0x1122334455667788ULL);
322244258e3SGreg Clayton   ASSERT_EQ(offset, 1U);
323244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
324244258e3SGreg Clayton             ArrayRef<uint8_t>({0x88, 2, 3, 4, 5, 6, 7, 8}));
325244258e3SGreg Clayton 
326244258e3SGreg Clayton   // Put only the least significant 2 byte2 from the uint64_t into the encoder
327244258e3SGreg Clayton   offset = encoder.PutUnsigned(0, 2, 0x1122334455667788ULL);
328244258e3SGreg Clayton   ASSERT_EQ(offset, 2U);
329244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
330244258e3SGreg Clayton             ArrayRef<uint8_t>({0x77, 0x88, 3, 4, 5, 6, 7, 8}));
331244258e3SGreg Clayton 
332244258e3SGreg Clayton   // Put only the least significant 4 bytes from the uint64_t into the encoder
333244258e3SGreg Clayton   offset = encoder.PutUnsigned(0, 4, 0x1122334455667788ULL);
334244258e3SGreg Clayton   ASSERT_EQ(offset, 4U);
335244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
336244258e3SGreg Clayton             ArrayRef<uint8_t>({0x55, 0x66, 0x77, 0x88, 5, 6, 7, 8}));
337244258e3SGreg Clayton 
338244258e3SGreg Clayton   // Put the full uint64_t value into the encoder
339244258e3SGreg Clayton   offset = encoder.PutUnsigned(0, 8, 0x1122334455667788ULL);
340244258e3SGreg Clayton   ASSERT_EQ(offset, 8U);
341244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
342244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
343244258e3SGreg Clayton }
344244258e3SGreg Clayton 
TEST(DataEncoderTest,PutData)345244258e3SGreg Clayton TEST(DataEncoderTest, PutData) {
346*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
347244258e3SGreg Clayton   const uint32_t addr_size = 4;
348244258e3SGreg Clayton   char one_byte[] = {11};
349244258e3SGreg Clayton   char two_bytes[] = {12, 13};
350244258e3SGreg Clayton   char to_many_bytes[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
351244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderLittle,
352244258e3SGreg Clayton                       addr_size);
353244258e3SGreg Clayton   uint32_t offset = 0;
354244258e3SGreg Clayton   // Test putting zero bytes from a invalid array (NULL)
355244258e3SGreg Clayton   offset = encoder.PutData(offset, nullptr, 0);
356244258e3SGreg Clayton   ASSERT_EQ(offset, 0U);
357*220854a4SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>(init));
358244258e3SGreg Clayton   // Test putting zero bytes from a valid array
359244258e3SGreg Clayton   offset = encoder.PutData(offset, one_byte, 0);
360244258e3SGreg Clayton   ASSERT_EQ(offset, 0U);
361*220854a4SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>(init));
362244258e3SGreg Clayton   // Test putting one byte from a valid array
363244258e3SGreg Clayton   offset = encoder.PutData(offset, one_byte, sizeof(one_byte));
364244258e3SGreg Clayton   ASSERT_EQ(offset, 1U);
365244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 2, 3, 4, 5, 6, 7, 8}));
366244258e3SGreg Clayton   offset = encoder.PutData(offset, two_bytes, sizeof(two_bytes));
367244258e3SGreg Clayton   ASSERT_EQ(offset, 3U);
368244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 12, 13, 4, 5, 6, 7, 8}));
369244258e3SGreg Clayton   offset = encoder.PutData(0, to_many_bytes, sizeof(to_many_bytes));
370244258e3SGreg Clayton   ASSERT_EQ(offset, UINT32_MAX);
371244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({11, 12, 13, 4, 5, 6, 7, 8}));
372244258e3SGreg Clayton }
373244258e3SGreg Clayton 
TEST(DataEncoderTest,PutCString)374244258e3SGreg Clayton TEST(DataEncoderTest, PutCString) {
375*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
376244258e3SGreg Clayton   const uint32_t addr_size = 4;
377244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderLittle,
378244258e3SGreg Clayton                       addr_size);
379244258e3SGreg Clayton   // Test putting invalid string pointer
380244258e3SGreg Clayton   ASSERT_EQ(encoder.PutCString(0, nullptr), UINT32_MAX);
381*220854a4SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>(init));
382244258e3SGreg Clayton   // Test putting an empty string
383244258e3SGreg Clayton   uint32_t offset = 0;
384244258e3SGreg Clayton   offset = encoder.PutCString(offset, "");
385244258e3SGreg Clayton   ASSERT_EQ(offset, 1U);
386244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(), ArrayRef<uint8_t>({'\0', 2, 3, 4, 5, 6, 7, 8}));
387244258e3SGreg Clayton   // Test putting valid C string
388244258e3SGreg Clayton   offset = encoder.PutCString(offset, "hello");
389244258e3SGreg Clayton   ASSERT_EQ(offset, 7U);
390244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
391244258e3SGreg Clayton             ArrayRef<uint8_t>({'\0', 'h', 'e', 'l', 'l', 'o', '\0', 8}));
392244258e3SGreg Clayton   // Test putting valid C string but where it won't fit in existing data and
393244258e3SGreg Clayton   // make sure data stay unchanged.
394244258e3SGreg Clayton   offset = encoder.PutCString(offset, "world");
395244258e3SGreg Clayton   ASSERT_EQ(offset, UINT32_MAX);
396244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
397244258e3SGreg Clayton             ArrayRef<uint8_t>({'\0', 'h', 'e', 'l', 'l', 'o', '\0', 8}));
398244258e3SGreg Clayton }
399244258e3SGreg Clayton 
TEST(DataEncoderTest,PutAddressLittle4)400244258e3SGreg Clayton TEST(DataEncoderTest, PutAddressLittle4) {
401*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
402244258e3SGreg Clayton   const uint32_t addr_size = 4;
403244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderLittle,
404244258e3SGreg Clayton                       addr_size);
405244258e3SGreg Clayton   uint32_t offset = 0;
406244258e3SGreg Clayton   offset = encoder.PutAddress(offset, 0x11223344);
407244258e3SGreg Clayton   ASSERT_EQ(offset, addr_size);
408244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
409244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 5, 6, 7, 8}));
410244258e3SGreg Clayton   offset = encoder.PutAddress(offset, 0x55667788);
411244258e3SGreg Clayton   ASSERT_EQ(offset, addr_size*2);
412244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
413244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x88, 0x77, 0x66, 0x55}));
414244258e3SGreg Clayton   // Make sure we can put an address when it won't fit in the existing buffer
415244258e3SGreg Clayton   // and that the buffer doesn't get modified.
416244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(addr_size+1, 0x10203040), UINT32_MAX);
417244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
418244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x88, 0x77, 0x66, 0x55}));
419244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(addr_size+2, 0x10203040), UINT32_MAX);
420244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
421244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x88, 0x77, 0x66, 0x55}));
422244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(addr_size+3, 0x10203040), UINT32_MAX);
423244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
424244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x88, 0x77, 0x66, 0x55}));
425244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(addr_size+4, 0x10203040), UINT32_MAX);
426244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
427244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x88, 0x77, 0x66, 0x55}));
428244258e3SGreg Clayton }
429244258e3SGreg Clayton 
TEST(DataEncoderTest,PutAddressBig4)430244258e3SGreg Clayton TEST(DataEncoderTest, PutAddressBig4) {
431*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
432244258e3SGreg Clayton   const uint32_t addr_size = 4;
433244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderBig,
434244258e3SGreg Clayton                       addr_size);
435244258e3SGreg Clayton   uint32_t offset = 0;
436244258e3SGreg Clayton   offset = encoder.PutAddress(offset, 0x11223344);
437244258e3SGreg Clayton   ASSERT_EQ(offset, addr_size);
438244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
439244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 5, 6, 7, 8}));
440244258e3SGreg Clayton   offset = encoder.PutAddress(offset, 0x55667788);
441244258e3SGreg Clayton   ASSERT_EQ(offset, addr_size*2);
442244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
443244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
444244258e3SGreg Clayton   // Make sure we can put an address when it won't fit in the existing buffer
445244258e3SGreg Clayton   // and that the buffer doesn't get modified.
446244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(addr_size+1, 0x10203040), UINT32_MAX);
447244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
448244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
449244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(addr_size+2, 0x10203040), UINT32_MAX);
450244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
451244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
452244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(addr_size+3, 0x10203040), UINT32_MAX);
453244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
454244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
455244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(addr_size+4, 0x10203040), UINT32_MAX);
456244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
457244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
458244258e3SGreg Clayton }
459244258e3SGreg Clayton 
TEST(DataEncoderTest,PutAddressLittle8)460244258e3SGreg Clayton TEST(DataEncoderTest, PutAddressLittle8) {
461*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
462244258e3SGreg Clayton   const uint32_t addr_size = 8;
463244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderLittle,
464244258e3SGreg Clayton                       addr_size);
465244258e3SGreg Clayton   uint32_t offset = 0;
466244258e3SGreg Clayton   offset = encoder.PutAddress(offset, 0x11223344);
467244258e3SGreg Clayton   ASSERT_EQ(offset, addr_size);
468244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
469244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00}));
470244258e3SGreg Clayton   // Make sure we can put an address when it won't fit in the existing buffer
471244258e3SGreg Clayton   // and that the buffer doesn't get modified.
472244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(1, 0x10203040), UINT32_MAX);
473244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
474244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00}));
475244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(2, 0x10203040), UINT32_MAX);
476244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
477244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00}));
478244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(3, 0x10203040), UINT32_MAX);
479244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
480244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00}));
481244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(4, 0x10203040), UINT32_MAX);
482244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
483244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00}));
484244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(5, 0x10203040), UINT32_MAX);
485244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
486244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00}));
487244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(6, 0x10203040), UINT32_MAX);
488244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
489244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00}));
490244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(7, 0x10203040), UINT32_MAX);
491244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
492244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00}));
493244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(8, 0x10203040), UINT32_MAX);
494244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
495244258e3SGreg Clayton             ArrayRef<uint8_t>({0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00}));
496244258e3SGreg Clayton }
497244258e3SGreg Clayton 
TEST(DataEncoderTest,PutAddressBig8)498244258e3SGreg Clayton TEST(DataEncoderTest, PutAddressBig8) {
499*220854a4SGreg Clayton   const std::vector<uint8_t> init = {1, 2, 3, 4, 5, 6, 7, 8};
500244258e3SGreg Clayton   const uint32_t addr_size = 8;
501244258e3SGreg Clayton   DataEncoder encoder(init.data(), init.size(), lldb::eByteOrderBig,
502244258e3SGreg Clayton                       addr_size);
503244258e3SGreg Clayton   uint32_t offset = 0;
504244258e3SGreg Clayton   offset = encoder.PutAddress(offset, 0x1122334455667788);
505244258e3SGreg Clayton   ASSERT_EQ(offset, addr_size);
506244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
507244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
508244258e3SGreg Clayton   // Make sure we can put an address when it won't fit in the existing buffer
509244258e3SGreg Clayton   // and that the buffer doesn't get modified.
510244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(1, 0x10203040), UINT32_MAX);
511244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
512244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
513244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(2, 0x10203040), UINT32_MAX);
514244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
515244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
516244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(3, 0x10203040), UINT32_MAX);
517244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
518244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
519244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(4, 0x10203040), UINT32_MAX);
520244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
521244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
522244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(5, 0x10203040), UINT32_MAX);
523244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
524244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
525244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(6, 0x10203040), UINT32_MAX);
526244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
527244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
528244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(7, 0x10203040), UINT32_MAX);
529244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
530244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
531244258e3SGreg Clayton   ASSERT_EQ(encoder.PutAddress(8, 0x10203040), UINT32_MAX);
532244258e3SGreg Clayton   ASSERT_EQ(encoder.GetData(),
533244258e3SGreg Clayton             ArrayRef<uint8_t>({0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}));
534244258e3SGreg Clayton }
535