diff options
Diffstat (limited to 'sources/shiboken6/tests/smartbinding')
8 files changed, 49 insertions, 13 deletions
diff --git a/sources/shiboken6/tests/smartbinding/CMakeLists.txt b/sources/shiboken6/tests/smartbinding/CMakeLists.txt index b4b86d733..2e729321e 100644 --- a/sources/shiboken6/tests/smartbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/smartbinding/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(smart) set(smart_TYPESYSTEM @@ -21,22 +24,30 @@ ${CMAKE_CURRENT_BINARY_DIR}/smart/std_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/std_optional_int_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/std_optional_integer_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/std_unique_ptr_integer_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_unique_ptr_integer2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/std_unique_ptr_int_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/stdoptionaltestbench_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/stduniqueptrtestbench_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/stduniqueptrvirtualmethodtester_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/test_wrapper.cpp ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/smart-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/smart-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${smart_SRC} -COMMAND Shiboken6::shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/smart-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${smart_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'smart' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${smart_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/smart-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${smart_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'smart' test binding..." ) add_library(smart MODULE ${smart_SRC}) diff --git a/sources/shiboken6/tests/smartbinding/smart-binding.txt.in b/sources/shiboken6/tests/smartbinding/smart-binding.txt.in index 699f0bfe6..a2c73c6bf 100644 --- a/sources/shiboken6/tests/smartbinding/smart-binding.txt.in +++ b/sources/shiboken6/tests/smartbinding/smart-binding.txt.in @@ -13,3 +13,4 @@ typesystem-path = @CMAKE_CURRENT_SOURCE_DIR@ enable-parent-ctor-heuristic use-isnull-as-nb_nonzero +lean-headers diff --git a/sources/shiboken6/tests/smartbinding/smart_pointer_test.py b/sources/shiboken6/tests/smartbinding/smart_pointer_test.py index 74dc89bc4..8d4272558 100644 --- a/sources/shiboken6/tests/smartbinding/smart_pointer_test.py +++ b/sources/shiboken6/tests/smartbinding/smart_pointer_test.py @@ -231,6 +231,9 @@ class SmartPointerTests(unittest.TestCase): # Create a shared pointer to an Integer2 integer2 = o.createSharedPtrInteger2() + # User defined name + self.assertEqual(type(integer2).__name__, "SmartInteger2Ptr") + self.assertTrue("smart.Test.SmartInteger2Ptr" in repr(type(integer2))) self.assertEqual(integer2.value(), 456) # pass Smart<Integer2> to a function that accepts Smart<Integer> @@ -259,7 +262,7 @@ class SmartPointerTests(unittest.TestCase): self.assertTrue(five > four) self.assertRaises(NotImplementedError, - lambda : Obj.createNullSharedPtrInteger() == four) + lambda: Obj.createNullSharedPtrInteger() == four) def testSmartPointerObjectComparison(self): """Test a pointee class without comparison operators.""" diff --git a/sources/shiboken6/tests/smartbinding/smartbinding.pyproject b/sources/shiboken6/tests/smartbinding/smartbinding.pyproject new file mode 100644 index 000000000..d0855ef82 --- /dev/null +++ b/sources/shiboken6/tests/smartbinding/smartbinding.pyproject @@ -0,0 +1,7 @@ +{ + "files": ["smart_pointer_test.py", + "std_optional_test.py", + "std_shared_ptr_test.py", + "std_unique_ptr_test.py", + "typesystem_smart.xml"] +} diff --git a/sources/shiboken6/tests/smartbinding/std_optional_test.py b/sources/shiboken6/tests/smartbinding/std_optional_test.py index be969d0f5..bee573548 100644 --- a/sources/shiboken6/tests/smartbinding/std_optional_test.py +++ b/sources/shiboken6/tests/smartbinding/std_optional_test.py @@ -2,7 +2,6 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -import gc import os import sys import unittest diff --git a/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py index b4b9808c6..2e6aea3d9 100644 --- a/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py +++ b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py @@ -2,7 +2,6 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -import gc import os import sys import unittest @@ -28,6 +27,8 @@ class VirtualTester(StdSharedPtrVirtualMethodTester): class StdSharedPtrTests(unittest.TestCase): def testInteger(self): p = StdSharedPtrTestBench.createInteger() + # PYSIDE-2462: Ensure Integer's __dir__ entries in the pointer's + self.assertTrue("printInteger" in dir(p)) StdSharedPtrTestBench.printInteger(p) self.assertTrue(p) call_func_on_ptr(p) diff --git a/sources/shiboken6/tests/smartbinding/std_unique_ptr_test.py b/sources/shiboken6/tests/smartbinding/std_unique_ptr_test.py index f21466302..9c7ef2f01 100644 --- a/sources/shiboken6/tests/smartbinding/std_unique_ptr_test.py +++ b/sources/shiboken6/tests/smartbinding/std_unique_ptr_test.py @@ -2,7 +2,6 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -import gc import os import sys import unittest @@ -11,7 +10,7 @@ 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, StdUniquePtrTestBench, StdUniquePtrVirtualMethodTester, std +from smart import Integer, Integer2, StdUniquePtrTestBench, StdUniquePtrVirtualMethodTester, std def call_func_on_ptr(ptr): @@ -54,6 +53,17 @@ class StdUniquePtrTests(unittest.TestCase): np = std.unique_ptr_Integer(iv) self.assertEqual(np.value(), 42) + def test_derived(self): + iv2 = Integer2() # Construct from pointee + iv2.setValue(42) + p = std.unique_ptr_Smart_Integer2(iv2) + self.assertEqual(p.value(), 42) + StdUniquePtrTestBench.printInteger2(p) # unique_ptr by ref + self.assertTrue(p) + StdUniquePtrTestBench.printInteger(p) # conversion + # FIXME: This fails, pointer is moved in value conversion + # self.assertTrue(p) + def testInt(self): p = StdUniquePtrTestBench.createInt() # unique_ptr by ref StdUniquePtrTestBench.printInt(p) diff --git a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml index 748e5a0d3..261d5f15d 100644 --- a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml +++ b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml @@ -28,7 +28,7 @@ --> <smart-pointer-type name="SharedPtr" type="shared" getter="data" ref-count-method="useCount" null-check-method="isNull" - instantiations="Integer,Smart::Integer2,Obj"/> + instantiations="Integer,Smart::Integer2=Test::SmartInteger2Ptr,Obj"/> <object-type name="Obj" /> <value-type name="Integer" /> @@ -57,7 +57,7 @@ <smart-pointer-type name="unique_ptr" type="unique" getter="get" value-check-method="operator bool" reset-method="reset" - instantiations="Integer,int"> + instantiations="Integer,Smart::Integer2,int"> <include file-name="memory" location="global"/> </smart-pointer-type> @@ -74,4 +74,8 @@ <object-type name="StdUniquePtrTestBench"/> <object-type name="StdUniquePtrVirtualMethodTester"/> + <namespace-type name="Test"> + <enum-type name="DummyEnum"/> + </namespace-type> + </typesystem> |