1""" 2Test lldb data formatter subsystem. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class NSDictionarySyntheticTestCase(TestBase): 14 15 def setUp(self): 16 # Call super's setUp(). 17 TestBase.setUp(self) 18 # Find the line number to break at. 19 self.line = line_number('main.m', '// Set break point at this line.') 20 21 @skipUnlessDarwin 22 def test_rdar11988289_with_run_command(self): 23 """Test that NSDictionary reports its synthetic children properly.""" 24 self.build() 25 self.run_tests() 26 27 @skipUnlessDarwin 28 def test_rdar11988289_with_run_command_no_const(self): 29 """Test that NSDictionary reports its synthetic children properly.""" 30 disable_constant_classes = { 31 'CC': 32 'xcrun clang', # FIXME: Remove when flags are available upstream. 33 'CFLAGS_EXTRAS': 34 '-fno-constant-nsnumber-literals ' + 35 '-fno-constant-nsarray-literals ' + 36 '-fno-constant-nsdictionary-literals' 37 } 38 self.build(dictionary=disable_constant_classes) 39 self.run_tests() 40 41 def run_tests(self): 42 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 43 44 lldbutil.run_break_set_by_file_and_line( 45 self, "main.m", self.line, num_expected_locations=1, loc_exact=True) 46 47 self.runCmd("run", RUN_SUCCEEDED) 48 49 # The stop reason of the thread should be breakpoint. 50 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 51 substrs=['stopped', 52 'stop reason = breakpoint']) 53 54 # This is the function to remove the custom formats in order to have a 55 # clean slate for the next test case. 56 def cleanup(): 57 self.runCmd('type format clear', check=False) 58 self.runCmd('type summary clear', check=False) 59 self.runCmd('type synth clear', check=False) 60 61 # Execute the cleanup function during test case tear down. 62 self.addTearDownHook(cleanup) 63 64 # Now check that we are displaying Cocoa classes correctly 65 self.expect('frame variable dictionary', 66 substrs=['3 key/value pairs']) 67 self.expect('frame variable mutabledict', 68 substrs=['4 key/value pairs']) 69 self.expect( 70 'frame variable dictionary --ptr-depth 1', 71 substrs=[ 72 '3 key/value pairs', 73 '[0] = ', 74 'key = 0x', 75 'value = 0x', 76 '[1] = ', 77 '[2] = ']) 78 self.expect( 79 'frame variable mutabledict --ptr-depth 1', 80 substrs=[ 81 '4 key/value pairs', 82 '[0] = ', 83 'key = 0x', 84 'value = 0x', 85 '[1] = ', 86 '[2] = ', 87 '[3] = ']) 88 self.expect( 89 'frame variable dictionary --ptr-depth 1 --dynamic-type no-run-target', 90 substrs=[ 91 '3 key/value pairs', 92 '@"bar"', 93 '@"2 elements"', 94 '@"baz"', 95 '2 key/value pairs']) 96 self.expect( 97 'frame variable mutabledict --ptr-depth 1 --dynamic-type no-run-target', 98 substrs=[ 99 '4 key/value pairs', 100 '(int)23', 101 '@"123"', 102 '@"http://www.apple.com"', 103 '@"sourceofstuff"', 104 '3 key/value pairs']) 105 self.expect( 106 'frame variable mutabledict --ptr-depth 2 --dynamic-type no-run-target', 107 substrs=[ 108 '4 key/value pairs', 109 '(int)23', 110 '@"123"', 111 '@"http://www.apple.com"', 112 '@"sourceofstuff"', 113 '3 key/value pairs', 114 '@"bar"', 115 '@"2 elements"']) 116 self.expect( 117 'frame variable mutabledict --ptr-depth 3 --dynamic-type no-run-target', 118 substrs=[ 119 '4 key/value pairs', 120 '(int)23', 121 '@"123"', 122 '@"http://www.apple.com"', 123 '@"sourceofstuff"', 124 '3 key/value pairs', 125 '@"bar"', 126 '@"2 elements"', 127 '(int)1', 128 '@"two"']) 129 130 self.assertTrue( 131 self.frame().FindVariable("dictionary").MightHaveChildren(), 132 "dictionary says it does not have children!") 133 self.assertTrue( 134 self.frame().FindVariable("mutabledict").MightHaveChildren(), 135 "mutable says it does not have children!") 136