blob: bd93ce827a5162d699c854bfd30f238ac7ef3b65 [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
23 @dwarf_test
24 def test_with_dwarf(self):
25 """Test that the C++11 support for char16_t and char32_t works correctly."""
26 self.buildDwarf()
27 self.char1632()
28
29 def setUp(self):
30 # Call super's setUp().
31 TestBase.setUp(self)
32 # Find the line number to break for main.cpp.
33 self.source = 'main.cpp'
34 self.line = line_number(self.source, '// Set break point at this line.')
35
36 def char1632(self):
37 """Test that the C++11 support for char16_t and char32_t works correctly."""
38 exe = os.path.join(os.getcwd(), "a.out")
39
40 # Create a target by the debugger.
41 target = self.dbg.CreateTarget(exe)
42 self.assertTrue(target, VALID_TARGET)
43
44 # Break on the struct declration statement in main.cpp.
45 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line)
46
47 # Now launch the process, and do not stop at entry point.
48 process = target.LaunchSimple(None, None, os.getcwd())
49
50 if not process:
51 self.fail("SBTarget.Launch() failed")
52
53 if self.TraceOn():
54 self.runCmd("frame variable")
55
56 # Check that we correctly report the const types
57 self.expect("frame variable cs16 cs32",
Enrico Granata3f4844e2013-01-11 03:01:25 +000058 substrs = ['(const char16_t *) cs16 = ','(const char32_t *) cs32 = ','u"hello world ྒྙྐ"','U"hello world ྒྙྐ"'])
Enrico Granataf5545f92013-01-10 22:08:35 +000059
60 # Check that we correctly report the non-const types
61 self.expect("frame variable s16 s32",
Enrico Granata3f4844e2013-01-11 03:01:25 +000062 substrs = ['(char16_t *) s16 = ','(char32_t *) s32 = ','u"ﺸﺵۻ"','U"ЕЙРГЖО"'])
Enrico Granataf5545f92013-01-10 22:08:35 +000063
64 self.runCmd("next") # step to after the string is nullified
65
66 # check that we don't crash on NULL
67 self.expect("frame variable s32",
68 substrs = ['(char32_t *) s32 = 0x00000000'])
69
70 self.runCmd("next")
71 self.runCmd("next")
72
Enrico Granata3f4844e2013-01-11 03:01:25 +000073 # check that the new strings show
Enrico Granataf5545f92013-01-10 22:08:35 +000074 self.expect("frame variable s16 s32",
75 substrs = ['(char16_t *) s16 = 0x','(char32_t *) s32 = ','"色ハ匂ヘト散リヌルヲ"','"෴"'])
76
Enrico Granatacd8cd612013-01-14 23:53:26 +000077 # Check that we can run expressions that return charN_t
78 self.expect("expression u'a'",substrs = ['(char16_t) $',"61 u'a'"])
79 self.expect("expression U'a'",substrs = ['(char32_t) $',"61 U'a'"])
80
Enrico Granataf5545f92013-01-10 22:08:35 +000081if __name__ == '__main__':
82 import atexit
83 lldb.SBDebugger.Initialize()
84 atexit.register(lambda: lldb.SBDebugger.Terminate())
85 unittest2.main()