blob: 8c33a95105c04f0a8dc1ad6debe0a8881889026c [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
16 def test_expr_with_dsym(self):
17 self.buildDsym()
18 self.expr()
19
20 def test_expr_with_dwarf(self):
21 self.buildDwarf()
22 self.expr()
23
24 def setUp(self):
25 # Call super's setUp().
26 TestBase.setUp(self)
27 # Find the line number to break inside main().
28 self.line = line_number('main.m', '// Set breakpoint 0 here.')
29
30 def applies(self):
31 if platform.system() != "Darwin":
32 return False
33 if StrictVersion('12.0.0') > platform.release():
34 return False
35
36 return True
37
38 def common_setup(self):
39 exe = os.path.join(os.getcwd(), "a.out")
40 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
41
42 # Break inside the foo function which takes a bar_ptr argument.
43 self.expect("breakpoint set -f main.m -l %d" % self.line, BREAKPOINT_CREATED,
44 startstr = "Breakpoint created")
45
46 self.runCmd("run", RUN_SUCCEEDED)
47
48 # The stop reason of the thread should be breakpoint.
49 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
50 substrs = ['stopped',
51 'stop reason = breakpoint'])
52
53 # The breakpoint should have a hit count of 1.
54 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
55 substrs = [' resolved, hit count = 1'])
56
57 def expr(self):
58 if not self.applies():
59 return
60
61 print "Hello!"
62
63 self.common_setup()
64
65 self.expect("expr -o -- immutable_array[0]", VARIABLES_DISPLAYED_CORRECTLY,
66 substrs = ["foo"])
67
68 self.expect("expr -o -- mutable_array[0]", VARIABLES_DISPLAYED_CORRECTLY,
69 substrs = ["foo"])
70
71 self.expect("expr -o -- mutable_array[0] = @\"bar\"", VARIABLES_DISPLAYED_CORRECTLY,
72 substrs = ["bar"])
73
74 self.expect("expr -o -- mutable_array[0]", VARIABLES_DISPLAYED_CORRECTLY,
75 substrs = ["bar"])
76
77 self.expect("expr -o -- immutable_dictionary[@\"key\"]", VARIABLES_DISPLAYED_CORRECTLY,
78 substrs = ["value"])
79
80 self.expect("expr -o -- mutable_dictionary[@\"key\"]", VARIABLES_DISPLAYED_CORRECTLY,
81 substrs = ["value"])
82
83 self.expect("expr -o -- mutable_dictionary[@\"key\"] = @\"object\"", VARIABLES_DISPLAYED_CORRECTLY,
84 substrs = ["object"])
85
86 self.expect("expr -o -- mutable_dictionary[@\"key\"]", VARIABLES_DISPLAYED_CORRECTLY,
87 substrs = ["object"])
88
89 self.expect("expr -o -- @[ @\"foo\", @\"bar\" ]", VARIABLES_DISPLAYED_CORRECTLY,
90 substrs = ["NSArray", "foo", "bar"])
91
92 self.expect("expr -o -- @{ @\"key\" : @\"object\" }", VARIABLES_DISPLAYED_CORRECTLY,
93 substrs = ["NSDictionary", "key", "object"])
94
95 self.expect("expr -o -- @'a'", VARIABLES_DISPLAYED_CORRECTLY,
96 substrs = ["NSNumber", str(ord('a'))])
97
98 self.expect("expr -o -- @1", VARIABLES_DISPLAYED_CORRECTLY,
99 substrs = ["NSNumber", "1"])
100
101 self.expect("expr -o -- @1l", VARIABLES_DISPLAYED_CORRECTLY,
102 substrs = ["NSNumber", "1"])
103
104 self.expect("expr -o -- @1ul", VARIABLES_DISPLAYED_CORRECTLY,
105 substrs = ["NSNumber", "1"])
106
107 self.expect("expr -o -- @1ll", VARIABLES_DISPLAYED_CORRECTLY,
108 substrs = ["NSNumber", "1"])
109
110 self.expect("expr -o -- @1ull", VARIABLES_DISPLAYED_CORRECTLY,
111 substrs = ["NSNumber", "1"])
112
113 #<rdar://problem/10924364>
114 #self.expect("expr -o -- @123.45", VARIABLES_DISPLAYED_CORRECTLY,
115 # substrs = ["NSNumber", "123.45"])
116 #self.expect("expr -o -- @123.45f", VARIABLES_DISPLAYED_CORRECTLY,
117 # substrs = ["NSNumber", "123.45"])
118
119
120if __name__ == '__main__':
121 import atexit
122 lldb.SBDebugger.Initialize()
123 atexit.register(lambda: lldb.SBDebugger.Terminate())
124 unittest2.main()