xref: /llvm-project/lldb/test/API/lang/cpp/union-static-data-members/TestCppUnionStaticMembers.py (revision dcbf1e4e49f3253c8633edeb4e91694631d61b81)
1"""
2Tests that frame variable and expr work for
3C++ unions and their static data members.
4"""
5import lldb
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test.decorators import *
8import lldbsuite.test.lldbutil as lldbutil
9
10class CppUnionStaticMembersTestCase(TestBase):
11    def test_print_union(self):
12        """Tests that frame variable and expr work
13        for union with static data members"""
14        self.build()
15
16        (target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(
17            self, "return 0", lldb.SBFileSpec("main.cpp")
18        )
19
20        self.expect("frame variable foo", substrs=["val = 42"])
21        self.expect("frame variable bar", substrs=["val = 137"])
22
23        self.expect_expr("foo", result_type="Foo", result_children=[ValueCheck(
24                name="val", value="42"
25            )])
26        self.expect_expr("bar", result_type="Bar", result_children=[ValueCheck(
27                name="val", value="137"
28            )])
29
30    @expectedFailureWindows
31    def test_expr_union_static_members(self):
32        """Tests that frame variable and expr work
33        for union static data members"""
34        self.build()
35
36        (target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(
37            self, "return 0", lldb.SBFileSpec("main.cpp")
38        )
39
40        self.expect_expr("Foo::sVal1", result_type="const int", result_value="-42")
41        self.expect_expr("Foo::sVal2", result_type="Foo", result_children=[ValueCheck(
42                name="val", value="42"
43            )])
44
45    @expectedFailureWindows
46    def test_union_in_anon_namespace(self):
47        """Tests that frame variable and expr work
48           for union static data members in anonymous
49           namespaces"""
50        self.build()
51
52        (target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(
53            self, "return 0", lldb.SBFileSpec("main.cpp")
54        )
55
56        self.expect_expr("Bar::sVal1", result_type="const int", result_value="-137")
57        self.expect_expr("Bar::sVal2", result_type="Bar", result_children=[ValueCheck(
58                name="val", value="137"
59            )])
60