xref: /llvm-project/lldb/test/API/functionalities/data-formatter/boolreference/TestFormattersBoolRefPtr.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest lldb data formatter subsystem.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprecht
699451b44SJordan Rupprechtimport lldb
799451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
999451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprechtclass DataFormatterBoolRefPtr(TestBase):
1399451b44SJordan Rupprecht    @skipUnlessDarwin
1499451b44SJordan Rupprecht    def test_boolrefptr_with_run_command(self):
1599451b44SJordan Rupprecht        """Test the formatters we use for BOOL& and BOOL* in Objective-C."""
1699451b44SJordan Rupprecht        self.build()
1799451b44SJordan Rupprecht        self.boolrefptr_data_formatter_commands()
1899451b44SJordan Rupprecht
1999451b44SJordan Rupprecht    def setUp(self):
2099451b44SJordan Rupprecht        # Call super's setUp().
2199451b44SJordan Rupprecht        TestBase.setUp(self)
2299451b44SJordan Rupprecht        # Find the line number to break at.
23*2238dcc3SJonas Devlieghere        self.line = line_number("main.mm", "// Set break point at this line.")
2499451b44SJordan Rupprecht
2599451b44SJordan Rupprecht    def boolrefptr_data_formatter_commands(self):
2699451b44SJordan Rupprecht        """Test the formatters we use for BOOL& and BOOL* in Objective-C."""
2799451b44SJordan Rupprecht        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
2899451b44SJordan Rupprecht
2999451b44SJordan Rupprecht        lldbutil.run_break_set_by_file_and_line(
30*2238dcc3SJonas Devlieghere            self, "main.mm", self.line, num_expected_locations=1, loc_exact=True
31*2238dcc3SJonas Devlieghere        )
3299451b44SJordan Rupprecht
3399451b44SJordan Rupprecht        self.runCmd("run", RUN_SUCCEEDED)
3499451b44SJordan Rupprecht
3599451b44SJordan Rupprecht        # The stop reason of the thread should be breakpoint.
36*2238dcc3SJonas Devlieghere        self.expect(
37*2238dcc3SJonas Devlieghere            "thread list",
38*2238dcc3SJonas Devlieghere            STOPPED_DUE_TO_BREAKPOINT,
39*2238dcc3SJonas Devlieghere            substrs=["stopped", "stop reason = breakpoint"],
40*2238dcc3SJonas Devlieghere        )
4199451b44SJordan Rupprecht
4299451b44SJordan Rupprecht        # This is the function to remove the custom formats in order to have a
4399451b44SJordan Rupprecht        # clean slate for the next test case.
4499451b44SJordan Rupprecht        def cleanup():
45*2238dcc3SJonas Devlieghere            self.runCmd("type format clear", check=False)
46*2238dcc3SJonas Devlieghere            self.runCmd("type summary clear", check=False)
47*2238dcc3SJonas Devlieghere            self.runCmd("type synth clear", check=False)
4899451b44SJordan Rupprecht
4999451b44SJordan Rupprecht        # Execute the cleanup function during test case tear down.
5099451b44SJordan Rupprecht        self.addTearDownHook(cleanup)
5199451b44SJordan Rupprecht
52*2238dcc3SJonas Devlieghere        isArm = "arm" in self.getArchitecture()
5399451b44SJordan Rupprecht
5499451b44SJordan Rupprecht        # Now check that we use the right summary for BOOL&
55*2238dcc3SJonas Devlieghere        self.expect("frame variable yes_ref", substrs=["YES"])
56*2238dcc3SJonas Devlieghere        self.expect("frame variable no_ref", substrs=["NO"])
5733ece572SDavide Italiano        if not (isArm):
58*2238dcc3SJonas Devlieghere            self.expect("frame variable unset_ref", substrs=["12"])
5999451b44SJordan Rupprecht
6099451b44SJordan Rupprecht        # Now check that we use the right summary for BOOL*
61*2238dcc3SJonas Devlieghere        self.expect("frame variable yes_ptr", substrs=["YES"])
62*2238dcc3SJonas Devlieghere        self.expect("frame variable no_ptr", substrs=["NO"])
6333ece572SDavide Italiano        if not (isArm):
64*2238dcc3SJonas Devlieghere            self.expect("frame variable unset_ptr", substrs=["12"])
6599451b44SJordan Rupprecht
6699451b44SJordan Rupprecht        # Now check that we use the right summary for BOOL
67*2238dcc3SJonas Devlieghere        self.expect("frame variable yes", substrs=["YES"])
68*2238dcc3SJonas Devlieghere        self.expect("frame variable no", substrs=["NO"])
6933ece572SDavide Italiano        if not (isArm):
70*2238dcc3SJonas Devlieghere            self.expect("frame variable unset", substrs=["12"])
71dc057e87SShafik Yaghmour
72f8994453SJonas Devlieghere        # BOOL is bool instead of signed char on ARM.
73f8994453SJonas Devlieghere        converted_YES = "-1" if not isArm else "YES"
74f8994453SJonas Devlieghere
75*2238dcc3SJonas Devlieghere        self.expect_expr(
76*2238dcc3SJonas Devlieghere            "myField",
77*2238dcc3SJonas Devlieghere            result_type="BoolBitFields",
78dc057e87SShafik Yaghmour            result_children=[
79dc057e87SShafik Yaghmour                ValueCheck(name="fieldOne", summary="NO"),
80f8994453SJonas Devlieghere                ValueCheck(name="fieldTwo", summary=converted_YES),
81dc057e87SShafik Yaghmour                ValueCheck(name="fieldThree", summary="NO"),
82dc057e87SShafik Yaghmour                ValueCheck(name="fieldFour", summary="NO"),
83*2238dcc3SJonas Devlieghere                ValueCheck(name="fieldFive", summary=converted_YES),
84*2238dcc3SJonas Devlieghere            ],
85*2238dcc3SJonas Devlieghere        )
86