56 lines · python
1"""Test calling methods on super."""2 3 4import lldb5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7from lldbsuite.test import lldbutil8 9 10class TestObjCSuperMethod(TestBase):11 def setUp(self):12 # Call super's setUp().13 TestBase.setUp(self)14 # Find the line numbers to break inside main().15 self.main_source = "class.m"16 self.break_line = line_number(self.main_source, "// Set breakpoint here.")17 18 @add_test_categories(["pyapi"])19 def test_with_python_api(self):20 """Test calling methods on super."""21 self.build()22 exe = self.getBuildArtifact("a.out")23 24 target = self.dbg.CreateTarget(exe)25 self.assertTrue(target, VALID_TARGET)26 27 bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line)28 self.assertTrue(bpt, VALID_BREAKPOINT)29 30 # Now launch the process, and do not stop at entry point.31 process = target.LaunchSimple(None, None, self.get_process_working_directory())32 33 self.assertTrue(process, PROCESS_IS_VALID)34 35 # The stop reason of the thread should be breakpoint.36 thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt)37 38 # Make sure we stopped at the first breakpoint.39 self.assertNotEqual(len(thread_list), 0, "No thread stopped at our breakpoint.")40 self.assertEqual(41 len(thread_list), 1, "More than one thread stopped at our breakpoint."42 )43 44 # Now make sure we can call a function in the class method we've45 # stopped in.46 frame = thread_list[0].GetFrameAtIndex(0)47 self.assertTrue(frame, "Got a valid frame 0 frame.")48 49 cmd_value = frame.EvaluateExpression("[self get]")50 self.assertTrue(cmd_value.IsValid())51 self.assertEqual(cmd_value.GetValueAsUnsigned(), 2)52 53 cmd_value = frame.EvaluateExpression("[super get]")54 self.assertTrue(cmd_value.IsValid())55 self.assertEqual(cmd_value.GetValueAsUnsigned(), 1)56