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 NSArraySyntheticTestCase(TestBase):
14
15    def setUp(self):
16        # Call super's setUp().
17        TestBase.setUp(self)
18        # Find the line number to break at.
19        self.line = line_number('main.m', '// Set break point at this line.')
20
21    @skipUnlessDarwin
22    def test_rdar11086338_with_run_command(self):
23        """Test that NSArray reports its synthetic children properly."""
24        self.build()
25        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
26
27        lldbutil.run_break_set_by_file_and_line(
28            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
29
30        self.runCmd("run", RUN_SUCCEEDED)
31
32        # The stop reason of the thread should be breakpoint.
33        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
34                    substrs=['stopped',
35                             'stop reason = breakpoint'])
36
37        # This is the function to remove the custom formats in order to have a
38        # clean slate for the next test case.
39        def cleanup():
40            self.runCmd('type format clear', check=False)
41            self.runCmd('type summary clear', check=False)
42            self.runCmd('type synth clear', check=False)
43
44        # Execute the cleanup function during test case tear down.
45        self.addTearDownHook(cleanup)
46
47        # Now check that we are displaying Cocoa classes correctly
48        self.expect('frame variable arr',
49                    substrs=['@"6 elements"'])
50        self.expect('frame variable other_arr',
51                    substrs=['@"4 elements"'])
52        self.expect('frame variable empty_arr',
53                    substrs=['@"0 elements"'])
54        self.expect(
55            'frame variable arr --ptr-depth 1',
56            substrs=[
57                '@"6 elements"',
58                '[0] = 0x',
59                '[1] = 0x',
60                '[2] = 0x',
61                '[3] = 0x',
62                '[4] = 0x',
63                '[5] = 0x'])
64        self.expect(
65            'frame variable other_arr --ptr-depth 1',
66            substrs=[
67                '@"4 elements"',
68                '[0] = 0x',
69                '[1] = 0x',
70                '[2] = 0x',
71                '[3] = 0x'])
72        self.expect(
73            'frame variable empty_arr --ptr-depth 1',
74            substrs=[
75                '@"0 elements"'])
76        self.expect(
77            'frame variable arr --ptr-depth 1 -d no-run-target',
78            substrs=[
79                '@"6 elements"',
80                '@"hello"',
81                '@"world"',
82                '@"this"',
83                '@"is"',
84                '@"me"',
85                '@"http://www.apple.com'])
86        self.expect(
87            'frame variable other_arr --ptr-depth 1 -d no-run-target',
88            substrs=[
89                '@"4 elements"',
90                '(int)5',
91                '@"a string"',
92                '@"6 elements"'])
93        self.expect(
94            'frame variable other_arr --ptr-depth 2 -d no-run-target',
95            substrs=[
96                '@"4 elements"',
97                '@"6 elements" {',
98                '@"hello"',
99                '@"world"',
100                '@"this"',
101                '@"is"',
102                '@"me"',
103                '@"http://www.apple.com'])
104
105        self.assertTrue(
106            self.frame().FindVariable("arr").MightHaveChildren(),
107            "arr says it does not have children!")
108        self.assertTrue(
109            self.frame().FindVariable("other_arr").MightHaveChildren(),
110            "arr says it does not have children!")
111        self.assertFalse(
112            self.frame().FindVariable("empty_arr").MightHaveChildren(),
113            "arr says it does have children!")
114