blob: 885bec8012e86761e9928c4af8677452d2db3467 [file] [log] [blame]
Enrico Granatab2698cd2012-09-13 18:27:09 +00001"""
2Test lldb data formatter subsystem.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import datetime
Jim Ingham63dfc722012-09-22 00:05:11 +000010import lldbutil
Enrico Granatab2698cd2012-09-13 18:27:09 +000011
Enrico Granata54ed7e12015-08-25 23:55:10 +000012class NSArraySyntheticTestCase(TestBase):
Enrico Granatab2698cd2012-09-13 18:27:09 +000013
Greg Clayton4570d3e2013-12-10 23:19:29 +000014 mydir = TestBase.compute_mydir(__file__)
Enrico Granatab2698cd2012-09-13 18:27:09 +000015
Enrico Granatab2698cd2012-09-13 18:27:09 +000016 def setUp(self):
17 # Call super's setUp().
18 TestBase.setUp(self)
19 # Find the line number to break at.
20 self.line = line_number('main.m', '// Set break point at this line.')
21
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000022 @skipUnlessDarwin
23 def test_rdar11086338_with_run_command(self):
Enrico Granatab2698cd2012-09-13 18:27:09 +000024 """Test that NSArray reports its synthetic children properly."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000025 self.build()
Enrico Granatab2698cd2012-09-13 18:27:09 +000026 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
27
Jim Ingham63dfc722012-09-22 00:05:11 +000028 lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
Enrico Granatab2698cd2012-09-13 18:27:09 +000029
Sean Callanan05834cd2015-07-01 23:56:30 +000030 self.runCmd("run", RUN_SUCCEEDED)
Enrico Granatab2698cd2012-09-13 18:27:09 +000031
32 # The stop reason of the thread should be breakpoint.
33 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
34 substrs = ['stopped',
35 'stop reason = breakpoint'])
36
37 # This is the function to remove the custom formats in order to have a
38 # clean slate for the next test case.
39 def cleanup():
40 self.runCmd('type format clear', check=False)
41 self.runCmd('type summary clear', check=False)
42 self.runCmd('type synth clear', check=False)
43
44 # Execute the cleanup function during test case tear down.
45 self.addTearDownHook(cleanup)
46
47 # Now check that we are displaying Cocoa classes correctly
48 self.expect('frame variable arr',
Enrico Granata675f49b2015-10-07 18:36:53 +000049 substrs = ['@"6 elements"'])
Enrico Granatab2698cd2012-09-13 18:27:09 +000050 self.expect('frame variable other_arr',
Enrico Granata675f49b2015-10-07 18:36:53 +000051 substrs = ['@"4 elements"'])
Enrico Granatab2698cd2012-09-13 18:27:09 +000052 self.expect('frame variable arr --ptr-depth 1',
Enrico Granata675f49b2015-10-07 18:36:53 +000053 substrs = ['@"6 elements"','[0] = 0x','[1] = 0x','[2] = 0x','[3] = 0x','[4] = 0x','[5] = 0x'])
Enrico Granatab2698cd2012-09-13 18:27:09 +000054 self.expect('frame variable other_arr --ptr-depth 1',
Enrico Granata675f49b2015-10-07 18:36:53 +000055 substrs = ['@"4 elements"','[0] = 0x','[1] = 0x','[2] = 0x','[3] = 0x'])
Enrico Granatab2698cd2012-09-13 18:27:09 +000056 self.expect('frame variable arr --ptr-depth 1 -d no-run-target',
Enrico Granata675f49b2015-10-07 18:36:53 +000057 substrs = ['@"6 elements"','@"hello"','@"world"','@"this"','@"is"','@"me"','@"http://www.apple.com'])
Enrico Granatab2698cd2012-09-13 18:27:09 +000058 self.expect('frame variable other_arr --ptr-depth 1 -d no-run-target',
Enrico Granata675f49b2015-10-07 18:36:53 +000059 substrs = ['@"4 elements"','(int)5','@"a string"','@"6 elements"'])
Enrico Granatab2698cd2012-09-13 18:27:09 +000060 self.expect('frame variable other_arr --ptr-depth 2 -d no-run-target',
Enrico Granata675f49b2015-10-07 18:36:53 +000061 substrs = ['@"4 elements"','@"6 elements" {','@"hello"','@"world"','@"this"','@"is"','@"me"','@"http://www.apple.com'])
Enrico Granatab2698cd2012-09-13 18:27:09 +000062
Enrico Granata44818162012-10-24 01:23:57 +000063 self.assertTrue(self.frame().FindVariable("arr").MightHaveChildren(), "arr says it does not have children!")
64 self.assertTrue(self.frame().FindVariable("other_arr").MightHaveChildren(), "arr says it does not have children!")
65
Enrico Granatab2698cd2012-09-13 18:27:09 +000066
67if __name__ == '__main__':
68 import atexit
69 lldb.SBDebugger.Initialize()
70 atexit.register(lambda: lldb.SBDebugger.Terminate())
71 unittest2.main()