blob: 03fc03d1f65d9742b164e541ddb816df24447874 [file] [log] [blame]
Sean Callanan226b70c2012-03-08 02:39:03 +00001"""Test that the Objective-C syntax for dictionary/array literals and indexing works"""
2
3import os, time
4import unittest2
5import lldb
6import platform
7
8from distutils.version import StrictVersion
9
10from lldbtest import *
11
12class ObjCNewSyntaxTestCase(TestBase):
13
14 mydir = os.path.join("lang", "objc", "objc-new-syntax")
15
Filipe Cabecinhas22889542012-05-30 05:44:59 +000016 @unittest2.expectedFailure
Johnny Chen24086bc2012-04-06 19:54:10 +000017 @dsym_test
Sean Callanan226b70c2012-03-08 02:39:03 +000018 def test_expr_with_dsym(self):
19 self.buildDsym()
20 self.expr()
21
Filipe Cabecinhas22889542012-05-30 05:44:59 +000022 @unittest2.expectedFailure
Johnny Chen24086bc2012-04-06 19:54:10 +000023 @dwarf_test
Sean Callanan226b70c2012-03-08 02:39:03 +000024 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 Callanan226b70c2012-03-08 02:39:03 +000065 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 Callanan44078802012-05-17 23:29:56 +0000115 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 Callanan00612222012-05-21 22:25:12 +0000123 substrs = ["NSString", "world"])
Sean Callanan226b70c2012-03-08 02:39:03 +0000124
125
126if __name__ == '__main__':
127 import atexit
128 lldb.SBDebugger.Initialize()
129 atexit.register(lambda: lldb.SBDebugger.Terminate())
130 unittest2.main()