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