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