From 39236c01ae6c9bc99ee3a02d8294679e12d9b734 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 22 May 2017 16:44:51 +0200 Subject: move everying into sources/pyside2 in preparation for a subtree merge. this should not be necessary to do in a separate commit, but git is a tad stupid about following history correctly without it. --- sources/pyside2/tests/QtQml/CMakeLists.txt | 20 ++++ sources/pyside2/tests/QtQml/bug_1029.py | 58 ++++++++++ sources/pyside2/tests/QtQml/bug_1029.qml | 43 ++++++++ sources/pyside2/tests/QtQml/bug_451.py | 100 +++++++++++++++++ sources/pyside2/tests/QtQml/bug_451.qml | 54 ++++++++++ sources/pyside2/tests/QtQml/bug_456.py | 70 ++++++++++++ sources/pyside2/tests/QtQml/bug_456.qml | 59 +++++++++++ sources/pyside2/tests/QtQml/bug_557.py | 43 ++++++++ sources/pyside2/tests/QtQml/bug_726.py | 71 +++++++++++++ sources/pyside2/tests/QtQml/bug_726.qml | 59 +++++++++++ sources/pyside2/tests/QtQml/bug_814.py | 73 +++++++++++++ sources/pyside2/tests/QtQml/bug_814.qml | 36 +++++++ sources/pyside2/tests/QtQml/bug_825.py | 82 ++++++++++++++ sources/pyside2/tests/QtQml/bug_825.qml | 38 +++++++ sources/pyside2/tests/QtQml/bug_847.py | 79 ++++++++++++++ sources/pyside2/tests/QtQml/bug_847.qml | 62 +++++++++++ sources/pyside2/tests/QtQml/bug_915.py | 58 ++++++++++ sources/pyside2/tests/QtQml/bug_926.py | 69 ++++++++++++ sources/pyside2/tests/QtQml/bug_926.qml | 45 ++++++++ sources/pyside2/tests/QtQml/bug_951.py | 61 +++++++++++ sources/pyside2/tests/QtQml/bug_951.qml | 35 ++++++ sources/pyside2/tests/QtQml/bug_995.py | 43 ++++++++ sources/pyside2/tests/QtQml/bug_995.qml | 40 +++++++ sources/pyside2/tests/QtQml/bug_997.py | 52 +++++++++ sources/pyside2/tests/QtQml/bug_997.qml | 34 ++++++ sources/pyside2/tests/QtQml/connect_python_qml.py | 65 ++++++++++++ sources/pyside2/tests/QtQml/connect_python_qml.qml | 48 +++++++++ sources/pyside2/tests/QtQml/hw.qml | 48 +++++++++ .../pyside2/tests/QtQml/javascript_exceptions.py | 103 ++++++++++++++++++ .../pyside2/tests/QtQml/javascript_exceptions.qml | 53 +++++++++ .../tests/QtQml/qqmlincubator_incubateWhile.py | 96 +++++++++++++++++ .../tests/QtQml/qqmlincubator_incubateWhile.qml | 67 ++++++++++++ .../qqmlincubator_incubateWhile_component.qml | 35 ++++++ sources/pyside2/tests/QtQml/qqmlnetwork_test.py | 70 ++++++++++++ .../pyside2/tests/QtQml/qquickitem_grabToImage.py | 79 ++++++++++++++ .../pyside2/tests/QtQml/qquickitem_grabToImage.qml | 69 ++++++++++++ sources/pyside2/tests/QtQml/qquickview_test.py | 86 +++++++++++++++ sources/pyside2/tests/QtQml/registertype.py | 118 +++++++++++++++++++++ sources/pyside2/tests/QtQml/registertype.qml | 57 ++++++++++ sources/pyside2/tests/QtQml/view.qml | 43 ++++++++ sources/pyside2/tests/QtQml/viewmodel.qml | 42 ++++++++ 41 files changed, 2463 insertions(+) create mode 100755 sources/pyside2/tests/QtQml/CMakeLists.txt create mode 100755 sources/pyside2/tests/QtQml/bug_1029.py create mode 100755 sources/pyside2/tests/QtQml/bug_1029.qml create mode 100755 sources/pyside2/tests/QtQml/bug_451.py create mode 100755 sources/pyside2/tests/QtQml/bug_451.qml create mode 100755 sources/pyside2/tests/QtQml/bug_456.py create mode 100755 sources/pyside2/tests/QtQml/bug_456.qml create mode 100755 sources/pyside2/tests/QtQml/bug_557.py create mode 100755 sources/pyside2/tests/QtQml/bug_726.py create mode 100755 sources/pyside2/tests/QtQml/bug_726.qml create mode 100755 sources/pyside2/tests/QtQml/bug_814.py create mode 100755 sources/pyside2/tests/QtQml/bug_814.qml create mode 100755 sources/pyside2/tests/QtQml/bug_825.py create mode 100755 sources/pyside2/tests/QtQml/bug_825.qml create mode 100755 sources/pyside2/tests/QtQml/bug_847.py create mode 100755 sources/pyside2/tests/QtQml/bug_847.qml create mode 100755 sources/pyside2/tests/QtQml/bug_915.py create mode 100755 sources/pyside2/tests/QtQml/bug_926.py create mode 100755 sources/pyside2/tests/QtQml/bug_926.qml create mode 100755 sources/pyside2/tests/QtQml/bug_951.py create mode 100755 sources/pyside2/tests/QtQml/bug_951.qml create mode 100755 sources/pyside2/tests/QtQml/bug_995.py create mode 100755 sources/pyside2/tests/QtQml/bug_995.qml create mode 100755 sources/pyside2/tests/QtQml/bug_997.py create mode 100755 sources/pyside2/tests/QtQml/bug_997.qml create mode 100644 sources/pyside2/tests/QtQml/connect_python_qml.py create mode 100755 sources/pyside2/tests/QtQml/connect_python_qml.qml create mode 100755 sources/pyside2/tests/QtQml/hw.qml create mode 100644 sources/pyside2/tests/QtQml/javascript_exceptions.py create mode 100644 sources/pyside2/tests/QtQml/javascript_exceptions.qml create mode 100644 sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile.py create mode 100644 sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile.qml create mode 100644 sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile_component.qml create mode 100755 sources/pyside2/tests/QtQml/qqmlnetwork_test.py create mode 100644 sources/pyside2/tests/QtQml/qquickitem_grabToImage.py create mode 100644 sources/pyside2/tests/QtQml/qquickitem_grabToImage.qml create mode 100755 sources/pyside2/tests/QtQml/qquickview_test.py create mode 100755 sources/pyside2/tests/QtQml/registertype.py create mode 100755 sources/pyside2/tests/QtQml/registertype.qml create mode 100755 sources/pyside2/tests/QtQml/view.qml create mode 100755 sources/pyside2/tests/QtQml/viewmodel.qml (limited to 'sources/pyside2/tests/QtQml') diff --git a/sources/pyside2/tests/QtQml/CMakeLists.txt b/sources/pyside2/tests/QtQml/CMakeLists.txt new file mode 100755 index 000000000..8460a8f0b --- /dev/null +++ b/sources/pyside2/tests/QtQml/CMakeLists.txt @@ -0,0 +1,20 @@ +PYSIDE_TEST(bug_451.py) +PYSIDE_TEST(bug_456.py) +PYSIDE_TEST(bug_557.py) +PYSIDE_TEST(bug_726.py) +PYSIDE_TEST(bug_814.py) +PYSIDE_TEST(bug_825.py) +PYSIDE_TEST(bug_847.py) +PYSIDE_TEST(bug_915.py) +PYSIDE_TEST(bug_926.py) +PYSIDE_TEST(bug_951.py) +PYSIDE_TEST(bug_995.py) +PYSIDE_TEST(bug_997.py) +PYSIDE_TEST(bug_1029.py) +PYSIDE_TEST(qqmlnetwork_test.py) +PYSIDE_TEST(qquickview_test.py) +PYSIDE_TEST(connect_python_qml.py) +PYSIDE_TEST(registertype.py) +PYSIDE_TEST(javascript_exceptions.py) +PYSIDE_TEST(qqmlincubator_incubateWhile.py) +PYSIDE_TEST(qquickitem_grabToImage.py) diff --git a/sources/pyside2/tests/QtQml/bug_1029.py b/sources/pyside2/tests/QtQml/bug_1029.py new file mode 100755 index 000000000..c5555393b --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_1029.py @@ -0,0 +1,58 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import sys +import gc + +from PySide2.QtCore import QUrl +from PySide2.QtGui import QGuiApplication +from PySide2.QtQml import qmlRegisterType +from PySide2.QtQuick import QQuickView, QQuickItem + +def register_qml_types(): + class TestClass(QQuickItem): + def __init__(self, parent = None): + QQuickItem.__init__(self, parent) + + qmlRegisterType(TestClass, "UserTypes", 1, 0, "TestClass") + +def main(): + app = QGuiApplication([]) + + # reg qml types here + register_qml_types() + + # force gc to run + gc.collect() + + view = QQuickView() + url = QUrl(__file__.replace(".py", ".qml")) + view.setSource(url) + +if __name__ == "__main__": + main() diff --git a/sources/pyside2/tests/QtQml/bug_1029.qml b/sources/pyside2/tests/QtQml/bug_1029.qml new file mode 100755 index 000000000..d47f31f44 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_1029.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import UserTypes 1.0 + +Rectangle +{ + width: 200 + height: 200 + + color: "#ff0000" + + TestClass + { + + } +} diff --git a/sources/pyside2/tests/QtQml/bug_451.py b/sources/pyside2/tests/QtQml/bug_451.py new file mode 100755 index 000000000..58ee64eb4 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_451.py @@ -0,0 +1,100 @@ +############################################################################# +## +## Copyright (C) 2016 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 bug 451: http://bugs.openbossa.org/show_bug.cgi?id=451 + +An archive of said bug: +https://srinikom.github.io/pyside-bz-archive/451.html +''' + +import sys +import unittest + +from helper import adjust_filename + +from PySide2 import QtCore, QtGui, QtQuick + +class PythonObject(QtCore.QObject): + def __init__(self): + QtCore.QObject.__init__(self, None) + self._called = "" + self._arg1 = None + self._arg2 = None + + def setCalled(self, v): + self._called = v + + def setArg1(self, v): + self._arg1 = v + + def setArg2(self, v): + self._arg2 = v + + def getCalled(self): + return self._called + + def getArg1(self): + return self._arg1 + + def getArg2(self): + return self._arg2 + + called = QtCore.Property(str, getCalled, setCalled) + arg1 = QtCore.Property(int, getArg1, setArg1) + arg2 = QtCore.Property('QVariant', getArg2, setArg2) + +class TestBug(unittest.TestCase): + def testQMLFunctionCall(self): + app = QtGui.QGuiApplication(sys.argv) + view = QtQuick.QQuickView() + + obj = PythonObject() + context = view.rootContext() + context.setContextProperty("python", obj) + view.setSource(QtCore.QUrl.fromLocalFile(adjust_filename('bug_451.qml', __file__))) + root = view.rootObject() + root.simpleFunction() + self.assertEqual(obj.called, "simpleFunction") + + root.oneArgFunction(42) + self.assertEqual(obj.called, "oneArgFunction") + self.assertEqual(obj.arg1, 42) + + root.twoArgFunction(10, app) + self.assertEqual(obj.called, "twoArgFunction") + self.assertEqual(obj.arg1, 10) + self.assertEqual(obj.arg2, app) + + rvalue = root.returnFunction() + self.assertEqual(obj.called, "returnFunction") + self.assertEqual(rvalue, 42) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/bug_451.qml b/sources/pyside2/tests/QtQml/bug_451.qml new file mode 100755 index 000000000..60219b68e --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_451.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: page + + function simpleFunction() { + python.called = "simpleFunction" + } + + function oneArgFunction(x) { + python.called = "oneArgFunction" + python.arg1 = x + } + + function twoArgFunction(x, y) { + python.called = "twoArgFunction" + python.arg1 = x + python.arg2 = y + } + + function returnFunction() { + python.called = "returnFunction" + return 42 + } + +} diff --git a/sources/pyside2/tests/QtQml/bug_456.py b/sources/pyside2/tests/QtQml/bug_456.py new file mode 100755 index 000000000..d9a67fe19 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_456.py @@ -0,0 +1,70 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import unittest + +from helper import adjust_filename, TimedQApplication + +from PySide2 import QtCore, QtGui, QtQuick + +class RotateValue(QtCore.QObject): + def __init__(self): + super(RotateValue,self).__init__() + + @QtCore.Slot(result=int) + def val(self): + return 100 + + def setRotation(self, v): + self._rotation = v + + def getRotation(self): + return self._rotation + + rotation = QtCore.Property(int, getRotation, setRotation) + +class TestConnectionWithInvalidSignature(TimedQApplication): + + def testSlotRetur(self): + view = QtQuick.QQuickView() + rotatevalue = RotateValue() + + timer = QtCore.QTimer() + timer.start(2000) + + context = view.rootContext() + context.setContextProperty("rotatevalue", rotatevalue) + view.setSource(QtCore.QUrl.fromLocalFile(adjust_filename('bug_456.qml', __file__))) + root = view.rootObject() + button = root.findChild(QtCore.QObject, "buttonMouseArea") + view.show() + button.entered.emit() + self.assertEqual(rotatevalue.rotation, 100) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/bug_456.qml b/sources/pyside2/tests/QtQml/bug_456.qml new file mode 100755 index 000000000..ebbff02d5 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_456.qml @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: page + + width: 500; height: 200 + color: "lightgray" + + Rectangle { + id: button + width: 150; height: 40 + color: "darkgray" + anchors.horizontalCenter: page.horizontalCenter + y: 120 + MouseArea { + id: buttonMouseArea + objectName: "buttonMouseArea" + anchors.fill: parent + onEntered: { + rotatevalue.rotation = rotatevalue.val() + } + } + Text { + id: buttonText + text: "Press me!" + anchors.horizontalCenter: button.horizontalCenter + anchors.verticalCenter: button.verticalCenter + font.pointSize: 16; + } + } +} diff --git a/sources/pyside2/tests/QtQml/bug_557.py b/sources/pyside2/tests/QtQml/bug_557.py new file mode 100755 index 000000000..96e89d6d6 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_557.py @@ -0,0 +1,43 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import sys +from helper import adjust_filename + +from PySide2.QtCore import QUrl +from PySide2.QtGui import QGuiApplication +from PySide2.QtQml import QQmlEngine, QQmlComponent + +app = QGuiApplication(sys.argv) + +engine = QQmlEngine() +component = QQmlComponent(engine) + +# This should segfault if the QDeclarativeComponent has not QQmlEngine +component.loadUrl(QUrl.fromLocalFile(adjust_filename('foo.qml', __file__))) + diff --git a/sources/pyside2/tests/QtQml/bug_726.py b/sources/pyside2/tests/QtQml/bug_726.py new file mode 100755 index 000000000..f440b64da --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_726.py @@ -0,0 +1,71 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import unittest + +from helper import adjust_filename, TimedQApplication + +from PySide2 import QtCore, QtGui, QtQuick + +class ProxyObject(QtCore.QObject): + def __init__(self): + super(ProxyObject,self).__init__() + self._o = None + self._receivedName = "" + + @QtCore.Slot(result='QObject*') + def getObject(self): + if self._o: + return self._o + + self._o = QtCore.QObject() + self._o.setObjectName("PySideObject") + return self._o + + @QtCore.Slot(str) + def receivedObject(self, name): + self._receivedName = name + + +class TestConnectionWithInvalidSignature(TimedQApplication): + + def testSlotRetur(self): + view = QtQuick.QQuickView() + proxy = ProxyObject() + + context = view.rootContext() + context.setContextProperty("proxy", proxy) + view.setSource(QtCore.QUrl.fromLocalFile(adjust_filename('bug_726.qml', __file__))) + root = view.rootObject() + button = root.findChild(QtCore.QObject, "buttonMouseArea") + view.show() + button.entered.emit() + self.assertEqual(proxy._receivedName, "PySideObject") + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/bug_726.qml b/sources/pyside2/tests/QtQml/bug_726.qml new file mode 100755 index 000000000..d03376409 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_726.qml @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: page + + width: 500; height: 200 + color: "lightgray" + + Rectangle { + id: button + width: 150; height: 40 + color: "darkgray" + anchors.horizontalCenter: page.horizontalCenter + y: 120 + MouseArea { + id: buttonMouseArea + objectName: "buttonMouseArea" + anchors.fill: parent + onEntered: { + proxy.receivedObject(proxy.getObject().objectName) + } + } + Text { + id: buttonText + text: "Press me!" + anchors.horizontalCenter: button.horizontalCenter + anchors.verticalCenter: button.verticalCenter + font.pointSize: 16; + } + } +} diff --git a/sources/pyside2/tests/QtQml/bug_814.py b/sources/pyside2/tests/QtQml/bug_814.py new file mode 100755 index 000000000..be6eea964 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_814.py @@ -0,0 +1,73 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2011 Thomas Perl +## 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 PySide bug 814 +# http://bugs.pyside.org/show_bug.cgi?id=814 +# archive: +# https://srinikom.github.io/pyside-bz-archive/814.html +# 2011-04-08 Thomas Perl +# Released under the same terms as PySide itself + +import unittest + +from helper import adjust_filename, TimedQApplication + +from PySide2.QtCore import QUrl, QAbstractListModel, QModelIndex, Qt +from PySide2.QtQuick import QQuickView + +class ListModel(QAbstractListModel): + def __init__(self): + QAbstractListModel.__init__(self) + + def roleNames(self): + return { Qt.DisplayRole: 'pysideModelData' } + + def rowCount(self, parent = QModelIndex()): + return 3 + + def data(self, index, role): + if index.isValid() and role == Qt.DisplayRole: + return 'blubb' + return None + +class TestBug814(TimedQApplication): + def testAbstractItemModelTransferToQML(self): + view = QQuickView() + model = ListModel() + view.rootContext().setContextProperty("pythonModel", model) + view.setSource(QUrl.fromLocalFile(adjust_filename('bug_814.qml', __file__))) + root = view.rootObject() + view.show() + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/QtQml/bug_814.qml b/sources/pyside2/tests/QtQml/bug_814.qml new file mode 100755 index 000000000..bc5c23fa1 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_814.qml @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +ListView { + width: 300; height: 300 + delegate: Text { text: pysideModelData } + model: pythonModel +} + diff --git a/sources/pyside2/tests/QtQml/bug_825.py b/sources/pyside2/tests/QtQml/bug_825.py new file mode 100755 index 000000000..8e896f599 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_825.py @@ -0,0 +1,82 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import unittest + +from helper import adjust_filename + +from PySide2.QtCore import Qt, QUrl, QTimer +from PySide2.QtGui import QGuiApplication, QPen +from PySide2.QtWidgets import QGraphicsItem +from PySide2.QtQml import qmlRegisterType +from PySide2.QtQuick import QQuickView, QQuickItem, QQuickPaintedItem + +paintCalled = False + +class MetaA(type): + pass + +class A(object): + __metaclass__ = MetaA + +MetaB = type(QQuickPaintedItem) +B = QQuickPaintedItem + +class MetaC(MetaA, MetaB): + pass + +class C(A, B): + __metaclass__ = MetaC + +class Bug825 (C): + def __init__(self, parent = None): + QQuickPaintedItem.__init__(self, parent) + + def paint(self, painter): + global paintCalled + pen = QPen(Qt.black, 2) + painter.setPen(pen); + painter.drawPie(self.boundingRect(), 0, 128); + paintCalled = True + +class TestBug825 (unittest.TestCase): + def testIt(self): + global paintCalled + app = QGuiApplication([]) + qmlRegisterType(Bug825, 'bugs', 1, 0, 'Bug825') + self.assertRaises(TypeError, qmlRegisterType, A, 'bugs', 1, 0, 'A') + + view = QQuickView() + view.setSource(QUrl.fromLocalFile(adjust_filename('bug_825.qml', __file__))) + view.show() + QTimer.singleShot(250, view.close) + app.exec_() + self.assertTrue(paintCalled) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/bug_825.qml b/sources/pyside2/tests/QtQml/bug_825.qml new file mode 100755 index 000000000..04572dc97 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_825.qml @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import bugs 1.0 + +Item { + width: 300; height: 200 + + Bug825 { + anchors.fill: parent + } +} diff --git a/sources/pyside2/tests/QtQml/bug_847.py b/sources/pyside2/tests/QtQml/bug_847.py new file mode 100755 index 000000000..e46888d17 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_847.py @@ -0,0 +1,79 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2011 Thomas Perl +## 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$ +## +############################################################################# + +# Testcase for PySide bug 847 +# Released under the same terms as PySide itself +# 2011-05-04 Thomas Perl + +from __future__ import print_function + +import unittest + +from helper import adjust_filename, UsesQApplication + +from PySide2.QtCore import Slot, Signal, QUrl, QTimer, QCoreApplication +from PySide2.QtQuick import QQuickView + +class View(QQuickView): + def __init__(self): + QQuickView.__init__(self) + + called = Signal(int, int) + + @Slot(int, int) + def blubb(self, x, y): + self.called.emit(x, y) + +class TestQML(UsesQApplication): + def done(self, x, y): + self._sucess = True + self.app.quit() + print("done called") + + def testPythonSlot(self): + self._sucess = False + view = View() + + # Connect first, then set the property. + view.called.connect(self.done) + view.setSource(QUrl.fromLocalFile(adjust_filename('bug_847.qml', __file__))) + view.rootObject().setProperty('pythonObject', view) + + view.show() + # Essentially a timeout in case method invocation fails. + QTimer.singleShot(2000, QCoreApplication.instance().quit) + self.app.exec_() + self.assertTrue(self._sucess) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/QtQml/bug_847.qml b/sources/pyside2/tests/QtQml/bug_847.qml new file mode 100755 index 000000000..ea764ede9 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_847.qml @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 500 + height: 500 + color: 'red' + + property variant pythonObject: undefined + + Text { + anchors.centerIn: parent + text: 'click me' + color: 'white' + } + + onPythonObjectChanged: { + if (pythonObject) { + // Delay execution of method invocation, so that the event loop has a chance to start, + // which will subsequently be stopped by the method. + timer.start() + } + } + + Timer { + id: timer + interval: 100; running: false; + onTriggered: { + if (pythonObject) { + pythonObject.blubb(42, 84) + } + } + } +} + diff --git a/sources/pyside2/tests/QtQml/bug_915.py b/sources/pyside2/tests/QtQml/bug_915.py new file mode 100755 index 000000000..c94612334 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_915.py @@ -0,0 +1,58 @@ +#!/usr/bin/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 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$ +## +############################################################################# + +import unittest + +from helper import TimedQApplication + +from PySide2.QtQuick import QQuickView, QQuickItem + +class TestBug915(TimedQApplication): + def testReturnPolicy(self): + view = QQuickView() + + item1 = QQuickItem() + item1.setObjectName("Item1") + item1.setParentItem(view.contentItem()) + self.assertEqual(item1.objectName(), "Item1") # check if the item still valid + + item2 = QQuickItem() + item2.setObjectName("Item2") + item2.setParentItem(view.contentItem()) + item1 = None + self.assertEqual(item2.objectName(), "Item2") # check if the item still valid + + view = None + +if __name__ == '__main__': + unittest.main() + + diff --git a/sources/pyside2/tests/QtQml/bug_926.py b/sources/pyside2/tests/QtQml/bug_926.py new file mode 100755 index 000000000..5f6251aa5 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_926.py @@ -0,0 +1,69 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import sys +import unittest + +from helper import adjust_filename + +from PySide2.QtCore import QUrl, QTimer, QObject, Signal, Property +from PySide2.QtGui import QGuiApplication +from PySide2.QtQml import qmlRegisterType +from PySide2.QtQuick import QQuickView + +class MyClass (QObject): + + def __init__(self): + super(MyClass,self).__init__() + self.__url = QUrl() + + def getUrl(self): + return self.__url + + def setUrl(self,value): + newUrl = QUrl(value) + if (newUrl != self.__url): + self.__url = newUrl + self.urlChanged.emit() + + urlChanged = Signal() + urla = Property(QUrl, getUrl, setUrl, notify = urlChanged) + +class TestBug926 (unittest.TestCase): + def testIt(self): + app = QGuiApplication([]) + qmlRegisterType(MyClass,'Example',1,0,'MyClass') + view = QQuickView() + view.setSource(QUrl.fromLocalFile(adjust_filename('bug_926.qml', __file__))) + self.assertEqual(len(view.errors()), 0) + view.show() + QTimer.singleShot(0, app.quit) + app.exec_() + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/bug_926.qml b/sources/pyside2/tests/QtQml/bug_926.qml new file mode 100755 index 000000000..0133ebf52 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_926.qml @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Example 1.0 + +Rectangle { + width: 100 + height: 62 + + MyClass { + id: myClass + urla: "http://www.pyside.org" + } + + Text { + id: name + text: myClass.urla + } +} diff --git a/sources/pyside2/tests/QtQml/bug_951.py b/sources/pyside2/tests/QtQml/bug_951.py new file mode 100755 index 000000000..897412bd1 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_951.py @@ -0,0 +1,61 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import unittest + +from helper import adjust_filename, TimedQApplication + +from PySide2.QtCore import QUrl +from PySide2.QtQml import qmlRegisterType +from PySide2.QtQuick import QQuickItem, QQuickView + +class MyItem(QQuickItem): + COMPONENT_COMPLETE_CALLED = False + def __init__(self,parent=None): + super(MyItem, self).__init__(parent) + self.setObjectName("myitem") + + def componentComplete(self): + MyItem.COMPONENT_COMPLETE_CALLED = True + super(MyItem, self).componentComplete() + +class TestRegisterQMLType(TimedQApplication): + def setup(self): + TimedQApplication.setup(self, 100 * 3) # 3s + + def testSignalEmission(self): + qmlRegisterType(MyItem, "my.item", 1, 0, "MyItem") + + view = QQuickView() + view.setSource(QUrl.fromLocalFile(adjust_filename('bug_951.qml', __file__))) + + self.app.exec_() + self.assertTrue(MyItem.COMPONENT_COMPLETE_CALLED) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/bug_951.qml b/sources/pyside2/tests/QtQml/bug_951.qml new file mode 100755 index 000000000..8b93bfc6d --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_951.qml @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import my.item 1.0 +Rectangle{ + width:10 + height:10 + MyItem{ } +} diff --git a/sources/pyside2/tests/QtQml/bug_995.py b/sources/pyside2/tests/QtQml/bug_995.py new file mode 100755 index 000000000..d891f3445 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_995.py @@ -0,0 +1,43 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +from helper import adjust_filename, UsesQApplication + +from PySide2.QtGui import QGuiApplication +from PySide2.QtQuick import QQuickView + +app = QGuiApplication([]) +view = QQuickView(adjust_filename('bug_995.qml', __file__)) +view.show() +view.resize(200, 200) +contentItem = view.contentItem() +item = contentItem.childAt(100, 100) + +# it CAN NOT crash here +print(item) + diff --git a/sources/pyside2/tests/QtQml/bug_995.qml b/sources/pyside2/tests/QtQml/bug_995.qml new file mode 100755 index 000000000..fcc33975c --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_995.qml @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 100 + height: 100 + color: "red" + + Text { + text: "Hello World" + anchors.centerIn: parent + } +} diff --git a/sources/pyside2/tests/QtQml/bug_997.py b/sources/pyside2/tests/QtQml/bug_997.py new file mode 100755 index 000000000..fcb260cf3 --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_997.py @@ -0,0 +1,52 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import unittest + +from helper import adjust_filename, UsesQApplication + +from PySide2 import QtCore, QtQml, QtQuick + +class TestBug(UsesQApplication): + def testQMLFunctionCall(self): + ownerData = QtQml.QQmlPropertyMap() + ownerData.insert('name', 'John Smith') + ownerData.insert('phone', '555-5555') + ownerData.insert('newValue', '') + + view = QtQuick.QQuickView() + ctxt = view.rootContext() + ctxt.setContextProperty('owner', ownerData) + view.setSource(QtCore.QUrl.fromLocalFile(adjust_filename('bug_997.qml', __file__))) + view.show() + QtCore.QTimer.singleShot(1000, self.app.quit) + self.app.exec_() + self.assertEqual(ownerData.value('newName'), ownerData.value('name')) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/bug_997.qml b/sources/pyside2/tests/QtQml/bug_997.qml new file mode 100755 index 000000000..24f5ae51f --- /dev/null +++ b/sources/pyside2/tests/QtQml/bug_997.qml @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Text { + text: owner.name + " " + owner.phone + Component.onCompleted: { owner.newName = owner.name } +} diff --git a/sources/pyside2/tests/QtQml/connect_python_qml.py b/sources/pyside2/tests/QtQml/connect_python_qml.py new file mode 100644 index 000000000..3eeffd0d3 --- /dev/null +++ b/sources/pyside2/tests/QtQml/connect_python_qml.py @@ -0,0 +1,65 @@ +############################################################################# +## +## Copyright (C) 2016 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 bug #442 + +archive: +https://srinikom.github.io/pyside-bz-archive/442.html +''' + +import unittest + +from helper import adjust_filename, TimedQApplication + +from PySide2 import QtCore, QtGui, QtQuick + +class TestConnectionWithInvalidSignature(TimedQApplication): + def onButtonClicked(self): + self.buttonClicked = True + self.app.quit() + + def onButtonFailClicked(self): + pass + + def testFailConnection(self): + self.buttonClicked = False + self.buttonFailClicked = False + view = QtQuick.QQuickView() + view.setSource(QtCore.QUrl.fromLocalFile(adjust_filename('connect_python_qml.qml', __file__))) + root = view.rootObject() + button = root.findChild(QtCore.QObject, "buttonMouseArea") + self.assertRaises(TypeError, QtCore.QObject.connect, [button,QtCore.SIGNAL('entered()'), self.onButtonFailClicked]) + button.entered.connect(self.onButtonClicked) + button.entered.emit() + view.show() + self.app.exec_() + self.assertTrue(self.buttonClicked) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/connect_python_qml.qml b/sources/pyside2/tests/QtQml/connect_python_qml.qml new file mode 100755 index 000000000..79a364159 --- /dev/null +++ b/sources/pyside2/tests/QtQml/connect_python_qml.qml @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: page + width: 500; height: 200 + color: "lightgray" + + Rectangle { + id: button + width: 150; height: 40 + color: "darkgray" + anchors.horizontalCenter: page.horizontalCenter + y: 150 + MouseArea { + id: buttonMouseArea + objectName: "buttonMouseArea" + anchors.fill: parent + } + } +} diff --git a/sources/pyside2/tests/QtQml/hw.qml b/sources/pyside2/tests/QtQml/hw.qml new file mode 100755 index 000000000..0e682bf40 --- /dev/null +++ b/sources/pyside2/tests/QtQml/hw.qml @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: page + width: 500; height: 200 + color: "lightgray" + + Text { + id: helloText + text: "Hello world!" + y: 30 + anchors.horizontalCenter: page.horizontalCenter + font.pointSize: 24; font.bold: true + } + + Image { + // It's okay for this to fail. + source: "http://localhost/logo.png" + } +} diff --git a/sources/pyside2/tests/QtQml/javascript_exceptions.py b/sources/pyside2/tests/QtQml/javascript_exceptions.py new file mode 100644 index 000000000..513a22a3e --- /dev/null +++ b/sources/pyside2/tests/QtQml/javascript_exceptions.py @@ -0,0 +1,103 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import unittest + +from helper import adjust_filename, UsesQApplication + +from PySide2.QtCore import Slot, Property, Signal, QObject, QUrl +from PySide2.QtQml import QJSEngine, qmlRegisterType +from PySide2.QtQuick import QQuickView + +test_error_message = "This is an error." + +method_test_string = """ +(function (obj) { + obj.methodThrows(); +}) +""" + +property_test_string = """ +(function (obj) { + obj.propertyThrows; +}) +""" + +test_1 = False +test_2 = False + +class TestClass(QObject): + @Slot() + def methodThrows(self): + raise TypeError(test_error_message) + + @Property(str) + def propertyThrows(self): + raise TypeError(test_error_message) + + @Slot(int) + def passTest(self, test): + global test_1, test_2 + + if test == 1: + test_1 = True + else: + test_2 = True + +class JavaScriptExceptionsTest(UsesQApplication): + def test_jsengine(self): + engine = QJSEngine() + test_object = TestClass() + test_value = engine.newQObject(test_object) + + result_1 = engine.evaluate(method_test_string).call([test_value]) + + self.assertTrue(result_1.isError()) + self.assertEqual(result_1.property('message').toString(), test_error_message) + self.assertEqual(result_1.property('name').toString(), 'TypeError') + + result_2 = engine.evaluate(property_test_string).call([test_value]) + + self.assertTrue(result_2.isError()) + self.assertEqual(result_2.property('message').toString(), test_error_message) + self.assertEqual(result_2.property('name').toString(), 'TypeError') + + def test_qml_type(self): + qmlRegisterType(TestClass, 'JavaScriptExceptions', 1, 0, 'JavaScriptExceptions'); + + view = QQuickView() + qml_url = QUrl.fromLocalFile(adjust_filename('javascript_exceptions.qml', __file__)) + + view.setSource(qml_url) + + self.assertTrue(test_1) + self.assertTrue(test_2) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/javascript_exceptions.qml b/sources/pyside2/tests/QtQml/javascript_exceptions.qml new file mode 100644 index 000000000..6d0e062cf --- /dev/null +++ b/sources/pyside2/tests/QtQml/javascript_exceptions.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Controls 1.0 +import JavaScriptExceptions 1.0 + +Rectangle { + JavaScriptExceptions { + id: obj + } + + Component.onCompleted: { + // Method call test + try { + obj.methodThrows(); + } catch(e) { + obj.passTest(1); + } + + // Property accessor test + try { + obj.propertyThrows; + } catch(e) { + obj.passTest(2); + } + } +} \ No newline at end of file diff --git a/sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile.py b/sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile.py new file mode 100644 index 000000000..26be20f15 --- /dev/null +++ b/sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile.py @@ -0,0 +1,96 @@ +#!/usr/bin/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 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$ +## +############################################################################# + +import unittest +import sys +from helper import adjust_filename + +from PySide2.QtCore import QObject, QUrl, Slot, QTimer +from PySide2.QtGui import QGuiApplication +from PySide2.QtQml import QQmlIncubationController, VolatileBool +from PySide2.QtQuick import QQuickView + +class CustomIncubationController(QObject, QQmlIncubationController): + def __init__(self, test): + QObject.__init__(self) + QQmlIncubationController.__init__(self) + self.test = test + self.interrupted = False + + # Incubate every 50 milliseconds + self.startTimer(50) + self.incubationShouldContinue = VolatileBool(True) + self.test.assertEqual(self.incubationShouldContinue.get(), True) + + @Slot() + def interrupter(self): + if not self.interrupted: + self.interrupted = True + self.incubationShouldContinue.set(False) + self.test.assertEqual(self.incubationShouldContinue.get(), False) + QTimer.singleShot(0, QGuiApplication.instance().quit) + + def timerEvent(self, ev): + # Incubate items for 2000 milliseconds, or until the volatile bool is set to false. + self.incubateWhile(self.incubationShouldContinue, 2000) + +class TestBug(unittest.TestCase): + def testIncubateWhileCall(self): + app = QGuiApplication(sys.argv) + view = QQuickView() + controller = CustomIncubationController(self) + view.engine().setIncubationController(controller) + view.setResizeMode(QQuickView.SizeRootObjectToView) + view.setSource(QUrl.fromLocalFile(adjust_filename('qqmlincubator_incubateWhile.qml', + __file__))) + view.show() + + root = view.rootObject() + # The QML code will issue an interrupt signal after half of its items are loaded. + root.shouldInterrupt.connect(controller.interrupter) + res = app.exec_() + + itemsToCreate = root.property("itemsToCreate") + loadedItems = root.property("loadedItems") + self.assertEqual(loadedItems, itemsToCreate / 2) + + # Finish incubating the remaining items. + controller.incubateFor(1000) + loadedItems = root.property("loadedItems") + self.assertEqual(loadedItems, itemsToCreate) + + # Deleting the view before it goes out of scope is required to make sure all child QML + # instances are destroyed in the correct order. + del view + del app + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile.qml b/sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile.qml new file mode 100644 index 000000000..3f4fe8214 --- /dev/null +++ b/sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile.qml @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ +import QtQuick 2.0 + + +Rectangle { + id: root + objectName: "theNicestRoot" + width: 400; height: 400 + + signal shouldInterrupt() + property int loadedItems: 0 + property int itemsToCreate: 10 + + Row { + anchors.centerIn: parent + spacing: 20 + + Rectangle { + id: initialRectangle + width: 10; height: 10 + color: "red" + } + + Repeater { + model: itemsToCreate + Loader { + id: loader + asynchronous: true + source: "qqmlincubator_incubateWhile_component.qml" + onLoaded: { + root.loadedItems += 1 + + // Interrupt incubation after half of the items are loaded. + if (root.loadedItems >= (itemsToCreate / 2)) { + root.shouldInterrupt() + } + } + } + } + } +} diff --git a/sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile_component.qml b/sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile_component.qml new file mode 100644 index 000000000..654cf2281 --- /dev/null +++ b/sources/pyside2/tests/QtQml/qqmlincubator_incubateWhile_component.qml @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: root + width: 10; height: 10 + color: "yellow" +} diff --git a/sources/pyside2/tests/QtQml/qqmlnetwork_test.py b/sources/pyside2/tests/QtQml/qqmlnetwork_test.py new file mode 100755 index 000000000..fab3af8c8 --- /dev/null +++ b/sources/pyside2/tests/QtQml/qqmlnetwork_test.py @@ -0,0 +1,70 @@ +############################################################################# +## +## Copyright (C) 2016 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 cases for QQmlNetwork''' + +from __future__ import print_function + +import unittest + +from PySide2.QtCore import QUrl +from PySide2.QtQuick import QQuickView +from PySide2.QtQml import QQmlNetworkAccessManagerFactory +from PySide2.QtNetwork import QNetworkAccessManager + +from helper import adjust_filename, TimedQApplication + +class CustomManager(QNetworkAccessManager): + def createRequest(self, op, req, data = None): + print(">> createRequest ", self, op, req.url(), data) + return QNetworkAccessManager.createRequest(self, op, req, data) + +class CustomFactory(QQmlNetworkAccessManagerFactory): + def create(self, parent = None): + return CustomManager() + +class TestQQmlNetworkFactory(TimedQApplication): + def setUp(self): + TimedQApplication.setUp(self, timeout=1000) + + def testQQuickNetworkFactory(self): + view = QQuickView() + self.factory = CustomFactory() + view.engine().setNetworkAccessManagerFactory(self.factory) + + url = QUrl.fromLocalFile(adjust_filename('hw.qml', __file__)) + + view.setSource(url) + view.show() + + self.assertEqual(view.status(), QQuickView.Ready) + + self.app.exec_() + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/qquickitem_grabToImage.py b/sources/pyside2/tests/QtQml/qquickitem_grabToImage.py new file mode 100644 index 000000000..91835e689 --- /dev/null +++ b/sources/pyside2/tests/QtQml/qquickitem_grabToImage.py @@ -0,0 +1,79 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import unittest +from helper import adjust_filename, TimedQApplication +from PySide2 import QtCore, QtGui, QtQuick + +class TestGrabToSharedPointerImage(TimedQApplication): + def setUp(self): + TimedQApplication.setUp(self, 1000) + + def testQQuickItemGrabToImageSharedPointer(self): + view = QtQuick.QQuickView() + view.setSource(QtCore.QUrl.fromLocalFile( + adjust_filename('qquickitem_grabToImage.qml', __file__))) + view.show() + + # Get the QQuickItem objects for the blue Rectangle and the Image item. + root = view.rootObject() + blueRectangle = root.findChild(QtQuick.QQuickItem, "blueRectangle") + imageContainer = root.findChild(QtQuick.QQuickItem, "imageContainer") + + # Start the image grabbing. + grabResultSharedPtr = blueRectangle.grabToImage() + + # Implicit call of operator bool() of the smart pointer, to check that it holds + # a valid pointer. + self.assertTrue(grabResultSharedPtr) + + self.grabbedColor = None + def onGrabReady(): + # Signal early exit. + QtCore.QTimer.singleShot(0, self.app.quit) + + # Show the grabbed image in the QML Image item. + imageContainer.setProperty("source", grabResultSharedPtr.url()) + + # Wait for signal when grabbing is complete. + grabResultSharedPtr.ready.connect(onGrabReady) + self.app.exec_() + + # Get the first pixel color of the grabbed image. + self.image = grabResultSharedPtr.image() + self.assertTrue(self.image) + self.grabbedColor = self.image.pixelColor(0,0) + self.assertTrue(self.grabbedColor.isValid()) + + # Compare the grabbed color with the one we set in the rectangle. + blueColor = QtGui.QColor("blue") + self.assertEqual(self.grabbedColor, blueColor) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/qquickitem_grabToImage.qml b/sources/pyside2/tests/QtQml/qquickitem_grabToImage.qml new file mode 100644 index 000000000..d103cf076 --- /dev/null +++ b/sources/pyside2/tests/QtQml/qquickitem_grabToImage.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: root + width: 600 + height: 600 + + Rectangle { + id: blue + objectName: "blueRectangle" + width: 200 + height: 200 + anchors.top: root.top + anchors.horizontalCenter: root.horizontalCenter + color: "blue" + } + + Text { + text: qsTr("Original blue rectangle") + anchors.left: blue.right + anchors.verticalCenter: blue.verticalCenter + } + + Image { + id: imageContainer + objectName: "imageContainer" + width: 200 + height: 200 + anchors.bottom: root.bottom + anchors.horizontalCenter: root.horizontalCenter + } + + Text { + text: qsTr("Image with the source URL set to the result of calling QQuickItem::grabToImage on the rectangle. If you see a second blue rectangle, that means it works.") + anchors.left: imageContainer.right + anchors.verticalCenter: imageContainer.verticalCenter + wrapMode: Text.WrapAtWordBoundaryOrAnywhere + width: 200 + } + +} diff --git a/sources/pyside2/tests/QtQml/qquickview_test.py b/sources/pyside2/tests/QtQml/qquickview_test.py new file mode 100755 index 000000000..e65eb3afc --- /dev/null +++ b/sources/pyside2/tests/QtQml/qquickview_test.py @@ -0,0 +1,86 @@ +############################################################################# +## +## Copyright (C) 2016 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 cases for QQuickView''' + +import unittest + +from helper import adjust_filename, TimedQApplication + +from PySide2.QtCore import QUrl, QObject, Property, Slot +from PySide2.QtQuick import QQuickView + +class MyObject(QObject): + def __init__(self, text, parent=None): + QObject.__init__(self, parent) + self._text = text + + def getText(self): + return self._text + + + @Slot(str) + def qmlText(self, text): + self._qmlText = text + + title = Property(str, getText) + + +class TestQQuickView(TimedQApplication): + + def testQQuickViewList(self): + view = QQuickView() + + dataList = ["Item 1", "Item 2", "Item 3", "Item 4"] + + ctxt = view.rootContext() + ctxt.setContextProperty("myModel", dataList) + + url = QUrl.fromLocalFile(adjust_filename('view.qml', __file__)) + view.setSource(url) + view.show() + + self.assertEqual(view.status(), QQuickView.Ready) + + + def testModelExport(self): + view = QQuickView() + dataList = [MyObject("Item 1"), MyObject("Item 2"), MyObject("Item 3"), MyObject("Item 4")] + + ctxt = view.rootContext() + ctxt.setContextProperty("myModel", dataList) + + url = QUrl.fromLocalFile(adjust_filename('viewmodel.qml', __file__)) + view.setSource(url) + view.show() + + self.assertEqual(view.status(), QQuickView.Ready) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/registertype.py b/sources/pyside2/tests/QtQml/registertype.py new file mode 100755 index 000000000..82bac32b1 --- /dev/null +++ b/sources/pyside2/tests/QtQml/registertype.py @@ -0,0 +1,118 @@ +############################################################################# +## +## Copyright (C) 2016 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$ +## +############################################################################# + +import sys +import unittest + +import helper + +from PySide2.QtCore import Property, QTimer, QUrl +from PySide2.QtGui import QGuiApplication, QPen, QColor, QPainter +from PySide2.QtQml import qmlRegisterType, ListProperty +from PySide2.QtQuick import QQuickView, QQuickItem, QQuickPaintedItem + +class PieSlice (QQuickPaintedItem): + def __init__(self, parent = None): + QQuickPaintedItem.__init__(self, parent) + self._color = QColor() + self._fromAngle = 0 + self._angleSpan = 0 + + def getColor(self): + return self._color + + def setColor(self, value): + self._color = value + + def getFromAngle(self): + return self._angle + + def setFromAngle(self, value): + self._fromAngle = value + + def getAngleSpan(self): + return self._angleSpan + + def setAngleSpan(self, value): + self._angleSpan = value + + color = Property(QColor, getColor, setColor) + fromAngle = Property(int, getFromAngle, setFromAngle) + angleSpan = Property(int, getAngleSpan, setAngleSpan) + + def paint(self, painter): + global paintCalled + pen = QPen(self._color, 2) + painter.setPen(pen); + painter.setRenderHints(QPainter.Antialiasing, True); + painter.drawPie(self.boundingRect(), self._fromAngle * 16, self._angleSpan * 16); + paintCalled = True + +class PieChart (QQuickItem): + def __init__(self, parent = None): + QQuickItem.__init__(self, parent) + self._name = '' + self._slices = [] + + def getName(self): + return self._name + + def setName(self, value): + self._name = value + + name = Property(str, getName, setName) + + def appendSlice(self, _slice): + global appendCalled + _slice.setParentItem(self) + self._slices.append(_slice) + appendCalled = True + + slices = ListProperty(PieSlice, append=appendSlice) + +appendCalled = False +paintCalled = False + +class TestQmlSupport(unittest.TestCase): + + def testIt(self): + app = QGuiApplication([]) + + qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart'); + qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice"); + + view = QQuickView() + view.setSource(QUrl.fromLocalFile(helper.adjust_filename('registertype.qml', __file__))) + view.show() + QTimer.singleShot(250, view.close) + app.exec_() + self.assertTrue(appendCalled) + self.assertTrue(paintCalled) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtQml/registertype.qml b/sources/pyside2/tests/QtQml/registertype.qml new file mode 100755 index 000000000..cfa7fce8f --- /dev/null +++ b/sources/pyside2/tests/QtQml/registertype.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Charts 1.0 + +Item { + width: 300; height: 200 + + PieChart { + anchors.centerIn: parent + width: 100; height: 100 + + slices: [ + PieSlice { + anchors.fill: parent + color: "red" + fromAngle: 0; angleSpan: 110 + }, + PieSlice { + anchors.fill: parent + color: "black" + fromAngle: 110; angleSpan: 50 + }, + PieSlice { + anchors.fill: parent + color: "blue" + fromAngle: 160; angleSpan: 100 + } + ] + } +} diff --git a/sources/pyside2/tests/QtQml/view.qml b/sources/pyside2/tests/QtQml/view.qml new file mode 100755 index 000000000..8cc50e782 --- /dev/null +++ b/sources/pyside2/tests/QtQml/view.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +ListView { + width: 100 + height: 100 + anchors.fill: parent + model: myModel + delegate: Component { + Rectangle { + height: 25 + width: 100 + Text { text: modelData } + } + } +} diff --git a/sources/pyside2/tests/QtQml/viewmodel.qml b/sources/pyside2/tests/QtQml/viewmodel.qml new file mode 100755 index 000000000..18f799da8 --- /dev/null +++ b/sources/pyside2/tests/QtQml/viewmodel.qml @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +ListView { + width: 100; height: 100 + anchors.fill: parent + + model: myModel + delegate: Rectangle { + height: 25 + width: 100 + Text { text: title } + } +} + -- cgit v1.2.3