]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethods2.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / objc / foundation / TestObjCMethods2.py
1 """
2 Test more expression command sequences with objective-c.
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15
16 @skipUnlessDarwin
17 class FoundationTestCase2(TestBase):
18
19     mydir = TestBase.compute_mydir(__file__)
20
21     def setUp(self):
22         # Call super's setUp().
23         TestBase.setUp(self)
24         # Find the line numbers to break at.
25         self.lines = []
26         self.lines.append(
27             line_number(
28                 'main.m',
29                 '// Break here for selector: tests'))
30         self.lines.append(
31             line_number(
32                 'main.m',
33                 '// Break here for NSArray tests'))
34         self.lines.append(
35             line_number(
36                 'main.m',
37                 '// Break here for NSString tests'))
38         self.lines.append(
39             line_number(
40                 'main.m',
41                 '// Break here for description test'))
42         self.lines.append(
43             line_number(
44                 'main.m',
45                 '// Set break point at this line'))
46
47     def test_more_expr_commands(self):
48         """More expression commands for objective-c."""
49         self.build()
50         exe = os.path.join(os.getcwd(), "a.out")
51         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
52
53         # Create a bunch of breakpoints.
54         for line in self.lines:
55             lldbutil.run_break_set_by_file_and_line(
56                 self, "main.m", line, num_expected_locations=1, loc_exact=True)
57
58         self.runCmd("run", RUN_SUCCEEDED)
59
60         # Test_Selector:
61         self.runCmd("thread backtrace")
62         self.expect("expression (char *)sel_getName(sel)",
63                     substrs=["(char *)",
64                              "length"])
65
66         self.runCmd("process continue")
67
68         # Test_NSArray:
69         self.runCmd("thread backtrace")
70         self.runCmd("process continue")
71
72         # Test_NSString:
73         self.runCmd("thread backtrace")
74         self.runCmd("process continue")
75
76         # Test_MyString:
77         self.runCmd("thread backtrace")
78         self.expect("expression (char *)sel_getName(_cmd)",
79                     substrs=["(char *)",
80                              "description"])
81
82         self.runCmd("process continue")
83
84     def test_NSArray_expr_commands(self):
85         """Test expression commands for NSArray."""
86         self.build()
87         exe = os.path.join(os.getcwd(), "a.out")
88         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
89
90         # Break inside Test_NSArray:
91         line = self.lines[1]
92         lldbutil.run_break_set_by_file_and_line(
93             self, "main.m", line, num_expected_locations=1, loc_exact=True)
94
95         self.runCmd("run", RUN_SUCCEEDED)
96
97         # Test_NSArray:
98         self.runCmd("thread backtrace")
99         self.expect("expression (int)[nil_mutable_array count]",
100                     patterns=["\(int\) \$.* = 0"])
101         self.expect("expression (int)[array1 count]",
102                     patterns=["\(int\) \$.* = 3"])
103         self.expect("expression (int)[array2 count]",
104                     patterns=["\(int\) \$.* = 3"])
105         self.expect("expression (int)array1.count",
106                     patterns=["\(int\) \$.* = 3"])
107         self.expect("expression (int)array2.count",
108                     patterns=["\(int\) \$.* = 3"])
109         self.runCmd("process continue")
110
111     def test_NSString_expr_commands(self):
112         """Test expression commands for NSString."""
113         self.build()
114         exe = os.path.join(os.getcwd(), "a.out")
115         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
116
117         # Break inside Test_NSString:
118         line = self.lines[2]
119         lldbutil.run_break_set_by_file_and_line(
120             self, "main.m", line, num_expected_locations=1, loc_exact=True)
121
122         self.runCmd("run", RUN_SUCCEEDED)
123
124         # Test_NSString:
125         self.runCmd("thread backtrace")
126         self.expect("expression (int)[str length]",
127                     patterns=["\(int\) \$.* ="])
128         self.expect("expression (int)[str_id length]",
129                     patterns=["\(int\) \$.* ="])
130         self.expect("expression (id)[str description]",
131                     patterns=["\(id\) \$.* = 0x"])
132         self.expect("expression (id)[str_id description]",
133                     patterns=["\(id\) \$.* = 0x"])
134         self.expect("expression str.length")
135         self.expect('expression str = @"new"')
136         self.runCmd("image lookup -t NSString")
137         self.expect('expression str = (id)[NSString stringWithCString: "new"]')
138         self.runCmd("process continue")
139
140     @expectedFailureAll(archs=["i[3-6]86"], bugnumber="<rdar://problem/28814052>")
141     def test_MyString_dump_with_runtime(self):
142         """Test dump of a known Objective-C object by dereferencing it."""
143         self.build()
144         exe = os.path.join(os.getcwd(), "a.out")
145         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
146
147         line = self.lines[4]
148
149         lldbutil.run_break_set_by_file_and_line(
150             self, "main.m", line, num_expected_locations=1, loc_exact=True)
151
152         self.runCmd("run", RUN_SUCCEEDED)
153
154         self.expect(
155             "expression --show-types -- *my",
156             patterns=[
157                 "\(MyString\) \$.* = ",
158                 "\(MyBase\)"])
159         self.runCmd("process continue")
160
161     @expectedFailureAll(archs=["i[3-6]86"], bugnumber="<rdar://problem/28814052>")
162     def test_runtime_types(self):
163         """Test commands that require runtime types"""
164         self.build()
165         exe = os.path.join(os.getcwd(), "a.out")
166         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
167
168         # Break inside Test_NSString:
169         line = self.lines[2]
170         lldbutil.run_break_set_by_source_regexp(
171             self, "NSString tests")
172
173         self.runCmd("run", RUN_SUCCEEDED)
174
175         # Test_NSString:
176         self.runCmd("thread backtrace")
177         self.expect("expression [str length]",
178                     patterns=["\(NSUInteger\) \$.* ="])
179         self.expect("expression str.length")
180         self.expect('expression str = [NSString stringWithCString: "new"]')
181         self.expect(
182             'po [NSError errorWithDomain:@"Hello" code:35 userInfo:@{@"NSDescription" : @"be completed."}]',
183             substrs=[
184                 "Error Domain=Hello",
185                 "Code=35",
186                 "be completed."])
187         self.runCmd("process continue")
188
189     @expectedFailureAll(archs=["i[3-6]86"], bugnumber="<rdar://problem/28814052>")
190     def test_NSError_p(self):
191         """Test that p of the result of an unknown method does require a cast."""
192         self.build()
193         exe = os.path.join(os.getcwd(), "a.out")
194         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
195
196         line = self.lines[4]
197
198         lldbutil.run_break_set_by_file_and_line(
199             self, "main.m", line, num_expected_locations=1, loc_exact=True)
200
201         self.runCmd("run", RUN_SUCCEEDED)
202
203         self.expect("p [NSError thisMethodIsntImplemented:0]", error=True, patterns=[
204                     "no known method", "cast the message send to the method's return type"])
205         self.runCmd("process continue")