diff options
Diffstat (limited to 'sources/shiboken2/tests/samplebinding')
5 files changed, 141 insertions, 2 deletions
diff --git a/sources/shiboken2/tests/samplebinding/CMakeLists.txt b/sources/shiboken2/tests/samplebinding/CMakeLists.txt index 1b97bd0e8..78ddfca0a 100644 --- a/sources/shiboken2/tests/samplebinding/CMakeLists.txt +++ b/sources/shiboken2/tests/samplebinding/CMakeLists.txt @@ -7,6 +7,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_sample.xml set(sample_SRC ${CMAKE_CURRENT_BINARY_DIR}/sample/abstractmodifications_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/abstract_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/arraymodifytest_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/base1_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/base2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/base3_wrapper.cpp @@ -109,6 +110,8 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/time_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/templateptr_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/unremovednamespace_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/virtualdaughter_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/virtualdaughter2_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/virtualfinaldaughter_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/virtualdtor_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/virtualmethods_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/voidholder_wrapper.cpp diff --git a/sources/shiboken2/tests/samplebinding/array_numpy_test.py b/sources/shiboken2/tests/samplebinding/array_numpy_test.py new file mode 100644 index 000000000..bde46f2e3 --- /dev/null +++ b/sources/shiboken2/tests/samplebinding/array_numpy_test.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +############################################################################# +## +## Copyright (C) 2017 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $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$ +## +############################################################################# + +'''Test case for NumPy Array types.''' + +import unittest +import sample + +hasNumPy = False + +try: + import numpy + hasNumPy = True +except ImportError: + pass + +class ArrayTester(unittest.TestCase): + '''Test case for NumPy arrays.''' + + def testIntArray(self): + intList = numpy.array([1, 2, 3, 4], dtype = 'int32') + self.assertEqual(sample.sumIntArray(intList), 10) + + def testDoubleArray(self): + doubleList = numpy.array([1, 2, 3, 4], dtype = 'double') + self.assertEqual(sample.sumDoubleArray(doubleList), 10) + + def testIntMatrix(self): + intMatrix = numpy.array([[1, 2, 3], [4, 5, 6]], dtype = 'int32') + self.assertEqual(sample.sumIntMatrix(intMatrix), 21) + + def testDoubleMatrix(self): + doubleMatrix = numpy.array([[1, 2, 3], [4, 5, 6]], dtype = 'double') + self.assertEqual(sample.sumDoubleMatrix(doubleMatrix), 21) + +if __name__ == '__main__' and hasNumPy: + unittest.main() diff --git a/sources/shiboken2/tests/samplebinding/array_sequence_test.py b/sources/shiboken2/tests/samplebinding/array_sequence_test.py new file mode 100644 index 000000000..0fd2ec636 --- /dev/null +++ b/sources/shiboken2/tests/samplebinding/array_sequence_test.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +############################################################################# +## +## Copyright (C) 2017 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $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$ +## +############################################################################# + +'''Test case for Array types (PySequence).''' + +import unittest +import sample + +class ArrayTester(unittest.TestCase): + '''Test case for arrays.''' + + def testIntArray(self): + intList = [1, 2, 3, 4] + self.assertEqual(sample.sumIntArray(intList), 10) + + def testIntArrayModified(self): + intList = [1, 2, 3, 4] + tester = sample.ArrayModifyTest() + self.assertEqual(tester.sumIntArray(4, intList), 10) + + def testDoubleArray(self): + doubleList = [1.2, 2.3, 3.4, 4.5] + self.assertEqual(sample.sumDoubleArray(doubleList), 11.4) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken2/tests/samplebinding/enum_test.py b/sources/shiboken2/tests/samplebinding/enum_test.py index 6468d3cc4..711215c35 100644 --- a/sources/shiboken2/tests/samplebinding/enum_test.py +++ b/sources/shiboken2/tests/samplebinding/enum_test.py @@ -110,6 +110,11 @@ class EnumTest(unittest.TestCase): self.assertEqual(SampleNamespace.AnonymousClassEnum_Value0, 0) self.assertEqual(SampleNamespace.AnonymousClassEnum_Value1, 1) + def testEnumClasses(self): + # C++ 11: values of enum classes need to be fully qualified to match C++ + sum = Event.EventTypeClass.Value1 + Event.EventTypeClass.Value2 + self.assertEqual(sum, 1) + def testEnumTpPrintImplementation(self): '''Without SbkEnum.tp_print 'print' returns the enum represented as an int.''' tmpfile = createTempFile() diff --git a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml index e4e8f7e22..5a12eeccd 100644 --- a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml +++ b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml @@ -501,11 +501,21 @@ <function signature="gimmeInt()" /> <function signature="gimmeDouble()" /> <function signature="makeCString()" /> + <function signature="sumIntArray(int[4])"/> + <function signature="sumDoubleArray(double[4])"/> + <function signature="sumIntMatrix(int[2][3])"/> + <function signature="sumDoubleMatrix(double[2][3])"/> <function signature="multiplyPair(std::pair<double, double>)" /> <function signature="returnCString()" /> <function signature="overloadedFunc(double)" /> <function signature="overloadedFunc(int)" /> + <value-type name="ArrayModifyTest"> + <modify-function signature="sumIntArray(int, int*)"> + <modify-argument index="2"><array/></modify-argument> + </modify-function> + </value-type> + <value-type name="ClassWithFunctionPointer"> <suppress-warning text="skipping function 'ClassWithFunctionPointer::callFunctionPointer', unmatched parameter type 'void (*)(void*)'" /> </value-type> @@ -538,6 +548,7 @@ <value-type name="SomeInnerClass"> <object-type name="OkThisIsRecursiveEnough"> <enum-type name="NiceEnum" /> + <enum-type name="NiceEnumClass" /> </object-type> <enum-type name="ProtectedEnum"/> </value-type> @@ -787,6 +798,7 @@ <value-type name="Event"> <enum-type name="EventType"/> + <enum-type name="EventTypeClass" class="yes"/> </value-type> <value-type name="BlackBox"> @@ -1159,7 +1171,7 @@ <!-- change the name of this virtual method --> <modify-function signature="className()" rename="name"/> - <modify-function signature="sumPointArray(int, const Point*)"> + <modify-function signature="sumPointArray(int, const Point[])"> <modify-argument index="1"> <remove-argument/> <conversion-rule class="native"> @@ -1477,6 +1489,8 @@ </modify-function> </value-type> <value-type name="VirtualDaughter" /> + <object-type name="VirtualDaughter2" /> + <object-type name="VirtualFinalDaughter" /> <value-type name="VirtualDtor"> <modify-function signature="create()"> @@ -1950,7 +1964,7 @@ <define-ownership owner="c++"/> </modify-argument> </modify-function> - <modify-function signature="acceptSequence(const char**)"> + <modify-function signature="acceptSequence(const char*[])"> <modify-argument index="1"> <replace-type modified-type="PySequence" /> <conversion-rule class="native"> |