1# coding=utf8 2""" 3Test that C++ supports wchar_t correctly. 4""" 5 6 7 8import lldb 9from lldbsuite.test.lldbtest import * 10import lldbsuite.test.lldbutil as lldbutil 11 12 13class CxxWCharTTestCase(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 17 def setUp(self): 18 # Call super's setUp(). 19 TestBase.setUp(self) 20 # Find the line number to break for main.cpp. 21 self.source = 'main.cpp' 22 self.line = line_number( 23 self.source, '// Set break point at this line.') 24 25 def test(self): 26 """Test that C++ supports wchar_t correctly.""" 27 self.build() 28 exe = self.getBuildArtifact("a.out") 29 30 # Create a target by the debugger. 31 target = self.dbg.CreateTarget(exe) 32 self.assertTrue(target, VALID_TARGET) 33 34 # Break on the struct declration statement in main.cpp. 35 lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line) 36 37 # Now launch the process, and do not stop at entry point. 38 process = target.LaunchSimple( 39 None, None, self.get_process_working_directory()) 40 41 if not process: 42 self.fail("SBTarget.Launch() failed") 43 44 # Check that we correctly report templates on wchar_t 45 self.expect("frame variable foo_y", 46 substrs=['(Foo<wchar_t>) foo_y = ']) 47 48 # Check that we correctly report templates on int 49 self.expect("frame variable foo_x", 50 substrs=['(Foo<int>) foo_x = ']) 51 52 # Check that we correctly report wchar_t 53 self.expect("frame variable foo_y.object", 54 substrs=['(wchar_t) foo_y.object = ']) 55 56 # Check that we correctly report int 57 self.expect("frame variable foo_x.object", 58 substrs=['(int) foo_x.object = ']) 59 60 # Check that we can run expressions that return wchar_t 61 self.expect("expression L'a'", substrs=['(wchar_t) $', "L'a'"]) 62 63 # Mazel Tov if this works! 64 self.expect("frame variable mazeltov", 65 substrs=['(const wchar_t *) mazeltov = ', 'L"מזל טוב"']) 66 67 self.expect( 68 "frame variable ws_NULL", 69 substrs=['(wchar_t *) ws_NULL = 0x0']) 70 self.expect("frame variable ws_empty", substrs=[' L""']) 71 72 self.expect("frame variable array", substrs=[ 73 'L"Hey, I\'m a super wchar_t string']) 74 self.expect("frame variable array", substrs=['[0]'], matching=False) 75 76 self.expect('frame variable wchar_zero', substrs=["L'\\0'"]) 77 self.expect('expression wchar_zero', substrs=["L'\\0'"]) 78