aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlbert Astals Cid <albert.astals@canonical.com>2016-11-22 12:26:54 +0100
committerAlbert Astals Cid <albert.astals@canonical.com>2016-11-30 15:01:01 +0000
commitb19ebe1d23e1f2fd334cef4ec2731ab5cc69dbd7 (patch)
treec59fe68a63512fc3dea9aa78b6da9f5d5f0bbeaf /tests
parent63c34dc6c1c6f24f8e83f295adc70fdcc392f8c5 (diff)
Fix SignalSpy with QQmlPropertyMap signals
2e7d4ecdc59942b484159ca827f5d5dbc8787a1b caused the regression. To fix the regression I try accessing the signal name first and if it is not a function try accessing the handler name. Comes with a unit test to test both cases. Change-Id: I3897f344df9c6219636c70259eed503d9b76f09e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/quicktest/quicktest.pro3
-rw-r--r--tests/auto/quicktest/signalspy/data/signalspy.qml60
-rw-r--r--tests/auto/quicktest/signalspy/mypropertymap.cpp38
-rw-r--r--tests/auto/quicktest/signalspy/mypropertymap.h41
-rw-r--r--tests/auto/quicktest/signalspy/signalspy.pro9
-rw-r--r--tests/auto/quicktest/signalspy/tst_signalspy.cpp95
7 files changed, 247 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 556f5ddc7a..f25742fb14 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -2,6 +2,7 @@ TEMPLATE=subdirs
SUBDIRS=\
qml \
quick \
+ quicktest \
qmltest \
qmldevtools \
cmake \
diff --git a/tests/auto/quicktest/quicktest.pro b/tests/auto/quicktest/quicktest.pro
new file mode 100644
index 0000000000..3b4ec23a64
--- /dev/null
+++ b/tests/auto/quicktest/quicktest.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ signalspy
diff --git a/tests/auto/quicktest/signalspy/data/signalspy.qml b/tests/auto/quicktest/signalspy/data/signalspy.qml
new file mode 100644
index 0000000000..6c365e296a
--- /dev/null
+++ b/tests/auto/quicktest/signalspy/data/signalspy.qml
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $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 QtTest 1.1
+import MyImport 1.0
+
+Rectangle {
+ id:rect
+ width: 200
+ height: 200
+ color:"red"
+
+ MouseArea {
+ id: mouseArea
+ anchors.fill: parent
+ }
+
+ MyPropertyMap {
+ id: propertyMap
+ objectName: "propertyMap"
+ }
+
+ SignalSpy {
+ objectName: "mouseSpy"
+ target: mouseArea
+ signalName: "pressed"
+ }
+
+ SignalSpy {
+ objectName: "propertyMapSpy"
+ target: propertyMap
+ signalName: "mySignal"
+ }
+}
diff --git a/tests/auto/quicktest/signalspy/mypropertymap.cpp b/tests/auto/quicktest/signalspy/mypropertymap.cpp
new file mode 100644
index 0000000000..91bd93dde0
--- /dev/null
+++ b/tests/auto/quicktest/signalspy/mypropertymap.cpp
@@ -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 the Qt Toolkit.
+**
+** $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$
+**
+****************************************************************************/
+
+#include "mypropertymap.h"
+
+MyPropertyMap::MyPropertyMap(QObject *parent): QQmlPropertyMap(this, parent)
+{
+}
+
+MyPropertyMap::~MyPropertyMap()
+{
+}
+
diff --git a/tests/auto/quicktest/signalspy/mypropertymap.h b/tests/auto/quicktest/signalspy/mypropertymap.h
new file mode 100644
index 0000000000..d69548fe88
--- /dev/null
+++ b/tests/auto/quicktest/signalspy/mypropertymap.h
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $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$
+**
+****************************************************************************/
+
+#include <QQmlPropertyMap>
+
+class MyPropertyMap : public QQmlPropertyMap
+{
+ Q_OBJECT
+
+public:
+ MyPropertyMap(QObject *parent = nullptr);
+ ~MyPropertyMap();
+
+Q_SIGNALS:
+ void mySignal();
+};
diff --git a/tests/auto/quicktest/signalspy/signalspy.pro b/tests/auto/quicktest/signalspy/signalspy.pro
new file mode 100644
index 0000000000..c8f9be1f36
--- /dev/null
+++ b/tests/auto/quicktest/signalspy/signalspy.pro
@@ -0,0 +1,9 @@
+CONFIG += testcase
+TARGET = tst_signalspy
+macos:CONFIG -= app_bundle
+
+SOURCES += tst_signalspy.cpp mypropertymap.cpp
+HEADERS += mypropertymap.h
+QT += quick testlib
+
+include (../../shared/util.pri)
diff --git a/tests/auto/quicktest/signalspy/tst_signalspy.cpp b/tests/auto/quicktest/signalspy/tst_signalspy.cpp
new file mode 100644
index 0000000000..f54da7819c
--- /dev/null
+++ b/tests/auto/quicktest/signalspy/tst_signalspy.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $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$
+**
+****************************************************************************/
+
+#include <qtest.h>
+
+#include <qqmlengine.h>
+#include <qquickitem.h>
+#include <qquickview.h>
+
+#include "../../shared/util.h"
+#include "mypropertymap.h"
+
+class tst_SignalSpy : public QQmlDataTest
+{
+ Q_OBJECT
+public:
+ tst_SignalSpy();
+
+private slots:
+ void testValid();
+ void testCount();
+
+private:
+ QQmlEngine engine;
+};
+
+tst_SignalSpy::tst_SignalSpy()
+{
+ qmlRegisterType<MyPropertyMap>("MyImport", 1, 0, "MyPropertyMap");
+}
+
+void tst_SignalSpy::testValid()
+{
+ QQuickView window;
+ window.setSource(testFileUrl("signalspy.qml"));
+ QVERIFY(window.rootObject() != 0);
+
+ QObject *mouseSpy = window.rootObject()->findChild<QObject*>("mouseSpy");
+ QVERIFY(mouseSpy->property("valid").toBool());
+
+ QObject *propertyMapSpy = window.rootObject()->findChild<QObject*>("propertyMapSpy");
+ QVERIFY(propertyMapSpy->property("valid").toBool());
+}
+
+void tst_SignalSpy::testCount()
+{
+ QQuickView window;
+ window.resize(200, 200);
+ window.setSource(testFileUrl("signalspy.qml"));
+ window.show();
+ QTest::qWaitForWindowActive(&window);
+ QVERIFY(window.rootObject() != 0);
+
+ QObject *mouseSpy = window.rootObject()->findChild<QObject*>("mouseSpy");
+ QCOMPARE(mouseSpy->property("count").toInt(), 0);
+
+ QObject *propertyMapSpy = window.rootObject()->findChild<QObject*>("propertyMapSpy");
+ QCOMPARE(propertyMapSpy->property("count").toInt(), 0);
+
+ QTest::mouseClick(&window, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(100, 100));
+ QTRY_COMPARE(mouseSpy->property("count").toInt(), 1);
+
+ MyPropertyMap *propertyMap = static_cast<MyPropertyMap *>(window.rootObject()->findChild<QObject*>("propertyMap"));
+ Q_EMIT propertyMap->mySignal();
+ QCOMPARE(propertyMapSpy->property("count").toInt(), 1);
+}
+
+QTEST_MAIN(tst_SignalSpy)
+
+#include "tst_signalspy.moc"