1"""
2Test calling std::String member functions.
3"""
4
5import unittest2
6import lldb
7import lldbutil
8from lldbtest import *
9
10class ExprCommandCallFunctionTestCase(TestBase):
11
12    mydir = os.path.join("expression_command", "call-function")
13
14    def setUp(self):
15        # Call super's setUp().
16        TestBase.setUp(self)
17        # Find the line number to break for main.c.
18        self.line = line_number('main.cpp',
19                                '// Please test these expressions while stopped at this line:')
20
21    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
22    @dsym_test
23    def test_with_dsym(self):
24        """Test calling std::String member function."""
25        self.buildDsym()
26        self.call_function()
27
28    @dwarf_test
29    @expectedFailureFreeBSD # llvm.org/pr16697
30    @expectedFailureGcc # llvm.org/pr14437, fails with GCC 4.6.3 and 4.7.2
31    @expectedFailureIcc # llvm.org/pr14437, fails with ICC 13.1
32    def test_with_dwarf(self):
33        """Test calling std::String member function."""
34        self.buildDwarf()
35        self.call_function()
36
37    def call_function(self):
38        """Test calling std::String member function."""
39        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
40
41        # Some versions of GCC encode two locations for the 'return' statement in main.cpp
42        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
43
44        self.runCmd("run", RUN_SUCCEEDED)
45
46        self.expect("print str",
47            substrs = ['Hello world'])
48
49        # Should be fixed with r142717.
50        #
51        # rdar://problem/9471744 test failure: ./dotest.py -C clang -v -w -t -p CallStdString
52        # runCmd: print str.c_str()
53        # runCmd failed!
54        # error: Couldn't convert the expression to DWARF
55        self.expect("print str.c_str()",
56            substrs = ['Hello world'])
57
58if __name__ == '__main__':
59    import atexit
60    lldb.SBDebugger.Initialize()
61    atexit.register(lambda: lldb.SBDebugger.Terminate())
62    unittest2.main()
63