1# coding=utf8
2"""
3Test that the C++11 support for char16_t and char32_t works correctly.
4"""
5
6
7
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14class Char1632TestCase(TestBase):
15
16    def setUp(self):
17        # Call super's setUp().
18        TestBase.setUp(self)
19        # Find the line number to break for main.cpp.
20        self.source = 'main.cpp'
21        self.lines = [line_number(self.source, '// breakpoint1'),
22                      line_number(self.source, '// breakpoint2')]
23
24    @expectedFailureAll(
25        compiler="icc",
26        bugnumber="ICC (13.1) does not emit the DW_TAG_base_type for char16_t and char32_t.")
27    def test(self):
28        """Test that the C++11 support for char16_t and char32_t works correctly."""
29        self.build()
30        exe = self.getBuildArtifact("a.out")
31
32        # Create a target by the debugger.
33        target = self.dbg.CreateTarget(exe)
34        self.assertTrue(target, VALID_TARGET)
35
36        # Set breakpoints
37        for line in self.lines:
38            lldbutil.run_break_set_by_file_and_line(self, "main.cpp", line)
39
40        # Now launch the process, and do not stop at entry point and stop at
41        # breakpoint1
42        process = target.LaunchSimple(
43            None, None, self.get_process_working_directory())
44
45        if not process:
46            self.fail("SBTarget.Launch() failed")
47
48        if self.TraceOn():
49            self.runCmd("frame variable")
50
51        # Check that we correctly report the const types
52        self.expect(
53            "frame variable cs16 cs32",
54            substrs=[
55                '(const char16_t *) cs16 = ',
56                'u"hello world ྒྙྐ"',
57                '(const char32_t *) cs32 = ',
58                'U"hello world ྒྙྐ"'])
59
60        # Check that we correctly report the non-const types
61        self.expect(
62            "frame variable s16 s32",
63            substrs=[
64                '(char16_t *) s16 = ',
65                'u"ﺸﺵۻ"',
66                '(char32_t *) s32 = ',
67                'U"ЕЙРГЖО"'])
68
69        # Check that we correctly report the array types
70        self.expect(
71            "frame variable as16 as32",
72            patterns=[
73                '\(char16_t\[[0-9]+\]\) as16 = ',
74                '\(char32_t\[[0-9]+\]\) as32 = '],
75            substrs=[
76                'u"ﺸﺵۻ"',
77                'U"ЕЙРГЖО"'])
78
79        self.runCmd("next")  # step to after the string is nullified
80
81        # check that we don't crash on NULL
82        self.expect("frame variable s32",
83                    substrs=['(char32_t *) s32 = 0x00000000'])
84
85        # continue and hit breakpoint2
86        self.runCmd("continue")
87
88        # check that the new strings show
89        self.expect(
90            "frame variable s16 s32",
91            substrs=[
92                '(char16_t *) s16 = 0x',
93                '"色ハ匂ヘト散リヌルヲ"',
94                '(char32_t *) s32 = ',
95                '"෴"'])
96
97        # check the same as above for arrays
98        self.expect(
99            "frame variable as16 as32",
100            patterns=[
101                '\(char16_t\[[0-9]+\]\) as16 = ',
102                '\(char32_t\[[0-9]+\]\) as32 = '],
103            substrs=[
104                '"色ハ匂ヘト散リヌルヲ"',
105                '"෴"'])
106
107        # check that zero values are properly handles
108        self.expect_expr('cs16_zero', result_summary="U+0000 u'\\0'")
109        self.expect_expr('cs32_zero', result_summary="U+0x00000000 U'\\0'")
110
111        # Check that we can run expressions that return charN_t
112        self.expect_expr("u'a'", result_type="char16_t", result_summary="U+0061 u'a'")
113        self.expect_expr("U'a'", result_type="char32_t", result_summary="U+0x00000061 U'a'")
114