Home | History | Annotate | Download | only in char1632_t
      1 # coding=utf8
      2 """
      3 Test that the C++11 support for char16_t and char32_t works correctly.
      4 """
      5 
      6 import os, time
      7 import unittest2
      8 import lldb
      9 from lldbtest import *
     10 import lldbutil
     11 
     12 class Char1632TestCase(TestBase):
     13 
     14     mydir = os.path.join("lang", "cpp", "char1632_t")
     15 
     16     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     17     @dsym_test
     18     def test_with_dsym(self):
     19         """Test that the C++11 support for char16_t and char32_t works correctly."""
     20         self.buildDsym()
     21         self.char1632()
     22 
     23     @expectedFailureIcc # ICC (13.1) does not emit the DW_TAG_base_type for char16_t and char32_t.
     24     @dwarf_test
     25     def test_with_dwarf(self):
     26         """Test that the C++11 support for char16_t and char32_t works correctly."""
     27         self.buildDwarf()
     28         self.char1632()
     29 
     30     def setUp(self):
     31         # Call super's setUp().
     32         TestBase.setUp(self)
     33         # Find the line number to break for main.cpp.
     34         self.source = 'main.cpp'
     35         self.line = line_number(self.source, '// Set break point at this line.')
     36 
     37     def char1632(self):
     38         """Test that the C++11 support for char16_t and char32_t works correctly."""
     39         exe = os.path.join(os.getcwd(), "a.out")
     40 
     41         # Create a target by the debugger.
     42         target = self.dbg.CreateTarget(exe)
     43         self.assertTrue(target, VALID_TARGET)
     44 
     45         # Break on the struct declration statement in main.cpp.
     46         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line)
     47 
     48         # Now launch the process, and do not stop at entry point.
     49         process = target.LaunchSimple(None, None, os.getcwd())
     50 
     51         if not process:
     52             self.fail("SBTarget.Launch() failed")
     53 
     54         if self.TraceOn():
     55              self.runCmd("frame variable")
     56 
     57         # Check that we correctly report the const types
     58         self.expect("frame variable cs16 cs32",
     59             substrs = ['(const char16_t *) cs16 = ','(const char32_t *) cs32 = ','u"hello world "','U"hello world "'])
     60 
     61         # Check that we correctly report the non-const types
     62         self.expect("frame variable s16 s32",
     63             substrs = ['(char16_t *) s16 = ','(char32_t *) s32 = ','u""','U""'])
     64 
     65         self.runCmd("next") # step to after the string is nullified
     66 
     67         # check that we don't crash on NULL
     68         self.expect("frame variable s32",
     69             substrs = ['(char32_t *) s32 = 0x00000000'])
     70 
     71         self.runCmd("next")
     72         self.runCmd("next")
     73 
     74         # check that the new strings show
     75         self.expect("frame variable s16 s32",
     76             substrs = ['(char16_t *) s16 = 0x','(char32_t *) s32 = ','""','""'])
     77 
     78         # Check that we can run expressions that return charN_t
     79         self.expect("expression u'a'",substrs = ['(char16_t) $',"61 u'a'"])
     80         self.expect("expression U'a'",substrs = ['(char32_t) $',"61 U'a'"])
     81 
     82 if __name__ == '__main__':
     83     import atexit
     84     lldb.SBDebugger.Initialize()
     85     atexit.register(lambda: lldb.SBDebugger.Terminate())
     86     unittest2.main()
     87