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 @skipUnlessDarwin 24 @add_test_categories(['pyapi']) 25 #<rdar://problem/9745789> "expression" can't call functions in class methods 26 def test_with_python_api(self): 27 """Test calling functions in static methods.""" 28 self.build() 29 exe = self.getBuildArtifact("a.out") 30 31 target = self.dbg.CreateTarget(exe) 32 self.assertTrue(target, VALID_TARGET) 33 34 bpt = target.BreakpointCreateByLocation( 35 self.main_source, self.break_line) 36 self.assertTrue(bpt, VALID_BREAKPOINT) 37 38 # Now launch the process, and do not stop at entry point. 39 process = target.LaunchSimple( 40 None, None, self.get_process_working_directory()) 41 42 self.assertTrue(process, PROCESS_IS_VALID) 43 44 # The stop reason of the thread should be breakpoint. 45 thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) 46 47 # Make sure we stopped at the first breakpoint. 48 self.assertTrue( 49 len(thread_list) != 0, 50 "No thread stopped at our breakpoint.") 51 self.assertEquals(len(thread_list), 1, 52 "More than one thread stopped at our breakpoint.") 53 54 # Now make sure we can call a function in the static method we've 55 # stopped in. 56 frame = thread_list[0].GetFrameAtIndex(0) 57 self.assertTrue(frame, "Got a valid frame 0 frame.") 58 59 cmd_value = frame.EvaluateExpression("(char *) sel_getName (_cmd)") 60 self.assertTrue(cmd_value.IsValid()) 61 sel_name = cmd_value.GetSummary() 62 self.assertTrue( 63 sel_name == "\"doSomethingWithString:\"", 64 "Got the right value for the selector as string.") 65 66 cmd_value = frame.EvaluateExpression( 67 "[self doSomethingElseWithString:string]") 68 self.assertTrue(cmd_value.IsValid()) 69 string_length = cmd_value.GetValueAsUnsigned() 70 self.assertTrue( 71 string_length == 27, 72 "Got the right value from another class method on the same class.") 73