1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: system-windows
10 // REQUIRES: libcxx_gdb
11 //
12 // RUN: %cxx %flags %s -o %t.exe %compile_flags -g %link_flags
13 // Ensure locale-independence for unicode tests.
14 // RUN: %libcxx_gdb -nx -batch -iex "set autoload off" -ex "source %libcxx_src_root/utils/gdb/libcxx/printers.py" -ex "python register_libcxx_printer_loader()" -ex "source %libcxx_src_root/test/pretty_printers/gdb_pretty_printer_test.py" %t.exe
15
16 #include <bitset>
17 #include <deque>
18 #include <list>
19 #include <map>
20 #include <memory>
21 #include <queue>
22 #include <set>
23 #include <sstream>
24 #include <stack>
25 #include <string>
26 #include <tuple>
27 #include <unordered_map>
28 #include <unordered_set>
29
30 #include "test_macros.h"
31
32 // To write a pretty-printer test:
33 //
34 // 1. Declare a variable of the type you want to test
35 //
36 // 2. Set its value to something which will test the pretty printer in an
37 // interesting way.
38 //
39 // 3. Call ComparePrettyPrintToChars with that variable, and a "const char*"
40 // value to compare to the printer's output.
41 //
42 // Or
43 //
44 // Call ComparePrettyPrintToChars with that variable, and a "const char*"
45 // *python* regular expression to match against the printer's output.
46 // The set of special characters in a Python regular expression overlaps
47 // with a lot of things the pretty printers print--brackets, for
48 // example--so take care to escape appropriately.
49 //
50 // Alternatively, construct a string that gdb can parse as an expression,
51 // so that printing the value of the expression will test the pretty printer
52 // in an interesting way. Then, call CompareExpressionPrettyPrintToChars or
53 // CompareExpressionPrettyPrintToRegex to compare the printer's output.
54
55 // Avoids setting a breakpoint in every-single instantiation of
56 // ComparePrettyPrintTo*. Also, make sure neither it, nor the
57 // variables we need present in the Compare functions are optimized
58 // away.
59 #ifdef TEST_COMPILER_GCC
60 #define OPT_NONE __attribute__((noinline))
61 #else
62 #define OPT_NONE __attribute__((optnone))
63 #endif
64 void StopForDebugger(void *value, void *check) OPT_NONE;
StopForDebugger(void * value,void * check)65 void StopForDebugger(void *value, void *check) {}
66
67
68 // Prevents the compiler optimizing away the parameter in the caller function.
69 template <typename Type>
70 void MarkAsLive(Type &&t) OPT_NONE;
71 template <typename Type>
MarkAsLive(Type && t)72 void MarkAsLive(Type &&t) {}
73
74 // In all of the Compare(Expression)PrettyPrintTo(Regex/Chars) functions below,
75 // the python script sets a breakpoint just before the call to StopForDebugger,
76 // compares the result to the expectation.
77 //
78 // The expectation is a literal string to be matched exactly in
79 // *PrettyPrintToChars functions, and is a python regular expression in
80 // *PrettyPrintToRegex functions.
81 //
82 // In ComparePrettyPrint* functions, the value is a variable of any type. In
83 // CompareExpressionPrettyPrint functions, the value is a string expression that
84 // gdb will parse and print the result.
85 //
86 // The python script will print either "PASS", or a detailed failure explanation
87 // along with the line that has invoke the function. The testing will continue
88 // in either case.
89
ComparePrettyPrintToChars(TypeToPrint value,const char * expectation)90 template <typename TypeToPrint> void ComparePrettyPrintToChars(
91 TypeToPrint value,
92 const char *expectation) {
93 StopForDebugger(&value, &expectation);
94 }
95
ComparePrettyPrintToRegex(TypeToPrint value,const char * expectation)96 template <typename TypeToPrint> void ComparePrettyPrintToRegex(
97 TypeToPrint value,
98 const char *expectation) {
99 StopForDebugger(&value, &expectation);
100 }
101
CompareExpressionPrettyPrintToChars(std::string value,const char * expectation)102 void CompareExpressionPrettyPrintToChars(
103 std::string value,
104 const char *expectation) {
105 StopForDebugger(&value, &expectation);
106 }
107
CompareExpressionPrettyPrintToRegex(std::string value,const char * expectation)108 void CompareExpressionPrettyPrintToRegex(
109 std::string value,
110 const char *expectation) {
111 StopForDebugger(&value, &expectation);
112 }
113
114 namespace example {
115 struct example_struct {
116 int a = 0;
117 int arr[1000];
118 };
119 }
120
121 // If enabled, the self test will "fail"--because we want to be sure it properly
122 // diagnoses tests that *should* fail. Evaluate the output by hand.
framework_self_test()123 void framework_self_test() {
124 #ifdef FRAMEWORK_SELF_TEST
125 // Use the most simple data structure we can.
126 const char a = 'a';
127
128 // Tests that should pass
129 ComparePrettyPrintToChars(a, "97 'a'");
130 ComparePrettyPrintToRegex(a, ".*");
131
132 // Tests that should fail.
133 ComparePrettyPrintToChars(a, "b");
134 ComparePrettyPrintToRegex(a, "b");
135 #endif
136 }
137
138 // A simple pass-through allocator to check that we handle CompressedPair
139 // correctly.
140 template <typename T> class UncompressibleAllocator : public std::allocator<T> {
141 public:
142 char X;
143 };
144
string_test()145 void string_test() {
146 std::string short_string("kdjflskdjf");
147 // The display_hint "string" adds quotes the printed result.
148 ComparePrettyPrintToChars(short_string, "\"kdjflskdjf\"");
149
150 std::basic_string<char, std::char_traits<char>, UncompressibleAllocator<char>>
151 long_string("mehmet bizim dostumuz agzi kirik testimiz");
152 ComparePrettyPrintToChars(long_string,
153 "\"mehmet bizim dostumuz agzi kirik testimiz\"");
154 }
155
u16string_test()156 void u16string_test() {
157 std::u16string test0 = u"Hello World";
158 ComparePrettyPrintToChars(test0, "u\"Hello World\"");
159 std::u16string test1 = u"\U00010196\u20AC\u00A3\u0024";
160 ComparePrettyPrintToChars(test1, "u\"\U00010196\u20AC\u00A3\u0024\"");
161 std::u16string test2 = u"\u0024\u0025\u0026\u0027";
162 ComparePrettyPrintToChars(test2, "u\"\u0024\u0025\u0026\u0027\"");
163 std::u16string test3 = u"mehmet bizim dostumuz agzi kirik testimiz";
164 ComparePrettyPrintToChars(test3,
165 ("u\"mehmet bizim dostumuz agzi kirik testimiz\""));
166 }
167
u32string_test()168 void u32string_test() {
169 std::u32string test0 = U"Hello World";
170 ComparePrettyPrintToChars(test0, "U\"Hello World\"");
171 std::u32string test1 =
172 U"\U0001d552\U0001d553\U0001d554\U0001d555\U0001d556\U0001d557";
173 ComparePrettyPrintToChars(
174 test1,
175 ("U\"\U0001d552\U0001d553\U0001d554\U0001d555\U0001d556\U0001d557\""));
176 std::u32string test2 = U"\U00004f60\U0000597d";
177 ComparePrettyPrintToChars(test2, ("U\"\U00004f60\U0000597d\""));
178 std::u32string test3 = U"mehmet bizim dostumuz agzi kirik testimiz";
179 ComparePrettyPrintToChars(test3, ("U\"mehmet bizim dostumuz agzi kirik testimiz\""));
180 }
181
tuple_test()182 void tuple_test() {
183 std::tuple<int, int, int> test0(2, 3, 4);
184 ComparePrettyPrintToChars(
185 test0,
186 "std::tuple containing = {[1] = 2, [2] = 3, [3] = 4}");
187
188 std::tuple<> test1;
189 ComparePrettyPrintToChars(
190 test1,
191 "empty std::tuple");
192 }
193
unique_ptr_test()194 void unique_ptr_test() {
195 std::unique_ptr<std::string> matilda(new std::string("Matilda"));
196 ComparePrettyPrintToRegex(
197 std::move(matilda),
198 R"(std::unique_ptr<std::string> containing = {__ptr_ = 0x[a-f0-9]+})");
199 std::unique_ptr<int> forty_two(new int(42));
200 ComparePrettyPrintToRegex(std::move(forty_two),
201 R"(std::unique_ptr<int> containing = {__ptr_ = 0x[a-f0-9]+})");
202
203 std::unique_ptr<int> this_is_null;
204 ComparePrettyPrintToChars(std::move(this_is_null),
205 R"(std::unique_ptr is nullptr)");
206 }
207
bitset_test()208 void bitset_test() {
209 std::bitset<258> i_am_empty(0);
210 ComparePrettyPrintToChars(i_am_empty, "std::bitset<258>");
211
212 std::bitset<0> very_empty;
213 ComparePrettyPrintToChars(very_empty, "std::bitset<0>");
214
215 std::bitset<15> b_000001111111100(1020);
216 ComparePrettyPrintToChars(b_000001111111100,
217 "std::bitset<15> = {[2] = 1, [3] = 1, [4] = 1, [5] = 1, [6] = 1, "
218 "[7] = 1, [8] = 1, [9] = 1}");
219
220 std::bitset<258> b_0_129_132(0);
221 b_0_129_132[0] = true;
222 b_0_129_132[129] = true;
223 b_0_129_132[132] = true;
224 ComparePrettyPrintToChars(b_0_129_132,
225 "std::bitset<258> = {[0] = 1, [129] = 1, [132] = 1}");
226 }
227
list_test()228 void list_test() {
229 std::list<int> i_am_empty{};
230 ComparePrettyPrintToChars(i_am_empty, "std::list is empty");
231
232 std::list<int> one_two_three {1, 2, 3};
233 ComparePrettyPrintToChars(one_two_three,
234 "std::list with 3 elements = {1, 2, 3}");
235
236 std::list<std::string> colors {"red", "blue", "green"};
237 ComparePrettyPrintToChars(colors,
238 R"(std::list with 3 elements = {"red", "blue", "green"})");
239 }
240
deque_test()241 void deque_test() {
242 std::deque<int> i_am_empty{};
243 ComparePrettyPrintToChars(i_am_empty, "std::deque is empty");
244
245 std::deque<int> one_two_three {1, 2, 3};
246 ComparePrettyPrintToChars(one_two_three,
247 "std::deque with 3 elements = {1, 2, 3}");
248
249 std::deque<example::example_struct> bfg;
250 for (int i = 0; i < 10; ++i) {
251 example::example_struct current;
252 current.a = i;
253 bfg.push_back(current);
254 }
255 for (int i = 0; i < 3; ++i) {
256 bfg.pop_front();
257 }
258 for (int i = 0; i < 3; ++i) {
259 bfg.pop_back();
260 }
261 ComparePrettyPrintToRegex(bfg,
262 "std::deque with 4 elements = {"
263 "{a = 3, arr = {[^}]+}}, "
264 "{a = 4, arr = {[^}]+}}, "
265 "{a = 5, arr = {[^}]+}}, "
266 "{a = 6, arr = {[^}]+}}}");
267 }
268
map_test()269 void map_test() {
270 std::map<int, int> i_am_empty{};
271 ComparePrettyPrintToChars(i_am_empty, "std::map is empty");
272
273 std::map<int, std::string> one_two_three;
274 one_two_three.insert({1, "one"});
275 one_two_three.insert({2, "two"});
276 one_two_three.insert({3, "three"});
277 ComparePrettyPrintToChars(one_two_three,
278 "std::map with 3 elements = "
279 R"({[1] = "one", [2] = "two", [3] = "three"})");
280
281 std::map<int, example::example_struct> bfg;
282 for (int i = 0; i < 4; ++i) {
283 example::example_struct current;
284 current.a = 17 * i;
285 bfg.insert({i, current});
286 }
287 ComparePrettyPrintToRegex(bfg,
288 R"(std::map with 4 elements = {)"
289 R"(\[0\] = {a = 0, arr = {[^}]+}}, )"
290 R"(\[1\] = {a = 17, arr = {[^}]+}}, )"
291 R"(\[2\] = {a = 34, arr = {[^}]+}}, )"
292 R"(\[3\] = {a = 51, arr = {[^}]+}}})");
293 }
294
multimap_test()295 void multimap_test() {
296 std::multimap<int, int> i_am_empty{};
297 ComparePrettyPrintToChars(i_am_empty, "std::multimap is empty");
298
299 std::multimap<int, std::string> one_two_three;
300 one_two_three.insert({1, "one"});
301 one_two_three.insert({3, "three"});
302 one_two_three.insert({1, "ein"});
303 one_two_three.insert({2, "two"});
304 one_two_three.insert({2, "zwei"});
305 one_two_three.insert({1, "bir"});
306
307 ComparePrettyPrintToChars(one_two_three,
308 "std::multimap with 6 elements = "
309 R"({[1] = "one", [1] = "ein", [1] = "bir", )"
310 R"([2] = "two", [2] = "zwei", [3] = "three"})");
311 }
312
queue_test()313 void queue_test() {
314 std::queue<int> i_am_empty;
315 ComparePrettyPrintToChars(i_am_empty,
316 "std::queue wrapping = {std::deque is empty}");
317
318 std::queue<int> one_two_three(std::deque<int>{1, 2, 3});
319 ComparePrettyPrintToChars(one_two_three,
320 "std::queue wrapping = {"
321 "std::deque with 3 elements = {1, 2, 3}}");
322 }
323
priority_queue_test()324 void priority_queue_test() {
325 std::priority_queue<int> i_am_empty;
326 ComparePrettyPrintToChars(i_am_empty,
327 "std::priority_queue wrapping = {std::vector of length 0, capacity 0}");
328
329 std::priority_queue<int> one_two_three;
330 one_two_three.push(11111);
331 one_two_three.push(22222);
332 one_two_three.push(33333);
333
334 ComparePrettyPrintToRegex(one_two_three,
335 R"(std::priority_queue wrapping = )"
336 R"({std::vector of length 3, capacity 3 = {33333)");
337
338 ComparePrettyPrintToRegex(one_two_three, ".*11111.*");
339 ComparePrettyPrintToRegex(one_two_three, ".*22222.*");
340 }
341
set_test()342 void set_test() {
343 std::set<int> i_am_empty;
344 ComparePrettyPrintToChars(i_am_empty, "std::set is empty");
345
346 std::set<int> one_two_three {3, 1, 2};
347 ComparePrettyPrintToChars(one_two_three,
348 "std::set with 3 elements = {1, 2, 3}");
349
350 std::set<std::pair<int, int>> prime_pairs {
351 std::make_pair(3, 5), std::make_pair(5, 7), std::make_pair(3, 5)};
352
353 ComparePrettyPrintToChars(prime_pairs,
354 "std::set with 2 elements = {"
355 "{first = 3, second = 5}, {first = 5, second = 7}}");
356 }
357
stack_test()358 void stack_test() {
359 std::stack<int> test0;
360 ComparePrettyPrintToChars(test0,
361 "std::stack wrapping = {std::deque is empty}");
362 test0.push(5);
363 test0.push(6);
364 ComparePrettyPrintToChars(
365 test0, "std::stack wrapping = {std::deque with 2 elements = {5, 6}}");
366 std::stack<bool> test1;
367 test1.push(true);
368 test1.push(false);
369 ComparePrettyPrintToChars(
370 test1,
371 "std::stack wrapping = {std::deque with 2 elements = {true, false}}");
372
373 std::stack<std::string> test2;
374 test2.push("Hello");
375 test2.push("World");
376 ComparePrettyPrintToChars(test2,
377 "std::stack wrapping = {std::deque with 2 elements "
378 "= {\"Hello\", \"World\"}}");
379 }
380
multiset_test()381 void multiset_test() {
382 std::multiset<int> i_am_empty;
383 ComparePrettyPrintToChars(i_am_empty, "std::multiset is empty");
384
385 std::multiset<std::string> one_two_three {"1:one", "2:two", "3:three", "1:one"};
386 ComparePrettyPrintToChars(one_two_three,
387 "std::multiset with 4 elements = {"
388 R"("1:one", "1:one", "2:two", "3:three"})");
389 }
390
vector_test()391 void vector_test() {
392 std::vector<bool> test0 = {true, false};
393 ComparePrettyPrintToChars(test0,
394 "std::vector<bool> of "
395 "length 2, capacity 64 = {1, 0}");
396 for (int i = 0; i < 31; ++i) {
397 test0.push_back(true);
398 test0.push_back(false);
399 }
400 ComparePrettyPrintToRegex(
401 test0,
402 "std::vector<bool> of length 64, "
403 "capacity 64 = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, "
404 "0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, "
405 "0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}");
406 test0.push_back(true);
407 ComparePrettyPrintToRegex(
408 test0,
409 "std::vector<bool> of length 65, "
410 "capacity 128 = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, "
411 "1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, "
412 "1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}");
413
414 std::vector<int> test1;
415 ComparePrettyPrintToChars(test1, "std::vector of length 0, capacity 0");
416
417 std::vector<int> test2 = {5, 6, 7};
418 ComparePrettyPrintToChars(test2,
419 "std::vector of length "
420 "3, capacity 3 = {5, 6, 7}");
421
422 std::vector<int, UncompressibleAllocator<int>> test3({7, 8});
423 ComparePrettyPrintToChars(std::move(test3),
424 "std::vector of length "
425 "2, capacity 2 = {7, 8}");
426 }
427
set_iterator_test()428 void set_iterator_test() {
429 std::set<int> one_two_three {1111, 2222, 3333};
430 auto it = one_two_three.find(2222);
431 MarkAsLive(it);
432 CompareExpressionPrettyPrintToRegex("it",
433 R"(std::__tree_const_iterator = {\[0x[a-f0-9]+\] = 2222})");
434
435 auto not_found = one_two_three.find(1234);
436 MarkAsLive(not_found);
437 // Because the end_node is not easily detected, just be sure it doesn't crash.
438 CompareExpressionPrettyPrintToRegex("not_found",
439 R"(std::__tree_const_iterator ( = {\[0x[a-f0-9]+\] = .*}|<error reading variable:.*>))");
440 }
441
map_iterator_test()442 void map_iterator_test() {
443 std::map<int, std::string> one_two_three;
444 one_two_three.insert({1, "one"});
445 one_two_three.insert({2, "two"});
446 one_two_three.insert({3, "three"});
447 auto it = one_two_three.begin();
448 MarkAsLive(it);
449 CompareExpressionPrettyPrintToRegex("it",
450 R"(std::__map_iterator = )"
451 R"({\[0x[a-f0-9]+\] = {first = 1, second = "one"}})");
452
453 auto not_found = one_two_three.find(7);
454 MarkAsLive(not_found);
455 CompareExpressionPrettyPrintToRegex("not_found",
456 R"(std::__map_iterator = {\[0x[a-f0-9]+\] = end\(\)})");
457 }
458
unordered_set_test()459 void unordered_set_test() {
460 std::unordered_set<int> i_am_empty;
461 ComparePrettyPrintToChars(i_am_empty, "std::unordered_set is empty");
462
463 std::unordered_set<int> numbers {12345, 67890, 222333, 12345};
464 numbers.erase(numbers.find(222333));
465 ComparePrettyPrintToRegex(numbers, "std::unordered_set with 2 elements = ");
466 ComparePrettyPrintToRegex(numbers, ".*12345.*");
467 ComparePrettyPrintToRegex(numbers, ".*67890.*");
468
469 std::unordered_set<std::string> colors {"red", "blue", "green"};
470 ComparePrettyPrintToRegex(colors, "std::unordered_set with 3 elements = ");
471 ComparePrettyPrintToRegex(colors, R"(.*"red".*)");
472 ComparePrettyPrintToRegex(colors, R"(.*"blue".*)");
473 ComparePrettyPrintToRegex(colors, R"(.*"green".*)");
474 }
475
unordered_multiset_test()476 void unordered_multiset_test() {
477 std::unordered_multiset<int> i_am_empty;
478 ComparePrettyPrintToChars(i_am_empty, "std::unordered_multiset is empty");
479
480 std::unordered_multiset<int> numbers {12345, 67890, 222333, 12345};
481 ComparePrettyPrintToRegex(numbers,
482 "std::unordered_multiset with 4 elements = ");
483 ComparePrettyPrintToRegex(numbers, ".*12345.*12345.*");
484 ComparePrettyPrintToRegex(numbers, ".*67890.*");
485 ComparePrettyPrintToRegex(numbers, ".*222333.*");
486
487 std::unordered_multiset<std::string> colors {"red", "blue", "green", "red"};
488 ComparePrettyPrintToRegex(colors,
489 "std::unordered_multiset with 4 elements = ");
490 ComparePrettyPrintToRegex(colors, R"(.*"red".*"red".*)");
491 ComparePrettyPrintToRegex(colors, R"(.*"blue".*)");
492 ComparePrettyPrintToRegex(colors, R"(.*"green".*)");
493 }
494
unordered_map_test()495 void unordered_map_test() {
496 std::unordered_map<int, int> i_am_empty;
497 ComparePrettyPrintToChars(i_am_empty, "std::unordered_map is empty");
498
499 std::unordered_map<int, std::string> one_two_three;
500 one_two_three.insert({1, "one"});
501 one_two_three.insert({2, "two"});
502 one_two_three.insert({3, "three"});
503 ComparePrettyPrintToRegex(one_two_three,
504 "std::unordered_map with 3 elements = ");
505 ComparePrettyPrintToRegex(one_two_three, R"(.*\[1\] = "one".*)");
506 ComparePrettyPrintToRegex(one_two_three, R"(.*\[2\] = "two".*)");
507 ComparePrettyPrintToRegex(one_two_three, R"(.*\[3\] = "three".*)");
508 }
509
unordered_multimap_test()510 void unordered_multimap_test() {
511 std::unordered_multimap<int, int> i_am_empty;
512 ComparePrettyPrintToChars(i_am_empty, "std::unordered_multimap is empty");
513
514 std::unordered_multimap<int, std::string> one_two_three;
515 one_two_three.insert({1, "one"});
516 one_two_three.insert({2, "two"});
517 one_two_three.insert({3, "three"});
518 one_two_three.insert({2, "two"});
519 ComparePrettyPrintToRegex(one_two_three,
520 "std::unordered_multimap with 4 elements = ");
521 ComparePrettyPrintToRegex(one_two_three, R"(.*\[1\] = "one".*)");
522 ComparePrettyPrintToRegex(one_two_three, R"(.*\[2\] = "two".*\[2\] = "two")");
523 ComparePrettyPrintToRegex(one_two_three, R"(.*\[3\] = "three".*)");
524 }
525
unordered_map_iterator_test()526 void unordered_map_iterator_test() {
527 std::unordered_map<int, int> ones_to_eights;
528 ones_to_eights.insert({1, 8});
529 ones_to_eights.insert({11, 88});
530 ones_to_eights.insert({111, 888});
531
532 auto ones_to_eights_begin = ones_to_eights.begin();
533 MarkAsLive(ones_to_eights_begin);
534 CompareExpressionPrettyPrintToRegex("ones_to_eights_begin",
535 R"(std::__hash_map_iterator = {\[1+\] = 8+})");
536
537 auto not_found = ones_to_eights.find(5);
538 MarkAsLive(not_found);
539 CompareExpressionPrettyPrintToRegex("not_found",
540 R"(std::__hash_map_iterator = end\(\))");
541 }
542
unordered_set_iterator_test()543 void unordered_set_iterator_test() {
544 std::unordered_set<int> ones;
545 ones.insert(111);
546 ones.insert(1111);
547 ones.insert(11111);
548
549 auto ones_begin = ones.begin();
550 MarkAsLive(ones_begin);
551 CompareExpressionPrettyPrintToRegex("ones_begin",
552 R"(std::__hash_const_iterator = {1+})");
553
554 auto not_found = ones.find(5);
555 MarkAsLive(not_found);
556 CompareExpressionPrettyPrintToRegex("not_found",
557 R"(std::__hash_const_iterator = end\(\))");
558 }
559
560 // Check that libc++ pretty printers do not handle pointers.
pointer_negative_test()561 void pointer_negative_test() {
562 int abc = 123;
563 int *int_ptr = &abc;
564 // Check that the result is equivalent to "p/r int_ptr" command.
565 ComparePrettyPrintToRegex(int_ptr, R"(\(int \*\) 0x[a-f0-9]+)");
566 }
567
shared_ptr_test()568 void shared_ptr_test() {
569 // Shared ptr tests while using test framework call another function
570 // due to which there is one more count for the pointer. Hence, all the
571 // following tests are testing with expected count plus 1.
572 std::shared_ptr<const int> test0 = std::make_shared<const int>(5);
573 ComparePrettyPrintToRegex(
574 test0,
575 R"(std::shared_ptr<int> count 2, weak 0 containing = {__ptr_ = 0x[a-f0-9]+})");
576
577 std::shared_ptr<const int> test1(test0);
578 ComparePrettyPrintToRegex(
579 test1,
580 R"(std::shared_ptr<int> count 3, weak 0 containing = {__ptr_ = 0x[a-f0-9]+})");
581
582 {
583 std::weak_ptr<const int> test2 = test1;
584 ComparePrettyPrintToRegex(
585 test0,
586 R"(std::shared_ptr<int> count 3, weak 1 containing = {__ptr_ = 0x[a-f0-9]+})");
587 }
588
589 ComparePrettyPrintToRegex(
590 test0,
591 R"(std::shared_ptr<int> count 3, weak 0 containing = {__ptr_ = 0x[a-f0-9]+})");
592
593 std::shared_ptr<const int> test3;
594 ComparePrettyPrintToChars(test3, "std::shared_ptr is nullptr");
595 }
596
streampos_test()597 void streampos_test() {
598 std::streampos test0 = 67;
599 ComparePrettyPrintToChars(
600 test0, "std::fpos with stream offset:67 with state: {count:0 value:0}");
601 std::istringstream input("testing the input stream here");
602 std::streampos test1 = input.tellg();
603 ComparePrettyPrintToChars(
604 test1, "std::fpos with stream offset:0 with state: {count:0 value:0}");
605 std::unique_ptr<char[]> buffer(new char[5]);
606 input.read(buffer.get(), 5);
607 test1 = input.tellg();
608 ComparePrettyPrintToChars(
609 test1, "std::fpos with stream offset:5 with state: {count:0 value:0}");
610 }
611
main(int argc,char * argv[])612 int main(int argc, char* argv[]) {
613 framework_self_test();
614
615 string_test();
616
617 u32string_test();
618 tuple_test();
619 unique_ptr_test();
620 shared_ptr_test();
621 bitset_test();
622 list_test();
623 deque_test();
624 map_test();
625 multimap_test();
626 queue_test();
627 priority_queue_test();
628 stack_test();
629 set_test();
630 multiset_test();
631 vector_test();
632 set_iterator_test();
633 map_iterator_test();
634 unordered_set_test();
635 unordered_multiset_test();
636 unordered_map_test();
637 unordered_multimap_test();
638 unordered_map_iterator_test();
639 unordered_set_iterator_test();
640 pointer_negative_test();
641 streampos_test();
642 return 0;
643 }
644