blob: 9fc272133d76669385aaf4a312ec8e5ffe57a0f2 [file] [log] [blame]
Sean Callananfc89c142011-11-01 23:38:03 +00001"""Test calling functions in class methods."""
2
3import os, time
4import unittest2
5import lldb
6import lldbutil
7from lldbtest import *
8
Johnny Chen14c62c82011-11-17 18:47:38 +00009class TestObjCClassMethod(TestBase):
Sean Callananfc89c142011-11-01 23:38:03 +000010
Greg Clayton4570d3e2013-12-10 23:19:29 +000011 mydir = TestBase.compute_mydir(__file__)
Sean Callananfc89c142011-11-01 23:38:03 +000012
13 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
14 @python_api_test
15
Johnny Chen5604c982012-05-15 21:27:40 +000016 @expectedFailurei386
Johnny Chen24086bc2012-04-06 19:54:10 +000017 @dsym_test
Sean Callananfc89c142011-11-01 23:38:03 +000018 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 Malea93aec0f2012-11-23 21:59:29 +000023 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chen5604c982012-05-15 21:27:40 +000024 @expectedFailurei386
Sean Callananfc89c142011-11-01 23:38:03 +000025 @python_api_test
Johnny Chen24086bc2012-04-06 19:54:10 +000026 @dwarf_test
Sean Callananfc89c142011-11-01 23:38:03 +000027 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
70if __name__ == '__main__':
71 import atexit
72 lldb.SBDebugger.Initialize()
73 atexit.register(lambda: lldb.SBDebugger.Terminate())
74 unittest2.main()