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 NSSetSyntheticTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    def setUp(self):
18        # Call super's setUp().
19        TestBase.setUp(self)
20        # Find the line number to break at.
21        self.line = line_number('main.m', '// Set break point at this line.')
22
23    @skipUnlessDarwin
24    def test_rdar12529957_with_run_command(self):
25        """Test that NSSet reports its synthetic children properly."""
26        self.build()
27        self.run_tests()
28
29    @skipUnlessDarwin
30    def test_rdar12529957_with_run_command_no_const(self):
31        """Test that NSSet reports its synthetic children properly."""
32        disable_constant_classes = {
33            'CC':
34            'xcrun clang',  # FIXME: Remove when flags are available upstream.
35            'CFLAGS_EXTRAS':
36            '-fno-constant-nsnumber-literals ' +
37            '-fno-constant-nsarray-literals ' +
38            '-fno-constant-nsdictionary-literals'
39        }
40        self.build(dictionary=disable_constant_classes)
41        self.run_tests()
42
43    def run_tests(self):
44        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
45
46        lldbutil.run_break_set_by_file_and_line(
47            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
48
49        self.runCmd("run", RUN_SUCCEEDED)
50
51        # The stop reason of the thread should be breakpoint.
52        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
53                    substrs=['stopped',
54                             'stop reason = breakpoint'])
55
56        # This is the function to remove the custom formats in order to have a
57        # clean slate for the next test case.
58        def cleanup():
59            self.runCmd('type format clear', check=False)
60            self.runCmd('type summary clear', check=False)
61            self.runCmd('type synth clear', check=False)
62
63        # Execute the cleanup function during test case tear down.
64        self.addTearDownHook(cleanup)
65
66        # Now check that we are displaying Cocoa classes correctly
67        self.expect('frame variable set',
68                    substrs=['4 elements'])
69        self.expect('frame variable mutable',
70                    substrs=['9 elements'])
71        self.expect(
72            'frame variable set --ptr-depth 1 -d run -T',
73            substrs=[
74                '4 elements',
75                '[0]',
76                'hello',
77                '[1]',
78                '(int)2',
79                '[2]',
80                '(int)1',
81                '[3]',
82                'world',
83            ])
84        self.expect(
85            'frame variable mutable --ptr-depth 1 -d run -T',
86            substrs=[
87                '9 elements',
88                '(int)5',
89                '@"3 elements"',
90                '@"www.apple.com"',
91                '(int)3',
92                '@"world"',
93                '(int)4'])
94
95        self.runCmd("next")
96        self.expect('frame variable mutable',
97                    substrs=['0 elements'])
98
99        self.runCmd("next")
100        self.expect('frame variable mutable',
101                    substrs=['4 elements'])
102        self.expect(
103            'frame variable mutable --ptr-depth 1 -d run -T',
104            substrs=[
105                '4 elements',
106                '[0]',
107                '(int)1',
108                '[1]',
109                '(int)2',
110                '[2]',
111                'hello',
112                '[3]',
113                'world',
114            ])
115
116        self.runCmd("next")
117        self.expect('frame variable mutable', substrs=['4 elements'])
118        self.expect(
119            'frame variable mutable --ptr-depth 1 -d run -T',
120            substrs=[
121                '4 elements',
122                '[0]',
123                '(int)1',
124                '[1]',
125                '(int)2',
126                '[2]',
127                'hello',
128                '[3]',
129                'world',
130            ])
131