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