diff options
Diffstat (limited to 'sources/shiboken6/tests/minimalbinding')
13 files changed, 312 insertions, 314 deletions
diff --git a/sources/shiboken6/tests/minimalbinding/CMakeLists.txt b/sources/shiboken6/tests/minimalbinding/CMakeLists.txt index 63ad8a577..7f132bd34 100644 --- a/sources/shiboken6/tests/minimalbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/minimalbinding/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(minimal) set(minimal_TYPESYSTEM @@ -6,22 +9,30 @@ ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_minimal.xml set(minimal_SRC ${CMAKE_CURRENT_BINARY_DIR}/minimal/minimal_module_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/minimal/containeruser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/minimal/obj_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/minimal/val_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/minimal/listuser_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/minimal/spanuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/minimal/minbooluser_wrapper.cpp ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/minimal-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/minimal-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${minimal_SRC} -COMMAND shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/minimal-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${minimal_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'minimal' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${minimal_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/minimal-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${minimal_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'minimal' test binding..." ) add_library(minimal MODULE ${minimal_SRC}) diff --git a/sources/shiboken6/tests/minimalbinding/brace_pattern_test.py b/sources/shiboken6/tests/minimalbinding/brace_pattern_test.py index e036eafb9..946a869db 100644 --- a/sources/shiboken6/tests/minimalbinding/brace_pattern_test.py +++ b/sources/shiboken6/tests/minimalbinding/brace_pattern_test.py @@ -1,41 +1,5 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of Qt for Python. -## -## $QT_BEGIN_LICENSE:LGPL$ -## 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 Lesser General Public License Usage -## Alternatively, this file may be used under the terms of the GNU Lesser -## General Public License version 3 as published by the Free Software -## Foundation and appearing in the file LICENSE.LGPL3 included in the -## packaging of this file. Please review the following information to -## ensure the GNU Lesser General Public License version 3 requirements -## will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -## -## GNU General Public License Usage -## Alternatively, this file may be used under the terms of the GNU -## General Public License version 2.0 or (at your option) the GNU General -## Public license version 3 or any later version approved by the KDE Free -## Qt Foundation. The licenses are as published by the Free Software -## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -## 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-2.0.html and -## https://www.gnu.org/licenses/gpl-3.0.html. -## -## $QT_END_LICENSE$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only import os import re @@ -47,8 +11,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from shiboken6 import Shiboken -_init_pyside_extension() # trigger bootstrap +from shiboken6 import Shiboken # noqa: F401 from shibokensupport.signature.lib.tool import build_brace_pattern @@ -58,8 +21,9 @@ against a slower reference implementation. The pattern is crucial, because it is used heavily in signature.parser . """ -# A slow reference parser for braces and strings + def check(s): + """A slow reference parser for braces and strings""" open, close = "[{(<", "]})>" escape, quote = "\\", '"' instring = blind = False @@ -78,8 +42,7 @@ def check(s): stack.append(c) elif c in close: pos = close.index(c) - if ((len(stack) > 0) and - (open[pos] == stack[len(stack)-1])): + if len(stack) > 0 and open[pos] == stack[len(stack) - 1]: stack.pop() else: return False diff --git a/sources/shiboken6/tests/minimalbinding/containeruser_test.py b/sources/shiboken6/tests/minimalbinding/containeruser_test.py new file mode 100644 index 000000000..25d683957 --- /dev/null +++ b/sources/shiboken6/tests/minimalbinding/containeruser_test.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() + +from minimal import ContainerUser + + +class ContainerTest(unittest.TestCase): + """Simple test for converting std::vector and using an opaque container. + For advanced tests, see ListUser.""" + def testVectorConversion(self): + v = ContainerUser.createIntVector(4) + self.assertEqual(ContainerUser.sumIntVector(v), 6) + + def testVectorOpaqueContainer(self): + cu = ContainerUser() + oc = cu.intVector() + self.assertEqual(oc[0], 1) + oc[0] = 42 + self.assertEqual(cu.intVector()[0], 42) + + def testArrayConversion(self): + v = ContainerUser.createIntArray() + self.assertEqual(ContainerUser.sumIntArray(v), 6) + + def testArrayOpaqueContainer(self): + cu = ContainerUser() + oc = cu.intArray() + self.assertEqual(oc[0], 1) + oc[0] = 42 + self.assertEqual(cu.intArray()[0], 42) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/minimalbinding/global.h b/sources/shiboken6/tests/minimalbinding/global.h index 1b06245c4..fc5c59a26 100644 --- a/sources/shiboken6/tests/minimalbinding/global.h +++ b/sources/shiboken6/tests/minimalbinding/global.h @@ -1,33 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "obj.h" +#include "containeruser.h" #include "val.h" #include "minbool.h" #include "listuser.h" +#include "spanuser.h" #include "typedef.h" diff --git a/sources/shiboken6/tests/minimalbinding/listuser_test.py b/sources/shiboken6/tests/minimalbinding/listuser_test.py index b5048aa44..b30bb653a 100644 --- a/sources/shiboken6/tests/minimalbinding/listuser_test.py +++ b/sources/shiboken6/tests/minimalbinding/listuser_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 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$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 from functools import reduce import os @@ -39,12 +12,15 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from minimal import ListUser, Val, Obj +from minimal import ListUser, Val, Obj, StdIntList class ExtListUser(ListUser): def __init__(self): - ListUser.__init__(self) + super().__init__() + self._stdIntList = StdIntList() + self._stdIntList.append(1) + self._stdIntList.append(2) def createIntList(self, num): return list(range(0, num * 2, 2)) @@ -56,7 +32,7 @@ class ExtListUser(ListUser): return [not mb1, not mb2] def oredMinBoolList(self, minBoolList): - return not reduce(lambda a, b: a|b, minBoolList) + return not reduce(lambda a, b: a | b, minBoolList) def createValList(self, num): return [Val(i) for i in range(0, num * 2, 2)] @@ -78,6 +54,9 @@ class ExtListUser(ListUser): def sumListOfIntLists(self, intListList): return sum([sum(line) for line in intListList]) * 2 + def returnIntListByPtr(self): + return self._stdIntList + class IntListConversionTest(unittest.TestCase): @@ -116,8 +95,14 @@ class IntListConversionTest(unittest.TestCase): def testSumIntList(self): lu = ListUser() lst = range(4) - self.assertEqual(lu.sumIntList(lst), sum(lst)) - self.assertEqual(lu.callSumIntList(lst), sum(lst)) + expected = sum(lst) + self.assertEqual(lu.sumIntList(lst), expected) + self.assertEqual(lu.callSumIntList(lst), expected) + self.assertEqual(lu.sumIntListDefaultParam(lst), expected) + self.assertEqual(lu.sumIntListDefaultParamConstRef(lst), expected) + # PYSIDE-2454: Check container default parameters (1,2,3) + self.assertEqual(lu.sumIntListDefaultParam(), 6) + self.assertEqual(lu.sumIntListDefaultParamConstRef(), 6) def testSumIntListFromExtendedClass(self): lu = ExtListUser() @@ -318,10 +303,74 @@ class ListOfIntListConversionTest(unittest.TestCase): def testSumListOfIntListsFromExtendedClass(self): lu = ExtListUser() lst = [range(4)] * 4 - self.assertEqual(lu.sumListOfIntLists(lst), sum([sum(line) for line in [range(4)] * 4]) * 2) - self.assertEqual(lu.callSumListOfIntLists(lst), sum([sum(line) for line in [range(4)] * 4]) * 2) + self.assertEqual(lu.sumListOfIntLists(lst), + sum([sum(line) for line in [range(4)] * 4]) * 2) + self.assertEqual(lu.callSumListOfIntLists(lst), + sum([sum(line) for line in [range(4)] * 4]) * 2) + + def testOpaqueContainer(self): + lu = ListUser() + + # Set via Python + python_list = [1, 2] + lu.setStdIntList(python_list) + self.assertEqual(len(lu.m_stdIntList), 2) + self.assertEqual(lu.m_stdIntList[0], 1) + self.assertEqual(lu.m_stdIntList[1], 2) + + # Set via C++ + cpp_list = StdIntList() + cpp_list.append(3) + cpp_list.append(4) + lu.setStdIntList(cpp_list) + self.assertEqual(len(lu.m_stdIntList), 2) + self.assertEqual(lu.m_stdIntList[0], 3) + self.assertEqual(lu.m_stdIntList[1], 4) + + # Access field directly via reference + lu.m_stdIntList.append(5) + self.assertEqual(len(lu.m_stdIntList), 3) + self.assertEqual(lu.m_stdIntList[2], 5) + + # Access list via getter + il = lu.getIntList() + il.append(6) + self.assertEqual(len(lu.m_stdIntList), 4) + self.assertEqual(lu.m_stdIntList[3], 6) + + # Access a const list via getter and verify that it cannot be modified + const_l = lu.getConstIntList() + self.assertEqual(len(const_l), 4) + self.assertRaises(TypeError, const_l.append, 6) + + def testListByPtrOpaque(self): + """Test a function taking C++ list by pointer for which an opaque + container exists.""" + lu = ListUser() + python_list = [1, 2] + self.assertEqual(lu.modifyIntListPtr(python_list), 2) + + # Pass an opaque container and verify whether it is modified by C++ + cpp_list = StdIntList() + cpp_list.append(1) + cpp_list.append(2) + self.assertEqual(lu.modifyIntListPtr(cpp_list), 2) + self.assertEqual(len(cpp_list), 3) + + def testListByPtr(self): + """Test a function taking C++ list by pointer for which no opaque + container exists.""" + lu = ListUser() + python_list = [1.1, 22.2] + self.assertEqual(lu.modifyDoubleListPtr(python_list), 2) + + def testReturnListByPtr(self): + """Test that a virtual function returning a list by pointer can be + reimplemented by a Python function returning an opaque container.""" + lu = ExtListUser() + size = lu.callReturnIntListByPtr() # Call virtual from C++ + self.assertEqual(size, 2) if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/minimalbinding/minbool_test.py b/sources/shiboken6/tests/minimalbinding/minbool_test.py index 789803371..d9ce0eac0 100644 --- a/sources/shiboken6/tests/minimalbinding/minbool_test.py +++ b/sources/shiboken6/tests/minimalbinding/minbool_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 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$ -## -############################################################################# +# 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 os import sys @@ -40,32 +13,34 @@ init_paths() from minimal import MinBoolUser + class DerivedMinBoolUser (MinBoolUser): def returnMyselfVirtual(self): return MinBoolUser() + class MinBoolTest(unittest.TestCase): def testMinBoolUser(self): mbuTrue = MinBoolUser() mbuFalse = MinBoolUser() mbuTrue.setMinBool(True) - self.assertEqual(mbuFalse.minBool(), False) - self.assertEqual(mbuTrue.minBool(), True) - self.assertEqual(mbuTrue.callInvertedMinBool(), False) + self.assertFalse(mbuFalse.minBool()) + self.assertTrue(mbuTrue.minBool()) + self.assertFalse(mbuTrue.callInvertedMinBool()) - self.assertEqual(mbuTrue.minBool() == True, True) - self.assertEqual(False == mbuFalse.minBool(), True) - self.assertEqual(mbuTrue.minBool() == mbuFalse.minBool(), False) + self.assertTrue(mbuTrue.minBool()) + self.assertFalse(mbuFalse.minBool()) + self.assertTrue(mbuTrue.minBool() != mbuFalse.minBool()) - self.assertEqual(mbuFalse.minBool() != True, True) - self.assertEqual(True != mbuFalse.minBool(), True) - self.assertEqual(mbuTrue.minBool() != mbuFalse.minBool(), True) + self.assertFalse(mbuFalse.minBool()) + self.assertFalse(mbuFalse.minBool()) + self.assertTrue(mbuTrue.minBool() != mbuFalse.minBool()) def testVirtuals(self): dmbu = DerivedMinBoolUser() self.assertEqual(dmbu.invertedMinBool(), True) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/minimalbinding/minimal-binding.txt.in b/sources/shiboken6/tests/minimalbinding/minimal-binding.txt.in index 85b139676..101567070 100644 --- a/sources/shiboken6/tests/minimalbinding/minimal-binding.txt.in +++ b/sources/shiboken6/tests/minimalbinding/minimal-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/minimalbinding/minimalbinding.pyproject b/sources/shiboken6/tests/minimalbinding/minimalbinding.pyproject new file mode 100644 index 000000000..ab19dc443 --- /dev/null +++ b/sources/shiboken6/tests/minimalbinding/minimalbinding.pyproject @@ -0,0 +1,10 @@ +{ + "files": ["brace_pattern_test.py", + "containeruser_test.py", + "listuser_test.py", + "minbool_test.py", + "obj_test.py", + "typedef_test.py", + "val_test.py", + "typesystem_minimal.xml"] +} diff --git a/sources/shiboken6/tests/minimalbinding/obj_test.py b/sources/shiboken6/tests/minimalbinding/obj_test.py index 1abd6e04c..e873845de 100644 --- a/sources/shiboken6/tests/minimalbinding/obj_test.py +++ b/sources/shiboken6/tests/minimalbinding/obj_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 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$ -## -############################################################################# +# 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 os import sys @@ -39,6 +12,7 @@ from shiboken_paths import init_paths init_paths() from minimal import Obj + class ExtObj(Obj): def __init__(self, objId): Obj.__init__(self, objId) @@ -118,4 +92,3 @@ class ObjTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/minimalbinding/spanuser_test.py b/sources/shiboken6/tests/minimalbinding/spanuser_test.py new file mode 100644 index 000000000..6db6aa616 --- /dev/null +++ b/sources/shiboken6/tests/minimalbinding/spanuser_test.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() + +from minimal import SpanUser + + +class IntSpanTest(unittest.TestCase): + + def testCreateIntSpan(self): + if not SpanUser.enabled(): + return + expected = [1, 2, 3] + self.assertEqual(SpanUser.getIntSpan3(), expected) + self.assertEqual(SpanUser.getIntSpan(), expected) + self.assertEqual(SpanUser.getConstIntSpan3(), expected) + + self.assertEqual(SpanUser.sumIntSpan3(expected), 6) + self.assertEqual(SpanUser.sumIntSpan(expected), 6) + self.assertEqual(SpanUser.sumConstIntSpan3(expected), 6) + + def testSpanOpaqueContainer(self): + if not SpanUser.enabled(): + return + oc = SpanUser.getIntSpan3_OpaqueContainer() # 1,2,3 + oc[1] = 10 + oc = SpanUser.getIntSpan3_OpaqueContainer() + # note: This converts to std::vector + self.assertEqual(SpanUser.sumIntSpan3(oc), 14) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/minimalbinding/typedef_test.py b/sources/shiboken6/tests/minimalbinding/typedef_test.py index 9076cbe5e..c2fc8fc12 100644 --- a/sources/shiboken6/tests/minimalbinding/typedef_test.py +++ b/sources/shiboken6/tests/minimalbinding/typedef_test.py @@ -1,35 +1,7 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 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$ -## -############################################################################# - -from functools import reduce +# 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 os import sys import unittest @@ -38,7 +10,9 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from minimal import * +from minimal import (arrayFunc, arrayFuncInt, arrayFuncIntReturn, + arrayFuncIntReturnTypedef, arrayFuncIntTypedef, + arrayFuncReturn, arrayFuncReturnTypedef, arrayFuncTypedef) try: import numpy as np @@ -58,29 +32,37 @@ class TypedefTest(unittest.TestCase): self.assertTrue(arrayFuncInt(none), "None is empty, arrayFuncInt should return true") self.assertFalse(arrayFuncInt(full), "Full is NOT empty, arrayFuncInt should return false") - self.assertTrue(arrayFuncInt(np.array(none)), "None is empty, arrayFuncInt should return true") - self.assertFalse(arrayFuncInt(np.array(full)), "Full is NOT empty, arrayFuncInt should return false") + self.assertTrue(arrayFuncInt(np.array(none)), + "None is empty, arrayFuncInt should return true") + self.assertFalse(arrayFuncInt(np.array(full)), + "Full is NOT empty, arrayFuncInt should return false") def test_arrayFuncIntTypedef(self): none = () full = (1, 2, 3) - self.assertTrue(arrayFuncIntTypedef(none), "None is empty, arrayFuncIntTypedef should return true") - self.assertFalse(arrayFuncIntTypedef(full), "Full is NOT empty, arrayFuncIntTypedef should return false") + self.assertTrue(arrayFuncIntTypedef(none), + "None is empty, arrayFuncIntTypedef should return true") + self.assertFalse(arrayFuncIntTypedef(full), + "Full is NOT empty, arrayFuncIntTypedef should return false") - self.assertTrue(arrayFuncIntTypedef(np.array(none)), "None is empty, arrayFuncIntTypedef should return true") - self.assertFalse(arrayFuncIntTypedef(np.array(full)), "Full is NOT empty, arrayFuncIntTypedef should return false") + self.assertTrue(arrayFuncIntTypedef(np.array(none)), + "None is empty, arrayFuncIntTypedef should return true") + self.assertFalse(arrayFuncIntTypedef(np.array(full)), + "Full is NOT empty, arrayFuncIntTypedef should return false") def test_arrayFuncIntReturn(self): none = arrayFuncIntReturn(0) full = arrayFuncIntReturn(self.the_size) self.assertTrue((len(none) == 0), "none should be empty") - self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + self.assertTrue((len(full) == self.the_size), + f"full should have {self.the_size} elements") def test_arrayFuncIntReturnTypedef(self): none = arrayFuncIntReturnTypedef(0) full = arrayFuncIntReturnTypedef(self.the_size) self.assertTrue((len(none) == 0), "none should be empty") - self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + self.assertTrue((len(full) == self.the_size), + f"full should have {self.the_size} elements") def test_arrayFunc(self): none = () @@ -89,30 +71,37 @@ class TypedefTest(unittest.TestCase): self.assertFalse(arrayFunc(full), "Full is NOT empty, arrayFunc should return false") self.assertTrue(arrayFunc(np.array(none)), "None is empty, arrayFunc should return true") - self.assertFalse(arrayFunc(np.array(full)), "Full is NOT empty, arrayFunc should return false") + self.assertFalse(arrayFunc(np.array(full)), + "Full is NOT empty, arrayFunc should return false") def test_arrayFuncTypedef(self): none = () full = (1, 2, 3) - self.assertTrue(arrayFuncTypedef(none), "None is empty, arrayFuncTypedef should return true") - self.assertFalse(arrayFuncTypedef(full), "Full is NOT empty, arrayFuncTypedef should return false") + self.assertTrue(arrayFuncTypedef(none), + "None is empty, arrayFuncTypedef should return true") + self.assertFalse(arrayFuncTypedef(full), + "Full is NOT empty, arrayFuncTypedef should return false") - self.assertTrue(arrayFuncTypedef(np.array(none)), "None is empty, arrayFuncTypedef should return true") - self.assertFalse(arrayFuncTypedef(np.array(full)), "Full is NOT empty, arrayFuncTypedef should return false") + self.assertTrue(arrayFuncTypedef(np.array(none)), + "None is empty, arrayFuncTypedef should return true") + self.assertFalse(arrayFuncTypedef(np.array(full)), + "Full is NOT empty, arrayFuncTypedef should return false") def test_arrayFuncReturn(self): none = arrayFuncReturn(0) full = arrayFuncReturn(self.the_size) self.assertTrue((len(none) == 0), "none should be empty") - self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + self.assertTrue((len(full) == self.the_size), + f"full should have {self.the_size} elements") def test_arrayFuncReturnTypedef(self): none = arrayFuncReturnTypedef(0) full = arrayFuncReturnTypedef(self.the_size) self.assertTrue((len(none) == 0), "none should be empty") - self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + self.assertTrue((len(full) == self.the_size), + f"full should have {self.the_size} elements") if __name__ == '__main__': - if np != None: + if np is not None: unittest.main() diff --git a/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml b/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml index 625615fa1..e18bf8686 100644 --- a/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml +++ b/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml @@ -1,7 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <typesystem package="minimal"> - <primitive-type name="bool"/> - <primitive-type name="int"/> <primitive-type name="MinBool" target-lang-api-name="PyBool" default-constructor="MinBool(false)"> <include file-name="minbool.h" location="global"/> @@ -17,65 +15,59 @@ </conversion-rule> </primitive-type> - <container-type name="std::list" type="list"> - <include file-name="list" location="global"/> - <conversion-rule> - <native-to-target> - PyObject* %out = PyList_New(Py_ssize_t(%in.size())); - Py_ssize_t idx = 0; - for (auto it = %in.cbegin(), end = %in.cend(); it != end; ++it, ++idx) { - %INTYPE_0 cppItem(*it); - PyList_SET_ITEM(%out, idx, %CONVERTTOPYTHON[%INTYPE_0](cppItem)); - } - return %out; - </native-to-target> - <target-to-native> - <add-conversion type="PySequence"> - Shiboken::AutoDecRef seq(PySequence_Fast(%in, 0)); - const Py_ssize_t size = PySequence_Fast_GET_SIZE(seq.object()); - for (Py_ssize_t i = 0; i < size; ++i) { - PyObject* pyItem = PySequence_Fast_GET_ITEM(seq.object(), i); - %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); - %out.push_back(cppItem); - } - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> + <opaque-container name="std::list" opaque-containers="int:StdIntList"/> + + <opaque-container name="std::vector" opaque-containers="int:StdIntVector"/> + + <opaque-container name="std::array" opaque-containers="int,3:StdIntArray"/> + + <?if c++20?> <!-- FIXME PYSIDE 7: Remove "if" --> + <opaque-container name="std::span" opaque-containers="int,3:StdIntSpan3"/> + <?endif?> <object-type name="Obj"/> <value-type name="Val"> <enum-type name="ValEnum"/> </value-type> - <value-type name="ListUser"/> + <value-type name="ListUser"> + <modify-field name="m_stdIntList" opaque-container="yes"/> + <modify-function signature="getIntList()"> + <modify-argument index="return"> + <replace-type modified-type="StdIntList"/> + </modify-argument> + </modify-function> + <modify-function signature="getConstIntList()const"> + <modify-argument index="return"> + <replace-type modified-type="StdIntList"/> + </modify-argument> + </modify-function> + </value-type> + + <value-type name="SpanUser"> + <?if c++20?> <!-- FIXME PYSIDE 7: Remove "if" --> + <modify-function signature="getIntSpan3_OpaqueContainer()"> + <modify-argument index="return"> + <replace-type modified-type="StdIntSpan3"/> + </modify-argument> + </modify-function> + <?endif?> + </value-type> + <value-type name="MinBoolUser"/> - <container-type name="std::vector" type="vector"> - <include file-name="vector" location="global"/> - <conversion-rule> - <native-to-target> - %INTYPE::size_type vectorSize = %in.size(); - PyObject* %out = PyList_New(Py_ssize_t(vectorSize)); - for (%INTYPE::size_type idx = 0; idx < vectorSize; ++idx) { - %INTYPE_0 cppItem(%in[idx]); - PyList_SET_ITEM(%out, idx, %CONVERTTOPYTHON[%INTYPE_0](cppItem)); - } - return %out; - </native-to-target> - <target-to-native> - <add-conversion type="PySequence"> - Shiboken::AutoDecRef seq(PySequence_Fast(%in, 0)); - const Py_ssize_t vectorSize = PySequence_Fast_GET_SIZE(seq.object()); - %out.reserve(vectorSize); - for (Py_ssize_t idx = 0; idx < vectorSize; ++idx ) { - PyObject* pyItem = PySequence_Fast_GET_ITEM(seq.object(), idx); - %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); - %out.push_back(cppItem); - } - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> + <value-type name="ContainerUser"> + <modify-function signature="intVector()"> + <modify-argument index="return"> + <replace-type modified-type="StdIntVector"/> + </modify-argument> + </modify-function> + <modify-function signature="intArray()"> + <modify-argument index="return"> + <replace-type modified-type="StdIntArray"/> + </modify-argument> + </modify-function> + </value-type> + <!-- Test wrapping of a typedef --> <function signature="arrayFuncInt(std::vector<int>)" /> <!-- Note manual expansion of the typedef --> diff --git a/sources/shiboken6/tests/minimalbinding/val_test.py b/sources/shiboken6/tests/minimalbinding/val_test.py index 63d2cf300..b8225a247 100644 --- a/sources/shiboken6/tests/minimalbinding/val_test.py +++ b/sources/shiboken6/tests/minimalbinding/val_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 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$ -## -############################################################################# +# 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 os import sys @@ -119,4 +92,3 @@ class ValTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - |