diff options
Diffstat (limited to 'sources/shiboken2/tests/smartbinding')
5 files changed, 0 insertions, 318 deletions
diff --git a/sources/shiboken2/tests/smartbinding/CMakeLists.txt b/sources/shiboken2/tests/smartbinding/CMakeLists.txt deleted file mode 100644 index 88a7bc059..000000000 --- a/sources/shiboken2/tests/smartbinding/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -project(smart) - -set(smart_TYPESYSTEM -${CMAKE_CURRENT_SOURCE_DIR}/typesystem_smart.xml -) - -set(smart_SRC -${CMAKE_CURRENT_BINARY_DIR}/smart/smart_module_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/smart/obj_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/smart/integer_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_obj_wrapper.cpp -${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_integer_wrapper.cpp -${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 -) - -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/smart-binding.txt.in" - "${CMAKE_CURRENT_BINARY_DIR}/smart-binding.txt" @ONLY) - -add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${smart_SRC} -COMMAND shiboken2 --project-file=${CMAKE_CURRENT_BINARY_DIR}/smart-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${smart_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h shiboken2 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'smart' test binding..." -) - -add_library(smart MODULE ${smart_SRC}) -target_include_directories(smart PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(smart PUBLIC libsmart libshiboken) -set_property(TARGET smart PROPERTY PREFIX "") -set_property(TARGET smart PROPERTY OUTPUT_NAME "smart${PYTHON_EXTENSION_SUFFIX}") - -if(WIN32) - set_property(TARGET smart PROPERTY SUFFIX ".pyd") -endif() - -create_generator_target(smart) diff --git a/sources/shiboken2/tests/smartbinding/global.h b/sources/shiboken2/tests/smartbinding/global.h deleted file mode 100644 index 959859b40..000000000 --- a/sources/shiboken2/tests/smartbinding/global.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "smart.h" diff --git a/sources/shiboken2/tests/smartbinding/smart-binding.txt.in b/sources/shiboken2/tests/smartbinding/smart-binding.txt.in deleted file mode 100644 index 699f0bfe6..000000000 --- a/sources/shiboken2/tests/smartbinding/smart-binding.txt.in +++ /dev/null @@ -1,15 +0,0 @@ -[generator-project] - -generator-set = shiboken - -header-file = @CMAKE_CURRENT_SOURCE_DIR@/global.h -typesystem-file = @smart_TYPESYSTEM@ - -output-directory = @CMAKE_CURRENT_BINARY_DIR@ - -include-path = @libsmart_SOURCE_DIR@ - -typesystem-path = @CMAKE_CURRENT_SOURCE_DIR@ - -enable-parent-ctor-heuristic -use-isnull-as-nb_nonzero diff --git a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py deleted file mode 100644 index e07856e61..000000000 --- a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py +++ /dev/null @@ -1,179 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2017 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $QT_BEGIN_LICENSE:GPL-EXCEPT$ -## Commercial License Usage -## Licensees holding valid commercial Qt licenses may use this file in -## accordance with the commercial license agreement provided with the -## Software or, alternatively, in accordance with the terms contained in -## a written agreement between you and The Qt Company. For licensing terms -## and conditions see https://www.qt.io/terms-conditions. For further -## information use the contact form at https://www.qt.io/contact-us. -## -## GNU General Public License Usage -## Alternatively, this file may be used under the terms of the GNU -## General Public License version 3 as published by the Free Software -## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -## included in the packaging of this file. Please review the following -## information to ensure the GNU General Public License requirements will -## be met: https://www.gnu.org/licenses/gpl-3.0.html. -## -## $QT_END_LICENSE$ -## -############################################################################# - -import unittest -from copy import copy -from smart import Obj, Registry, Integer - -def objCount(): - return Registry.getInstance().countObjects() - -def integerCount(): - return Registry.getInstance().countIntegers() - -class SmartPointerTests(unittest.TestCase): - def testObjSmartPointer(self): - # Uncomment to see more debug info about creation of objects and ref counts. - # Registry.getInstance().setShouldPrint(True) - - # Create Obj. - o = Obj() - self.assertEqual(objCount(), 1) - - # Create a shared pointer to an Obj together with an Obj. - ptrToObj = o.giveSharedPtrToObj() - self.assertEqual(objCount(), 2) - - # Delete the old Obj. - o = None - self.assertEqual(objCount(), 1) - - # Get a wrapper to the Obj inside of the shared pointer, object count should not change. - obj = ptrToObj.data() - self.assertEqual(objCount(), 1) - obj.m_integer = 50 - self.assertEqual(obj.m_integer, 50) - - # Set and get a member value via shared pointer (like operator->). - ptrToObj.m_integer = 100 - self.assertEqual(ptrToObj.m_integer, 100) - - # Get inner PyObject via shared pointer (like operator->) and set value in it. - ptrToObj.m_internalInteger.m_int = 200 - self.assertEqual(ptrToObj.m_internalInteger.m_int, 200) - - # Pass smart pointer as argument to a method, return value is the value of m_integer of - # passed Obj inside the smart pointer. - result = ptrToObj.takeSharedPtrToObj(ptrToObj) - self.assertEqual(result, 100) - - # Pass an Integer as an argument that returns itself. - result = ptrToObj.takeInteger(ptrToObj.m_internalInteger) - self.assertEqual(integerCount(), 2) - result = None - self.assertEqual(integerCount(), 1) - - # Make a copy of the shared pointer, object count should not change. - ptrToObj2 = copy(ptrToObj) - self.assertEqual(objCount(), 1) - - # Delete the first shared pointer, object count should not change because the second - # one still has a reference. - del ptrToObj - self.assertEqual(objCount(), 1) - - # Delete the second smart pointer, object should be deleted. - del ptrToObj2 - self.assertEqual(objCount(), 0) - self.assertEqual(integerCount(), 0) - - def testIntegerSmartPointer(self): - # Uncomment to see more debug info about creation of objects and ref counts. - # Registry.getInstance().setShouldPrint(True) - - # Create Obj. - o = Obj() - self.assertEqual(objCount(), 1) - - # Create a shared pointer to an Integer together with an Integer. - ptrToInteger = o.giveSharedPtrToInteger() - self.assertEqual(objCount(), 1) - self.assertEqual(integerCount(), 2) - - # Get a wrapper to the Integer inside of the shared pointer, integer count should not - # change. - integer = ptrToInteger.data() - self.assertEqual(integerCount(), 2) - integer.m_int = 50 - self.assertEqual(integer.m_int, 50) - - # Set and get a member value via shared pointer (like operator->). - ptrToInteger.m_int = 100 - self.assertEqual(ptrToInteger.m_int, 100) - - # Pass smart pointer as argument to a method, return value is the value of m_int of - # passed Integer inside the smart pointer. - result = o.takeSharedPtrToInteger(ptrToInteger) - self.assertEqual(result, 100) - - # Make a copy of the shared pointer, integer count should not change. - ptrToInteger2 = copy(ptrToInteger) - self.assertEqual(integerCount(), 2) - - # Delete the first shared pointer, integer count should not change because the second - # one still has a reference. - del ptrToInteger - self.assertEqual(integerCount(), 2) - - # Delete the second smart pointer, integer should be deleted. - del ptrToInteger2 - self.assertEqual(objCount(), 1) - self.assertEqual(integerCount(), 1) - - # Delete the original object which was used to create the integer. - del o - self.assertEqual(objCount(), 0) - self.assertEqual(integerCount(), 0) - - def testSmartPointersWithNamespace(self): - # Create the main object - o = Obj() - self.assertEqual(objCount(), 1) - - # Create a shared pointer to an Integer together with an Integer. - ptrToInteger = o.giveSharedPtrToInteger2() - self.assertEqual(objCount(), 1) - self.assertEqual(integerCount(), 2) - - integer = ptrToInteger.data() - self.assertTrue(integer) - - def testListOfSmartPointers(self): - # Create the main object - o = Obj() - - # Create a list of shared objects - ptrToObjList = o.giveSharedPtrToObjList(10) - self.assertEqual(len(ptrToObjList), 10) - self.assertEqual(objCount(), 11) - - # Remove one from the list - ptrToObjList.pop() - self.assertEqual(len(ptrToObjList), 9) - self.assertEqual(objCount(), 10) - - # clear and delete all objects in the list - ptrToObjList.clear() - self.assertEqual(len(ptrToObjList), 0) - self.assertEqual(objCount(), 1) - -if __name__ == '__main__': - unittest.main() diff --git a/sources/shiboken2/tests/smartbinding/typesystem_smart.xml b/sources/shiboken2/tests/smartbinding/typesystem_smart.xml deleted file mode 100644 index 0bb485957..000000000 --- a/sources/shiboken2/tests/smartbinding/typesystem_smart.xml +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<typesystem package="smart"> - <primitive-type name="int" /> - <primitive-type name="char" /> - <primitive-type name="float" /> - <primitive-type name="bool" /> - - <template name="cpplist_to_pylist_convertion"> - PyObject *%out = PyList_New(int(%in.size())); - int idx = 0; - for (const auto &cppItem : %in) - PyList_SET_ITEM(%out, idx++, %CONVERTTOPYTHON[%INTYPE_0](cppItem)); - return %out; - </template> - <template name="pyseq_to_cpplist_convertion"> - Shiboken::AutoDecRef seq(PySequence_Fast(%in, 0)); - for (int i = 0, size = PySequence_Fast_GET_SIZE(seq.object()); i < size; ++i) { - PyObject* pyItem = PySequence_Fast_GET_ITEM(seq.object(), i); - %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); - %out.push_back(cppItem); - } - </template> - <container-type name="std::vector" type="list"> - <include file-name="list" location="global"/> - <conversion-rule> - <native-to-target> - <insert-template name="cpplist_to_pylist_convertion"/> - </native-to-target> - <target-to-native> - <add-conversion type="PySequence"> - <insert-template name="pyseq_to_cpplist_convertion"/> - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> - - - <!-- Used in tests to check what C++ objects are allocated. --> - <object-type name="Registry" /> - - <!-- Current limitation: shared pointer python objects can only be instantiated from API usage, - like when they are returned as a result of a method, or passed as arguments. It is not - possible to explicitly instantiate a new shared pointer in python e.g. o = SharedPtr_Foo() - won't work. - --> - <smart-pointer-type name="SharedPtr" type="shared" getter="data" ref-count-method="useCount" /> - - <object-type name="Obj" /> - <value-type name="Integer" /> - <namespace-type name="Smart" generate="no"> - <value-type name="Integer2" /> - </namespace-type> - <!-- Just used to silence the warnings that shiboken doens't know what to do with this type --> - <custom-type name="RefData" /> -</typesystem> |