1#coding=utf8
2"""
3Test that C++ supports wchar_t correctly.
4"""
5
6import os, time
7import unittest2
8import lldb
9from lldbtest import *
10import lldbutil
11
12class CxxWCharTTestCase(TestBase):
13
14    mydir = os.path.join("lang", "cpp", "wchar_t")
15
16    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
17    @dsym_test
18    def test_with_dsym(self):
19        """Test that C++ supports wchar_t correctly."""
20        self.buildDsym()
21        self.wchar_t()
22
23    @dwarf_test
24    def test_with_dwarf(self):
25        """Test that C++ supports wchar_t correctly."""
26        self.buildDwarf()
27        self.wchar_t()
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 wchar_t(self):
37        """Test that C++ supports wchar_t 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        # Check that we correctly report templates on wchar_t
54        self.expect("frame variable foo_y",
55            substrs = ['(Foo<wchar_t>) foo_y = '])
56
57        # Check that we correctly report templates on int
58        self.expect("frame variable foo_x",
59            substrs = ['(Foo<int>) foo_x = '])
60
61        # Check that we correctly report wchar_t
62        self.expect("frame variable foo_y.object",
63            substrs = ['(wchar_t) foo_y.object = '])
64
65        # Check that we correctly report int
66        self.expect("frame variable foo_x.object",
67            substrs = ['(int) foo_x.object = '])
68
69        # Check that we can run expressions that return wchar_t
70        self.expect("expression L'a'",substrs = ['(wchar_t) $',"61 L'a'"])
71
72        # Mazel Tov if this works!
73        self.expect("frame variable mazeltov",
74            substrs = ['(const wchar_t *) mazeltov = ','L"מזל טוב"'])
75
76
77if __name__ == '__main__':
78    import atexit
79    lldb.SBDebugger.Initialize()
80    atexit.register(lambda: lldb.SBDebugger.Terminate())
81    unittest2.main()
82