blob: 6c3c1832753c34b37bfb8df6a9652920b13cb8e0 [file] [log] [blame]
Sean Callananfc89c142011-11-01 23:38:03 +00001"""Test calling functions in class methods."""
2
Zachary Turner35d017f2015-10-23 17:04:29 +00003from __future__ import print_function
4
Zachary Turner0a0490b2015-10-27 20:12:05 +00005import use_lldb_suite
Zachary Turner77db4a82015-10-22 20:06:20 +00006
Sean Callananfc89c142011-11-01 23:38:03 +00007import os, time
Sean Callananfc89c142011-11-01 23:38:03 +00008import lldb
9import lldbutil
10from lldbtest import *
11
Johnny Chen14c62c82011-11-17 18:47:38 +000012class TestObjCClassMethod(TestBase):
Sean Callananfc89c142011-11-01 23:38:03 +000013
Greg Clayton4570d3e2013-12-10 23:19:29 +000014 mydir = TestBase.compute_mydir(__file__)
Sean Callananfc89c142011-11-01 23:38:03 +000015
Sean Callananfc89c142011-11-01 23:38:03 +000016 def setUp(self):
17 # Call super's setUp().
18 TestBase.setUp(self)
19 # Find the line numbers to break inside main().
20 self.main_source = "class.m"
21 self.break_line = line_number(self.main_source, '// Set breakpoint here.')
22
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000023 @skipUnlessDarwin
24 @expectedFailurei386
Pavel Labathdc8b2d32015-10-26 09:28:32 +000025 @add_test_categories(['pyapi'])
Sean Callananfc89c142011-11-01 23:38:03 +000026 #rdar://problem/9745789 "expression" can't call functions in class methods
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000027 def test_with_python_api(self):
28 """Test calling functions in class methods."""
29 self.build()
Sean Callananfc89c142011-11-01 23:38:03 +000030 exe = os.path.join(os.getcwd(), "a.out")
31
32 target = self.dbg.CreateTarget(exe)
33 self.assertTrue(target, VALID_TARGET)
34
35 bpt = target.BreakpointCreateByLocation(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.
Greg Claytonc6947512013-12-13 19:18:59 +000039 process = target.LaunchSimple (None, None, self.get_process_working_directory())
Sean Callananfc89c142011-11-01 23:38:03 +000040
41 self.assertTrue(process, PROCESS_IS_VALID)
42
43 # The stop reason of the thread should be breakpoint.
44 thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt)
45
46 # Make sure we stopped at the first breakpoint.
47 self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.")
48 self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.")
49
50 # Now make sure we can call a function in the class method we've stopped in.
51 frame = thread_list[0].GetFrameAtIndex(0)
52 self.assertTrue (frame, "Got a valid frame 0 frame.")
53
54 cmd_value = frame.EvaluateExpression ("(int)[Foo doSomethingWithString:@\"Hello\"]")
55 self.assertTrue (cmd_value.IsValid())
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000056 self.assertTrue (cmd_value.GetValueAsUnsigned() == 5)