Home | History | Annotate | Download | only in objc-class-method
      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 
      9 class TestObjCClassMethod(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     @expectedFailurei386
     17     @dsym_test
     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 
     23     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     24     @expectedFailurei386
     25     @python_api_test
     26     @dwarf_test
     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()
     75