Home | History | Annotate | Download | only in objc-new-syntax
      1 """Test that the Objective-C syntax for dictionary/array literals and indexing works"""
      2 
      3 import os, time
      4 import unittest2
      5 import lldb
      6 import platform
      7 import lldbutil
      8 
      9 from distutils.version import StrictVersion
     10 
     11 from lldbtest import *
     12 
     13 class ObjCNewSyntaxTestCase(TestBase):
     14 
     15     mydir = os.path.join("lang", "objc", "objc-new-syntax")
     16 
     17     @unittest2.expectedFailure
     18     @dsym_test
     19     def test_expr_with_dsym(self):
     20         self.buildDsym()
     21         self.expr()
     22 
     23     @unittest2.expectedFailure
     24     @dwarf_test
     25     def test_expr_with_dwarf(self):
     26         self.buildDwarf()
     27         self.expr()
     28 
     29     def setUp(self):
     30         # Call super's setUp().
     31         TestBase.setUp(self)
     32         # Find the line number to break inside main().
     33         self.line = line_number('main.m', '// Set breakpoint 0 here.')
     34 
     35     def applies(self):
     36         if platform.system() != "Darwin":
     37             return False
     38         if StrictVersion('12.0.0') > platform.release():
     39             return False
     40 
     41         return True
     42 
     43     def common_setup(self):
     44         exe = os.path.join(os.getcwd(), "a.out")
     45         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
     46 
     47         # Break inside the foo function which takes a bar_ptr argument.
     48         lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
     49 
     50         self.runCmd("run", RUN_SUCCEEDED)
     51 
     52         # The stop reason of the thread should be breakpoint.
     53         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
     54             substrs = ['stopped',
     55                        'stop reason = breakpoint'])
     56 
     57         # The breakpoint should have a hit count of 1.
     58         self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
     59             substrs = [' resolved, hit count = 1'])
     60 
     61     def expr(self):
     62         if not self.applies():
     63             return
     64 
     65         self.common_setup()
     66 
     67         self.expect("expr --object-description -- immutable_array[0]", VARIABLES_DISPLAYED_CORRECTLY,
     68             substrs = ["foo"])
     69 
     70         self.expect("expr --object-description -- mutable_array[0]", VARIABLES_DISPLAYED_CORRECTLY,
     71             substrs = ["foo"])
     72 
     73         self.expect("expr --object-description -- mutable_array[0] = @\"bar\"", VARIABLES_DISPLAYED_CORRECTLY,
     74             substrs = ["bar"])
     75 
     76         self.expect("expr --object-description -- mutable_array[0]", VARIABLES_DISPLAYED_CORRECTLY,
     77             substrs = ["bar"])
     78 
     79         self.expect("expr --object-description -- immutable_dictionary[@\"key\"]", VARIABLES_DISPLAYED_CORRECTLY,
     80             substrs = ["value"])
     81 
     82         self.expect("expr --object-description -- mutable_dictionary[@\"key\"]", VARIABLES_DISPLAYED_CORRECTLY,
     83             substrs = ["value"])
     84 
     85         self.expect("expr --object-description -- mutable_dictionary[@\"key\"] = @\"object\"", VARIABLES_DISPLAYED_CORRECTLY,
     86             substrs = ["object"])
     87 
     88         self.expect("expr --object-description -- mutable_dictionary[@\"key\"]", VARIABLES_DISPLAYED_CORRECTLY,
     89             substrs = ["object"])
     90 
     91         self.expect("expr --object-description -- @[ @\"foo\", @\"bar\" ]", VARIABLES_DISPLAYED_CORRECTLY,
     92             substrs = ["NSArray", "foo", "bar"])
     93 
     94         self.expect("expr --object-description -- @{ @\"key\" : @\"object\" }", VARIABLES_DISPLAYED_CORRECTLY,
     95             substrs = ["NSDictionary", "key", "object"])
     96 
     97         self.expect("expr --object-description -- @'a'", VARIABLES_DISPLAYED_CORRECTLY,
     98             substrs = ["NSNumber", str(ord('a'))])
     99 
    100         self.expect("expr --object-description -- @1", VARIABLES_DISPLAYED_CORRECTLY,
    101             substrs = ["NSNumber", "1"])
    102 
    103         self.expect("expr --object-description -- @1l", VARIABLES_DISPLAYED_CORRECTLY,
    104             substrs = ["NSNumber", "1"])
    105 
    106         self.expect("expr --object-description -- @1ul", VARIABLES_DISPLAYED_CORRECTLY,
    107             substrs = ["NSNumber", "1"])
    108 
    109         self.expect("expr --object-description -- @1ll", VARIABLES_DISPLAYED_CORRECTLY,
    110             substrs = ["NSNumber", "1"])
    111 
    112         self.expect("expr --object-description -- @1ull", VARIABLES_DISPLAYED_CORRECTLY,
    113             substrs = ["NSNumber", "1"])
    114 
    115         self.expect("expr --object-description -- @123.45", VARIABLES_DISPLAYED_CORRECTLY,
    116             substrs = ["NSNumber", "123.45"])
    117         self.expect("expr --object-description -- @123.45f", VARIABLES_DISPLAYED_CORRECTLY,
    118             substrs = ["NSNumber", "123.45"])
    119 
    120         self.expect("expr --object-description -- @( 1 + 3 )", VARIABLES_DISPLAYED_CORRECTLY,
    121             substrs = ["NSNumber", "4"])
    122         self.expect("expr --object-description -- @(\"Hello world\" + 6)", VARIABLES_DISPLAYED_CORRECTLY,
    123             substrs = ["NSString", "world"])
    124 
    125             
    126 if __name__ == '__main__':
    127     import atexit
    128     lldb.SBDebugger.Initialize()
    129     atexit.register(lambda: lldb.SBDebugger.Terminate())
    130     unittest2.main()
    131