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 def test_plain_objc_with_run_command(self): 17 """Test basic ObjC formatting behavior.""" 18 self.build() 19 self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( 20 self, "// Set break point at this line.", lldb.SBFileSpec("main.m", False) 21 ) 22 23 # The stop reason of the thread should be breakpoint. 24 self.expect( 25 "thread list", 26 STOPPED_DUE_TO_BREAKPOINT, 27 substrs=["stopped", "stop reason = breakpoint"], 28 ) 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 59 self.expect("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("frame variable myclass", substrs=["(Class) myclass = NSValue"]) 66 self.expect( 67 "frame variable myclass2", substrs=["(Class) myclass2 = ", "NS", "String"] 68 ) 69 self.expect("frame variable myclass3", substrs=["(Class) myclass3 = Molecule"]) 70 self.expect( 71 "frame variable myclass4", substrs=["(Class) myclass4 = NSMutableArray"] 72 ) 73 self.expect("frame variable myclass5", substrs=["(Class) myclass5 = nil"]) 74