Merge lp:~kalikiana/ubuntu-ui-toolkit/ubuntuTestCaseCxx into lp:ubuntu-ui-toolkit

Proposed by Cris Dywan
Status: Merged
Merged at revision: 981
Proposed branch: lp:~kalikiana/ubuntu-ui-toolkit/ubuntuTestCaseCxx
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 220 lines (+131/-22)
6 files modified
modules/Ubuntu/Test/Test.pro (+1/-0)
modules/Ubuntu/Test/plugin/plugin.pro (+25/-0)
modules/Ubuntu/Test/plugin/uctestcase.cpp (+50/-0)
modules/Ubuntu/Test/plugin/uctestcase.h (+47/-0)
tests/unit/plugin_dependency.pri (+3/-0)
tests/unit_x11/tst_layouts/tst_layouts.cpp (+5/-22)
To merge this branch: bzr merge lp:~kalikiana/ubuntu-ui-toolkit/ubuntuTestCaseCxx
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Zsombor Egri Approve
Review via email: mp+199162@code.launchpad.net

Commit message

Introduce UbuntuTestCase API for C++

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

94 +void UbuntuTestCase::setFile(const QString& file) {
95 + Q_ASSERT(!file.isEmpty());
96 + if (rootObject())
97 + delete rootObject();
98 + setSource(QUrl::fromLocalFile(file));
99 + Q_ASSERT(status() == QQuickView::Ready);
100 + Q_ASSERT(rootObject());
101 + show();
102 + QTest::qWaitForWindowExposed(this);
103 +}

I see the approach you had taken is the way the InverseMouseArea test does. I found out that this approach is not the best one, as the Ubuntu Components plugin is not reloaded when the next test (root object) is set. This may lead in leaving the singletons in the plugin in a state which is not expected when the app starts. And that is not good.

A better approach would be to use the QScopedPointer in each test function. That would make sure we get rid of the test view each time the test fails, and will also destroy the view when the test ends. Just like it is done in tst_layouts.cpp.

review: Needs Fixing
Revision history for this message
Zsombor Egri (zsombi) wrote :

