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 ObjCDataFormatterNSContainer(ObjCDataFormatterTestCase):
16
17    @skipUnlessDarwin
18    def test_nscontainers_with_run_command(self):
19        """Test formatters for  NS container classes."""
20        self.appkit_tester_impl(self.nscontainers_data_formatter_commands)
21
22    def nscontainers_data_formatter_commands(self):
23        self.expect(
24            'frame variable newArray nsDictionary newDictionary nscfDictionary cfDictionaryRef newMutableDictionary newMutableDictionaryRef cfarray_ref mutable_array_ref',
25            substrs=[
26                '(NSArray *) newArray = ',
27                ' @"50 elements"',
28                '(NSDictionary *) nsDictionary = ',
29                ' 2 key/value pairs',
30                '(NSDictionary *) newDictionary = ',
31                ' 12 key/value pairs',
32                '(NSDictionary *) nscfDictionary = ',
33                ' 4 key/value pairs',
34                '(CFDictionaryRef) cfDictionaryRef = ',
35                ' 2 key/value pairs',
36                '(NSDictionary *) newMutableDictionary = ',
37                ' 21 key/value pairs',
38                '(CFMutableDictionaryRef) newMutableDictionaryRef = ',
39                ' 21 key/value pairs',
40                '(CFArrayRef) cfarray_ref = ',
41                ' @"3 elements"',
42                '(CFMutableArrayRef) mutable_array_ref = ',
43                ' @"11 elements"',
44            ])
45
46        self.expect(
47            'frame variable -d run-target *nscfDictionary',
48            patterns=[
49                '\(__NSCFDictionary\) \*nscfDictionary =',
50                'key = 0x.* @"foo"',
51                'value = 0x.* @"foo"',
52                'key = 0x.* @"bar"',
53                'value = 0x.* @"bar"',
54                'key = 0x.* @"baz"',
55                'value = 0x.* @"baz"',
56                'key = 0x.* @"quux"',
57                'value = 0x.* @"quux"',
58                ])
59
60
61        self.expect(
62            'frame variable -d run-target *cfDictionaryRef',
63            patterns=[
64                '\(const __CFDictionary\) \*cfDictionaryRef =',
65                'key = 0x.* @"foo"',
66                'value = 0x.* @"foo"',
67                'key = 0x.* @"bar"',
68                'value = 0x.* @"bar"',
69                ])
70
71
72        self.expect(
73          'frame var nscfSet cfSetRef',
74          substrs=[
75          '(NSSet *) nscfSet = ',
76          '2 elements',
77          '(CFSetRef) cfSetRef = ',
78          '2 elements',
79          ])
80
81        self.expect(
82          'frame variable -d run-target *nscfSet',
83          patterns=[
84              '\(__NSCFSet\) \*nscfSet =',
85              '\[0\] = 0x.* @".*"',
86              '\[1\] = 0x.* @".*"',
87                    ])
88
89        self.expect(
90          'frame variable -d run-target *cfSetRef',
91          patterns=[
92              '\(const __CFSet\) \*cfSetRef =',
93              '\[0\] = 0x.* @".*"',
94              '\[1\] = 0x.* @".*"',
95                    ])
96
97        self.expect(
98            'frame variable iset1 iset2 imset',
99            substrs=['4 indexes', '512 indexes', '10 indexes'])
100
101        self.expect(
102            'frame variable binheap_ref',
103            substrs=['(CFBinaryHeapRef) binheap_ref = ', '@"21 items"'])
104
105        self.expect(
106            'expression -d run -- (NSArray*)[NSArray new]',
107            substrs=['@"0 elements"'])
108