blob: 1b4388febeb30399ebcdc035fa69f2d49c8eebbc [file] [log] [blame]
Sean Callanan94482842015-04-07 20:33:10 +00001"""Test passing structs to Objective-C methods."""
2
Zachary Turner35d017f2015-10-23 17:04:29 +00003from __future__ import print_function
4
Zachary Turner77db4a82015-10-22 20:06:20 +00005import lldb_shared
6
Sean Callanan94482842015-04-07 20:33:10 +00007import os, time
Sean Callanan94482842015-04-07 20:33:10 +00008import lldb
9import lldbutil
10from lldbtest import *
11
12class TestObjCStructArgument(TestBase):
13
14 mydir = TestBase.compute_mydir(__file__)
15
Sean Callanan94482842015-04-07 20:33:10 +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 = "test.m"
21 self.break_line = line_number(self.main_source, '// Set breakpoint here.')
22
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000023 @skipUnlessDarwin
24 @python_api_test
25 def test_with_python_api(self):
Sean Callanan94482842015-04-07 20:33:10 +000026 """Test passing structs to Objective-C methods."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000027 self.build()
Sean Callanan94482842015-04-07 20:33:10 +000028 exe = os.path.join(os.getcwd(), "a.out")
29
30 target = self.dbg.CreateTarget(exe)
31 self.assertTrue(target, VALID_TARGET)
32
33 bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line)
34 self.assertTrue(bpt, VALID_BREAKPOINT)
35
36 # Now launch the process, and do not stop at entry point.
37 process = target.LaunchSimple (None, None, self.get_process_working_directory())
38
39 self.assertTrue(process, PROCESS_IS_VALID)
40
41 # The stop reason of the thread should be breakpoint.
42 thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt)
43
44 # Make sure we stopped at the first breakpoint.
45 self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.")
46 self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.")
47
48 frame = thread_list[0].GetFrameAtIndex(0)
49 self.assertTrue (frame, "Got a valid frame 0 frame.")
50
51 self.expect("p [summer sumThings:tts]", substrs = ['9'])
52
53 self.expect("po [NSValue valueWithRect:rect]", substrs = ['NSRect: {{0, 0}, {10, 20}}'])
54
55 # Now make sure we can call a method that returns a struct without crashing.
56 cmd_value = frame.EvaluateExpression ("[provider getRange]")
57 self.assertTrue (cmd_value.IsValid())