This is awesome! I like it!!! We must extend this with all kinds of helpers we need for touch, flick, other stuff!!! Thanks!!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Test/Test.pro'
2--- modules/Ubuntu/Test/Test.pro 2013-07-24 12:34:45 +0000
3+++ modules/Ubuntu/Test/Test.pro 2014-03-19 12:49:53 +0000
4@@ -1,4 +1,5 @@
5 TEMPLATE = subdirs
6+SUBDIRS += plugin
7 OTHER_FILES += $$system(ls *.qml)
8 include(deployment.pri)
9
10
11=== added directory 'modules/Ubuntu/Test/plugin'
12=== added file 'modules/Ubuntu/Test/plugin/plugin.pro'
13--- modules/Ubuntu/Test/plugin/plugin.pro 1970-01-01 00:00:00 +0000
14+++ modules/Ubuntu/Test/plugin/plugin.pro 2014-03-19 12:49:53 +0000
15@@ -0,0 +1,25 @@
16+TEMPLATE = lib
17+TARGET = ../UbuntuTest
18+QT += core-private qml qml-private quick quick-private
19+
20+equals(QT_MAJOR_VERSION, 5):lessThan(QT_MINOR_VERSION, 2) {
21+ QT += v8-private
22+}
23+
24+CONFIG += qt plugin no_keywords
25+
26+QMAKE_CXXFLAGS += -Werror
27+
28+TARGET = $$qtLibraryTarget($$TARGET)
29+uri = Ubuntu.Test
30+
31+HEADERS += \
32+ uctestcase.h \
33+
34+SOURCES += \
35+ uctestcase.cpp \
36+
37+# deployment rules for the plugin
38+installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /)
39+target.path = $$installPath
40+INSTALLS += target
41
42=== added file 'modules/Ubuntu/Test/plugin/uctestcase.cpp'
43--- modules/Ubuntu/Test/plugin/uctestcase.cpp 1970-01-01 00:00:00 +0000
44+++ modules/Ubuntu/Test/plugin/uctestcase.cpp 2014-03-19 12:49:53 +0000
45@@ -0,0 +1,50 @@
46+/*
47+ * Copyright 2013-2014 Canonical Ltd.
48+ *
49+ * This program is free software; you can redistribute it and/or modify
50+ * it under the terms of the GNU Lesser General Public License as published by
51+ * the Free Software Foundation; version 3.
52+ *
53+ * This program is distributed in the hope that it will be useful,
54+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
55+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56+ * GNU Lesser General Public License for more details.
57+ *
58+ * You should have received a copy of the GNU Lesser General Public License
59+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
60+ *
61+ * Author: Christian Dywan <christian.dywan@canonical.com>
62+ */
63+
64+#include "uctestcase.h"
65+
66+#include <stdlib.h>
67+
68+#include <QtQml/QQmlEngine>
69+#include <QtCore/QDir>
70+#include <QtCore/QDebug>
71+#include <QtTest/QtTest>
72+#include <QtQuick/QQuickItem>
73+
74+/*!
75+ * \ingroup ubuntu
76+ * \brief UbuntuTestCase is the C++ pendant to the QML UbuntuTestCase.
77+ */
78+UbuntuTestCase::UbuntuTestCase(const QString& file, QWindow* parent) : QQuickView(parent)
79+{
80+ QString modules("../../../modules");
81+ Q_ASSERT(QDir(modules).exists());
82+ QString modulePath(QDir(modules).absolutePath());
83+ engine()->addImportPath(modulePath);
84+
85+ m_spy = new QSignalSpy(engine(), SIGNAL(warnings(QList<QQmlError>)));
86+ m_spy->setParent(this);
87+
88+ Q_ASSERT(!file.isEmpty());
89+ setSource(QUrl::fromLocalFile(file));
90+ Q_ASSERT(status() == QQuickView::Ready);
91+ Q_ASSERT(rootObject());
92+ show();
93+ QTest::qWaitForWindowExposed(this);
94+}
95+
96
97=== added file 'modules/Ubuntu/Test/plugin/uctestcase.h'
98--- modules/Ubuntu/Test/plugin/uctestcase.h 1970-01-01 00:00:00 +0000
99+++ modules/Ubuntu/Test/plugin/uctestcase.h 2014-03-19 12:49:53 +0000
100@@ -0,0 +1,47 @@
101+/*
102+ * Copyright 2013-2014 Canonical Ltd.
103+ *
104+ * This program is free software; you can redistribute it and/or modify
105+ * it under the terms of the GNU Lesser General Public License as published by
106+ * the Free Software Foundation; version 3.
107+ *
108+ * This program is distributed in the hope that it will be useful,
109+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
110+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
111+ * GNU Lesser General Public License for more details.
112+ *
113+ * You should have received a copy of the GNU Lesser General Public License
114+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
115+ *
116+ * Author: Christian Dywan <christian.dywan@canonical.com>
117+ */
118+
119+#ifndef UBUNTU_TEST_UBUNTUTESTCASE_H
120+#define UBUNTU_TEST_UBUNTUTESTCASE_H
121+
122+#include <QtQuick/QQuickItem>
123+#include <QtQuick/QQuickView>
124+#include <QtTest/QSignalSpy>
125+
126+class UbuntuTestCase : public QQuickView
127+{
128+ Q_OBJECT
129+
130+public:
131+ UbuntuTestCase(const QString& file, QWindow* parent = 0);
132+ // getter
133+ template<class T>
134+ inline T findItem(const QString& objectName) const {
135+ T item = rootObject()->findChild<T>(objectName);
136+ if (item)
137+ return item;
138+ if (rootObject()->findChild<QObject*>(objectName))
139+ qFatal("Item '%s' found with unexpected type", qPrintable(objectName));
140+ qFatal("No item '%s' found", qPrintable(objectName));
141+ }
142+
143+private:
144+ QSignalSpy* m_spy;
145+};
146+
147+#endif // UBUNTU_TEST_UBUNTUTESTCASE_H
148
149=== modified file 'tests/unit/plugin_dependency.pri'
150--- tests/unit/plugin_dependency.pri 2013-10-30 13:57:33 +0000
151+++ tests/unit/plugin_dependency.pri 2014-03-19 12:49:53 +0000
152@@ -1,7 +1,10 @@
153 COMPONENTS_PATH = ../../../modules/Ubuntu/Components
154 INCLUDEPATH += $$COMPONENTS_PATH/plugin
155+INCLUDEPATH += ../../../modules/Ubuntu/Test/plugin
156 PRE_TARGETDEPS = $$COMPONENTS_PATH/libUbuntuComponents.so
157+PRE_TARGETDEPS += ../../../modules/Ubuntu/Test/libUbuntuTest.so
158 LIBS += $$COMPONENTS_PATH/libUbuntuComponents.so
159+LIBS += ../../../modules/Ubuntu/Test/libUbuntuTest.so
160 DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$_PRO_FILE_PWD_\\\"\"
161 QMAKE_CXXFLAGS += -Werror
162
163
164=== modified file 'tests/unit_x11/tst_layouts/tst_layouts.cpp'
165--- tests/unit_x11/tst_layouts/tst_layouts.cpp 2014-02-18 13:27:23 +0000
166+++ tests/unit_x11/tst_layouts/tst_layouts.cpp 2014-03-19 12:49:53 +0000
167@@ -28,6 +28,7 @@
168
169 #include "ullayouts.h"
170 #include "ucunits.h"
171+#include "uctestcase.h"
172 #include <QtQuick/private/qquickanchors_p.h>
173 #include <QtQuick/private/qquickanchors_p_p.h>
174
175@@ -58,18 +59,8 @@
176
177 QQuickView * loadTest(const QString &file)
178 {
179- QQuickView *view = new QQuickView;
180- view->engine()->addImportPath(m_modulePath);
181-
182- view->setSource(QUrl::fromLocalFile(file));
183- if (!view->rootObject()) {
184- delete view;
185- view = 0;
186- } else {
187- view->show();
188- QTest::qWaitForWindowExposed(view);
189- }
190- return view;
191+ UbuntuTestCase* testCase = new UbuntuTestCase(file);
192+ return qobject_cast<QQuickView*>(testCase);
193 }
194
195 QQuickItem *testItem(QQuickItem *that, const QString &identifier)
196@@ -85,10 +76,6 @@
197 private Q_SLOTS:
198 void initTestCase()
199 {
200- QString modules("../../../modules");
201- QVERIFY(QDir(modules).exists());
202-
203- m_modulePath = QDir(modules).absolutePath();
204 }
205
206 void cleanupTestCase()
207@@ -97,12 +84,8 @@
208
209 void testCase_NoLayouts()
210 {
211- QScopedPointer<QQuickView> view(loadTest("NoLayouts.qml"));
212- QVERIFY(view);
213-
214- ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(view->rootObject(), "layouts"));
215- QVERIFY(layouts);
216-
217+ QScopedPointer<UbuntuTestCase> testCase(new UbuntuTestCase("NoLayouts.qml"));
218+ ULLayouts *layouts = testCase->findItem<ULLayouts*>("layouts");
219 QVERIFY(layouts->layoutList().isEmpty());
220 }
221

Subscribers

People subscribed via source and target branches

to status/vote changes: