[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / lldb / unittests / Utility / StringExtractorTest.cpp
blob1908cf37b07abab9dd931c639e8f324625d58b0c
1 #include "gtest/gtest.h"
2 #include <limits.h>
4 #include "lldb/Utility/StringExtractor.h"
6 namespace {
7 class StringExtractorTest : public ::testing::Test {};
8 } // namespace
10 TEST_F(StringExtractorTest, InitEmpty) {
11 llvm::StringRef kEmptyString = "";
12 StringExtractor ex(kEmptyString);
14 ASSERT_EQ(true, ex.IsGood());
15 ASSERT_EQ(0u, ex.GetFilePos());
16 ASSERT_EQ(kEmptyString, ex.GetStringRef());
17 ASSERT_EQ(true, ex.Empty());
18 ASSERT_EQ(0u, ex.GetBytesLeft());
19 ASSERT_EQ(nullptr, ex.Peek());
22 TEST_F(StringExtractorTest, InitMisc) {
23 llvm::StringRef kInitMiscString = "Hello, StringExtractor!";
24 StringExtractor ex(kInitMiscString);
26 ASSERT_EQ(true, ex.IsGood());
27 ASSERT_EQ(0u, ex.GetFilePos());
28 ASSERT_EQ(kInitMiscString, ex.GetStringRef());
29 ASSERT_EQ(false, ex.Empty());
30 ASSERT_EQ(kInitMiscString.size(), ex.GetBytesLeft());
31 ASSERT_EQ(kInitMiscString[0], *ex.Peek());
34 TEST_F(StringExtractorTest, DecodeHexU8_Underflow) {
35 llvm::StringRef kEmptyString = "";
36 StringExtractor ex(kEmptyString);
38 ASSERT_EQ(-1, ex.DecodeHexU8());
39 ASSERT_EQ(true, ex.IsGood());
40 ASSERT_EQ(0u, ex.GetFilePos());
41 ASSERT_EQ(true, ex.Empty());
42 ASSERT_EQ(0u, ex.GetBytesLeft());
43 ASSERT_EQ(nullptr, ex.Peek());
46 TEST_F(StringExtractorTest, DecodeHexU8_Underflow2) {
47 StringExtractor ex("1");
49 ASSERT_EQ(-1, ex.DecodeHexU8());
50 ASSERT_EQ(true, ex.IsGood());
51 ASSERT_EQ(0u, ex.GetFilePos());
52 ASSERT_EQ(1u, ex.GetBytesLeft());
53 ASSERT_EQ('1', *ex.Peek());
56 TEST_F(StringExtractorTest, DecodeHexU8_InvalidHex) {
57 llvm::StringRef kInvalidHex = "xa";
58 StringExtractor ex(kInvalidHex);
60 ASSERT_EQ(-1, ex.DecodeHexU8());
61 ASSERT_EQ(true, ex.IsGood());
62 ASSERT_EQ(0u, ex.GetFilePos());
63 ASSERT_EQ(2u, ex.GetBytesLeft());
64 ASSERT_EQ('x', *ex.Peek());
67 TEST_F(StringExtractorTest, DecodeHexU8_InvalidHex2) {
68 llvm::StringRef kInvalidHex = "ax";
69 StringExtractor ex(kInvalidHex);
71 ASSERT_EQ(-1, ex.DecodeHexU8());
72 ASSERT_EQ(true, ex.IsGood());
73 ASSERT_EQ(0u, ex.GetFilePos());
74 ASSERT_EQ(2u, ex.GetBytesLeft());
75 ASSERT_EQ('a', *ex.Peek());
78 TEST_F(StringExtractorTest, DecodeHexU8_Exact) {
79 llvm::StringRef kValidHexPair = "12";
80 StringExtractor ex(kValidHexPair);
82 ASSERT_EQ(0x12, ex.DecodeHexU8());
83 ASSERT_EQ(true, ex.IsGood());
84 ASSERT_EQ(2u, ex.GetFilePos());
85 ASSERT_EQ(0u, ex.GetBytesLeft());
86 ASSERT_EQ(nullptr, ex.Peek());
89 TEST_F(StringExtractorTest, DecodeHexU8_Extra) {
90 llvm::StringRef kValidHexPair = "1234";
91 StringExtractor ex(kValidHexPair);
93 ASSERT_EQ(0x12, ex.DecodeHexU8());
94 ASSERT_EQ(true, ex.IsGood());
95 ASSERT_EQ(2u, ex.GetFilePos());
96 ASSERT_EQ(2u, ex.GetBytesLeft());
97 ASSERT_EQ('3', *ex.Peek());
100 TEST_F(StringExtractorTest, GetHexU8_Underflow) {
101 llvm::StringRef kEmptyString = "";
102 StringExtractor ex(kEmptyString);
104 ASSERT_EQ(0xab, ex.GetHexU8(0xab));
105 ASSERT_EQ(false, ex.IsGood());
106 ASSERT_EQ(UINT64_MAX, ex.GetFilePos());
107 ASSERT_EQ(true, ex.Empty());
108 ASSERT_EQ(0u, ex.GetBytesLeft());
109 ASSERT_EQ(nullptr, ex.Peek());
112 TEST_F(StringExtractorTest, GetHexU8_Underflow2) {
113 llvm::StringRef kOneNibble = "1";
114 StringExtractor ex(kOneNibble);
116 ASSERT_EQ(0xbc, ex.GetHexU8(0xbc));
117 ASSERT_EQ(false, ex.IsGood());
118 ASSERT_EQ(UINT64_MAX, ex.GetFilePos());
119 ASSERT_EQ(0u, ex.GetBytesLeft());
120 ASSERT_EQ(nullptr, ex.Peek());
123 TEST_F(StringExtractorTest, GetHexU8_InvalidHex) {
124 llvm::StringRef kInvalidHex = "xx";
125 StringExtractor ex(kInvalidHex);
127 ASSERT_EQ(0xcd, ex.GetHexU8(0xcd));
128 ASSERT_EQ(false, ex.IsGood());
129 ASSERT_EQ(UINT64_MAX, ex.GetFilePos());
130 ASSERT_EQ(0u, ex.GetBytesLeft());
131 ASSERT_EQ(nullptr, ex.Peek());
134 TEST_F(StringExtractorTest, GetHexU8_Exact) {
135 llvm::StringRef kValidHexPair = "12";
136 StringExtractor ex(kValidHexPair);
138 ASSERT_EQ(0x12, ex.GetHexU8(0x12));
139 ASSERT_EQ(true, ex.IsGood());
140 ASSERT_EQ(2u, ex.GetFilePos());
141 ASSERT_EQ(0u, ex.GetBytesLeft());
142 ASSERT_EQ(nullptr, ex.Peek());
145 TEST_F(StringExtractorTest, GetHexU8_Extra) {
146 llvm::StringRef kValidHexPair = "1234";
147 StringExtractor ex(kValidHexPair);
149 ASSERT_EQ(0x12, ex.GetHexU8(0x12));
150 ASSERT_EQ(true, ex.IsGood());
151 ASSERT_EQ(2u, ex.GetFilePos());
152 ASSERT_EQ(2u, ex.GetBytesLeft());
153 ASSERT_EQ('3', *ex.Peek());
156 TEST_F(StringExtractorTest, GetHexU8_Underflow_NoEof) {
157 llvm::StringRef kEmptyString = "";
158 StringExtractor ex(kEmptyString);
159 const bool kSetEofOnFail = false;
161 ASSERT_EQ(0xab, ex.GetHexU8(0xab, kSetEofOnFail));
162 ASSERT_EQ(false, ex.IsGood()); // this result seems inconsistent with
163 // kSetEofOnFail == false
164 ASSERT_EQ(UINT64_MAX, ex.GetFilePos());
165 ASSERT_EQ(true, ex.Empty());
166 ASSERT_EQ(0u, ex.GetBytesLeft());
167 ASSERT_EQ(nullptr, ex.Peek());
170 TEST_F(StringExtractorTest, GetHexU8_Underflow2_NoEof) {
171 llvm::StringRef kOneNibble = "1";
172 StringExtractor ex(kOneNibble);
173 const bool kSetEofOnFail = false;
175 ASSERT_EQ(0xbc, ex.GetHexU8(0xbc, kSetEofOnFail));
176 ASSERT_EQ(true, ex.IsGood());
177 ASSERT_EQ(0u, ex.GetFilePos());
178 ASSERT_EQ(1u, ex.GetBytesLeft());
179 ASSERT_EQ('1', *ex.Peek());
182 TEST_F(StringExtractorTest, GetHexU8_InvalidHex_NoEof) {
183 llvm::StringRef kInvalidHex = "xx";
184 StringExtractor ex(kInvalidHex);
185 const bool kSetEofOnFail = false;
187 ASSERT_EQ(0xcd, ex.GetHexU8(0xcd, kSetEofOnFail));
188 ASSERT_EQ(true, ex.IsGood());
189 ASSERT_EQ(0u, ex.GetFilePos());
190 ASSERT_EQ(2u, ex.GetBytesLeft());
191 ASSERT_EQ('x', *ex.Peek());
194 TEST_F(StringExtractorTest, GetHexU8_Exact_NoEof) {
195 llvm::StringRef kValidHexPair = "12";
196 StringExtractor ex(kValidHexPair);
197 const bool kSetEofOnFail = false;
199 ASSERT_EQ(0x12, ex.GetHexU8(0x12, kSetEofOnFail));
200 ASSERT_EQ(true, ex.IsGood());
201 ASSERT_EQ(2u, ex.GetFilePos());
202 ASSERT_EQ(0u, ex.GetBytesLeft());
203 ASSERT_EQ(nullptr, ex.Peek());
206 TEST_F(StringExtractorTest, GetHexU8_Extra_NoEof) {
207 llvm::StringRef kValidHexPair = "1234";
208 StringExtractor ex(kValidHexPair);
209 const bool kSetEofOnFail = false;
211 ASSERT_EQ(0x12, ex.GetHexU8(0x12, kSetEofOnFail));
212 ASSERT_EQ(true, ex.IsGood());
213 ASSERT_EQ(2u, ex.GetFilePos());
214 ASSERT_EQ(2u, ex.GetBytesLeft());
215 ASSERT_EQ('3', *ex.Peek());
218 TEST_F(StringExtractorTest, GetHexBytes) {
219 llvm::StringRef kHexEncodedBytes = "abcdef0123456789xyzw";
220 const size_t kValidHexPairs = 8;
221 StringExtractor ex(kHexEncodedBytes);
223 uint8_t dst[kValidHexPairs];
224 ASSERT_EQ(kValidHexPairs, ex.GetHexBytes(dst, 0xde));
225 EXPECT_EQ(0xab, dst[0]);
226 EXPECT_EQ(0xcd, dst[1]);
227 EXPECT_EQ(0xef, dst[2]);
228 EXPECT_EQ(0x01, dst[3]);
229 EXPECT_EQ(0x23, dst[4]);
230 EXPECT_EQ(0x45, dst[5]);
231 EXPECT_EQ(0x67, dst[6]);
232 EXPECT_EQ(0x89, dst[7]);
234 ASSERT_EQ(true, ex.IsGood());
235 ASSERT_EQ(2 * kValidHexPairs, ex.GetFilePos());
236 ASSERT_EQ(false, ex.Empty());
237 ASSERT_EQ(4u, ex.GetBytesLeft());
238 ASSERT_EQ('x', *ex.Peek());
241 TEST_F(StringExtractorTest, GetHexBytes_FullString) {
242 llvm::StringRef kHexEncodedBytes = "abcdef0123456789";
243 const size_t kValidHexPairs = 8;
244 StringExtractor ex(kHexEncodedBytes);
246 uint8_t dst[kValidHexPairs];
247 ASSERT_EQ(kValidHexPairs, ex.GetHexBytes(dst, 0xde));
248 EXPECT_EQ(0xab, dst[0]);
249 EXPECT_EQ(0xcd, dst[1]);
250 EXPECT_EQ(0xef, dst[2]);
251 EXPECT_EQ(0x01, dst[3]);
252 EXPECT_EQ(0x23, dst[4]);
253 EXPECT_EQ(0x45, dst[5]);
254 EXPECT_EQ(0x67, dst[6]);
255 EXPECT_EQ(0x89, dst[7]);
258 TEST_F(StringExtractorTest, GetHexBytes_OddPair) {
259 llvm::StringRef kHexEncodedBytes = "abcdef012345678w";
260 const size_t kValidHexPairs = 7;
261 StringExtractor ex(kHexEncodedBytes);
263 uint8_t dst[8];
264 ASSERT_EQ(kValidHexPairs, ex.GetHexBytes(dst, 0xde));
265 EXPECT_EQ(0xab, dst[0]);
266 EXPECT_EQ(0xcd, dst[1]);
267 EXPECT_EQ(0xef, dst[2]);
268 EXPECT_EQ(0x01, dst[3]);
269 EXPECT_EQ(0x23, dst[4]);
270 EXPECT_EQ(0x45, dst[5]);
271 EXPECT_EQ(0x67, dst[6]);
273 // This one should be invalid
274 EXPECT_EQ(0xde, dst[7]);
277 TEST_F(StringExtractorTest, GetHexBytes_OddPair2) {
278 llvm::StringRef kHexEncodedBytes = "abcdef012345678";
279 const size_t kValidHexPairs = 7;
280 StringExtractor ex(kHexEncodedBytes);
282 uint8_t dst[8];
283 ASSERT_EQ(kValidHexPairs, ex.GetHexBytes(dst, 0xde));
284 EXPECT_EQ(0xab, dst[0]);
285 EXPECT_EQ(0xcd, dst[1]);
286 EXPECT_EQ(0xef, dst[2]);
287 EXPECT_EQ(0x01, dst[3]);
288 EXPECT_EQ(0x23, dst[4]);
289 EXPECT_EQ(0x45, dst[5]);
290 EXPECT_EQ(0x67, dst[6]);
292 EXPECT_EQ(0xde, dst[7]);
295 TEST_F(StringExtractorTest, GetHexBytes_Underflow) {
296 llvm::StringRef kHexEncodedBytes = "abcdef0123456789xyzw";
297 const size_t kValidHexPairs = 8;
298 StringExtractor ex(kHexEncodedBytes);
300 uint8_t dst[12];
301 ASSERT_EQ(kValidHexPairs, ex.GetHexBytes(dst, 0xde));
302 EXPECT_EQ(0xab, dst[0]);
303 EXPECT_EQ(0xcd, dst[1]);
304 EXPECT_EQ(0xef, dst[2]);
305 EXPECT_EQ(0x01, dst[3]);
306 EXPECT_EQ(0x23, dst[4]);
307 EXPECT_EQ(0x45, dst[5]);
308 EXPECT_EQ(0x67, dst[6]);
309 EXPECT_EQ(0x89, dst[7]);
310 // these bytes should be filled with fail_fill_value 0xde
311 EXPECT_EQ(0xde, dst[8]);
312 EXPECT_EQ(0xde, dst[9]);
313 EXPECT_EQ(0xde, dst[10]);
314 EXPECT_EQ(0xde, dst[11]);
316 ASSERT_EQ(false, ex.IsGood());
317 ASSERT_EQ(UINT64_MAX, ex.GetFilePos());
318 ASSERT_EQ(false, ex.Empty());
319 ASSERT_EQ(0u, ex.GetBytesLeft());
320 ASSERT_EQ(nullptr, ex.Peek());
323 TEST_F(StringExtractorTest, GetHexBytes_Partial) {
324 llvm::StringRef kHexEncodedBytes = "abcdef0123456789xyzw";
325 const size_t kReadBytes = 4;
326 StringExtractor ex(kHexEncodedBytes);
328 uint8_t dst[12];
329 memset(dst, 0xab, sizeof(dst));
330 ASSERT_EQ(
331 kReadBytes,
332 ex.GetHexBytes(llvm::MutableArrayRef<uint8_t>(dst, kReadBytes), 0xde));
333 EXPECT_EQ(0xab, dst[0]);
334 EXPECT_EQ(0xcd, dst[1]);
335 EXPECT_EQ(0xef, dst[2]);
336 EXPECT_EQ(0x01, dst[3]);
337 // these bytes should be unchanged
338 EXPECT_EQ(0xab, dst[4]);
339 EXPECT_EQ(0xab, dst[5]);
340 EXPECT_EQ(0xab, dst[6]);
341 EXPECT_EQ(0xab, dst[7]);
342 EXPECT_EQ(0xab, dst[8]);
343 EXPECT_EQ(0xab, dst[9]);
344 EXPECT_EQ(0xab, dst[10]);
345 EXPECT_EQ(0xab, dst[11]);
347 ASSERT_EQ(true, ex.IsGood());
348 ASSERT_EQ(kReadBytes * 2, ex.GetFilePos());
349 ASSERT_EQ(false, ex.Empty());
350 ASSERT_EQ(12u, ex.GetBytesLeft());
351 ASSERT_EQ('2', *ex.Peek());
354 TEST_F(StringExtractorTest, GetHexBytesAvail) {
355 llvm::StringRef kHexEncodedBytes = "abcdef0123456789xyzw";
356 const size_t kValidHexPairs = 8;
357 StringExtractor ex(kHexEncodedBytes);
359 uint8_t dst[kValidHexPairs];
360 ASSERT_EQ(kValidHexPairs, ex.GetHexBytesAvail(dst));
361 EXPECT_EQ(0xab, dst[0]);
362 EXPECT_EQ(0xcd, dst[1]);
363 EXPECT_EQ(0xef, dst[2]);
364 EXPECT_EQ(0x01, dst[3]);
365 EXPECT_EQ(0x23, dst[4]);
366 EXPECT_EQ(0x45, dst[5]);
367 EXPECT_EQ(0x67, dst[6]);
368 EXPECT_EQ(0x89, dst[7]);
370 ASSERT_EQ(true, ex.IsGood());
371 ASSERT_EQ(2 * kValidHexPairs, ex.GetFilePos());
372 ASSERT_EQ(false, ex.Empty());
373 ASSERT_EQ(4u, ex.GetBytesLeft());
374 ASSERT_EQ('x', *ex.Peek());
377 TEST_F(StringExtractorTest, GetHexBytesAvail_FullString) {
378 llvm::StringRef kHexEncodedBytes = "abcdef0123456789";
379 const size_t kValidHexPairs = 8;
380 StringExtractor ex(kHexEncodedBytes);
382 uint8_t dst[kValidHexPairs];
383 ASSERT_EQ(kValidHexPairs, ex.GetHexBytesAvail(dst));
384 EXPECT_EQ(0xab, dst[0]);
385 EXPECT_EQ(0xcd, dst[1]);
386 EXPECT_EQ(0xef, dst[2]);
387 EXPECT_EQ(0x01, dst[3]);
388 EXPECT_EQ(0x23, dst[4]);
389 EXPECT_EQ(0x45, dst[5]);
390 EXPECT_EQ(0x67, dst[6]);
391 EXPECT_EQ(0x89, dst[7]);
394 TEST_F(StringExtractorTest, GetHexBytesAvail_OddPair) {
395 llvm::StringRef kHexEncodedBytes = "abcdef012345678w";
396 const size_t kValidHexPairs = 7;
397 StringExtractor ex(kHexEncodedBytes);
399 uint8_t dst[8];
400 ASSERT_EQ(kValidHexPairs, ex.GetHexBytesAvail(dst));
401 EXPECT_EQ(0xab, dst[0]);
402 EXPECT_EQ(0xcd, dst[1]);
403 EXPECT_EQ(0xef, dst[2]);
404 EXPECT_EQ(0x01, dst[3]);
405 EXPECT_EQ(0x23, dst[4]);
406 EXPECT_EQ(0x45, dst[5]);
407 EXPECT_EQ(0x67, dst[6]);
410 TEST_F(StringExtractorTest, GetHexBytesAvail_OddPair2) {
411 llvm::StringRef kHexEncodedBytes = "abcdef012345678";
412 const size_t kValidHexPairs = 7;
413 StringExtractor ex(kHexEncodedBytes);
415 uint8_t dst[8];
416 ASSERT_EQ(kValidHexPairs, ex.GetHexBytesAvail(dst));
417 EXPECT_EQ(0xab, dst[0]);
418 EXPECT_EQ(0xcd, dst[1]);
419 EXPECT_EQ(0xef, dst[2]);
420 EXPECT_EQ(0x01, dst[3]);
421 EXPECT_EQ(0x23, dst[4]);
422 EXPECT_EQ(0x45, dst[5]);
423 EXPECT_EQ(0x67, dst[6]);
426 TEST_F(StringExtractorTest, GetHexBytesAvail_Underflow) {
427 llvm::StringRef kHexEncodedBytes = "abcdef0123456789xyzw";
428 const size_t kValidHexPairs = 8;
429 StringExtractor ex(kHexEncodedBytes);
431 uint8_t dst[12];
432 memset(dst, 0xef, sizeof(dst));
433 ASSERT_EQ(kValidHexPairs, ex.GetHexBytesAvail(dst));
434 EXPECT_EQ(0xab, dst[0]);
435 EXPECT_EQ(0xcd, dst[1]);
436 EXPECT_EQ(0xef, dst[2]);
437 EXPECT_EQ(0x01, dst[3]);
438 EXPECT_EQ(0x23, dst[4]);
439 EXPECT_EQ(0x45, dst[5]);
440 EXPECT_EQ(0x67, dst[6]);
441 EXPECT_EQ(0x89, dst[7]);
442 // these bytes should be unchanged
443 EXPECT_EQ(0xef, dst[8]);
444 EXPECT_EQ(0xef, dst[9]);
445 EXPECT_EQ(0xef, dst[10]);
446 EXPECT_EQ(0xef, dst[11]);
448 ASSERT_EQ(true, ex.IsGood());
449 ASSERT_EQ(kValidHexPairs * 2, ex.GetFilePos());
450 ASSERT_EQ(false, ex.Empty());
451 ASSERT_EQ(4u, ex.GetBytesLeft());
452 ASSERT_EQ('x', *ex.Peek());
455 TEST_F(StringExtractorTest, GetHexBytesAvail_Partial) {
456 llvm::StringRef kHexEncodedBytes = "abcdef0123456789xyzw";
457 const size_t kReadBytes = 4;
458 StringExtractor ex(kHexEncodedBytes);
460 uint8_t dst[12];
461 memset(dst, 0xab, sizeof(dst));
462 ASSERT_EQ(kReadBytes, ex.GetHexBytesAvail(
463 llvm::MutableArrayRef<uint8_t>(dst, kReadBytes)));
464 EXPECT_EQ(0xab, dst[0]);
465 EXPECT_EQ(0xcd, dst[1]);
466 EXPECT_EQ(0xef, dst[2]);
467 EXPECT_EQ(0x01, dst[3]);
468 // these bytes should be unchanged
469 EXPECT_EQ(0xab, dst[4]);
470 EXPECT_EQ(0xab, dst[5]);
471 EXPECT_EQ(0xab, dst[6]);
472 EXPECT_EQ(0xab, dst[7]);
473 EXPECT_EQ(0xab, dst[8]);
474 EXPECT_EQ(0xab, dst[9]);
475 EXPECT_EQ(0xab, dst[10]);
476 EXPECT_EQ(0xab, dst[11]);
478 ASSERT_EQ(true, ex.IsGood());
479 ASSERT_EQ(kReadBytes * 2, ex.GetFilePos());
480 ASSERT_EQ(false, ex.Empty());
481 ASSERT_EQ(12u, ex.GetBytesLeft());
482 ASSERT_EQ('2', *ex.Peek());
485 TEST_F(StringExtractorTest, GetNameColonValueSuccess) {
486 llvm::StringRef kNameColonPairs = "key1:value1;key2:value2;";
487 StringExtractor ex(kNameColonPairs);
489 llvm::StringRef name;
490 llvm::StringRef value;
491 EXPECT_TRUE(ex.GetNameColonValue(name, value));
492 EXPECT_EQ("key1", name);
493 EXPECT_EQ("value1", value);
494 EXPECT_TRUE(ex.GetNameColonValue(name, value));
495 EXPECT_EQ("key2", name);
496 EXPECT_EQ("value2", value);
497 EXPECT_EQ(0u, ex.GetBytesLeft());
500 TEST_F(StringExtractorTest, GetNameColonValueContainsColon) {
501 llvm::StringRef kNameColonPairs = "key1:value1:value2;key2:value3;";
502 StringExtractor ex(kNameColonPairs);
504 llvm::StringRef name;
505 llvm::StringRef value;
506 EXPECT_TRUE(ex.GetNameColonValue(name, value));
507 EXPECT_EQ("key1", name);
508 EXPECT_EQ("value1:value2", value);
509 EXPECT_TRUE(ex.GetNameColonValue(name, value));
510 EXPECT_EQ("key2", name);
511 EXPECT_EQ("value3", value);
512 EXPECT_EQ(0u, ex.GetBytesLeft());
515 TEST_F(StringExtractorTest, GetNameColonValueNoSemicolon) {
516 llvm::StringRef kNameColonPairs = "key1:value1";
517 StringExtractor ex(kNameColonPairs);
519 llvm::StringRef name;
520 llvm::StringRef value;
521 EXPECT_FALSE(ex.GetNameColonValue(name, value));
522 EXPECT_EQ(0u, ex.GetBytesLeft());
525 TEST_F(StringExtractorTest, GetNameColonValueNoColon) {
526 llvm::StringRef kNameColonPairs = "key1value1;";
527 StringExtractor ex(kNameColonPairs);
529 llvm::StringRef name;
530 llvm::StringRef value;
531 EXPECT_FALSE(ex.GetNameColonValue(name, value));
532 EXPECT_EQ(0u, ex.GetBytesLeft());
535 TEST_F(StringExtractorTest, GetU32LittleEndian) {
536 StringExtractor ex("");
537 EXPECT_EQ(0x0ull, ex.GetHexMaxU32(true, 0));
539 ex.Reset("0");
540 EXPECT_EQ(0x0ull, ex.GetHexMaxU32(true, 1));
542 ex.Reset("1");
543 EXPECT_EQ(0x1ull, ex.GetHexMaxU32(true, 0));
545 ex.Reset("01");
546 EXPECT_EQ(0x1ull, ex.GetHexMaxU32(true, 0));
548 ex.Reset("001");
549 EXPECT_EQ(0x100ull, ex.GetHexMaxU32(true, 0));
551 ex.Reset("12");
552 EXPECT_EQ(0x12ull, ex.GetHexMaxU32(true, 0));
554 ex.Reset("123");
555 EXPECT_EQ(0x312ull, ex.GetHexMaxU32(true, 0));
557 ex.Reset("1203");
558 EXPECT_EQ(0x312ull, ex.GetHexMaxU32(true, 0));
560 ex.Reset("1234");
561 EXPECT_EQ(0x3412ull, ex.GetHexMaxU32(true, 0));
563 ex.Reset("12340");
564 EXPECT_EQ(0x3412ull, ex.GetHexMaxU32(true, 0));
566 ex.Reset("123400");
567 EXPECT_EQ(0x3412ull, ex.GetHexMaxU32(true, 0));
569 ex.Reset("12345670");
570 EXPECT_EQ(0x70563412ull, ex.GetHexMaxU32(true, 0));
572 ex.Reset("123456701");
573 EXPECT_EQ(0ull, ex.GetHexMaxU32(true, 0));
576 TEST_F(StringExtractorTest, GetU32BigEndian) {
577 StringExtractor ex("");
578 EXPECT_EQ(0x0ull, ex.GetHexMaxU32(false, 0));
580 ex.Reset("0");
581 EXPECT_EQ(0x0ull, ex.GetHexMaxU32(false, 1));
583 ex.Reset("1");
584 EXPECT_EQ(0x1ull, ex.GetHexMaxU32(false, 0));
586 ex.Reset("01");
587 EXPECT_EQ(0x1ull, ex.GetHexMaxU32(false, 0));
589 ex.Reset("001");
590 EXPECT_EQ(0x1ull, ex.GetHexMaxU32(false, 0));
592 ex.Reset("12");
593 EXPECT_EQ(0x12ull, ex.GetHexMaxU32(false, 0));
595 ex.Reset("123");
596 EXPECT_EQ(0x123ull, ex.GetHexMaxU32(false, 0));
598 ex.Reset("1203");
599 EXPECT_EQ(0x1203ull, ex.GetHexMaxU32(false, 0));
601 ex.Reset("1234");
602 EXPECT_EQ(0x1234ull, ex.GetHexMaxU32(false, 0));
604 ex.Reset("12340");
605 EXPECT_EQ(0x12340ull, ex.GetHexMaxU32(false, 0));
607 ex.Reset("123400");
608 EXPECT_EQ(0x123400ull, ex.GetHexMaxU32(false, 0));
610 ex.Reset("12345670");
611 EXPECT_EQ(0x12345670ull, ex.GetHexMaxU32(false, 0));
613 ex.Reset("123456700");
614 EXPECT_EQ(0ull, ex.GetHexMaxU32(false, 0));
617 TEST_F(StringExtractorTest, GetU64LittleEndian) {
618 StringExtractor ex("");
619 EXPECT_EQ(0x0ull, ex.GetHexMaxU64(true, 0));
621 ex.Reset("0");
622 EXPECT_EQ(0x0ull, ex.GetHexMaxU64(true, 1));
624 ex.Reset("1");
625 EXPECT_EQ(0x1ull, ex.GetHexMaxU64(true, 0));
627 ex.Reset("01");
628 EXPECT_EQ(0x1ull, ex.GetHexMaxU64(true, 0));
630 ex.Reset("001");
631 EXPECT_EQ(0x100ull, ex.GetHexMaxU64(true, 0));
633 ex.Reset("12");
634 EXPECT_EQ(0x12ull, ex.GetHexMaxU64(true, 0));
636 ex.Reset("123");
637 EXPECT_EQ(0x312ull, ex.GetHexMaxU64(true, 0));
639 ex.Reset("1203");
640 EXPECT_EQ(0x312ull, ex.GetHexMaxU64(true, 0));
642 ex.Reset("1234");
643 EXPECT_EQ(0x3412ull, ex.GetHexMaxU64(true, 0));
645 ex.Reset("12340");
646 EXPECT_EQ(0x3412ull, ex.GetHexMaxU64(true, 0));
648 ex.Reset("123400");
649 EXPECT_EQ(0x3412ull, ex.GetHexMaxU64(true, 0));
651 ex.Reset("123456789ABCDEF0");
652 EXPECT_EQ(0xF0DEBC9A78563412ULL, ex.GetHexMaxU64(true, 0));
654 ex.Reset("123456789ABCDEF01");
655 EXPECT_EQ(0ull, ex.GetHexMaxU64(true, 0));
658 TEST_F(StringExtractorTest, GetU64BigEndian) {
659 StringExtractor ex("");
660 EXPECT_EQ(0x0ull, ex.GetHexMaxU64(false, 0));
662 ex.Reset("0");
663 EXPECT_EQ(0x0ull, ex.GetHexMaxU64(false, 1));
665 ex.Reset("1");
666 EXPECT_EQ(0x1ull, ex.GetHexMaxU64(false, 0));
668 ex.Reset("01");
669 EXPECT_EQ(0x1ull, ex.GetHexMaxU64(false, 0));
671 ex.Reset("001");
672 EXPECT_EQ(0x1ull, ex.GetHexMaxU64(false, 0));
674 ex.Reset("12");
675 EXPECT_EQ(0x12ull, ex.GetHexMaxU64(false, 0));
677 ex.Reset("123");
678 EXPECT_EQ(0x123ull, ex.GetHexMaxU64(false, 0));
680 ex.Reset("1203");
681 EXPECT_EQ(0x1203ull, ex.GetHexMaxU64(false, 0));
683 ex.Reset("1234");
684 EXPECT_EQ(0x1234ull, ex.GetHexMaxU64(false, 0));
686 ex.Reset("12340");
687 EXPECT_EQ(0x12340ull, ex.GetHexMaxU64(false, 0));
689 ex.Reset("123400");
690 EXPECT_EQ(0x123400ull, ex.GetHexMaxU64(false, 0));
692 ex.Reset("123456789ABCDEF0");
693 EXPECT_EQ(0x123456789ABCDEF0ULL, ex.GetHexMaxU64(false, 0));
695 ex.Reset("123456789ABCDEF000");
696 EXPECT_EQ(0ull, ex.GetHexMaxU64(false, 0));