blob: 974779436492377aa251a55b3c389fc2eda9f5ae [file] [log] [blame]
Enrico Granataf5545f92013-01-10 22:08:35 +00001# coding=utf8
2"""
3Test that the C++11 support for char16_t and char32_t works correctly.
4"""
5
6import os, time
7import unittest2
8import lldb
9from lldbtest import *
10import lldbutil
11
12class 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
Matt Kopec93d8e422013-07-31 17:56:22 +000023 @expectedFailureIcc # ICC (13.1) does not emit the DW_TAG_base_type for char16_t and char32_t.
Enrico Granataf5545f92013-01-10 22:08:35 +000024 @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",
Enrico Granata3f4844e2013-01-11 03:01:25 +000059 substrs = ['(const char16_t *) cs16 = ','(const char32_t *) cs32 = ','u"hello world ྒྙྐ"','U"hello world ྒྙྐ"'])
Enrico Granataf5545f92013-01-10 22:08:35 +000060
61 # Check that we correctly report the non-const types
62 self.expect("frame variable s16 s32",
Enrico Granata3f4844e2013-01-11 03:01:25 +000063 substrs = ['(char16_t *) s16 = ','(char32_t *) s32 = ','u"ﺸﺵۻ"','U"ЕЙРГЖО"'])
Enrico Granataf5545f92013-01-10 22:08:35 +000064
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
Enrico Granata3f4844e2013-01-11 03:01:25 +000074 # check that the new strings show
Enrico Granataf5545f92013-01-10 22:08:35 +000075 self.expect("frame variable s16 s32",
76 substrs = ['(char16_t *) s16 = 0x','(char32_t *) s32 = ','"色ハ匂ヘト散リヌルヲ"','"෴"'])
77
Enrico Granatacd8cd612013-01-14 23:53:26 +000078 # 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
Enrico Granataf5545f92013-01-10 22:08:35 +000082if __name__ == '__main__':
83 import atexit
84 lldb.SBDebugger.Initialize()
85 atexit.register(lambda: lldb.SBDebugger.Terminate())
86 unittest2.main()