diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-06-28 13:46:03 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-06-29 18:31:04 +0200 |
commit | 0e8ab25c4ccbd46e62bbb81b169ec0d227cbfc33 (patch) | |
tree | 0c3a0724a48e658bb59dc0cdcedb4bd790ff7354 | |
parent | a6bebdb67e5a0d780242f3ff9f8ff5cf0f3da631 (diff) |
shiboken6: Add tests for shared pointer virtual calls
Task-number: PYSIDE-454
Change-Id: I9571b0df985a0823641d10c6455eafbc2fc0ac94
Reviewed-by: Christian Tismer <tismer@stackless.com>
5 files changed, 50 insertions, 1 deletions
diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp index b17babc8d..a7b73cc81 100644 --- a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp +++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp @@ -50,3 +50,17 @@ void StdSharedPtrTestBench::printInt(const std::shared_ptr<int> &p) std::cerr << "nullptr"; std::cerr << '\n'; } + +StdSharedPtrVirtualMethodTester::StdSharedPtrVirtualMethodTester() = default; +StdSharedPtrVirtualMethodTester::~StdSharedPtrVirtualMethodTester() = default; + +std::shared_ptr<Integer> StdSharedPtrVirtualMethodTester::callModifyInteger(const std::shared_ptr<Integer> &p) +{ + return doModifyInteger(p); +} + +std::shared_ptr<Integer> StdSharedPtrVirtualMethodTester::doModifyInteger(std::shared_ptr<Integer> p) +{ + p->setValue(p->value() + 1); + return p; +} diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h index 057b29174..8991cded6 100644 --- a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h +++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h @@ -25,4 +25,16 @@ public: static void printInt(const std::shared_ptr<int> &); }; +class LIB_SMART_API StdSharedPtrVirtualMethodTester +{ +public: + StdSharedPtrVirtualMethodTester(); + virtual ~StdSharedPtrVirtualMethodTester(); + + std::shared_ptr<Integer> callModifyInteger(const std::shared_ptr<Integer> &p); + +protected: + virtual std::shared_ptr<Integer> doModifyInteger(std::shared_ptr<Integer> p); +}; + #endif // STDSHAREDPTRTESTBENCH_H diff --git a/sources/shiboken6/tests/smartbinding/CMakeLists.txt b/sources/shiboken6/tests/smartbinding/CMakeLists.txt index bb5f6df49..196470f96 100644 --- a/sources/shiboken6/tests/smartbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/smartbinding/CMakeLists.txt @@ -14,6 +14,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/smart/registry_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/smart_integer2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_integer2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/stdsharedptrtestbench_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/stdsharedptrvirtualmethodtester_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/std_shared_ptr_integer_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/std_shared_ptr_int_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/std_wrapper.cpp diff --git a/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py index c0bead29d..b4b9808c6 100644 --- a/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py +++ b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py @@ -11,13 +11,20 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from smart import Integer, StdSharedPtrTestBench, std +from smart import Integer, StdSharedPtrTestBench, StdSharedPtrVirtualMethodTester, std def call_func_on_ptr(ptr): ptr.printInteger() +class VirtualTester(StdSharedPtrVirtualMethodTester): + + def doModifyInteger(self, p): + p.setValue(p.value() * 2) + return p + + class StdSharedPtrTests(unittest.TestCase): def testInteger(self): p = StdSharedPtrTestBench.createInteger() @@ -42,6 +49,20 @@ class StdSharedPtrTests(unittest.TestCase): p = StdSharedPtrTestBench.createInt() StdSharedPtrTestBench.printInt(p) + def testVirtuals(self): + """Test whether code generating virtual function overrides is generated + correctly.""" + p = StdSharedPtrTestBench.createInteger() + p.setValue(42) + v = StdSharedPtrVirtualMethodTester() + r = v.callModifyInteger(p) # Base implementation increments + self.assertEqual(r.value(), 43) + + p.setValue(42) + v = VirtualTester() + r = v.callModifyInteger(p) # Derived implementation doubles + self.assertEqual(r.value(), 84) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml index 7faa85a7f..a1bfe03aa 100644 --- a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml +++ b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml @@ -62,5 +62,6 @@ </namespace-type> <object-type name="StdSharedPtrTestBench"/> + <object-type name="StdSharedPtrVirtualMethodTester"/> </typesystem> |