aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/minimalbinding
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-28 07:51:22 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-28 09:34:35 +0000
commit2a2a0827fa54b2eeb48e0e2090dfc503492ef33e (patch)
tree4311f7ad34ff98fabcbe4c34e59a970ae4ff4bcf /sources/shiboken6/tests/minimalbinding
parentfb1c0f204e09ba29fa3d360d72231d4ed468c1e4 (diff)
Rename shiboken2 to shiboken6
Adapt CMake files, build scripts, tests and examples. Task-number: PYSIDE-904 Change-Id: I4cb5ee4c8df539546014b08202a7b1e98ed3ff07 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/tests/minimalbinding')
-rw-r--r--sources/shiboken6/tests/minimalbinding/CMakeLists.txt36
-rw-r--r--sources/shiboken6/tests/minimalbinding/brace_pattern_test.py125
-rw-r--r--sources/shiboken6/tests/minimalbinding/global.h33
-rw-r--r--sources/shiboken6/tests/minimalbinding/listuser_test.py326
-rw-r--r--sources/shiboken6/tests/minimalbinding/minbool_test.py70
-rw-r--r--sources/shiboken6/tests/minimalbinding/minimal-binding.txt.in15
-rw-r--r--sources/shiboken6/tests/minimalbinding/obj_test.py120
-rw-r--r--sources/shiboken6/tests/minimalbinding/typedef_test.py117
-rw-r--r--sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml93
-rw-r--r--sources/shiboken6/tests/minimalbinding/val_test.py121
10 files changed, 1056 insertions, 0 deletions
diff --git a/sources/shiboken6/tests/minimalbinding/CMakeLists.txt b/sources/shiboken6/tests/minimalbinding/CMakeLists.txt
new file mode 100644
index 000000000..63ad8a577
--- /dev/null
+++ b/sources/shiboken6/tests/minimalbinding/CMakeLists.txt
@@ -0,0 +1,36 @@
+project(minimal)
+
+set(minimal_TYPESYSTEM
+${CMAKE_CURRENT_SOURCE_DIR}/typesystem_minimal.xml
+)
+
+set(minimal_SRC
+${CMAKE_CURRENT_BINARY_DIR}/minimal/minimal_module_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/minbooluser_wrapper.cpp
+)
+
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/minimal-binding.txt.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/minimal-binding.txt" @ONLY)
+
+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..."
+)
+
+add_library(minimal MODULE ${minimal_SRC})
+target_include_directories(minimal PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
+target_link_libraries(minimal PUBLIC libminimal libshiboken)
+set_property(TARGET minimal PROPERTY PREFIX "")
+set_property(TARGET minimal PROPERTY OUTPUT_NAME "minimal${PYTHON_EXTENSION_SUFFIX}")
+if(WIN32)
+ set_property(TARGET minimal PROPERTY SUFFIX ".pyd")
+endif()
+
+create_generator_target(minimal)
diff --git a/sources/shiboken6/tests/minimalbinding/brace_pattern_test.py b/sources/shiboken6/tests/minimalbinding/brace_pattern_test.py
new file mode 100644
index 000000000..4afd46b91
--- /dev/null
+++ b/sources/shiboken6/tests/minimalbinding/brace_pattern_test.py
@@ -0,0 +1,125 @@
+#############################################################################
+##
+## 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$
+##
+#############################################################################
+
+from __future__ import absolute_import, print_function
+
+import os
+import re
+import sys
+import unittest
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from shiboken_paths import init_paths
+init_paths()
+
+import shiboken6
+_init_pyside_extension() # trigger bootstrap
+
+from shibokensupport.signature.lib.tool import build_brace_pattern
+
+"""
+This test tests the brace pattern from signature.lib.tool
+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):
+ open, close = "[{(<", "]})>"
+ escape, quote = "\\", '"'
+ instring = blind = False
+ stack = []
+ for c in s:
+ if instring:
+ if blind:
+ blind = False
+ elif c == escape:
+ blind = True
+ elif c == quote:
+ instring = False
+ stack.pop()
+ continue
+ if c in open:
+ stack.append(c)
+ elif c in close:
+ pos = close.index(c)
+ if ((len(stack) > 0) and
+ (open[pos] == stack[len(stack)-1])):
+ stack.pop()
+ else:
+ return False
+ elif c == escape:
+ return False
+ elif c == quote:
+ instring = True
+ stack.append(c)
+ return len(stack) == 0
+
+
+class TestBracePattern(unittest.TestCase):
+ tests = [
+ (r'{[]{()}}', True),
+ (r'[{}{})(]', False),
+ (r'[{}{} ")(" ]', True),
+ (r'[{}{} ")(\" ]', False),
+ (r'[{}{} ")(\" ]"]', True),
+ (r'a < b ( c [ d { "} \"\"}" } ] ) >', True),
+ (r'a < b ( c [ d { } ] ) >', True),
+ (r'a < b ( c [ d { "huh" } ] ) >', True),
+ (r'a < b ( c [ d { "huh\" \" \\\"" } ] ) >', True),
+ ]
+
+ def test_checkfunc(self):
+ for test, result in self.tests:
+ if result:
+ self.assertTrue(check(test))
+ else:
+ self.assertFalse(check(test))
+
+ def test_the_brace_pattern(self):
+ func = re.compile(build_brace_pattern(5) + "$", re.VERBOSE).match
+ for test, result in self.tests:
+ if result:
+ self.assertTrue(func(test))
+ else:
+ self.assertFalse(func(test))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/shiboken6/tests/minimalbinding/global.h b/sources/shiboken6/tests/minimalbinding/global.h
new file mode 100644
index 000000000..1b06245c4
--- /dev/null
+++ b/sources/shiboken6/tests/minimalbinding/global.h
@@ -0,0 +1,33 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#include "obj.h"
+#include "val.h"
+#include "minbool.h"
+#include "listuser.h"
+#include "typedef.h"
diff --git a/sources/shiboken6/tests/minimalbinding/listuser_test.py b/sources/shiboken6/tests/minimalbinding/listuser_test.py
new file mode 100644
index 000000000..3668cb55f
--- /dev/null
+++ b/sources/shiboken6/tests/minimalbinding/listuser_test.py
@@ -0,0 +1,326 @@
+#!/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
+import os
+import sys
+import unittest
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from shiboken_paths import init_paths
+init_paths()
+
+from minimal import ListUser, Val, Obj
+
+
+class ExtListUser(ListUser):
+ def __init__(self):
+ ListUser.__init__(self)
+
+ def createIntList(self, num):
+ return list(range(0, num * 2, 2))
+
+ def sumIntList(self, intList):
+ return sum(intList) * 2
+
+ def createMinBoolList(self, mb1, mb2):
+ return [not mb1, not mb2]
+
+ def oredMinBoolList(self, 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)]
+
+ def sumValList(self, valList):
+ return sum([val.valId() for val in valList]) * 2
+
+ def createObjList(self, o1, o2):
+ o1.setObjId(o1.objId() * 2)
+ o2.setObjId(o2.objId() * 2)
+ return [o1, o2]
+
+ def sumObjList(self, objList):
+ return sum([obj.objId() for obj in objList]) * 2
+
+ def createListOfIntLists(self, num):
+ return [self.createIntList(num)] * 4
+
+ def sumListOfIntLists(self, intListList):
+ return sum([sum(line) for line in intListList]) * 2
+
+
+class IntListConversionTest(unittest.TestCase):
+
+ def testCreateIntList(self):
+ num = 4
+ lu = ListUser()
+ lst = lu.createIntList(num)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), num)
+ for i in lst:
+ self.assertEqual(type(i), int)
+ self.assertEqual(lst, list(range(num)))
+ lst = lu.callCreateIntList(num)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), num)
+ for i in lst:
+ self.assertEqual(type(i), int)
+ self.assertEqual(lst, list(range(num)))
+
+ def testCreateIntListFromExtendedClass(self):
+ lu = ExtListUser()
+ num = 4
+ lst = lu.createIntList(num)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), num)
+ for i in lst:
+ self.assertEqual(type(i), int)
+ self.assertEqual(lst, list(range(0, num * 2, 2)))
+ lst = lu.callCreateIntList(num)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), num)
+ for i in lst:
+ self.assertEqual(type(i), int)
+ self.assertEqual(lst, list(range(0, num * 2, 2)))
+
+ def testSumIntList(self):
+ lu = ListUser()
+ lst = range(4)
+ self.assertEqual(lu.sumIntList(lst), sum(lst))
+ self.assertEqual(lu.callSumIntList(lst), sum(lst))
+
+ def testSumIntListFromExtendedClass(self):
+ lu = ExtListUser()
+ lst = range(4)
+ self.assertEqual(lu.sumIntList(lst), sum(lst) * 2)
+ self.assertEqual(lu.callSumIntList(lst), sum(lst) * 2)
+
+
+class MinBoolListConversionTest(unittest.TestCase):
+
+ def testCreateMinBoolList(self):
+ lu = ListUser()
+ lst = lu.createMinBoolList(True, False)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), 2)
+ for i in lst:
+ self.assertEqual(type(i), bool)
+ self.assertEqual(lst, [True, False])
+
+ lst = lu.callCreateMinBoolList(False, True)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), 2)
+ for i in lst:
+ self.assertEqual(type(i), bool)
+ self.assertEqual(lst, [False, True])
+
+ def testCreateMinBoolListFromExtendedClass(self):
+ lu = ExtListUser()
+ lst = lu.createMinBoolList(True, False)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), 2)
+ for i in lst:
+ self.assertEqual(type(i), bool)
+ self.assertEqual(lst, [False, True])
+
+ lst = lu.callCreateMinBoolList(False, True)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), 2)
+ for i in lst:
+ self.assertEqual(type(i), bool)
+ self.assertEqual(lst, [True, False])
+
+ def testOredMinBoolList(self):
+ lu = ListUser()
+ lst = [False, False, True]
+ self.assertTrue(lu.oredMinBoolList(lst))
+ self.assertTrue(lu.callOredMinBoolList(lst))
+ lst = [False, False, False]
+ self.assertFalse(lu.oredMinBoolList(lst))
+ self.assertFalse(lu.callOredMinBoolList(lst))
+
+ def testOredMinBoolListFromExtendedClass(self):
+ lu = ExtListUser()
+ lst = [False, False, True]
+ self.assertFalse(lu.oredMinBoolList(lst))
+ self.assertFalse(lu.callOredMinBoolList(lst))
+ lst = [False, False, False]
+ self.assertTrue(lu.oredMinBoolList(lst))
+ self.assertTrue(lu.callOredMinBoolList(lst))
+
+
+class ValListConversionTest(unittest.TestCase):
+
+ def testCreateValList(self):
+ num = 4
+ lu = ListUser()
+ lst = lu.createValList(num)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), num)
+ for i in lst:
+ self.assertEqual(type(i), Val)
+ self.assertEqual([val.valId() for val in lst], list(range(num)))
+ lst = lu.callCreateValList(num)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), num)
+ for i in lst:
+ self.assertEqual(type(i), Val)
+ self.assertEqual([val.valId() for val in lst], list(range(num)))
+
+ def testCreateValListFromExtendedClass(self):
+ lu = ExtListUser()
+ num = 4
+ lst = lu.createValList(num)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), num)
+ for i in lst:
+ self.assertEqual(type(i), Val)
+ self.assertEqual([val.valId() for val in lst], list(range(0, num * 2, 2)))
+ lst = lu.callCreateValList(num)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), num)
+ for i in lst:
+ self.assertEqual(type(i), Val)
+ self.assertEqual([val.valId() for val in lst], list(range(0, num * 2, 2)))
+
+ def testSumValList(self):
+ lu = ListUser()
+ lst = [Val(i) for i in range(4)]
+ self.assertEqual(lu.sumValList(lst), sum([val.valId() for val in lst]))
+ self.assertEqual(lu.callSumValList(lst), sum([val.valId() for val in lst]))
+
+ def testSumValListFromExtendedClass(self):
+ lu = ExtListUser()
+ lst = [Val(i) for i in range(4)]
+ self.assertEqual(lu.sumValList(lst), sum([val.valId() for val in lst]) * 2)
+ self.assertEqual(lu.callSumValList(lst), sum([val.valId() for val in lst]) * 2)
+
+
+class ObjListConversionTest(unittest.TestCase):
+
+ def testCreateObjList(self):
+ o1 = Obj(1)
+ o2 = Obj(2)
+ lu = ListUser()
+ lst = lu.createObjList(o1, o2)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), 2)
+ for i in lst:
+ self.assertEqual(type(i), Obj)
+ self.assertEqual(lst, [o1, o2])
+ self.assertEqual([obj.objId() for obj in lst], [1, 2])
+
+ lst = lu.callCreateObjList(o1, o2)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), 2)
+ for i in lst:
+ self.assertEqual(type(i), Obj)
+ self.assertEqual(lst, [o1, o2])
+ self.assertEqual([obj.objId() for obj in lst], [1, 2])
+
+ def testCreateObjListFromExtendedClass(self):
+ o1 = Obj(1)
+ o2 = Obj(2)
+ lu = ExtListUser()
+ lst = lu.createObjList(o1, o2)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), 2)
+ for i in lst:
+ self.assertEqual(type(i), Obj)
+ self.assertEqual(lst, [o1, o2])
+ self.assertEqual([obj.objId() for obj in lst], [2, 4])
+
+ lst = lu.callCreateObjList(o1, o2)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), 2)
+ for i in lst:
+ self.assertEqual(type(i), Obj)
+ self.assertEqual(lst, [o1, o2])
+ self.assertEqual([obj.objId() for obj in lst], [4, 8])
+
+ def testSumObjList(self):
+ lu = ListUser()
+ lst = [Obj(i) for i in list(range(4))]
+ self.assertEqual(lu.sumObjList(lst), sum([obj.objId() for obj in lst]))
+ self.assertEqual(lu.callSumObjList(lst), sum([obj.objId() for obj in lst]))
+
+ def testSumObjListFromExtendedClass(self):
+ lu = ExtListUser()
+ lst = [Obj(i) for i in list(range(4))]
+ self.assertEqual(lu.sumObjList(lst), sum([obj.objId() for obj in lst]) * 2)
+ self.assertEqual(lu.callSumObjList(lst), sum([obj.objId() for obj in lst]) * 2)
+
+
+class ListOfIntListConversionTest(unittest.TestCase):
+
+ def testCreateListOfIntLists(self):
+ num = 4
+ lu = ListUser()
+ lst = lu.createListOfIntLists(num)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), num)
+ for i in lst:
+ self.assertEqual(type(i), list)
+ self.assertEqual(i, list(range(num)))
+ for j in i:
+ self.assertEqual(type(j), int)
+ self.assertEqual(lst, [list(range(num))] * 4)
+
+ def testCreateListOfIntListsFromExtendedClass(self):
+ num = 4
+ lu = ExtListUser()
+ lst = lu.createListOfIntLists(num)
+ self.assertEqual(type(lst), list)
+ self.assertEqual(len(lst), num)
+ for i in lst:
+ self.assertEqual(type(i), list)
+ self.assertEqual(i, list(range(0, num * 2, 2)))
+ for j in i:
+ self.assertEqual(type(j), int)
+ self.assertEqual(lst, [list(range(0, num * 2, 2))] * 4)
+
+ def testSumListIntLists(self):
+ lu = ListUser()
+ lst = [range(4)] * 4
+ self.assertEqual(lu.sumListOfIntLists(lst), sum([sum(line) for line in [range(4)] * 4]))
+ self.assertEqual(lu.callSumListOfIntLists(lst), sum([sum(line) for line in [range(4)] * 4]))
+
+ 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)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/sources/shiboken6/tests/minimalbinding/minbool_test.py b/sources/shiboken6/tests/minimalbinding/minbool_test.py
new file mode 100644
index 000000000..adc0929fd
--- /dev/null
+++ b/sources/shiboken6/tests/minimalbinding/minbool_test.py
@@ -0,0 +1,70 @@
+#!/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$
+##
+#############################################################################
+
+import os
+import sys
+import unittest
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from shiboken_paths import init_paths
+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.assertEqual(mbuTrue.minBool() == True, True)
+ self.assertEqual(False == mbuFalse.minBool(), True)
+ self.assertEqual(mbuTrue.minBool() == mbuFalse.minBool(), False)
+
+ self.assertEqual(mbuFalse.minBool() != True, True)
+ self.assertEqual(True != mbuFalse.minBool(), True)
+ self.assertEqual(mbuTrue.minBool() != mbuFalse.minBool(), True)
+
+ 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
new file mode 100644
index 000000000..85b139676
--- /dev/null
+++ b/sources/shiboken6/tests/minimalbinding/minimal-binding.txt.in
@@ -0,0 +1,15 @@
+[generator-project]
+
+generator-set = shiboken
+
+header-file = @CMAKE_CURRENT_SOURCE_DIR@/global.h
+typesystem-file = @minimal_TYPESYSTEM@
+
+output-directory = @CMAKE_CURRENT_BINARY_DIR@
+
+include-path = @libminimal_SOURCE_DIR@
+
+typesystem-path = @CMAKE_CURRENT_SOURCE_DIR@
+
+enable-parent-ctor-heuristic
+use-isnull-as-nb_nonzero
diff --git a/sources/shiboken6/tests/minimalbinding/obj_test.py b/sources/shiboken6/tests/minimalbinding/obj_test.py
new file mode 100644
index 000000000..a0869a67b
--- /dev/null
+++ b/sources/shiboken6/tests/minimalbinding/obj_test.py
@@ -0,0 +1,120 @@
+#!/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$
+##
+#############################################################################
+
+import os
+import sys
+import unittest
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from shiboken_paths import init_paths
+init_paths()
+from minimal import Obj
+
+class ExtObj(Obj):
+ def __init__(self, objId):
+ Obj.__init__(self, objId)
+ self.virtual_method_called = False
+
+ def virtualMethod(self, val):
+ self.virtual_method_called = True
+ return not Obj.virtualMethod(self, val)
+
+ def passObjectType(self, obj):
+ obj.setObjId(obj.objId() + 1)
+ return obj
+
+ def passObjectTypeReference(self, obj):
+ obj.setObjId(obj.objId() + 1)
+ return obj
+
+
+class ObjTest(unittest.TestCase):
+
+ def testNormalMethod(self):
+ objId = 123
+ obj = Obj(objId)
+ self.assertEqual(obj.objId(), objId)
+
+ def testNormalMethodFromExtendedClass(self):
+ objId = 123
+ obj = ExtObj(objId)
+ self.assertEqual(obj.objId(), objId)
+
+ def testVirtualMethod(self):
+ obj = Obj(0)
+ even_number = 8
+ self.assertEqual(obj.virtualMethod(even_number), obj.callVirtualMethod(even_number))
+
+ def testVirtualMethodFromExtendedClass(self):
+ obj = ExtObj(0)
+ even_number = 8
+ self.assertEqual(obj.virtualMethod(even_number), obj.callVirtualMethod(even_number))
+ self.assertTrue(obj.virtual_method_called)
+
+ def testPassObjectType(self):
+ obj = Obj(0)
+ self.assertEqual(obj, obj.passObjectType(obj))
+ self.assertEqual(obj, obj.callPassObjectType(obj))
+
+ def testPassObjectTypeNone(self):
+ obj = Obj(0)
+ self.assertEqual(None, obj.passObjectType(None))
+ self.assertEqual(None, obj.callPassObjectType(None))
+
+ def testPassObjectTypeReference(self):
+ obj = Obj(0)
+ self.assertEqual(obj, obj.passObjectTypeReference(obj))
+ self.assertEqual(obj, obj.callPassObjectTypeReference(obj))
+
+ def testPassObjectTypeFromExtendedClass(self):
+ obj = ExtObj(0)
+ self.assertEqual(obj.objId(), 0)
+ sameObj = obj.passObjectType(obj)
+ self.assertEqual(obj, sameObj)
+ self.assertEqual(sameObj.objId(), 1)
+ sameObj = obj.callPassObjectType(obj)
+ self.assertEqual(obj, sameObj)
+ self.assertEqual(sameObj.objId(), 2)
+
+ def testPassObjectTypeReferenceFromExtendedClass(self):
+ obj = ExtObj(0)
+ self.assertEqual(obj.objId(), 0)
+ sameObj = obj.passObjectTypeReference(obj)
+ self.assertEqual(obj, sameObj)
+ self.assertEqual(sameObj.objId(), 1)
+ sameObj = obj.callPassObjectTypeReference(obj)
+ self.assertEqual(obj, sameObj)
+ self.assertEqual(sameObj.objId(), 2)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/sources/shiboken6/tests/minimalbinding/typedef_test.py b/sources/shiboken6/tests/minimalbinding/typedef_test.py
new file mode 100644
index 000000000..e8dd5cd16
--- /dev/null
+++ b/sources/shiboken6/tests/minimalbinding/typedef_test.py
@@ -0,0 +1,117 @@
+#!/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
+import os
+import sys
+import unittest
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from shiboken_paths import init_paths
+init_paths()
+from minimal import *
+
+try:
+ import numpy as np
+except ImportError as e:
+ print(e)
+ np = None
+
+
+class TypedefTest(unittest.TestCase):
+
+ def setUp(self):
+ self.the_size = 8
+
+ def test_arrayFuncInt(self):
+ none = ()
+ full = range(self.the_size)
+ 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")
+
+ 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(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")
+
+ 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")
+
+ def test_arrayFunc(self):
+ none = ()
+ full = range(self.the_size)
+ self.assertTrue(arrayFunc(none), "None is empty, arrayFunc should return true")
+ 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")
+
+ 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(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")
+
+ 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")
+
+
+if __name__ == '__main__':
+ if np != None:
+ unittest.main()
diff --git a/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml b/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml
new file mode 100644
index 000000000..03b88a970
--- /dev/null
+++ b/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml
@@ -0,0 +1,93 @@
+<?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"/>
+ <conversion-rule>
+ <native-to-target>
+ return PyBool_FromLong(%in.value());
+ </native-to-target>
+ <target-to-native>
+ <add-conversion type="PyBool" check="PyBool_Check(%in)">
+ %out = %OUTTYPE(%in == Py_True);
+ </add-conversion>
+ </target-to-native>
+ </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((int) %in.size());
+ %INTYPE::const_iterator it = %in.begin();
+ for (int idx = 0; it != %in.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));
+ for (int i = 0; i &lt; PySequence_Fast_GET_SIZE(seq.object()); 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>
+
+ <object-type name="Obj"/>
+ <value-type name="Val">
+ <enum-type name="ValEnum"/>
+ </value-type>
+ <value-type name="ListUser"/>
+ <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((int) vectorSize);
+ for (%INTYPE::size_type idx = 0; idx &lt; 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));
+ int vectorSize = PySequence_Fast_GET_SIZE(seq.object());
+ %out.reserve(vectorSize);
+ for (int idx = 0; idx &lt; 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>
+ <!-- Test wrapping of a typedef -->
+ <function signature="arrayFuncInt(std::vector&lt;int&gt;)" />
+ <!-- Note manual expansion of the typedef -->
+ <function signature="arrayFuncIntTypedef(std::vector&lt;int&gt;)" />
+
+ <function signature="arrayFuncIntReturn(int)" />
+ <function signature="arrayFuncIntReturnTypedef(int)" />
+
+ <!-- Test wrapping of a typedef of a typedef -->
+ <function signature="arrayFunc(std::vector&lt;int&gt;)" />
+ <!-- Note manual expansion of the typedef -->
+ <function signature="arrayFuncTypedef(std::vector&lt;int&gt;)" />
+
+ <function signature="arrayFuncReturn(int)" />
+ <function signature="arrayFuncReturnTypedef(int)" />
+</typesystem>
diff --git a/sources/shiboken6/tests/minimalbinding/val_test.py b/sources/shiboken6/tests/minimalbinding/val_test.py
new file mode 100644
index 000000000..f97e9487d
--- /dev/null
+++ b/sources/shiboken6/tests/minimalbinding/val_test.py
@@ -0,0 +1,121 @@
+#!/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$
+##
+#############################################################################
+
+import os
+import sys
+import unittest
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from shiboken_paths import init_paths
+init_paths()
+from minimal import Val
+
+
+class ExtVal(Val):
+ def __init__(self, valId):
+ Val.__init__(self, valId)
+
+ def passValueType(self, val):
+ return ExtVal(val.valId() + 1)
+
+ def passValueTypePointer(self, val):
+ val.setValId(val.valId() + 1)
+ return val
+
+ def passValueTypeReference(self, val):
+ val.setValId(val.valId() + 1)
+ return val
+
+
+class ValTest(unittest.TestCase):
+
+ def testNormalMethod(self):
+ valId = 123
+ val = Val(valId)
+ self.assertEqual(val.valId(), valId)
+
+ def testPassValueType(self):
+ val = Val(123)
+ val1 = val.passValueType(val)
+ self.assertNotEqual(val, val1)
+ self.assertEqual(val1.valId(), 123)
+ val2 = val.callPassValueType(val)
+ self.assertNotEqual(val, val2)
+ self.assertEqual(val2.valId(), 123)
+
+ def testPassValueTypePointer(self):
+ val = Val(0)
+ self.assertEqual(val, val.passValueTypePointer(val))
+ self.assertEqual(val, val.callPassValueTypePointer(val))
+
+ def testPassValueTypeReference(self):
+ val = Val(0)
+ self.assertEqual(val, val.passValueTypeReference(val))
+ self.assertEqual(val, val.callPassValueTypeReference(val))
+
+ def testPassAndReceiveEnumValue(self):
+ val = Val(0)
+ self.assertEqual(val.oneOrTheOtherEnumValue(Val.One), Val.Other)
+ self.assertEqual(val.oneOrTheOtherEnumValue(Val.Other), Val.One)
+
+ def testPassValueTypeFromExtendedClass(self):
+ val = ExtVal(0)
+ val1 = val.passValueType(val)
+ self.assertNotEqual(val, val1)
+ self.assertEqual(val1.valId(), val.valId() + 1)
+ val2 = val.callPassValueType(val)
+ self.assertNotEqual(val, val2)
+ self.assertEqual(val2.valId(), val.valId() + 1)
+
+ def testPassValueTypePointerFromExtendedClass(self):
+ val = ExtVal(0)
+ self.assertEqual(val.valId(), 0)
+ sameVal = val.passValueTypePointer(val)
+ self.assertEqual(val, sameVal)
+ self.assertEqual(sameVal.valId(), 1)
+ sameVal = val.callPassValueTypePointer(val)
+ self.assertEqual(val, sameVal)
+ self.assertEqual(sameVal.valId(), 2)
+
+ def testPassValueTypeReferenceFromExtendedClass(self):
+ val = ExtVal(0)
+ self.assertEqual(val.valId(), 0)
+ sameVal = val.passValueTypeReference(val)
+ self.assertEqual(val, sameVal)
+ self.assertEqual(sameVal.valId(), 1)
+ sameVal = val.callPassValueTypeReference(val)
+ self.assertEqual(val, sameVal)
+ self.assertEqual(sameVal.valId(), 2)
+
+
+if __name__ == '__main__':
+ unittest.main()
+