199451b44SJordan Rupprecht# encoding: utf-8 299451b44SJordan Rupprecht""" 399451b44SJordan RupprechtTest lldb data formatter subsystem. 499451b44SJordan Rupprecht""" 599451b44SJordan Rupprecht 699451b44SJordan Rupprecht 799451b44SJordan Rupprechtimport lldb 899451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 1099451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprechtfrom ObjCDataFormatterTestCase import ObjCDataFormatterTestCase 1399451b44SJordan Rupprecht 1499451b44SJordan Rupprecht 1599451b44SJordan Rupprechtclass ObjCDataFormatterKVO(ObjCDataFormatterTestCase): 1699451b44SJordan Rupprecht 1799451b44SJordan Rupprecht def test_kvo_with_run_command(self): 1899451b44SJordan Rupprecht """Test the behavior of formatters when KVO is in use.""" 1999451b44SJordan Rupprecht self.build() 2099451b44SJordan Rupprecht self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( 2199451b44SJordan Rupprecht self, '// Set break point at this line.', 2299451b44SJordan Rupprecht lldb.SBFileSpec('main.m', False)) 2399451b44SJordan Rupprecht 2499451b44SJordan Rupprecht # The stop reason of the thread should be breakpoint. 2599451b44SJordan Rupprecht self.expect( 2699451b44SJordan Rupprecht "thread list", 2799451b44SJordan Rupprecht STOPPED_DUE_TO_BREAKPOINT, 2899451b44SJordan Rupprecht substrs=['stopped', 'stop reason = breakpoint']) 2999451b44SJordan Rupprecht 3099451b44SJordan Rupprecht # This is the function to remove the custom formats in order to have a 3199451b44SJordan Rupprecht # clean slate for the next test case. 3299451b44SJordan Rupprecht def cleanup(): 3399451b44SJordan Rupprecht self.runCmd('type format clear', check=False) 3499451b44SJordan Rupprecht self.runCmd('type summary clear', check=False) 3599451b44SJordan Rupprecht self.runCmd('type synth clear', check=False) 3699451b44SJordan Rupprecht 3799451b44SJordan Rupprecht # Execute the cleanup function during test case tear down. 3899451b44SJordan Rupprecht self.addTearDownHook(cleanup) 3999451b44SJordan Rupprecht 4099451b44SJordan Rupprecht # as long as KVO is implemented by subclassing, this test should succeed 4199451b44SJordan Rupprecht # we should be able to dynamically figure out that the KVO implementor class 4299451b44SJordan Rupprecht # is a subclass of Molecule, and use the appropriate summary for it 4399451b44SJordan Rupprecht self.runCmd("type summary add -s JustAMoleculeHere Molecule") 4499451b44SJordan Rupprecht self.expect('frame variable molecule', substrs=['JustAMoleculeHere']) 4599451b44SJordan Rupprecht self.runCmd("next") 4699451b44SJordan Rupprecht self.expect("thread list", substrs=['stopped', 'step over']) 4799451b44SJordan Rupprecht self.expect('frame variable molecule', substrs=['JustAMoleculeHere']) 4899451b44SJordan Rupprecht 4999451b44SJordan Rupprecht self.runCmd("next") 5099451b44SJordan Rupprecht # check that NSMutableDictionary's formatter is not confused when 5199451b44SJordan Rupprecht # dealing with a KVO'd dictionary 5299451b44SJordan Rupprecht self.expect( 5399451b44SJordan Rupprecht 'frame variable newMutableDictionary', 5499451b44SJordan Rupprecht substrs=[ 5599451b44SJordan Rupprecht '(NSDictionary *) newMutableDictionary = ', 5699451b44SJordan Rupprecht ' 21 key/value pairs' 5799451b44SJordan Rupprecht ]) 5899451b44SJordan Rupprecht 59*833882b3SJim Ingham lldbutil.run_break_set_by_symbol(self, '-[Molecule setAtoms:]') 6099451b44SJordan Rupprecht 6199451b44SJordan Rupprecht self.runCmd("continue") 6299451b44SJordan Rupprecht self.expect("frame variable _cmd", substrs=['setAtoms:']) 63