Sean Callanan | 226b70c | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 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 | |
| 8 | from distutils.version import StrictVersion |
| 9 | |
| 10 | from lldbtest import * |
| 11 | |
| 12 | class ObjCNewSyntaxTestCase(TestBase): |
| 13 | |
| 14 | mydir = os.path.join("lang", "objc", "objc-new-syntax") |
| 15 | |
Filipe Cabecinhas | 2288954 | 2012-05-30 05:44:59 +0000 | [diff] [blame] | 16 | @unittest2.expectedFailure |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 17 | @dsym_test |
Sean Callanan | 226b70c | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 18 | def test_expr_with_dsym(self): |
| 19 | self.buildDsym() |
| 20 | self.expr() |
| 21 | |
Filipe Cabecinhas | 2288954 | 2012-05-30 05:44:59 +0000 | [diff] [blame] | 22 | @unittest2.expectedFailure |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 23 | @dwarf_test |
Sean Callanan | 226b70c | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 24 | def test_expr_with_dwarf(self): |
| 25 | self.buildDwarf() |
| 26 | self.expr() |
| 27 | |
| 28 | def setUp(self): |
| 29 | # Call super's setUp(). |
| 30 | TestBase.setUp(self) |
| 31 | # Find the line number to break inside main(). |
| 32 | self.line = line_number('main.m', '// Set breakpoint 0 here.') |
| 33 | |
| 34 | def applies(self): |
| 35 | if platform.system() != "Darwin": |
| 36 | return False |
| 37 | if StrictVersion('12.0.0') > platform.release(): |
| 38 | return False |
| 39 | |
| 40 | return True |
| 41 | |
| 42 | def common_setup(self): |
| 43 | exe = os.path.join(os.getcwd(), "a.out") |
| 44 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 45 | |
| 46 | # Break inside the foo function which takes a bar_ptr argument. |
| 47 | self.expect("breakpoint set -f main.m -l %d" % self.line, BREAKPOINT_CREATED, |
| 48 | startstr = "Breakpoint created") |
| 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 | |
Sean Callanan | 226b70c | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 65 | self.common_setup() |
| 66 | |
| 67 | self.expect("expr -o -- immutable_array[0]", VARIABLES_DISPLAYED_CORRECTLY, |
| 68 | substrs = ["foo"]) |
| 69 | |
| 70 | self.expect("expr -o -- mutable_array[0]", VARIABLES_DISPLAYED_CORRECTLY, |
| 71 | substrs = ["foo"]) |
| 72 | |
| 73 | self.expect("expr -o -- mutable_array[0] = @\"bar\"", VARIABLES_DISPLAYED_CORRECTLY, |
| 74 | substrs = ["bar"]) |
| 75 | |
| 76 | self.expect("expr -o -- mutable_array[0]", VARIABLES_DISPLAYED_CORRECTLY, |
| 77 | substrs = ["bar"]) |
| 78 | |
| 79 | self.expect("expr -o -- immutable_dictionary[@\"key\"]", VARIABLES_DISPLAYED_CORRECTLY, |
| 80 | substrs = ["value"]) |
| 81 | |
| 82 | self.expect("expr -o -- mutable_dictionary[@\"key\"]", VARIABLES_DISPLAYED_CORRECTLY, |
| 83 | substrs = ["value"]) |
| 84 | |
| 85 | self.expect("expr -o -- mutable_dictionary[@\"key\"] = @\"object\"", VARIABLES_DISPLAYED_CORRECTLY, |
| 86 | substrs = ["object"]) |
| 87 | |
| 88 | self.expect("expr -o -- mutable_dictionary[@\"key\"]", VARIABLES_DISPLAYED_CORRECTLY, |
| 89 | substrs = ["object"]) |
| 90 | |
| 91 | self.expect("expr -o -- @[ @\"foo\", @\"bar\" ]", VARIABLES_DISPLAYED_CORRECTLY, |
| 92 | substrs = ["NSArray", "foo", "bar"]) |
| 93 | |
| 94 | self.expect("expr -o -- @{ @\"key\" : @\"object\" }", VARIABLES_DISPLAYED_CORRECTLY, |
| 95 | substrs = ["NSDictionary", "key", "object"]) |
| 96 | |
| 97 | self.expect("expr -o -- @'a'", VARIABLES_DISPLAYED_CORRECTLY, |
| 98 | substrs = ["NSNumber", str(ord('a'))]) |
| 99 | |
| 100 | self.expect("expr -o -- @1", VARIABLES_DISPLAYED_CORRECTLY, |
| 101 | substrs = ["NSNumber", "1"]) |
| 102 | |
| 103 | self.expect("expr -o -- @1l", VARIABLES_DISPLAYED_CORRECTLY, |
| 104 | substrs = ["NSNumber", "1"]) |
| 105 | |
| 106 | self.expect("expr -o -- @1ul", VARIABLES_DISPLAYED_CORRECTLY, |
| 107 | substrs = ["NSNumber", "1"]) |
| 108 | |
| 109 | self.expect("expr -o -- @1ll", VARIABLES_DISPLAYED_CORRECTLY, |
| 110 | substrs = ["NSNumber", "1"]) |
| 111 | |
| 112 | self.expect("expr -o -- @1ull", VARIABLES_DISPLAYED_CORRECTLY, |
| 113 | substrs = ["NSNumber", "1"]) |
| 114 | |
Sean Callanan | 4407880 | 2012-05-17 23:29:56 +0000 | [diff] [blame] | 115 | self.expect("expr -o -- @123.45", VARIABLES_DISPLAYED_CORRECTLY, |
| 116 | substrs = ["NSNumber", "123.45"]) |
| 117 | self.expect("expr -o -- @123.45f", VARIABLES_DISPLAYED_CORRECTLY, |
| 118 | substrs = ["NSNumber", "123.45"]) |
| 119 | |
| 120 | self.expect("expr -o -- @( 1 + 3 )", VARIABLES_DISPLAYED_CORRECTLY, |
| 121 | substrs = ["NSNumber", "4"]) |
| 122 | self.expect("expr -o -- @(\"Hello world\" + 6)", VARIABLES_DISPLAYED_CORRECTLY, |
Sean Callanan | 0061222 | 2012-05-21 22:25:12 +0000 | [diff] [blame] | 123 | substrs = ["NSString", "world"]) |
Sean Callanan | 226b70c | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 124 | |
| 125 | |
| 126 | if __name__ == '__main__': |
| 127 | import atexit |
| 128 | lldb.SBDebugger.Initialize() |
| 129 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 130 | unittest2.main() |