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