1# encoding: utf-8
2"""
3Test lldb data formatter subsystem.
4"""
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase
13
14
15class ObjCDataFormatterKVO(ObjCDataFormatterTestCase):
16
17    @skipUnlessDarwin
18    def test_kvo_with_run_command(self):
19        """Test the behavior of formatters when KVO is in use."""
20        self.build()
21        self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
22            self, '// Set break point at this line.',
23            lldb.SBFileSpec('main.m', False))
24
25        # The stop reason of the thread should be breakpoint.
26        self.expect(
27            "thread list",
28            STOPPED_DUE_TO_BREAKPOINT,
29            substrs=['stopped', 'stop reason = breakpoint'])
30
31        # This is the function to remove the custom formats in order to have a
32        # clean slate for the next test case.
33        def cleanup():
34            self.runCmd('type format clear', check=False)
35            self.runCmd('type summary clear', check=False)
36            self.runCmd('type synth clear', check=False)
37
38        # Execute the cleanup function during test case tear down.
39        self.addTearDownHook(cleanup)
40
41        # as long as KVO is implemented by subclassing, this test should succeed
42        # we should be able to dynamically figure out that the KVO implementor class
43        # is a subclass of Molecule, and use the appropriate summary for it
44        self.runCmd("type summary add -s JustAMoleculeHere Molecule")
45        self.expect('frame variable molecule', substrs=['JustAMoleculeHere'])
46        self.runCmd("next")
47        self.expect("thread list", substrs=['stopped', 'step over'])
48        self.expect('frame variable molecule', substrs=['JustAMoleculeHere'])
49
50        self.runCmd("next")
51        # check that NSMutableDictionary's formatter is not confused when
52        # dealing with a KVO'd dictionary
53        self.expect(
54            'frame variable newMutableDictionary',
55            substrs=[
56                '(NSDictionary *) newMutableDictionary = ',
57                ' 21 key/value pairs'
58            ])
59
60        lldbutil.run_break_set_by_regexp(self, 'setAtoms')
61
62        self.runCmd("continue")
63        self.expect("frame variable _cmd", substrs=['setAtoms:'])
64