aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/minimalbinding/listuser_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/tests/minimalbinding/listuser_test.py')
-rw-r--r--sources/shiboken6/tests/minimalbinding/listuser_test.py123
1 files changed, 86 insertions, 37 deletions
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()
-