1"""Test calling functions in static methods.""" 2 3 4 5import lldb 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10 11class TestObjCStaticMethod(TestBase): 12 13 mydir = TestBase.compute_mydir(__file__) 14 15 def setUp(self): 16 # Call super's setUp(). 17 TestBase.setUp(self) 18 # Find the line numbers to break inside main(). 19 self.main_source = "static.m" 20 self.break_line = line_number( 21 self.main_source, '// Set breakpoint here.') 22 23 @add_test_categories(['pyapi']) 24 #<rdar://problem/9745789> "expression" can't call functions in class methods 25 def test_with_python_api(self): 26 """Test calling functions in static methods.""" 27 self.build() 28 exe = self.getBuildArtifact("a.out") 29 30 target = self.dbg.CreateTarget(exe) 31 self.assertTrue(target, VALID_TARGET) 32 33 bpt = target.BreakpointCreateByLocation( 34 self.main_source, self.break_line) 35 self.assertTrue(bpt, VALID_BREAKPOINT) 36 37 # Now launch the process, and do not stop at entry point. 38 process = target.LaunchSimple( 39 None, None, self.get_process_working_directory()) 40 41 self.assertTrue(process, PROCESS_IS_VALID) 42 43 # The stop reason of the thread should be breakpoint. 44 thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) 45 46 # Make sure we stopped at the first breakpoint. 47 self.assertTrue( 48 len(thread_list) != 0, 49 "No thread stopped at our breakpoint.") 50 self.assertEquals(len(thread_list), 1, 51 "More than one thread stopped at our breakpoint.") 52 53 # Now make sure we can call a function in the static method we've 54 # stopped in. 55 frame = thread_list[0].GetFrameAtIndex(0) 56 self.assertTrue(frame, "Got a valid frame 0 frame.") 57 58 cmd_value = frame.EvaluateExpression("(char *) sel_getName (_cmd)") 59 self.assertTrue(cmd_value.IsValid()) 60 sel_name = cmd_value.GetSummary() 61 self.assertTrue( 62 sel_name == "\"doSomethingWithString:\"", 63 "Got the right value for the selector as string.") 64 65 cmd_value = frame.EvaluateExpression( 66 "[self doSomethingElseWithString:string]") 67 self.assertTrue(cmd_value.IsValid()) 68 string_length = cmd_value.GetValueAsUnsigned() 69 self.assertTrue( 70 string_length == 27, 71 "Got the right value from another class method on the same class.") 72