xref: /llvm-project/lldb/test/API/lang/cpp/char1632_t/TestChar1632T.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht# coding=utf8
299451b44SJordan Rupprecht"""
399451b44SJordan RupprechtTest that the C++11 support for char16_t and char32_t works correctly.
499451b44SJordan Rupprecht"""
599451b44SJordan Rupprecht
699451b44SJordan Rupprecht
799451b44SJordan Rupprechtimport lldb
899451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
1099451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprecht
1399451b44SJordan Rupprechtclass Char1632TestCase(TestBase):
1499451b44SJordan Rupprecht    def setUp(self):
1599451b44SJordan Rupprecht        # Call super's setUp().
1699451b44SJordan Rupprecht        TestBase.setUp(self)
1799451b44SJordan Rupprecht        # Find the line number to break for main.cpp.
18*2238dcc3SJonas Devlieghere        self.source = "main.cpp"
19*2238dcc3SJonas Devlieghere        self.lines = [
20*2238dcc3SJonas Devlieghere            line_number(self.source, "// breakpoint1"),
21*2238dcc3SJonas Devlieghere            line_number(self.source, "// breakpoint2"),
22*2238dcc3SJonas Devlieghere        ]
2399451b44SJordan Rupprecht
2499451b44SJordan Rupprecht    @expectedFailureAll(
2599451b44SJordan Rupprecht        compiler="icc",
26*2238dcc3SJonas Devlieghere        bugnumber="ICC (13.1) does not emit the DW_TAG_base_type for char16_t and char32_t.",
27*2238dcc3SJonas Devlieghere    )
2899451b44SJordan Rupprecht    def test(self):
2999451b44SJordan Rupprecht        """Test that the C++11 support for char16_t and char32_t works correctly."""
3099451b44SJordan Rupprecht        self.build()
3199451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
3299451b44SJordan Rupprecht
3399451b44SJordan Rupprecht        # Create a target by the debugger.
3499451b44SJordan Rupprecht        target = self.dbg.CreateTarget(exe)
3599451b44SJordan Rupprecht        self.assertTrue(target, VALID_TARGET)
3699451b44SJordan Rupprecht
3799451b44SJordan Rupprecht        # Set breakpoints
3899451b44SJordan Rupprecht        for line in self.lines:
3999451b44SJordan Rupprecht            lldbutil.run_break_set_by_file_and_line(self, "main.cpp", line)
4099451b44SJordan Rupprecht
4199451b44SJordan Rupprecht        # Now launch the process, and do not stop at entry point and stop at
4299451b44SJordan Rupprecht        # breakpoint1
43*2238dcc3SJonas Devlieghere        process = target.LaunchSimple(None, None, self.get_process_working_directory())
4499451b44SJordan Rupprecht
4599451b44SJordan Rupprecht        if not process:
4699451b44SJordan Rupprecht            self.fail("SBTarget.Launch() failed")
4799451b44SJordan Rupprecht
4899451b44SJordan Rupprecht        if self.TraceOn():
4999451b44SJordan Rupprecht            self.runCmd("frame variable")
5099451b44SJordan Rupprecht
5199451b44SJordan Rupprecht        # Check that we correctly report the const types
5299451b44SJordan Rupprecht        self.expect(
5399451b44SJordan Rupprecht            "frame variable cs16 cs32",
5499451b44SJordan Rupprecht            substrs=[
55*2238dcc3SJonas Devlieghere                "(const char16_t *) cs16 = ",
5699451b44SJordan Rupprecht                'u"hello world ྒྙྐ"',
57*2238dcc3SJonas Devlieghere                "(const char32_t *) cs32 = ",
58*2238dcc3SJonas Devlieghere                'U"hello world ྒྙྐ"',
59*2238dcc3SJonas Devlieghere            ],
60*2238dcc3SJonas Devlieghere        )
6199451b44SJordan Rupprecht
6299451b44SJordan Rupprecht        # Check that we correctly report the non-const types
6399451b44SJordan Rupprecht        self.expect(
6499451b44SJordan Rupprecht            "frame variable s16 s32",
6599451b44SJordan Rupprecht            substrs=[
66*2238dcc3SJonas Devlieghere                "(char16_t *) s16 = ",
6799451b44SJordan Rupprecht                'u"ﺸﺵۻ"',
68*2238dcc3SJonas Devlieghere                "(char32_t *) s32 = ",
69*2238dcc3SJonas Devlieghere                'U"ЕЙРГЖО"',
70*2238dcc3SJonas Devlieghere            ],
71*2238dcc3SJonas Devlieghere        )
7299451b44SJordan Rupprecht
7399451b44SJordan Rupprecht        # Check that we correctly report the array types
7499451b44SJordan Rupprecht        self.expect(
7599451b44SJordan Rupprecht            "frame variable as16 as32",
7699451b44SJordan Rupprecht            patterns=[
77*2238dcc3SJonas Devlieghere                "\(char16_t\[[0-9]+\]\) as16 = ",
78*2238dcc3SJonas Devlieghere                "\(char32_t\[[0-9]+\]\) as32 = ",
79*2238dcc3SJonas Devlieghere            ],
80*2238dcc3SJonas Devlieghere            substrs=['u"ﺸﺵۻ"', 'U"ЕЙРГЖО"'],
81*2238dcc3SJonas Devlieghere        )
8299451b44SJordan Rupprecht
8399451b44SJordan Rupprecht        self.runCmd("next")  # step to after the string is nullified
8499451b44SJordan Rupprecht
8599451b44SJordan Rupprecht        # check that we don't crash on NULL
86*2238dcc3SJonas Devlieghere        self.expect("frame variable s32", substrs=["(char32_t *) s32 = 0x00000000"])
8799451b44SJordan Rupprecht
8899451b44SJordan Rupprecht        # continue and hit breakpoint2
8999451b44SJordan Rupprecht        self.runCmd("continue")
9099451b44SJordan Rupprecht
9199451b44SJordan Rupprecht        # check that the new strings show
9299451b44SJordan Rupprecht        self.expect(
9399451b44SJordan Rupprecht            "frame variable s16 s32",
9499451b44SJordan Rupprecht            substrs=[
95*2238dcc3SJonas Devlieghere                "(char16_t *) s16 = 0x",
9699451b44SJordan Rupprecht                '"色ハ匂ヘト散リヌルヲ"',
97*2238dcc3SJonas Devlieghere                "(char32_t *) s32 = ",
98*2238dcc3SJonas Devlieghere                '"෴"',
99*2238dcc3SJonas Devlieghere            ],
100*2238dcc3SJonas Devlieghere        )
10199451b44SJordan Rupprecht
10299451b44SJordan Rupprecht        # check the same as above for arrays
10399451b44SJordan Rupprecht        self.expect(
10499451b44SJordan Rupprecht            "frame variable as16 as32",
10599451b44SJordan Rupprecht            patterns=[
106*2238dcc3SJonas Devlieghere                "\(char16_t\[[0-9]+\]\) as16 = ",
107*2238dcc3SJonas Devlieghere                "\(char32_t\[[0-9]+\]\) as32 = ",
108*2238dcc3SJonas Devlieghere            ],
109*2238dcc3SJonas Devlieghere            substrs=['"色ハ匂ヘト散リヌルヲ"', '"෴"'],
110*2238dcc3SJonas Devlieghere        )
11199451b44SJordan Rupprecht
11299451b44SJordan Rupprecht        # check that zero values are properly handles
113*2238dcc3SJonas Devlieghere        self.expect_expr("cs16_zero", result_summary="U+0000 u'\\0'")
114*2238dcc3SJonas Devlieghere        self.expect_expr("cs32_zero", result_summary="U+0x00000000 U'\\0'")
11599451b44SJordan Rupprecht
11699451b44SJordan Rupprecht        # Check that we can run expressions that return charN_t
11799451b44SJordan Rupprecht        self.expect_expr("u'a'", result_type="char16_t", result_summary="U+0061 u'a'")
118*2238dcc3SJonas Devlieghere        self.expect_expr(
119*2238dcc3SJonas Devlieghere            "U'a'", result_type="char32_t", result_summary="U+0x00000061 U'a'"
120*2238dcc3SJonas Devlieghere        )
121