diff options
Diffstat (limited to 'sources/shiboken6/tests/samplebinding/derived_test.py')
-rw-r--r-- | sources/shiboken6/tests/samplebinding/derived_test.py | 82 |
1 files changed, 30 insertions, 52 deletions
diff --git a/sources/shiboken6/tests/samplebinding/derived_test.py b/sources/shiboken6/tests/samplebinding/derived_test.py index 8bdb051a8..346f29136 100644 --- a/sources/shiboken6/tests/samplebinding/derived_test.py +++ b/sources/shiboken6/tests/samplebinding/derived_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 '''Test cases for Derived class''' @@ -43,6 +16,7 @@ init_paths() import sample from sample import Abstract, Derived, DerivedUsingCt, OverloadedFuncEnum + class Deviant(Derived): def __init__(self): Derived.__init__(self) @@ -58,6 +32,16 @@ class Deviant(Derived): def className(self): return 'Deviant' + +class ImplementVirtualWithOutParameter(Derived): + def __init__(self, value): + super().__init__() + self._value = value + + def virtualWithOutParameter(self): + return self._value + + class DerivedTest(unittest.TestCase): '''Test case for Derived class''' @@ -67,22 +51,6 @@ class DerivedTest(unittest.TestCase): 'id_', 'pureVirtual', 'unpureVirtual']) self.assertTrue(inherited_methods.issubset(dir(Derived))) - def testOverloadedMethodCall(self): - '''Test if the correct overloaded method is being called.''' - derived = Derived() - - result = derived.overloaded(1, 2) - self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_ii) - - result = derived.overloaded(3) - self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_ii) - - result = derived.overloaded(4.4) - self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_d) - def testOtherOverloadedMethodCall(self): '''Another test to check overloaded method calling, just to double check.''' derived = Derived() @@ -100,21 +68,23 @@ class DerivedTest(unittest.TestCase): derived = Derived() result = derived.overloaded(1.1, 2.2) self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_ii) def testOverloadedMethodCallWithWrongNumberOfArguments(self): - '''Test if a call to an overloaded method with the wrong number of arguments raises an exception.''' + '''Test if a call to an overloaded method with the wrong number of arguments + raises an exception.''' derived = Derived() self.assertRaises(TypeError, derived.otherOverloaded, 1, 2, True) def testReimplementedPureVirtualMethodCall(self): - '''Test if a Python override of a implemented pure virtual method is correctly called from C++.''' + '''Test if a Python override of a implemented pure virtual method is + correctly called from C++.''' d = Deviant() d.callPureVirtual() self.assertTrue(d.pure_virtual_called) def testReimplementedVirtualMethodCall(self): - '''Test if a Python override of a reimplemented virtual method is correctly called from C++.''' + '''Test if a Python override of a reimplemented virtual method is + correctly called from C++.''' d = Deviant() d.callUnpureVirtual() self.assertTrue(d.unpure_virtual_called) @@ -126,7 +96,8 @@ class DerivedTest(unittest.TestCase): self.assertEqual(d.getClassName(), 'Derived') def testReimplementedVirtualMethodCallReturningString(self): - '''Test if a Python override of a reimplemented virtual method is correctly called from C++.''' + '''Test if a Python override of a reimplemented virtual method is + correctly called from C++.''' d = Deviant() self.assertEqual(d.className(), 'Deviant') self.assertEqual(d.getClassName(), 'Deviant') @@ -150,7 +121,8 @@ class DerivedTest(unittest.TestCase): self.assertEqual(Abstract.getObjectId(d), objId) def testObjectCreationWithParentType(self): - '''Derived class creates an instance of itself in C++ and returns it as a pointer to its ancestor Abstract.''' + '''Derived class creates an instance of itself in C++ and returns it as + a pointer to its ancestor Abstract.''' obj = Derived.createObject() self.assertEqual(type(obj), Derived) @@ -159,7 +131,13 @@ class DerivedTest(unittest.TestCase): obj = DerivedUsingCt(42) self.assertEqual(obj.value(), 42) + def testVirtualWithOutParameter(self): + d = Derived() + self.assertEqual(d.callVirtualWithOutParameter(), 42) + + d = ImplementVirtualWithOutParameter(1) + self.assertEqual(d.callVirtualWithOutParameter(), 1) + if __name__ == '__main__': unittest.main() - |