Skip to content

Commit 40275a4

Browse files
committed
[lldb][test] Add tests for formatting pointers to std::unordered_map
Ever since #143501 and #144517, these should pass. Adds tests for #146040
1 parent bc8dad1 commit 40275a4

File tree

2 files changed

+49
-21
lines changed

2 files changed

+49
-21
lines changed

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,28 @@
99

1010

1111
class LibcxxUnorderedMapDataFormatterTestCase(TestBase):
12-
def check_reference(self, var_name: str, expected_type: str):
13-
self.expect_var_path(
14-
var_name,
15-
summary="size=1",
16-
type=expected_type,
17-
children=[
18-
ValueCheck(
19-
name="[0]",
20-
children=[
21-
ValueCheck(name="first", summary='"Hello"'),
22-
ValueCheck(name="second", summary='"World"'),
23-
],
24-
),
25-
],
26-
)
12+
def check_ptr_or_ref(self, var_name: str):
13+
var = self.frame().FindVariable(var_name)
14+
self.assertTrue(var)
15+
16+
pair = var.GetChildAtIndex(0)
17+
self.assertTrue(pair)
18+
19+
self.assertEqual(pair.GetChildAtIndex(0).summary, '"Hello"')
20+
self.assertEqual(pair.GetChildAtIndex(1).summary, '"World"')
21+
22+
def check_ptr_ptr(self, var_name: str):
23+
var = self.frame().FindVariable(var_name)
24+
self.assertTrue(var)
25+
26+
ptr = var.GetChildAtIndex(0)
27+
self.assertTrue(ptr)
28+
29+
pair = ptr.GetChildAtIndex(0)
30+
self.assertTrue(pair)
31+
32+
self.assertEqual(pair.GetChildAtIndex(0).summary, '"Hello"')
33+
self.assertEqual(pair.GetChildAtIndex(1).summary, '"World"')
2734

2835
@add_test_categories(["libc++"])
2936
def test_iterator_formatters(self):
@@ -84,16 +91,25 @@ def test_iterator_formatters(self):
8491
lldbutil.continue_to_breakpoint(process, bkpt)
8592

8693
# Test references to std::unordered_map
87-
self.check_reference("ref1", "const StringMapT &")
88-
self.check_reference("ref2", "StringMapT &")
89-
self.check_reference("ref3", "StringMapTRef")
90-
self.check_reference("ref4", "const StringMapT &")
91-
self.check_reference("ref5", "const StringMapT &&")
92-
self.check_reference("ref6", "StringMapT &&")
94+
self.check_ptr_or_ref("ref1")
95+
self.check_ptr_or_ref("ref2")
96+
self.check_ptr_or_ref("ref3")
97+
self.check_ptr_or_ref("ref4")
98+
self.check_ptr_or_ref("ref5")
99+
self.check_ptr_or_ref("ref6")
93100

94101
# FIXME: we're getting this wrong.
95102
self.expect_var_path(
96103
"ref7",
97104
summary="size=0",
98105
type="const StringMapT *const &",
99106
)
107+
108+
lldbutil.continue_to_breakpoint(process, bkpt)
109+
110+
self.check_ptr_or_ref("ptr1")
111+
self.check_ptr_or_ref("ptr2")
112+
self.check_ptr_or_ref("ptr3")
113+
self.check_ptr_ptr("ptr4")
114+
self.check_ptr_ptr("ptr5")
115+
self.check_ptr_ptr("ptr6")

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using StringMapT = std::unordered_map<std::string, std::string>;
66
using StringMapTRef = const StringMapT &;
7+
using StringMapTPtr = const StringMapT *;
78

89
static void check_references(const StringMapT &ref1, StringMapT &ref2,
910
StringMapTRef ref3, StringMapTRef &ref4,
@@ -12,6 +13,12 @@ static void check_references(const StringMapT &ref1, StringMapT &ref2,
1213
std::printf("Break here");
1314
}
1415

16+
static void check_pointer(const StringMapT *ptr1, StringMapT *ptr2,
17+
StringMapTPtr ptr3, StringMapTPtr *ptr4,
18+
const StringMapT *const *ptr5, StringMapT **ptr6) {
19+
std::printf("Break here");
20+
}
21+
1522
int main() {
1623
StringMapT string_map;
1724
{
@@ -35,6 +42,11 @@ int main() {
3542
StringMapT tmp{{"Hello", "World"}};
3643
check_references(tmp, tmp, tmp, tmp, StringMapT{tmp}, StringMapT{tmp},
3744
&tmp);
45+
46+
StringMapT *tmp_ptr = &tmp;
47+
const StringMapT *const_tmp_ptr = &tmp;
48+
check_pointer(tmp_ptr, tmp_ptr, tmp_ptr, &const_tmp_ptr, &tmp_ptr,
49+
&tmp_ptr);
3850
}
3951

4052
return 0;

0 commit comments

Comments
 (0)