1# encoding: utf-8
2"""
3Test lldb data formatter subsystem.
4"""
5
6
7
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14class NSIndexPathDataFormatterTestCase(TestBase):
15
16    def appkit_tester_impl(self, commands):
17        self.build()
18        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
19
20        lldbutil.run_break_set_by_file_and_line(
21            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
22
23        self.runCmd("run", RUN_SUCCEEDED)
24
25        # The stop reason of the thread should be breakpoint.
26        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
27                    substrs=['stopped',
28                             'stop reason = breakpoint'])
29
30        # This is the function to remove the custom formats in order to have a
31        # clean slate for the next test case.
32        def cleanup():
33            self.runCmd('type format clear', check=False)
34            self.runCmd('type summary clear', check=False)
35            self.runCmd('type synth clear', check=False)
36
37        # Execute the cleanup function during test case tear down.
38        self.addTearDownHook(cleanup)
39        commands()
40
41    @skipUnlessDarwin
42    @expectedFailureAll(archs=['i386'], bugnumber="rdar://28656605")
43    @expectedFailureAll(archs=['armv7', 'armv7k', 'arm64_32'], bugnumber="rdar://problem/34561607") # NSIndexPath formatter isn't working for 32-bit arm
44    def test_nsindexpath_with_run_command(self):
45        """Test formatters for NSIndexPath."""
46        self.appkit_tester_impl(self.nsindexpath_data_formatter_commands)
47
48    def setUp(self):
49        # Call super's setUp().
50        TestBase.setUp(self)
51        # Find the line number to break at.
52        self.line = line_number('main.m', '// break here')
53
54    def nsindexpath_data_formatter_commands(self):
55        # check 'frame variable'
56        self.expect(
57            'frame variable --ptr-depth=1 -d run -- indexPath1',
58            substrs=['[0] = 1'])
59        self.expect(
60            'frame variable --ptr-depth=1 -d run -- indexPath2',
61            substrs=[
62                '[0] = 1',
63                '[1] = 2'])
64        self.expect(
65            'frame variable --ptr-depth=1 -d run -- indexPath3',
66            substrs=[
67                '[0] = 1',
68                '[1] = 2',
69                '[2] = 3'])
70        self.expect(
71            'frame variable --ptr-depth=1 -d run -- indexPath4',
72            substrs=[
73                '[0] = 1',
74                '[1] = 2',
75                '[2] = 3',
76                '[3] = 4'])
77        self.expect(
78            'frame variable --ptr-depth=1 -d run -- indexPath5',
79            substrs=[
80                '[0] = 1',
81                '[1] = 2',
82                '[2] = 3',
83                '[3] = 4',
84                '[4] = 5'])
85
86        # and 'expression'
87        self.expect(
88            'expression --ptr-depth=1 -d run -- indexPath1',
89            substrs=['[0] = 1'])
90        self.expect(
91            'expression --ptr-depth=1 -d run -- indexPath2',
92            substrs=[
93                '[0] = 1',
94                '[1] = 2'])
95        self.expect(
96            'expression --ptr-depth=1 -d run -- indexPath3',
97            substrs=[
98                '[0] = 1',
99                '[1] = 2',
100                '[2] = 3'])
101        self.expect('expression --ptr-depth=1 -d run -- indexPath4',
102                    substrs=['[0] = 1', '[1] = 2', '[2] = 3', '[3] = 4'])
103        self.expect(
104            'expression --ptr-depth=1 -d run -- indexPath5',
105            substrs=[
106                '[0] = 1',
107                '[1] = 2',
108                '[2] = 3',
109                '[3] = 4',
110                '[4] = 5'])
111