1"""
2Test lldb data formatter subsystem.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import datetime
10import lldbutil
11
12class DataFormatterOneIsSingularTestCase(TestBase):
13
14    mydir = os.path.join("functionalities", "data-formatter", "rdar-3534688")
15
16    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
17    @dsym_test
18    def test_one_is_singular_with_dsym_and_run_command(self):
19        """Test that 1 item is not as reported as 1 items."""
20        self.buildDsym()
21        self.oneness_data_formatter_commands()
22
23    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
24    @dwarf_test
25    def test_one_is_singular_with_dwarf_and_run_command(self):
26        """Test that 1 item is not as reported as 1 items."""
27        self.buildDwarf()
28        self.oneness_data_formatter_commands()
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 oneness_data_formatter_commands(self):
37        """Test that 1 item is not as reported as 1 items."""
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 key',
61                    substrs = ['@"1 object"'])
62        self.expect('frame variable key', matching=False,
63                    substrs = ['1 objects'])
64        self.expect('frame variable value',
65                    substrs = ['@"1 object"'])
66        self.expect('frame variable value', matching=False,
67                    substrs = ['1 objects'])
68        self.expect('frame variable dict',
69                    substrs = ['1 key/value pair'])
70        self.expect('frame variable dict', matching=False,
71                    substrs = ['1 key/value pairs'])
72        self.expect('frame variable mutable_bag_ref',
73                    substrs = ['@"1 value"'])
74        self.expect('frame variable mutable_bag_ref', matching=False,
75                    substrs = ['1 values'])
76        self.expect('frame variable nscounted_set',
77                    substrs = ['1 object'])
78        self.expect('frame variable nscounted_set', matching=False,
79                    substrs = ['1 objects'])
80        self.expect('frame variable imset',
81                    substrs = ['1 index'])
82        self.expect('frame variable imset', matching=False,
83                    substrs = ['1 indexes'])
84        self.expect('frame variable binheap_ref',
85                    substrs = ['@"1 item"'])
86        self.expect('frame variable binheap_ref', matching=False,
87                    substrs = ['1 items'])
88        self.expect('frame variable nsset',
89                    substrs = ['1 object'])
90        self.expect('frame variable nsset', matching=False,
91                    substrs = ['1 objects'])
92        self.expect('frame variable immutableData',
93                    substrs = ['1 byte'])
94        self.expect('frame variable immutableData', matching=False,
95                    substrs = ['1 bytes'])
96
97
98if __name__ == '__main__':
99    import atexit
100    lldb.SBDebugger.Initialize()
101    atexit.register(lambda: lldb.SBDebugger.Terminate())
102    unittest2.main()
103