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 ObjCDataFormatterNSPlain(ObjCDataFormatterTestCase): 16 17 def test_plain_objc_with_run_command(self): 18 """Test basic ObjC formatting behavior.""" 19 self.build() 20 self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( 21 self, '// Set break point at this line.', 22 lldb.SBFileSpec('main.m', False)) 23 24 # The stop reason of the thread should be breakpoint. 25 self.expect( 26 "thread list", 27 STOPPED_DUE_TO_BREAKPOINT, 28 substrs=['stopped', 'stop reason = breakpoint']) 29 30 # This is the function to remove the custom formats in order to have a 31 # clean slate for the next test case. 32 def cleanup(): 33 self.runCmd('type format clear', check=False) 34 self.runCmd('type summary clear', check=False) 35 self.runCmd('type synth clear', check=False) 36 37 # Execute the cleanup function during test case tear down. 38 self.addTearDownHook(cleanup) 39 40 self.runCmd("type summary add --summary-string \"${var%@}\" MyClass") 41 42 self.expect("frame variable object2", substrs=['MyOtherClass']) 43 44 self.expect("frame variable *object2", substrs=['MyOtherClass']) 45 46 # Now let's delete the 'MyClass' custom summary. 47 self.runCmd("type summary delete MyClass") 48 49 # The type format list should not show 'MyClass' at this point. 50 self.expect("type summary list", matching=False, substrs=['MyClass']) 51 52 self.runCmd("type summary add --summary-string \"a test\" MyClass") 53 54 self.expect( 55 "frame variable *object2", 56 substrs=['*object2 =', 'MyClass = a test', 'backup = ']) 57 58 self.expect( 59 "frame variable object2", matching=False, substrs=['a test']) 60 61 self.expect("frame variable object", substrs=['a test']) 62 63 self.expect("frame variable *object", substrs=['a test']) 64 65 self.expect( 66 'frame variable myclass', substrs=['(Class) myclass = NSValue']) 67 self.expect( 68 'frame variable myclass2', 69 substrs=['(Class) myclass2 = ', 'NS', 'String']) 70 self.expect( 71 'frame variable myclass3', substrs=['(Class) myclass3 = Molecule']) 72 self.expect( 73 'frame variable myclass4', 74 substrs=['(Class) myclass4 = NSMutableArray']) 75 self.expect( 76 'frame variable myclass5', substrs=['(Class) myclass5 = nil']) 77