|
| 1 | +import lldb |
| 2 | +from lldbsuite.test.lldbtest import * |
| 3 | +import lldbsuite.test.lldbutil as lldbutil |
| 4 | + |
| 5 | +class TestCase(TestBase): |
| 6 | + |
| 7 | + mydir = TestBase.compute_mydir(__file__) |
| 8 | + NO_DEBUG_INFO_TESTCASE = True |
| 9 | + |
| 10 | + def test(self): |
| 11 | + self.build() |
| 12 | + lldbutil.run_to_source_breakpoint(self,"// break here", lldb.SBFileSpec("main.cpp")) |
| 13 | + |
| 14 | + # Test covariant return types for pointers to class that contains the called function. |
| 15 | + self.expect_expr("derived.getPtr()", result_type="Derived *") |
| 16 | + self.expect_expr("base_ptr_to_derived->getPtr()", result_type="Base *") |
| 17 | + self.expect_expr("base.getPtr()", result_type="Base *") |
| 18 | + # The same tests with reference types. LLDB drops the reference when it turns the |
| 19 | + # result into a SBValue so check for the the underlying type of the result. |
| 20 | + self.expect_expr("derived.getRef()", result_type="Derived") |
| 21 | + self.expect_expr("base_ptr_to_derived->getRef()", result_type="Base") |
| 22 | + self.expect_expr("base.getRef()", result_type="Base") |
| 23 | + |
| 24 | + # Test covariant return types for pointers to class that does *not* contain the called function. |
| 25 | + self.expect_expr("derived.getOtherPtr()", result_type="OtherDerived *") |
| 26 | + self.expect_expr("base_ptr_to_derived->getOtherPtr()", result_type="OtherBase *") |
| 27 | + self.expect_expr("base.getOtherPtr()", result_type="OtherBase *") |
| 28 | + # The same tests with reference types. LLDB drops the reference when it turns the |
| 29 | + # result into a SBValue so check for the the underlying type of the result. |
| 30 | + self.expect_expr("derived.getOtherRef()", result_type="OtherDerived") |
| 31 | + self.expect_expr("base_ptr_to_derived->getOtherRef()", result_type="OtherBase") |
| 32 | + self.expect_expr("base.getOtherRef()", result_type="OtherBase") |
| 33 | + |
| 34 | + # Test that we call the right function and get the right value back. |
| 35 | + self.expect_expr("derived.getOtherPtr()->value()", result_summary='"derived"') |
| 36 | + self.expect_expr("base_ptr_to_derived->getOtherPtr()->value()", result_summary='"derived"') |
| 37 | + self.expect_expr("base.getOtherPtr()->value()", result_summary='"base"') |
| 38 | + self.expect_expr("derived.getOtherRef().value()", result_summary='"derived"') |
| 39 | + self.expect_expr("base_ptr_to_derived->getOtherRef().value()", result_summary='"derived"') |
| 40 | + self.expect_expr("base.getOtherRef().value()", result_summary='"base"') |
0 commit comments