1""" 2Test that objective-c constant strings are generated correctly by the expression 3parser. 4""" 5 6import os, time 7import unittest2 8import lldb 9from lldbtest import * 10import lldbutil 11 12@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 13class ConstStringTestCase(TestBase): 14 15 mydir = os.path.join("lang", "objc", "foundation") 16 d = {'OBJC_SOURCES': 'const-strings.m'} 17 18 @dsym_test 19 def test_break_with_dsym(self): 20 """Test constant string generation amd comparison by the expression parser.""" 21 self.buildDsym(dictionary=self.d) 22 self.setTearDownCleanup(self.d) 23 self.objc_const_strings() 24 25 @dwarf_test 26 def test_break_with_dwarf(self): 27 """Test constant string generation amd comparison by the expression parser.""" 28 self.buildDwarf(dictionary=self.d) 29 self.setTearDownCleanup(self.d) 30 self.objc_const_strings() 31 32 def setUp(self): 33 # Call super's setUp(). 34 TestBase.setUp(self) 35 # Find the line number to break inside main(). 36 self.main_source = "const-strings.m" 37 self.line = line_number(self.main_source, '// Set breakpoint here.') 38 39 def objc_const_strings(self): 40 """Test constant string generation amd comparison by the expression parser.""" 41 exe = os.path.join(os.getcwd(), "a.out") 42 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 43 44 lldbutil.run_break_set_by_file_and_line (self, self.main_source, self.line, num_expected_locations=1, loc_exact=True) 45 46 self.runCmd("run", RUN_SUCCEEDED) 47 self.expect("process status", STOPPED_DUE_TO_BREAKPOINT, 48 substrs = [" at %s:%d" % (self.main_source, self.line), 49 "stop reason = breakpoint"]) 50 51 self.expect('expression (int)[str compare:@"hello"]', 52 startstr = "(int) $0 = 0") 53 self.expect('expression (int)[str compare:@"world"]', 54 startstr = "(int) $1 = -1") 55 56 # Test empty strings, too. 57 self.expect('expression (int)[@"" length]', 58 startstr = "(int) $2 = 0") 59 60 self.expect('expression (int)[@"123" length]', 61 startstr = "(int) $3 = 3") 62 63 64if __name__ == '__main__': 65 import atexit 66 lldb.SBDebugger.Initialize() 67 atexit.register(lambda: lldb.SBDebugger.Terminate()) 68 unittest2.main() 69