aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/tests
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2/tests')
-rw-r--r--sources/shiboken2/tests/dumpcodemodel/main.cpp23
-rw-r--r--sources/shiboken2/tests/libsample/functions.cpp41
-rw-r--r--sources/shiboken2/tests/libsample/functions.h11
-rw-r--r--sources/shiboken2/tests/samplebinding/CMakeLists.txt1
-rw-r--r--sources/shiboken2/tests/samplebinding/array_numpy_test.py64
-rw-r--r--sources/shiboken2/tests/samplebinding/array_sequence_test.py53
-rw-r--r--sources/shiboken2/tests/samplebinding/typesystem_sample.xml14
-rw-r--r--sources/shiboken2/tests/test_generator/dummygenerator.cpp3
8 files changed, 195 insertions, 15 deletions
diff --git a/sources/shiboken2/tests/dumpcodemodel/main.cpp b/sources/shiboken2/tests/dumpcodemodel/main.cpp
index 9e62faa16..13dab6e8a 100644
--- a/sources/shiboken2/tests/dumpcodemodel/main.cpp
+++ b/sources/shiboken2/tests/dumpcodemodel/main.cpp
@@ -37,6 +37,8 @@
#include <QtCore/QFile>
#include <iostream>
+#include <algorithm>
+#include <iterator>
int main(int argc, char **argv)
{
@@ -53,22 +55,19 @@ int main(int argc, char **argv)
parser.addPositionalArgument(QStringLiteral("file"), QStringLiteral("C++ source file"));
parser.process(app);
- if (parser.positionalArguments().isEmpty())
+ const QStringList &positionalArguments = parser.positionalArguments();
+ if (positionalArguments.isEmpty())
parser.showHelp(1);
- const QString sourceFileName = parser.positionalArguments().at(0);
- QFile sourceFile(sourceFileName);
- if (!sourceFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
- QString message = QLatin1String("Cannot open \"") + QDir::toNativeSeparators(sourceFileName)
- + QLatin1String("\": ") + sourceFile.errorString();
+ QByteArrayList arguments;
+ std::transform(positionalArguments.cbegin(), positionalArguments.cend(),
+ std::back_inserter(arguments), QFile::encodeName);
+ const FileModelItem dom = AbstractMetaBuilderPrivate::buildDom(arguments, 0);
+ if (dom.isNull()) {
+ QString message = QLatin1String("Unable to parse ") + positionalArguments.join(QLatin1Char(' '));
std::cerr << qPrintable(message) << '\n';
- return -1;
- }
-
- const FileModelItem dom = AbstractMetaBuilderPrivate::buildDom(&sourceFile);
- sourceFile.close();
- if (dom.isNull())
return -2;
+ }
QString output;
{
diff --git a/sources/shiboken2/tests/libsample/functions.cpp b/sources/shiboken2/tests/libsample/functions.cpp
index 4a15cdae8..bf73d5ed7 100644
--- a/sources/shiboken2/tests/libsample/functions.cpp
+++ b/sources/shiboken2/tests/libsample/functions.cpp
@@ -28,7 +28,9 @@
#include "functions.h"
#include <string.h>
+#include <algorithm>
#include <iostream>
+#include <numeric>
using namespace std;
@@ -197,6 +199,45 @@ acceptOddBoolReference(OddBool& x)
return x;
}
+int sumIntArray(int array[4])
+{
+ return std::accumulate(array, array + 4, 0);
+}
+
+double sumDoubleArray(double array[4])
+{
+ return std::accumulate(array, array + 4, double(0));
+}
+
+int sumIntMatrix(int m[2][3])
+{
+ int result = 0;
+ for (int r = 0; r < 2; ++r) {
+ for (int c = 0; c < 3; ++c)
+ result += m[r][c];
+ }
+ return result;
+}
+
+double sumDoubleMatrix(double m[2][3])
+{
+ double result = 0;
+ for (int r = 0; r < 2; ++r) {
+ for (int c = 0; c < 3; ++c)
+ result += m[r][c];
+ }
+ return result;
+}
+
+ArrayModifyTest::ArrayModifyTest()
+{
+}
+
+int ArrayModifyTest::sumIntArray(int n, int *array)
+{
+ return std::accumulate(array, array + n, 0);
+}
+
ClassWithFunctionPointer::ClassWithFunctionPointer()
{
callFunctionPointer(0, &ClassWithFunctionPointer::doNothing);
diff --git a/sources/shiboken2/tests/libsample/functions.h b/sources/shiboken2/tests/libsample/functions.h
index 89a175bc4..a53f97c6e 100644
--- a/sources/shiboken2/tests/libsample/functions.h
+++ b/sources/shiboken2/tests/libsample/functions.h
@@ -81,6 +81,17 @@ LIBSAMPLE_API double acceptDouble(double x);
LIBSAMPLE_API int acceptIntReference(int& x);
LIBSAMPLE_API OddBool acceptOddBoolReference(OddBool& x);
+LIBSAMPLE_API int sumIntArray(int array[4]);
+LIBSAMPLE_API double sumDoubleArray(double array[4]);
+LIBSAMPLE_API int sumIntMatrix(int m[2][3]);
+LIBSAMPLE_API double sumDoubleMatrix(double m[2][3]);
+
+class LIBSAMPLE_API ArrayModifyTest
+{
+public:
+ ArrayModifyTest();
+ int sumIntArray(int n, int *array);
+};
class LIBSAMPLE_API ClassWithFunctionPointer
{
diff --git a/sources/shiboken2/tests/samplebinding/CMakeLists.txt b/sources/shiboken2/tests/samplebinding/CMakeLists.txt
index 1b97bd0e8..b3c9df0dd 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
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/typesystem_sample.xml b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
index 65f989e7e..e0085abbe 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&lt;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>
@@ -1159,7 +1169,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">
@@ -1950,7 +1960,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">
diff --git a/sources/shiboken2/tests/test_generator/dummygenerator.cpp b/sources/shiboken2/tests/test_generator/dummygenerator.cpp
index 51d2b33da..40d9fb771 100644
--- a/sources/shiboken2/tests/test_generator/dummygenerator.cpp
+++ b/sources/shiboken2/tests/test_generator/dummygenerator.cpp
@@ -52,7 +52,8 @@ DummyGenerator::doSetup(const QMap<QString, QString>& args)
QFile logFile(args["dump-arguments"]);
logFile.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&logFile);
- foreach (const QString& key, args.keys()) {
+ for (QMap<QString, QString>::const_iterator it = args.cbegin(), end = args.cend(); it != end; ++it) {
+ const QString& key = it.key();
if (key == "arg-1")
out << "header-file";
else if (key == "arg-2")