• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Test lldb data formatter subsystem.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import datetime
10import lldbutil
11
12class DataFormatterRdar11988289TestCase(TestBase):
13
14    mydir = os.path.join("functionalities", "data-formatter", "rdar-11988289")
15
16    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
17    @dsym_test
18    def test_rdar11988289_with_dsym_and_run_command(self):
19        """Test that NSDictionary reports its synthetic children properly."""
20        self.buildDsym()
21        self.rdar11988289_tester()
22
23    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
24    @dwarf_test
25    def test_rdar11988289_with_dwarf_and_run_command(self):
26        """Test that NSDictionary reports its synthetic children properly."""
27        self.buildDwarf()
28        self.rdar11988289_tester()
29
30    def setUp(self):
31        # Call super's setUp().
32        TestBase.setUp(self)
33        # Find the line number to break at.
34        self.line = line_number('main.m', '// Set break point at this line.')
35
36    def rdar11988289_tester(self):
37        """Test that NSDictionary reports its synthetic children properly."""
38        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
39
40        lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
41
42        self.runCmd("run", RUN_SUCCEEDED)
43
44        # The stop reason of the thread should be breakpoint.
45        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
46            substrs = ['stopped',
47                       'stop reason = breakpoint'])
48
49        # This is the function to remove the custom formats in order to have a
50        # clean slate for the next test case.
51        def cleanup():
52            self.runCmd('type format clear', check=False)
53            self.runCmd('type summary clear', check=False)
54            self.runCmd('type synth clear', check=False)
55
56        # Execute the cleanup function during test case tear down.
57        self.addTearDownHook(cleanup)
58
59        # Now check that we are displaying Cocoa classes correctly
60        self.expect('frame variable dictionary',
61                    substrs = ['3 key/value pairs'])
62        self.expect('frame variable mutabledict',
63                    substrs = ['4 key/value pairs'])
64        self.expect('frame variable dictionary --ptr-depth 1',
65                    substrs = ['3 key/value pairs','[0] = {','key = 0x','value = 0x','[1] = {','[2] = {'])
66        self.expect('frame variable mutabledict --ptr-depth 1',
67                    substrs = ['4 key/value pairs','[0] = {','key = 0x','value = 0x','[1] = {','[2] = {','[3] = {'])
68        self.expect('frame variable dictionary --ptr-depth 1 --dynamic-type no-run-target',
69                    substrs = ['3 key/value pairs','@"bar"','@"2 objects"','@"baz"','2 key/value pairs'])
70        self.expect('frame variable mutabledict --ptr-depth 1 --dynamic-type no-run-target',
71                    substrs = ['4 key/value pairs','(int)23','@"123"','@"http://www.apple.com"','@"puartist"','3 key/value pairs'])
72        self.expect('frame variable mutabledict --ptr-depth 2 --dynamic-type no-run-target',
73        substrs = ['4 key/value pairs','(int)23','@"123"','@"http://www.apple.com"','@"puartist"','3 key/value pairs {','@"bar"','@"2 objects"'])
74        self.expect('frame variable mutabledict --ptr-depth 3 --dynamic-type no-run-target',
75        substrs = ['4 key/value pairs','(int)23','@"123"','@"http://www.apple.com"','@"puartist"','3 key/value pairs {','@"bar"','@"2 objects"','(int)1','@"two"'])
76
77        self.assertTrue(self.frame().FindVariable("dictionary").MightHaveChildren(), "dictionary says it does not have children!")
78        self.assertTrue(self.frame().FindVariable("mutabledict").MightHaveChildren(), "mutable says it does not have children!")
79
80
81if __name__ == '__main__':
82    import atexit
83    lldb.SBDebugger.Initialize()
84    atexit.register(lambda: lldb.SBDebugger.Terminate())
85    unittest2.main()
86