blob: c740c27467a48fe7d53394afa66afb4d33b6ece0 [file] [log] [blame]
Raphael Isemannb1dfad02018-08-01 06:04:48 +00001//===-- StreamTest.cpp ------------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Raphael Isemannb1dfad02018-08-01 06:04:48 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Utility/StreamString.h"
10#include "gtest/gtest.h"
11
12using namespace lldb_private;
13
14namespace {
15struct StreamTest : ::testing::Test {
16 // Note: Stream is an abstract class, so we use StreamString to test it. To
17 // make it easier to change this later, only methods in this class explicitly
18 // refer to the StringStream class.
19 StreamString s;
20 // We return here a std::string because that way gtest can print better
21 // assertion messages.
22 std::string TakeValue() {
23 std::string result = s.GetString().str();
24 s.Clear();
25 return result;
26 }
27};
28}
29
30namespace {
31// A StreamTest where we expect the Stream output to be binary.
32struct BinaryStreamTest : StreamTest {
33 void SetUp() override {
34 s.GetFlags().Set(Stream::eBinary);
35 }
36};
37}
38
Raphael Isemann16d20132019-12-04 10:27:18 +010039TEST_F(StreamTest, AddressPrefix) {
Raphael Isemann1462f5a2019-12-05 14:41:09 +010040 DumpAddress(s.AsRawOstream(), 0x1, 1, "foo");
Raphael Isemann16d20132019-12-04 10:27:18 +010041 EXPECT_EQ("foo0x01", TakeValue());
42}
43
44TEST_F(StreamTest, AddressEmptyPrefix) {
Raphael Isemann1462f5a2019-12-05 14:41:09 +010045 DumpAddress(s.AsRawOstream(), 0x1, 1, nullptr);
Raphael Isemann16d20132019-12-04 10:27:18 +010046 EXPECT_EQ("0x01", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +010047 DumpAddress(s.AsRawOstream(), 0x1, 1, "");
Raphael Isemann16d20132019-12-04 10:27:18 +010048 EXPECT_EQ("0x01", TakeValue());
49}
50
51TEST_F(StreamTest, AddressSuffix) {
Raphael Isemann1462f5a2019-12-05 14:41:09 +010052 DumpAddress(s.AsRawOstream(), 0x1, 1, nullptr, "foo");
Raphael Isemann16d20132019-12-04 10:27:18 +010053 EXPECT_EQ("0x01foo", TakeValue());
54}
55
56TEST_F(StreamTest, AddressNoSuffix) {
Raphael Isemann1462f5a2019-12-05 14:41:09 +010057 DumpAddress(s.AsRawOstream(), 0x1, 1, nullptr, nullptr);
Raphael Isemann16d20132019-12-04 10:27:18 +010058 EXPECT_EQ("0x01", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +010059 DumpAddress(s.AsRawOstream(), 0x1, 1, nullptr, "");
Raphael Isemann16d20132019-12-04 10:27:18 +010060 EXPECT_EQ("0x01", TakeValue());
61}
62
63TEST_F(StreamTest, AddressPrefixAndSuffix) {
Raphael Isemann1462f5a2019-12-05 14:41:09 +010064 DumpAddress(s.AsRawOstream(), 0x1, 1, "foo", "bar");
Raphael Isemann16d20132019-12-04 10:27:18 +010065 EXPECT_EQ("foo0x01bar", TakeValue());
66}
67
68TEST_F(StreamTest, AddressSize) {
Raphael Isemann1462f5a2019-12-05 14:41:09 +010069 DumpAddress(s.AsRawOstream(), 0x0, 0);
Raphael Isemann16d20132019-12-04 10:27:18 +010070 EXPECT_EQ("0x0", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +010071 DumpAddress(s.AsRawOstream(), 0x1, 0);
Raphael Isemann16d20132019-12-04 10:27:18 +010072 EXPECT_EQ("0x1", TakeValue());
73
Raphael Isemann1462f5a2019-12-05 14:41:09 +010074 DumpAddress(s.AsRawOstream(), 0x1, 1);
Raphael Isemann16d20132019-12-04 10:27:18 +010075 EXPECT_EQ("0x01", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +010076 DumpAddress(s.AsRawOstream(), 0xf1, 1);
Raphael Isemann16d20132019-12-04 10:27:18 +010077 EXPECT_EQ("0xf1", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +010078 DumpAddress(s.AsRawOstream(), 0xff, 1);
Raphael Isemann16d20132019-12-04 10:27:18 +010079 EXPECT_EQ("0xff", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +010080 DumpAddress(s.AsRawOstream(), 0x100, 1);
Raphael Isemann16d20132019-12-04 10:27:18 +010081 EXPECT_EQ("0x100", TakeValue());
82
Raphael Isemann1462f5a2019-12-05 14:41:09 +010083 DumpAddress(s.AsRawOstream(), 0xf00, 4);
Raphael Isemann16d20132019-12-04 10:27:18 +010084 EXPECT_EQ("0x00000f00", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +010085 DumpAddress(s.AsRawOstream(), 0x100, 8);
Raphael Isemann16d20132019-12-04 10:27:18 +010086 EXPECT_EQ("0x0000000000000100", TakeValue());
Raphael Isemann16d20132019-12-04 10:27:18 +010087}
88
89TEST_F(StreamTest, AddressRange) {
Raphael Isemann1462f5a2019-12-05 14:41:09 +010090 DumpAddressRange(s.AsRawOstream(), 0x100, 0x101, 2);
Raphael Isemann16d20132019-12-04 10:27:18 +010091 EXPECT_EQ("[0x0100-0x0101)", TakeValue());
92}
93
94TEST_F(StreamTest, AddressRangeEmptyRange) {
Raphael Isemann1462f5a2019-12-05 14:41:09 +010095 DumpAddressRange(s.AsRawOstream(), 0x100, 0x100, 2);
Raphael Isemann16d20132019-12-04 10:27:18 +010096 EXPECT_EQ("[0x0100-0x0100)", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +010097 DumpAddressRange(s.AsRawOstream(), 0x0, 0x0, 2);
Raphael Isemann16d20132019-12-04 10:27:18 +010098 EXPECT_EQ("[0x0000-0x0000)", TakeValue());
99}
100
101TEST_F(StreamTest, AddressRangeInvalidRange) {
Raphael Isemann1462f5a2019-12-05 14:41:09 +0100102 DumpAddressRange(s.AsRawOstream(), 0x100, 0x0FF, 2);
Raphael Isemann16d20132019-12-04 10:27:18 +0100103 EXPECT_EQ("[0x0100-0x00ff)", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +0100104 DumpAddressRange(s.AsRawOstream(), 0x100, 0x0, 2);
Raphael Isemann16d20132019-12-04 10:27:18 +0100105 EXPECT_EQ("[0x0100-0x0000)", TakeValue());
106}
107
108TEST_F(StreamTest, AddressRangeSize) {
Raphael Isemann1462f5a2019-12-05 14:41:09 +0100109 DumpAddressRange(s.AsRawOstream(), 0x100, 0x101, 0);
Raphael Isemann16d20132019-12-04 10:27:18 +0100110 EXPECT_EQ("[0x100-0x101)", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +0100111 DumpAddressRange(s.AsRawOstream(), 0x100, 0x101, 2);
Raphael Isemann16d20132019-12-04 10:27:18 +0100112 EXPECT_EQ("[0x0100-0x0101)", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +0100113 DumpAddressRange(s.AsRawOstream(), 0x100, 0x101, 4);
Raphael Isemann16d20132019-12-04 10:27:18 +0100114 EXPECT_EQ("[0x00000100-0x00000101)", TakeValue());
115
Raphael Isemann1462f5a2019-12-05 14:41:09 +0100116 DumpAddressRange(s.AsRawOstream(), 0x100, 0x101, 4);
Raphael Isemann16d20132019-12-04 10:27:18 +0100117 EXPECT_EQ("[0x00000100-0x00000101)", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +0100118 DumpAddressRange(s.AsRawOstream(), 0x1, 0x101, 4);
Raphael Isemann16d20132019-12-04 10:27:18 +0100119 EXPECT_EQ("[0x00000001-0x00000101)", TakeValue());
Raphael Isemann1462f5a2019-12-05 14:41:09 +0100120 DumpAddressRange(s.AsRawOstream(), 0x101, 0x1, 4);
Raphael Isemann16d20132019-12-04 10:27:18 +0100121 EXPECT_EQ("[0x00000101-0x00000001)", TakeValue());
122
Raphael Isemann1462f5a2019-12-05 14:41:09 +0100123 DumpAddressRange(s.AsRawOstream(), 0x1, 0x101, 1);
Raphael Isemann16d20132019-12-04 10:27:18 +0100124 EXPECT_EQ("[0x01-0x101)", TakeValue());
125}
126
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000127TEST_F(StreamTest, ChangingByteOrder) {
128 s.SetByteOrder(lldb::eByteOrderPDP);
129 EXPECT_EQ(lldb::eByteOrderPDP, s.GetByteOrder());
130}
131
132TEST_F(StreamTest, PutChar) {
133 s.PutChar('a');
Raphael Isemann92b16732018-08-02 16:38:34 +0000134 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000135 EXPECT_EQ("a", TakeValue());
136
137 s.PutChar('1');
Raphael Isemann92b16732018-08-02 16:38:34 +0000138 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000139 EXPECT_EQ("1", TakeValue());
140}
141
142TEST_F(StreamTest, PutCharWhitespace) {
143 s.PutChar(' ');
Raphael Isemann92b16732018-08-02 16:38:34 +0000144 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000145 EXPECT_EQ(" ", TakeValue());
146
147 s.PutChar('\n');
Raphael Isemann92b16732018-08-02 16:38:34 +0000148 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000149 EXPECT_EQ("\n", TakeValue());
150
151 s.PutChar('\r');
Raphael Isemann92b16732018-08-02 16:38:34 +0000152 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000153 EXPECT_EQ("\r", TakeValue());
154
155 s.PutChar('\t');
Raphael Isemann92b16732018-08-02 16:38:34 +0000156 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000157 EXPECT_EQ("\t", TakeValue());
158}
159
160TEST_F(StreamTest, PutCString) {
161 s.PutCString("");
Raphael Isemann92b16732018-08-02 16:38:34 +0000162 EXPECT_EQ(0U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000163 EXPECT_EQ("", TakeValue());
164
165 s.PutCString("foobar");
Raphael Isemann92b16732018-08-02 16:38:34 +0000166 EXPECT_EQ(6U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000167 EXPECT_EQ("foobar", TakeValue());
168
169 s.PutCString(" ");
Raphael Isemann92b16732018-08-02 16:38:34 +0000170 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000171 EXPECT_EQ(" ", TakeValue());
172}
173
174TEST_F(StreamTest, PutCStringWithStringRef) {
175 s.PutCString(llvm::StringRef(""));
Raphael Isemann92b16732018-08-02 16:38:34 +0000176 EXPECT_EQ(0U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000177 EXPECT_EQ("", TakeValue());
178
179 s.PutCString(llvm::StringRef("foobar"));
Raphael Isemann92b16732018-08-02 16:38:34 +0000180 EXPECT_EQ(6U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000181 EXPECT_EQ("foobar", TakeValue());
182
183 s.PutCString(llvm::StringRef(" "));
Raphael Isemann92b16732018-08-02 16:38:34 +0000184 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000185 EXPECT_EQ(" ", TakeValue());
186}
187
188TEST_F(StreamTest, QuotedCString) {
189 s.QuotedCString("foo");
Raphael Isemann92b16732018-08-02 16:38:34 +0000190 EXPECT_EQ(5U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000191 EXPECT_EQ(R"("foo")", TakeValue());
192
193 s.QuotedCString("ba r");
Raphael Isemann92b16732018-08-02 16:38:34 +0000194 EXPECT_EQ(6U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000195 EXPECT_EQ(R"("ba r")", TakeValue());
196
197 s.QuotedCString(" ");
Raphael Isemann92b16732018-08-02 16:38:34 +0000198 EXPECT_EQ(3U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000199 EXPECT_EQ(R"(" ")", TakeValue());
200}
201
202TEST_F(StreamTest, PutCharNull) {
203 s.PutChar('\0');
Raphael Isemann92b16732018-08-02 16:38:34 +0000204 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000205 EXPECT_EQ(std::string("\0", 1), TakeValue());
206
207 s.PutChar('a');
Raphael Isemann92b16732018-08-02 16:38:34 +0000208 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000209 EXPECT_EQ(std::string("a", 1), TakeValue());
210}
211
Pavel Labath7f815a92019-02-12 14:28:55 +0000212TEST_F(StreamTest, PutStringAsRawHex8) {
213 s.PutStringAsRawHex8("");
Raphael Isemann92b16732018-08-02 16:38:34 +0000214 EXPECT_EQ(0U, s.GetWrittenBytes());
Raphael Isemannf4590de2018-08-01 21:07:18 +0000215 EXPECT_EQ("", TakeValue());
216
Pavel Labath7f815a92019-02-12 14:28:55 +0000217 s.PutStringAsRawHex8("foobar");
Raphael Isemann92b16732018-08-02 16:38:34 +0000218 EXPECT_EQ(12U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000219 EXPECT_EQ("666f6f626172", TakeValue());
220
Pavel Labath7f815a92019-02-12 14:28:55 +0000221 s.PutStringAsRawHex8(" ");
Raphael Isemann92b16732018-08-02 16:38:34 +0000222 EXPECT_EQ(2U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000223 EXPECT_EQ("20", TakeValue());
224}
225
226TEST_F(StreamTest, PutHex8) {
227 s.PutHex8((uint8_t)55);
Raphael Isemann92b16732018-08-02 16:38:34 +0000228 EXPECT_EQ(2U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000229 EXPECT_EQ("37", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000230
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000231 s.PutHex8(std::numeric_limits<uint8_t>::max());
Raphael Isemann92b16732018-08-02 16:38:34 +0000232 EXPECT_EQ(2U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000233 EXPECT_EQ("ff", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000234
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000235 s.PutHex8((uint8_t)0);
Raphael Isemann92b16732018-08-02 16:38:34 +0000236 EXPECT_EQ(2U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000237 EXPECT_EQ("00", TakeValue());
238}
239
240TEST_F(StreamTest, PutNHex8) {
241 s.PutNHex8(0, (uint8_t)55);
Raphael Isemann92b16732018-08-02 16:38:34 +0000242 EXPECT_EQ(0U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000243 EXPECT_EQ("", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000244
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000245 s.PutNHex8(1, (uint8_t)55);
Raphael Isemann92b16732018-08-02 16:38:34 +0000246 EXPECT_EQ(2U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000247 EXPECT_EQ("37", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000248
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000249 s.PutNHex8(2, (uint8_t)55);
Raphael Isemann92b16732018-08-02 16:38:34 +0000250 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000251 EXPECT_EQ("3737", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000252
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000253 s.PutNHex8(1, (uint8_t)56);
Raphael Isemann92b16732018-08-02 16:38:34 +0000254 EXPECT_EQ(2U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000255 EXPECT_EQ("38", TakeValue());
256}
257
258TEST_F(StreamTest, PutHex16ByteOrderLittle) {
259 s.PutHex16(0x1234U, lldb::eByteOrderLittle);
Raphael Isemann92b16732018-08-02 16:38:34 +0000260 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000261 EXPECT_EQ("3412", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000262
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000263 s.PutHex16(std::numeric_limits<uint16_t>::max(), lldb::eByteOrderLittle);
Raphael Isemann92b16732018-08-02 16:38:34 +0000264 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000265 EXPECT_EQ("ffff", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000266
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000267 s.PutHex16(0U, lldb::eByteOrderLittle);
Raphael Isemann92b16732018-08-02 16:38:34 +0000268 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000269 EXPECT_EQ("0000", TakeValue());
270}
271
272TEST_F(StreamTest, PutHex16ByteOrderBig) {
273 s.PutHex16(0x1234U, lldb::eByteOrderBig);
Raphael Isemann92b16732018-08-02 16:38:34 +0000274 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000275 EXPECT_EQ("1234", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000276
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000277 s.PutHex16(std::numeric_limits<uint16_t>::max(), lldb::eByteOrderBig);
Raphael Isemann92b16732018-08-02 16:38:34 +0000278 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000279 EXPECT_EQ("ffff", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000280
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000281 s.PutHex16(0U, lldb::eByteOrderBig);
Raphael Isemann92b16732018-08-02 16:38:34 +0000282 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000283 EXPECT_EQ("0000", TakeValue());
284}
285
286TEST_F(StreamTest, PutHex32ByteOrderLittle) {
287 s.PutHex32(0x12345678U, lldb::eByteOrderLittle);
Raphael Isemann92b16732018-08-02 16:38:34 +0000288 EXPECT_EQ(8U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000289 EXPECT_EQ("78563412", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000290
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000291 s.PutHex32(std::numeric_limits<uint32_t>::max(), lldb::eByteOrderLittle);
Raphael Isemann92b16732018-08-02 16:38:34 +0000292 EXPECT_EQ(8U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000293 EXPECT_EQ("ffffffff", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000294
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000295 s.PutHex32(0U, lldb::eByteOrderLittle);
Raphael Isemann92b16732018-08-02 16:38:34 +0000296 EXPECT_EQ(8U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000297 EXPECT_EQ("00000000", TakeValue());
298}
299
300TEST_F(StreamTest, PutHex32ByteOrderBig) {
301 s.PutHex32(0x12345678U, lldb::eByteOrderBig);
Raphael Isemann92b16732018-08-02 16:38:34 +0000302 EXPECT_EQ(8U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000303 EXPECT_EQ("12345678", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000304
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000305 s.PutHex32(std::numeric_limits<uint32_t>::max(), lldb::eByteOrderBig);
Raphael Isemann92b16732018-08-02 16:38:34 +0000306 EXPECT_EQ(8U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000307 EXPECT_EQ("ffffffff", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000308
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000309 s.PutHex32(0U, lldb::eByteOrderBig);
Raphael Isemann92b16732018-08-02 16:38:34 +0000310 EXPECT_EQ(8U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000311 EXPECT_EQ("00000000", TakeValue());
312}
313
314TEST_F(StreamTest, PutHex64ByteOrderLittle) {
315 s.PutHex64(0x1234567890ABCDEFU, lldb::eByteOrderLittle);
Raphael Isemann92b16732018-08-02 16:38:34 +0000316 EXPECT_EQ(16U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000317 EXPECT_EQ("efcdab9078563412", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000318
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000319 s.PutHex64(std::numeric_limits<uint64_t>::max(), lldb::eByteOrderLittle);
Raphael Isemann92b16732018-08-02 16:38:34 +0000320 EXPECT_EQ(16U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000321 EXPECT_EQ("ffffffffffffffff", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000322
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000323 s.PutHex64(0U, lldb::eByteOrderLittle);
Raphael Isemann92b16732018-08-02 16:38:34 +0000324 EXPECT_EQ(16U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000325 EXPECT_EQ("0000000000000000", TakeValue());
326}
327
328TEST_F(StreamTest, PutHex64ByteOrderBig) {
329 s.PutHex64(0x1234567890ABCDEFU, lldb::eByteOrderBig);
Raphael Isemann92b16732018-08-02 16:38:34 +0000330 EXPECT_EQ(16U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000331 EXPECT_EQ("1234567890abcdef", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000332
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000333 s.PutHex64(std::numeric_limits<uint64_t>::max(), lldb::eByteOrderBig);
Raphael Isemann92b16732018-08-02 16:38:34 +0000334 EXPECT_EQ(16U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000335 EXPECT_EQ("ffffffffffffffff", TakeValue());
Raphael Isemann92b16732018-08-02 16:38:34 +0000336
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000337 s.PutHex64(0U, lldb::eByteOrderBig);
Raphael Isemann92b16732018-08-02 16:38:34 +0000338 EXPECT_EQ(16U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000339 EXPECT_EQ("0000000000000000", TakeValue());
340}
341
Raphael Isemann0bb8d832018-08-01 17:12:58 +0000342TEST_F(StreamTest, PutMaxHex64ByteOrderBig) {
343 std::size_t bytes;
344 bytes = s.PutMaxHex64(0x12U, 1, lldb::eByteOrderBig);
345 EXPECT_EQ(2U, bytes);
346 bytes = s.PutMaxHex64(0x1234U, 2, lldb::eByteOrderBig);
347 EXPECT_EQ(4U, bytes);
348 bytes = s.PutMaxHex64(0x12345678U, 4, lldb::eByteOrderBig);
349 EXPECT_EQ(8U, bytes);
350 bytes = s.PutMaxHex64(0x1234567890ABCDEFU, 8, lldb::eByteOrderBig);
351 EXPECT_EQ(16U, bytes);
Raphael Isemann92b16732018-08-02 16:38:34 +0000352 EXPECT_EQ(30U, s.GetWrittenBytes());
Raphael Isemann0bb8d832018-08-01 17:12:58 +0000353 EXPECT_EQ("121234123456781234567890abcdef", TakeValue());
354}
355
356TEST_F(StreamTest, PutMaxHex64ByteOrderLittle) {
357 std::size_t bytes;
358 bytes = s.PutMaxHex64(0x12U, 1, lldb::eByteOrderLittle);
359 EXPECT_EQ(2U, bytes);
360 bytes = s.PutMaxHex64(0x1234U, 2, lldb::eByteOrderLittle);
361 EXPECT_EQ(4U, bytes);
362 bytes = s.PutMaxHex64(0x12345678U, 4, lldb::eByteOrderLittle);
363 EXPECT_EQ(8U, bytes);
364 bytes = s.PutMaxHex64(0x1234567890ABCDEFU, 8, lldb::eByteOrderLittle);
365 EXPECT_EQ(16U, bytes);
Raphael Isemann92b16732018-08-02 16:38:34 +0000366 EXPECT_EQ(30U, s.GetWrittenBytes());
Raphael Isemann0bb8d832018-08-01 17:12:58 +0000367 EXPECT_EQ("12341278563412efcdab9078563412", TakeValue());
368}
369
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000370// Shift operator tests.
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000371
372TEST_F(StreamTest, ShiftOperatorChars) {
373 s << 'a' << 'b';
Raphael Isemann92b16732018-08-02 16:38:34 +0000374 EXPECT_EQ(2U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000375 EXPECT_EQ("ab", TakeValue());
376}
377
378TEST_F(StreamTest, ShiftOperatorStrings) {
379 s << "cstring\n";
Raphael Isemann92b16732018-08-02 16:38:34 +0000380 EXPECT_EQ(8U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000381 s << llvm::StringRef("llvm::StringRef\n");
Raphael Isemann92b16732018-08-02 16:38:34 +0000382 EXPECT_EQ(24U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000383 EXPECT_EQ("cstring\nllvm::StringRef\n", TakeValue());
384}
385
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000386TEST_F(StreamTest, ShiftOperatorPtr) {
387 // This test is a bit tricky because pretty much everything related to
388 // pointer printing seems to lead to UB or IB. So let's make the most basic
389 // test that just checks that we print *something*. This way we at least know
390 // that pointer printing doesn't do really bad things (e.g. crashing, reading
391 // OOB/uninitialized memory which the sanitizers would spot).
392
393 // Shift our own pointer to the output.
394 int i = 3;
395 int *ptr = &i;
396 s << ptr;
397
Raphael Isemann92b16732018-08-02 16:38:34 +0000398 EXPECT_NE(0U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000399 EXPECT_TRUE(!TakeValue().empty());
400}
401
402TEST_F(StreamTest, PutPtr) {
403 // See the ShiftOperatorPtr test for the rationale.
404 int i = 3;
405 int *ptr = &i;
406 s.PutPointer(ptr);
407
Raphael Isemann92b16732018-08-02 16:38:34 +0000408 EXPECT_NE(0U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000409 EXPECT_TRUE(!TakeValue().empty());
410}
411
412// Alias to make it more clear that 'invalid' means for the Stream interface
413// that it should use the host byte order.
414const static auto hostByteOrder = lldb::eByteOrderInvalid;
415
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000416// PutRawBytes/PutBytesAsRawHex tests.
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000417
418TEST_F(StreamTest, PutBytesAsRawHex8ToBigEndian) {
419 uint32_t value = 0x12345678;
420 s.PutBytesAsRawHex8(static_cast<void*>(&value), sizeof(value),
421 hostByteOrder, lldb::eByteOrderBig);
Raphael Isemann92b16732018-08-02 16:38:34 +0000422 EXPECT_EQ(8U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000423 EXPECT_EQ("78563412", TakeValue());
424}
425
426TEST_F(StreamTest, PutRawBytesToBigEndian) {
427 uint32_t value = 0x12345678;
428 s.PutRawBytes(static_cast<void*>(&value), sizeof(value),
429 hostByteOrder, lldb::eByteOrderBig);
Raphael Isemann92b16732018-08-02 16:38:34 +0000430 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000431 EXPECT_EQ("\x78\x56\x34\x12", TakeValue());
432}
433
434TEST_F(StreamTest, PutBytesAsRawHex8ToLittleEndian) {
435 uint32_t value = 0x12345678;
436 s.PutBytesAsRawHex8(static_cast<void*>(&value), sizeof(value),
437 hostByteOrder, lldb::eByteOrderLittle);
Raphael Isemann92b16732018-08-02 16:38:34 +0000438 EXPECT_EQ(8U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000439 EXPECT_EQ("12345678", TakeValue());
440}
441
442TEST_F(StreamTest, PutRawBytesToLittleEndian) {
443 uint32_t value = 0x12345678;
444 s.PutRawBytes(static_cast<void*>(&value), sizeof(value),
445 hostByteOrder, lldb::eByteOrderLittle);
Raphael Isemann92b16732018-08-02 16:38:34 +0000446 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000447 EXPECT_EQ("\x12\x34\x56\x78", TakeValue());
448}
449
450TEST_F(StreamTest, PutBytesAsRawHex8ToMixedEndian) {
451 uint32_t value = 0x12345678;
452 s.PutBytesAsRawHex8(static_cast<void*>(&value), sizeof(value),
453 hostByteOrder, lldb::eByteOrderPDP);
454
455 // FIXME: PDP byte order is not actually implemented but Stream just silently
456 // prints the value in some random byte order...
457#if 0
458 EXPECT_EQ("34127856", TakeValue());
459#endif
460}
461
462TEST_F(StreamTest, PutRawBytesToMixedEndian) {
463 uint32_t value = 0x12345678;
464 s.PutRawBytes(static_cast<void*>(&value), sizeof(value),
465 lldb::eByteOrderInvalid, lldb::eByteOrderPDP);
466
467 // FIXME: PDP byte order is not actually implemented but Stream just silently
468 // prints the value in some random byte order...
469#if 0
470 EXPECT_EQ("\x34\x12\x78\x56", TakeValue());
471#endif
472}
473
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000474// ULEB128 support for binary streams.
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000475
476TEST_F(BinaryStreamTest, PutULEB128OneByte) {
477 auto bytes = s.PutULEB128(0x74ULL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000478 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000479 EXPECT_EQ("\x74", TakeValue());
480 EXPECT_EQ(1U, bytes);
481}
482
483TEST_F(BinaryStreamTest, PutULEB128TwoBytes) {
484 auto bytes = s.PutULEB128(0x1985ULL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000485 EXPECT_EQ(2U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000486 EXPECT_EQ("\x85\x33", TakeValue());
487 EXPECT_EQ(2U, bytes);
488}
489
490TEST_F(BinaryStreamTest, PutULEB128ThreeBytes) {
491 auto bytes = s.PutULEB128(0x5023ULL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000492 EXPECT_EQ(3U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000493 EXPECT_EQ("\xA3\xA0\x1", TakeValue());
494 EXPECT_EQ(3U, bytes);
495}
496
497TEST_F(BinaryStreamTest, PutULEB128FourBytes) {
498 auto bytes = s.PutULEB128(0xA48032ULL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000499 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000500 EXPECT_EQ("\xB2\x80\x92\x5", TakeValue());
501 EXPECT_EQ(4U, bytes);
502}
503
504TEST_F(BinaryStreamTest, PutULEB128FiveBytes) {
505 auto bytes = s.PutULEB128(0x12345678ULL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000506 EXPECT_EQ(5U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000507 EXPECT_EQ("\xF8\xAC\xD1\x91\x1", TakeValue());
508 EXPECT_EQ(5U, bytes);
509}
510
511TEST_F(BinaryStreamTest, PutULEB128SixBytes) {
512 auto bytes = s.PutULEB128(0xABFE3FAFDFULL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000513 EXPECT_EQ(6U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000514 EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\x15", TakeValue());
515 EXPECT_EQ(6U, bytes);
516}
517
518TEST_F(BinaryStreamTest, PutULEB128SevenBytes) {
519 auto bytes = s.PutULEB128(0xDABFE3FAFDFULL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000520 EXPECT_EQ(7U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000521 EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\x3", TakeValue());
522 EXPECT_EQ(7U, bytes);
523}
524
525TEST_F(BinaryStreamTest, PutULEB128EightBytes) {
526 auto bytes = s.PutULEB128(0x7CDABFE3FAFDFULL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000527 EXPECT_EQ(8U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000528 EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x3", TakeValue());
529 EXPECT_EQ(8U, bytes);
530}
531
532TEST_F(BinaryStreamTest, PutULEB128NineBytes) {
533 auto bytes = s.PutULEB128(0x327CDABFE3FAFDFULL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000534 EXPECT_EQ(9U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000535 EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x93\x3", TakeValue());
536 EXPECT_EQ(9U, bytes);
537}
538
539TEST_F(BinaryStreamTest, PutULEB128MaxValue) {
540 auto bytes = s.PutULEB128(std::numeric_limits<uint64_t>::max());
Raphael Isemann92b16732018-08-02 16:38:34 +0000541 EXPECT_EQ(10U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000542 EXPECT_EQ("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x1", TakeValue());
543 EXPECT_EQ(10U, bytes);
544}
545
546TEST_F(BinaryStreamTest, PutULEB128Zero) {
547 auto bytes = s.PutULEB128(0x0U);
Raphael Isemann92b16732018-08-02 16:38:34 +0000548 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000549 EXPECT_EQ(std::string("\0", 1), TakeValue());
550 EXPECT_EQ(1U, bytes);
551}
552
553TEST_F(BinaryStreamTest, PutULEB128One) {
554 auto bytes = s.PutULEB128(0x1U);
Raphael Isemann92b16732018-08-02 16:38:34 +0000555 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000556 EXPECT_EQ("\x1", TakeValue());
557 EXPECT_EQ(1U, bytes);
558}
559
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000560// SLEB128 support for binary streams.
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000561
562TEST_F(BinaryStreamTest, PutSLEB128OneByte) {
563 auto bytes = s.PutSLEB128(0x74LL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000564 EXPECT_EQ(2U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000565 EXPECT_EQ(std::string("\xF4\0", 2), TakeValue());
566 EXPECT_EQ(2U, bytes);
567}
568
569TEST_F(BinaryStreamTest, PutSLEB128TwoBytes) {
570 auto bytes = s.PutSLEB128(0x1985LL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000571 EXPECT_EQ(2U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000572 EXPECT_EQ("\x85\x33", TakeValue());
573 EXPECT_EQ(2U, bytes);
574}
575
576TEST_F(BinaryStreamTest, PutSLEB128ThreeBytes) {
577 auto bytes = s.PutSLEB128(0x5023LL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000578 EXPECT_EQ(3U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000579 EXPECT_EQ("\xA3\xA0\x1", TakeValue());
580 EXPECT_EQ(3U, bytes);
581}
582
583TEST_F(BinaryStreamTest, PutSLEB128FourBytes) {
584 auto bytes = s.PutSLEB128(0xA48032LL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000585 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000586 EXPECT_EQ("\xB2\x80\x92\x5", TakeValue());
587 EXPECT_EQ(4U, bytes);
588}
589
590TEST_F(BinaryStreamTest, PutSLEB128FiveBytes) {
591 auto bytes = s.PutSLEB128(0x12345678LL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000592 EXPECT_EQ(5U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000593 EXPECT_EQ("\xF8\xAC\xD1\x91\x1", TakeValue());
594 EXPECT_EQ(5U, bytes);
595}
596
597TEST_F(BinaryStreamTest, PutSLEB128SixBytes) {
598 auto bytes = s.PutSLEB128(0xABFE3FAFDFLL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000599 EXPECT_EQ(6U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000600 EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\x15", TakeValue());
601 EXPECT_EQ(6U, bytes);
602}
603
604TEST_F(BinaryStreamTest, PutSLEB128SevenBytes) {
605 auto bytes = s.PutSLEB128(0xDABFE3FAFDFLL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000606 EXPECT_EQ(7U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000607 EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\x3", TakeValue());
608 EXPECT_EQ(7U, bytes);
609}
610
611TEST_F(BinaryStreamTest, PutSLEB128EightBytes) {
612 auto bytes = s.PutSLEB128(0x7CDABFE3FAFDFLL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000613 EXPECT_EQ(8U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000614 EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x3", TakeValue());
615 EXPECT_EQ(8U, bytes);
616}
617
618TEST_F(BinaryStreamTest, PutSLEB128NineBytes) {
619 auto bytes = s.PutSLEB128(0x327CDABFE3FAFDFLL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000620 EXPECT_EQ(9U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000621 EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x93\x3", TakeValue());
622 EXPECT_EQ(9U, bytes);
623}
624
625TEST_F(BinaryStreamTest, PutSLEB128MaxValue) {
626 auto bytes = s.PutSLEB128(std::numeric_limits<int64_t>::max());
Raphael Isemann92b16732018-08-02 16:38:34 +0000627 EXPECT_EQ(10U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000628 EXPECT_EQ(std::string("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\0", 10), TakeValue());
629 EXPECT_EQ(10U, bytes);
630}
631
632TEST_F(BinaryStreamTest, PutSLEB128Zero) {
633 auto bytes = s.PutSLEB128(0x0);
Raphael Isemann92b16732018-08-02 16:38:34 +0000634 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000635 EXPECT_EQ(std::string("\0", 1), TakeValue());
636 EXPECT_EQ(1U, bytes);
637}
638
639TEST_F(BinaryStreamTest, PutSLEB128One) {
640 auto bytes = s.PutSLEB128(0x1);
Raphael Isemann92b16732018-08-02 16:38:34 +0000641 EXPECT_EQ(1U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000642 EXPECT_EQ(std::string("\x1", 1), TakeValue());
643 EXPECT_EQ(1U, bytes);
644}
645
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000646// SLEB128/ULEB128 support for non-binary streams.
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000647
648// The logic for this is very simple, so it should be enough to test some basic
649// use cases.
650
651TEST_F(StreamTest, PutULEB128) {
652 auto bytes = s.PutULEB128(0x74ULL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000653 EXPECT_EQ(4U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000654 EXPECT_EQ("0x74", TakeValue());
655 EXPECT_EQ(4U, bytes);
656}
657
658TEST_F(StreamTest, PutSLEB128) {
659 auto bytes = s.PutSLEB128(0x1985LL);
Raphael Isemann92b16732018-08-02 16:38:34 +0000660 EXPECT_EQ(6U, s.GetWrittenBytes());
Raphael Isemannb1dfad02018-08-01 06:04:48 +0000661 EXPECT_EQ("0x6533", TakeValue());
662 EXPECT_EQ(6U, bytes);
663}