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 ObjCDataFormatterKVO(ObjCDataFormatterTestCase): 16 17 def test_kvo_with_run_command(self): 18 """Test the behavior of formatters when KVO is in use.""" 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 # as long as KVO is implemented by subclassing, this test should succeed 41 # we should be able to dynamically figure out that the KVO implementor class 42 # is a subclass of Molecule, and use the appropriate summary for it 43 self.runCmd("type summary add -s JustAMoleculeHere Molecule") 44 self.expect('frame variable molecule', substrs=['JustAMoleculeHere']) 45 self.runCmd("next") 46 self.expect("thread list", substrs=['stopped', 'step over']) 47 self.expect('frame variable molecule', substrs=['JustAMoleculeHere']) 48 49 self.runCmd("next") 50 # check that NSMutableDictionary's formatter is not confused when 51 # dealing with a KVO'd dictionary 52 self.expect( 53 'frame variable newMutableDictionary', 54 substrs=[ 55 '(NSDictionary *) newMutableDictionary = ', 56 ' 21 key/value pairs' 57 ]) 58 59 lldbutil.run_break_set_by_symbol(self, '-[Molecule setAtoms:]') 60 61 self.runCmd("continue") 62 self.expect("frame variable _cmd", substrs=['setAtoms:']) 63