1 """Test the SBInputReader callbacks.""" 2 3 import os 4 import unittest2 5 import lldb 6 from lldbtest import TestBase, python_api_test, dwarf_test 7 8 9 class InputReaderCallbackCase(TestBase): 10 11 mydir = os.path.join("python_api", "input_reader") 12 13 @python_api_test 14 @dwarf_test 15 def test_with_dwarf_and_good_callback(self): 16 """Test the SBInputReader callbacks.""" 17 def callback(reader, notification, content): 18 global succeeded 19 if (notification == lldb.eInputReaderGotToken): 20 self.succeeded = True 21 return len(content) 22 self.buildDwarf() 23 self.input_reader_callback(callback) 24 25 def setUp(self): 26 # Call super's setUp(). 27 TestBase.setUp(self) 28 29 def input_reader_callback(self, callback): 30 """Test the SBInputReader callbacks.""" 31 self.succeeded = False 32 33 input_reader = lldb.SBInputReader() 34 input_reader.Initialize(self.dbg, callback, lldb.eInputReaderGranularityByte, "$", "^", False) 35 36 self.dbg.PushInputReader(input_reader) 37 self.dbg.DispatchInput("Hello!$") 38 self.assertFalse(self.dbg.InputReaderIsTopReader(input_reader)) 39 self.assertTrue(self.succeeded) 40 41 42 if __name__ == '__main__': 43 import atexit 44 lldb.SBDebugger.Initialize() 45 atexit.register(lambda: lldb.SBDebugger.Terminate()) 46 unittest2.main() 47