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        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
61
62        d1 = self.frame().FindVariable("d1")
63        d1.SetPreferSyntheticValue(True)
64        d1.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
65
66        self.assertEqual(
67            d1.GetNumChildren(), 1,
68            "dictionary has != 1 child elements")
69        pair = d1.GetChildAtIndex(0)
70        pair.SetPreferSyntheticValue(True)
71        pair.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
72
73        self.assertEqual(
74            pair.GetNumChildren(), 2,
75            "pair has != 2 child elements")
76
77        key = pair.GetChildMemberWithName("key")
78        value = pair.GetChildMemberWithName("value")
79
80        key.SetPreferSyntheticValue(True)
81        key.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
82        value.SetPreferSyntheticValue(True)
83        value.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
84
85        self.assertEqual(
86            key.GetSummary(), '@"key"',
87            "key doesn't contain key")
88        self.assertEqual(
89            value.GetSummary(), '@"value"',
90            "value doesn't contain value")
91