1"""Test that we properly vend children for a single entry NSDictionary""" 2 3 4 5import unittest2 6 7 8import lldb 9from lldbsuite.test.decorators import * 10from lldbsuite.test.lldbtest import * 11from lldbsuite.test import lldbutil 12 13 14class ObjCSingleEntryDictionaryTestCase(TestBase): 15 16 mydir = TestBase.compute_mydir(__file__) 17 18 def setUp(self): 19 # Call super's setUp(). 20 TestBase.setUp(self) 21 # Find the line number to break inside main(). 22 self.line = line_number('main.m', '// break here') 23 24 @skipUnlessDarwin 25 @expectedFailureAll(oslist=['watchos'], bugnumber="rdar://problem/34642736") # bug in NSDictionary formatting on watchos 26 def test_single_entry_dict(self): 27 self.build() 28 self.run_tests() 29 30 @skipUnlessDarwin 31 @expectedFailureAll(oslist=['watchos'], bugnumber="rdar://problem/34642736") # bug in NSDictionary formatting on watchos 32 def test_single_entry_dict_no_const(self): 33 disable_constant_classes = { 34 'CC': 35 'xcrun clang', # FIXME: Remove when flags are available upstream. 36 'CFLAGS_EXTRAS': 37 '-fno-constant-nsnumber-literals ' + 38 '-fno-constant-nsarray-literals ' + 39 '-fno-constant-nsdictionary-literals' 40 } 41 self.build(dictionary=disable_constant_classes) 42 self.run_tests() 43 44 def run_tests(self): 45 exe = self.getBuildArtifact("a.out") 46 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 47 48 # Break inside the foo function which takes a bar_ptr argument. 49 lldbutil.run_break_set_by_file_and_line( 50 self, "main.m", self.line, num_expected_locations=1, loc_exact=True) 51 52 self.runCmd("run", RUN_SUCCEEDED) 53 54 # The stop reason of the thread should be breakpoint. 55 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 56 substrs=['stopped', 57 'stop reason = breakpoint']) 58 59 # The breakpoint should have a hit count of 1. 60 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, 61 substrs=[' resolved, hit count = 1']) 62 63 d1 = self.frame().FindVariable("d1") 64 d1.SetPreferSyntheticValue(True) 65 d1.SetPreferDynamicValue(lldb.eDynamicCanRunTarget) 66 67 self.assertEqual( 68 d1.GetNumChildren(), 1, 69 "dictionary has != 1 child elements") 70 pair = d1.GetChildAtIndex(0) 71 pair.SetPreferSyntheticValue(True) 72 pair.SetPreferDynamicValue(lldb.eDynamicCanRunTarget) 73 74 self.assertEqual( 75 pair.GetNumChildren(), 2, 76 "pair has != 2 child elements") 77 78 key = pair.GetChildMemberWithName("key") 79 value = pair.GetChildMemberWithName("value") 80 81 key.SetPreferSyntheticValue(True) 82 key.SetPreferDynamicValue(lldb.eDynamicCanRunTarget) 83 value.SetPreferSyntheticValue(True) 84 value.SetPreferDynamicValue(lldb.eDynamicCanRunTarget) 85 86 self.assertEqual( 87 key.GetSummary(), '@"key"', 88 "key doesn't contain key") 89 self.assertEqual( 90 value.GetSummary(), '@"value"', 91 "value doesn't contain value") 92