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    @expectedFailureAll(oslist=['watchos'], bugnumber="rdar://problem/34642736") # bug in NSDictionary formatting on watchos
25    def test_single_entry_dict(self):
26        self.build()
27        exe = self.getBuildArtifact("a.out")
28        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
29
30        # Break inside the foo function which takes a bar_ptr argument.
31        lldbutil.run_break_set_by_file_and_line(
32            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
33
34        self.runCmd("run", RUN_SUCCEEDED)
35
36        # The stop reason of the thread should be breakpoint.
37        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
38                    substrs=['stopped',
39                             'stop reason = breakpoint'])
40
41        # The breakpoint should have a hit count of 1.
42        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
43                    substrs=[' resolved, hit count = 1'])
44
45        d1 = self.frame().FindVariable("d1")
46        d1.SetPreferSyntheticValue(True)
47        d1.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
48
49        self.assertEqual(
50            d1.GetNumChildren(), 1,
51            "dictionary has != 1 child elements")
52        pair = d1.GetChildAtIndex(0)
53        pair.SetPreferSyntheticValue(True)
54        pair.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
55
56        self.assertEqual(
57            pair.GetNumChildren(), 2,
58            "pair has != 2 child elements")
59
60        key = pair.GetChildMemberWithName("key")
61        value = pair.GetChildMemberWithName("value")
62
63        key.SetPreferSyntheticValue(True)
64        key.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
65        value.SetPreferSyntheticValue(True)
66        value.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
67
68        self.assertEqual(
69            key.GetSummary(), '@"key"',
70            "key doesn't contain key")
71        self.assertEqual(
72            value.GetSummary(), '@"value"',
73            "value doesn't contain value")
74