xref: /llvm-project/lldb/test/API/functionalities/data-formatter/boolreference/TestFormattersBoolRefPtr.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test lldb data formatter subsystem.
3"""
4
5
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10
11
12class DataFormatterBoolRefPtr(TestBase):
13    @skipUnlessDarwin
14    def test_boolrefptr_with_run_command(self):
15        """Test the formatters we use for BOOL& and BOOL* in Objective-C."""
16        self.build()
17        self.boolrefptr_data_formatter_commands()
18
19    def setUp(self):
20        # Call super's setUp().
21        TestBase.setUp(self)
22        # Find the line number to break at.
23        self.line = line_number("main.mm", "// Set break point at this line.")
24
25    def boolrefptr_data_formatter_commands(self):
26        """Test the formatters we use for BOOL& and BOOL* in Objective-C."""
27        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
28
29        lldbutil.run_break_set_by_file_and_line(
30            self, "main.mm", self.line, num_expected_locations=1, loc_exact=True
31        )
32
33        self.runCmd("run", RUN_SUCCEEDED)
34
35        # The stop reason of the thread should be breakpoint.
36        self.expect(
37            "thread list",
38            STOPPED_DUE_TO_BREAKPOINT,
39            substrs=["stopped", "stop reason = breakpoint"],
40        )
41
42        # This is the function to remove the custom formats in order to have a
43        # clean slate for the next test case.
44        def cleanup():
45            self.runCmd("type format clear", check=False)
46            self.runCmd("type summary clear", check=False)
47            self.runCmd("type synth clear", check=False)
48
49        # Execute the cleanup function during test case tear down.
50        self.addTearDownHook(cleanup)
51
52        isArm = "arm" in self.getArchitecture()
53
54        # Now check that we use the right summary for BOOL&
55        self.expect("frame variable yes_ref", substrs=["YES"])
56        self.expect("frame variable no_ref", substrs=["NO"])
57        if not (isArm):
58            self.expect("frame variable unset_ref", substrs=["12"])
59
60        # Now check that we use the right summary for BOOL*
61        self.expect("frame variable yes_ptr", substrs=["YES"])
62        self.expect("frame variable no_ptr", substrs=["NO"])
63        if not (isArm):
64            self.expect("frame variable unset_ptr", substrs=["12"])
65
66        # Now check that we use the right summary for BOOL
67        self.expect("frame variable yes", substrs=["YES"])
68        self.expect("frame variable no", substrs=["NO"])
69        if not (isArm):
70            self.expect("frame variable unset", substrs=["12"])
71
72        # BOOL is bool instead of signed char on ARM.
73        converted_YES = "-1" if not isArm else "YES"
74
75        self.expect_expr(
76            "myField",
77            result_type="BoolBitFields",
78            result_children=[
79                ValueCheck(name="fieldOne", summary="NO"),
80                ValueCheck(name="fieldTwo", summary=converted_YES),
81                ValueCheck(name="fieldThree", summary="NO"),
82                ValueCheck(name="fieldFour", summary="NO"),
83                ValueCheck(name="fieldFive", summary=converted_YES),
84            ],
85        )
86