blob: 21e5d84970d0aba52ed92c21429d5a89fffee49c [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
9class TestObjCStaticMethod(TestBase):
10
11 mydir = os.path.join("lang", "objc", "objc-class-method")
12
13 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
14 @python_api_test
15
16 def test_with_dsym_and_python_api(self):
17 """Test calling functions in class methods."""
18 self.buildDsym()
19 self.objc_class_method()
20
21 @python_api_test
22 def test_with_dwarf_and_python_api(self):
23 """Test calling functions in class methods."""
24 self.buildDwarf()
25 self.objc_class_method()
26
27 def setUp(self):
28 # Call super's setUp().
29 TestBase.setUp(self)
30 # Find the line numbers to break inside main().
31 self.main_source = "class.m"
32 self.break_line = line_number(self.main_source, '// Set breakpoint here.')
33
34 #rdar://problem/9745789 "expression" can't call functions in class methods
35 def objc_class_method(self):
36 """Test calling class methods."""
37 exe = os.path.join(os.getcwd(), "a.out")
38
39 target = self.dbg.CreateTarget(exe)
40 self.assertTrue(target, VALID_TARGET)
41
42 bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line)
43 self.assertTrue(bpt, VALID_BREAKPOINT)
44
45 # Now launch the process, and do not stop at entry point.
46 process = target.LaunchSimple (None, None, os.getcwd())
47
48 self.assertTrue(process, PROCESS_IS_VALID)
49
50 # The stop reason of the thread should be breakpoint.
51 thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt)
52
53 # Make sure we stopped at the first breakpoint.
54 self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.")
55 self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.")
56
57 # Now make sure we can call a function in the class method we've stopped in.
58 frame = thread_list[0].GetFrameAtIndex(0)
59 self.assertTrue (frame, "Got a valid frame 0 frame.")
60
61 cmd_value = frame.EvaluateExpression ("(int)[Foo doSomethingWithString:@\"Hello\"]")
62 self.assertTrue (cmd_value.IsValid())
63 self.assertTrue (cmd_value.GetValueAsUnsigned() == 5)
64
65if __name__ == '__main__':
66 import atexit
67 lldb.SBDebugger.Initialize()
68 atexit.register(lambda: lldb.SBDebugger.Terminate())
69 unittest2.main()