blob: 257b887ae53f642b8ced6af03e0e99b8a8bd7dac [file] [log] [blame]
Sean Callanan5207a342011-08-10 21:05:52 +00001"""
2Tests that C strings work as expected in expressions
3"""
4
5from lldbtest import *
6
7class CStringsTestCase(TestBase):
8
9 mydir = os.path.join("lang", "c", "strings")
10
11 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
12 def test_with_dsym_and_run_command(self):
13 """Tests that C strings work as expected in expressions"""
14 self.buildDsym()
15 self.static_method_commands()
16
17 def test_with_dwarf_and_run_command(self):
18 """Tests that C strings work as expected in expressions"""
19 self.buildDwarf()
20 self.static_method_commands()
21
22 def setUp(self):
23 TestBase.setUp(self)
24
25 def set_breakpoint(self, line):
26 self.expect("breakpoint set -f main.c -l %d" % line,
27 BREAKPOINT_CREATED,
28 startstr = "Breakpoint created")
29
30 def static_method_commands(self):
31 """Tests that C strings work as expected in expressions"""
32 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
33
34 self.set_breakpoint(line_number('main.c', '// breakpoint 1'))
35
36 self.runCmd("process launch", RUN_SUCCEEDED)
37
38 self.expect("expression -- a[2]",
39 startstr = "(char) $0 = 'c'")
40
41 self.expect("expression -- z[2]",
42 startstr = "(const char) $1 = 'x'")
43
44 self.expect("expression -- (int)strlen(\"hello\")",
45 startstr = "(int) $2 = 5")
46
47 self.expect("expression -- \"world\"[2]",
48 startstr = "(const char) $3 = 'r'")
49
50 self.expect("expression -- \"\"[0]",
51 startstr = "(const char) $4 = '\\0'")
52
53if __name__ == '__main__':
54 import atexit
55 lldb.SBDebugger.Initialize()
56 atexit.register(lambda: lldb.SBDebugger.Terminate())
57 unittest2.main()