| Sean Callanan | fc89c14 | 2011-11-01 23:38:03 +0000 | [diff] [blame] | 1 | """Test calling functions in class methods.""" |
| 2 | |
| 3 | import os, time |
| 4 | import unittest2 |
| 5 | import lldb |
| 6 | import lldbutil |
| 7 | from lldbtest import * |
| 8 | |
| Johnny Chen | 14c62c8 | 2011-11-17 18:47:38 +0000 | [diff] [blame] | 9 | class TestObjCClassMethod(TestBase): |
| Sean Callanan | fc89c14 | 2011-11-01 23:38:03 +0000 | [diff] [blame] | 10 | |
| Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 11 | mydir = TestBase.compute_mydir(__file__) |
| Sean Callanan | fc89c14 | 2011-11-01 23:38:03 +0000 | [diff] [blame] | 12 | |
| 13 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 14 | @python_api_test |
| 15 | |
| Johnny Chen | 5604c98 | 2012-05-15 21:27:40 +0000 | [diff] [blame] | 16 | @expectedFailurei386 |
| Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 17 | @dsym_test |
| Sean Callanan | fc89c14 | 2011-11-01 23:38:03 +0000 | [diff] [blame] | 18 | def test_with_dsym_and_python_api(self): |
| 19 | """Test calling functions in class methods.""" |
| 20 | self.buildDsym() |
| 21 | self.objc_class_method() |
| 22 | |
| Daniel Malea | 93aec0f | 2012-11-23 21:59:29 +0000 | [diff] [blame] | 23 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| Johnny Chen | 5604c98 | 2012-05-15 21:27:40 +0000 | [diff] [blame] | 24 | @expectedFailurei386 |
| Sean Callanan | fc89c14 | 2011-11-01 23:38:03 +0000 | [diff] [blame] | 25 | @python_api_test |
| Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 26 | @dwarf_test |
| Sean Callanan | fc89c14 | 2011-11-01 23:38:03 +0000 | [diff] [blame] | 27 | def test_with_dwarf_and_python_api(self): |
| 28 | """Test calling functions in class methods.""" |
| 29 | self.buildDwarf() |
| 30 | self.objc_class_method() |
| 31 | |
| 32 | def setUp(self): |
| 33 | # Call super's setUp(). |
| 34 | TestBase.setUp(self) |
| 35 | # Find the line numbers to break inside main(). |
| 36 | self.main_source = "class.m" |
| 37 | self.break_line = line_number(self.main_source, '// Set breakpoint here.') |
| 38 | |
| 39 | #rdar://problem/9745789 "expression" can't call functions in class methods |
| 40 | def objc_class_method(self): |
| 41 | """Test calling class methods.""" |
| 42 | exe = os.path.join(os.getcwd(), "a.out") |
| 43 | |
| 44 | target = self.dbg.CreateTarget(exe) |
| 45 | self.assertTrue(target, VALID_TARGET) |
| 46 | |
| 47 | bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line) |
| 48 | self.assertTrue(bpt, VALID_BREAKPOINT) |
| 49 | |
| 50 | # Now launch the process, and do not stop at entry point. |
| 51 | process = target.LaunchSimple (None, None, os.getcwd()) |
| 52 | |
| 53 | self.assertTrue(process, PROCESS_IS_VALID) |
| 54 | |
| 55 | # The stop reason of the thread should be breakpoint. |
| 56 | thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt) |
| 57 | |
| 58 | # Make sure we stopped at the first breakpoint. |
| 59 | self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.") |
| 60 | self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.") |
| 61 | |
| 62 | # Now make sure we can call a function in the class method we've stopped in. |
| 63 | frame = thread_list[0].GetFrameAtIndex(0) |
| 64 | self.assertTrue (frame, "Got a valid frame 0 frame.") |
| 65 | |
| 66 | cmd_value = frame.EvaluateExpression ("(int)[Foo doSomethingWithString:@\"Hello\"]") |
| 67 | self.assertTrue (cmd_value.IsValid()) |
| 68 | self.assertTrue (cmd_value.GetValueAsUnsigned() == 5) |
| 69 | |
| 70 | if __name__ == '__main__': |
| 71 | import atexit |
| 72 | lldb.SBDebugger.Initialize() |
| 73 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 74 | unittest2.main() |