Merge lp:~unity-team/unity/phablet.test_GenericLensView into lp:unity/phablet

Proposed by Andrea Cimitan
Status: Superseded
Proposed branch: lp:~unity-team/unity/phablet.test_GenericLensView
Merge into: lp:unity/phablet
Diff against target: 498 lines (+288/-15)
12 files modified
Dash/GenericLensView.qml (+1/-0)
plugins/Unity/categoryfilter.cpp (+0/-1)
plugins/Unity/categoryfilter.h (+4/-0)
tests/qmltests/CMakeLists.txt (+1/-0)
tests/qmltests/Dash/tst_GenericLensView.qml (+54/-0)
tests/qmltests/plugins/Unity/CMakeLists.txt (+10/-1)
tests/qmltests/plugins/Unity/categories/CategoryScene.qml (+86/-0)
tests/qmltests/plugins/Unity/categories/test_categories (+3/-0)
tests/qmltests/plugins/Unity/fake_lens.cpp (+106/-4)
tests/qmltests/plugins/Unity/fake_lens.h (+7/-0)
tests/qmltests/plugins/Unity/fake_lenses.cpp (+4/-8)
tests/qmltests/plugins/Unity/fake_unity_plugin.cpp (+12/-1)
To merge this branch: bzr merge lp:~unity-team/unity/phablet.test_GenericLensView
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Albert Astals Cid (community) Needs Fixing
Review via email: mp+160143@code.launchpad.net

This proposal has been superseded by a proposal from 2013-04-23.

Commit message

Add tests for the GenericLensView

Description of the change

Add tests for the GenericLensView

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
Albert Astals Cid (aacid) wrote :

You need to remerge this with trunk UnityTestCase is "gone"

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Dash/GenericLensView.qml'
2--- Dash/GenericLensView.qml 2013-02-15 09:49:36 +0000
3+++ Dash/GenericLensView.qml 2013-04-23 09:42:25 +0000
4@@ -86,6 +86,7 @@
5 }
6 pageHeader: PageHeader {
7 id: pageHeader
8+ objectName: "pageHeader"
9 width: categoryView.width
10 text: lensView.lens.name
11 searchEntryEnabled: true
12
13=== modified file 'plugins/Unity/categoryfilter.cpp'
14--- plugins/Unity/categoryfilter.cpp 2013-04-10 08:11:52 +0000
15+++ plugins/Unity/categoryfilter.cpp 2013-04-23 09:42:25 +0000
16@@ -43,4 +43,3 @@
17 Q_EMIT indexChanged(m_index);
18 }
19 }
20-
21
22=== modified file 'plugins/Unity/categoryfilter.h'
23--- plugins/Unity/categoryfilter.h 2013-04-05 22:03:12 +0000
24+++ plugins/Unity/categoryfilter.h 2013-04-23 09:42:25 +0000
25@@ -17,6 +17,9 @@
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29+#ifndef CATEGORY_FILTER_H
30+#define CATEGORY_FILTER_H
31+
32 // Utils
33 #include "plugins/Utils/qsortfilterproxymodelqml.h"
34
35@@ -42,3 +45,4 @@
36 int m_index;
37 };
38
39+#endif // CATEGORY_FILTER_H
40
41=== modified file 'tests/qmltests/CMakeLists.txt'
42--- tests/qmltests/CMakeLists.txt 2013-04-22 18:56:16 +0000
43+++ tests/qmltests/CMakeLists.txt 2013-04-23 09:42:25 +0000
44@@ -42,6 +42,7 @@
45 add_qml_test(Components Tile)
46 add_qml_test(Components PageHeader)
47 add_qml_test(Dash DashPreview)
48+add_qml_test(Dash GenericLensView IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
49 add_qml_test(Dash PeoplePreview)
50 add_qml_test(Dash FilterGrids IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins ${CMAKE_CURRENT_SOURCE_DIR}/plugins)
51 add_qml_test(Dash/Apps RunningApplicationsGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
52
53=== added file 'tests/qmltests/Dash/tst_GenericLensView.qml'
54--- tests/qmltests/Dash/tst_GenericLensView.qml 1970-01-01 00:00:00 +0000
55+++ tests/qmltests/Dash/tst_GenericLensView.qml 2013-04-23 09:42:25 +0000
56@@ -0,0 +1,54 @@
57+/*
58+ * Copyright 2013 Canonical Ltd.
59+ *
60+ * This program is free software; you can redistribute it and/or modify
61+ * it under the terms of the GNU General Public License as published by
62+ * the Free Software Foundation; version 3.
63+ *
64+ * This program is distributed in the hope that it will be useful,
65+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
66+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67+ * GNU General Public License for more details.
68+ *
69+ * You should have received a copy of the GNU General Public License
70+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
71+ */
72+
73+import QtQuick 2.0
74+import QtTest 1.0
75+import Unity 0.1
76+import ".."
77+import "../../../Dash"
78+import Ubuntu.Components 0.1
79+import Unity.Test 0.1 as UT
80+
81+Item {
82+ width: units.gu(120)
83+ height: units.gu(80)
84+
85+ Lenses {
86+ id: lenses
87+ }
88+
89+ GenericLensView {
90+ id: genericLensView
91+ anchors.fill: parent
92+
93+ UT.UnityTestCase {
94+ name: "GenericLensView"
95+ when: lenses.loaded
96+
97+ function init() {
98+ genericLensView.lens = lenses.get(0)
99+ }
100+
101+ function test_isCurrent() {
102+ var pageHeader = findChild(genericLensView, "pageHeader");
103+ genericLensView.isCurrent = true
104+ pageHeader.searchQuery = "test"
105+ genericLensView.isCurrent = false
106+ tryCompare(pageHeader, "searchQuery", "")
107+ }
108+ }
109+ }
110+}
111
112=== modified file 'tests/qmltests/plugins/Unity/CMakeLists.txt'
113--- tests/qmltests/plugins/Unity/CMakeLists.txt 2013-04-19 11:04:55 +0000
114+++ tests/qmltests/plugins/Unity/CMakeLists.txt 2013-04-23 09:42:25 +0000
115@@ -3,19 +3,26 @@
116 include(FindPkgConfig)
117 find_package(Qt5Core REQUIRED)
118 find_package(Qt5Quick REQUIRED)
119+pkg_search_module(DEE dee-1.0 REQUIRED)
120+pkg_search_module(GOBJECT gobject-2.0 REQUIRED)
121+pkg_search_module(DEEQT libdee-qt5 REQUIRED)
122
123-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -Wall -Wextra -std=c++11")
124 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
125
126 include_directories(
127 ${CMAKE_CURRENT_BINARY_DIR}
128 ${Qt5Core_INCLUDE_DIRS}
129 ${Qt5Quick_INCLUDE_DIRS}
130+ ${DEE_INCLUDE_DIRS}
131+ ${DEEQT_INCLUDE_DIRS}
132 )
133
134 add_definitions(-DQT_NO_KEYWORDS)
135
136 set(UnityQML_SOURCES
137+ ../../../../../plugins/Unity/categories.cpp
138+ ../../../../../plugins/Unity/categoryfilter.cpp
139+ ../../../../../plugins/Utils/qsortfilterproxymodelqml.cpp
140 fake_lens.cpp
141 fake_lenses.cpp
142 fake_unity_plugin.cpp
143@@ -25,6 +32,8 @@
144 target_link_libraries(FakeUnityQml
145 ${Qt5Core_LIBRARIES}
146 ${Qt5Quick_LIBRARIES}
147+ ${DEEQT_LDFLAGS}
148+ ${GOBJECT_LDFLAGS}
149 )
150
151 qt5_use_modules(FakeUnityQml Qml)
152
153=== added directory 'tests/qmltests/plugins/Unity/categories'
154=== added file 'tests/qmltests/plugins/Unity/categories/CategoryScene.qml'
155--- tests/qmltests/plugins/Unity/categories/CategoryScene.qml 1970-01-01 00:00:00 +0000
156+++ tests/qmltests/plugins/Unity/categories/CategoryScene.qml 2013-04-23 09:42:25 +0000
157@@ -0,0 +1,86 @@
158+/*
159+ * Copyright 2013 Canonical Ltd.
160+ *
161+ * This program is free software; you can redistribute it and/or modify
162+ * it under the terms of the GNU General Public License as published by
163+ * the Free Software Foundation; version 3.
164+ *
165+ * This program is distributed in the hope that it will be useful,
166+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
167+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
168+ * GNU General Public License for more details.
169+ *
170+ * You should have received a copy of the GNU General Public License
171+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
172+ */
173+
174+import QtQuick 2.0
175+import QtTest 1.0
176+import Unity 0.1
177+import Ubuntu.Components 0.1
178+
179+Item {
180+ id: root
181+ width: units.gu(30)
182+ height: units.gu(6) * 10
183+
184+ Lenses {
185+ id: lenses
186+ }
187+
188+ Connections {
189+ target: lenses
190+ onLoadedChanged: categories_view.model = lenses.get(0).categories
191+ }
192+
193+ Rectangle {
194+ anchors.fill: parent
195+ color: "grey"
196+
197+ ListView {
198+ id:categories_view
199+ interactive: true
200+
201+ anchors.fill: parent
202+ orientation: ListView.Horizontal
203+ boundsBehavior: Flickable.DragAndOvershootBounds
204+ flickDeceleration: units.gu(625)
205+ maximumFlickVelocity: width * 5
206+ snapMode: ListView.SnapOneItem
207+ highlightMoveDuration: 250
208+
209+ delegate: ListView {
210+ id: category
211+ width: ListView.view.width
212+ height: ListView.view.height
213+
214+ objectName: id
215+ model: results
216+
217+ delegate: Item {
218+ id: category_item
219+ anchors.horizontalCenter: parent.horizontalCenter
220+ width: image.width + text.width
221+ height: units.gu(6)
222+
223+ Image {
224+ id: image
225+ width: units.gu(5)
226+ height: units.gu(5)
227+ anchors.verticalCenter: parent.verticalCenter
228+
229+ source: column_1
230+ }
231+ Text {
232+ id: text;
233+ text: column_4
234+ anchors.left: image.right
235+ height: units.gu(5)
236+ verticalAlignment: Text.AlignVCenter
237+ anchors.leftMargin: units.gu(2)
238+ }
239+ }
240+ }
241+ }
242+ }
243+}
244
245=== added file 'tests/qmltests/plugins/Unity/categories/test_categories'
246--- tests/qmltests/plugins/Unity/categories/test_categories 1970-01-01 00:00:00 +0000
247+++ tests/qmltests/plugins/Unity/categories/test_categories 2013-04-23 09:42:25 +0000
248@@ -0,0 +1,3 @@
249+#!/bin/sh
250+
251+QML2_IMPORT_PATH=../../../../../builddir/tests/qmltests/plugins/ qmlscene CategoryScene.qml
252
253=== modified file 'tests/qmltests/plugins/Unity/fake_lens.cpp'
254--- tests/qmltests/plugins/Unity/fake_lens.cpp 2013-04-19 08:23:18 +0000
255+++ tests/qmltests/plugins/Unity/fake_lens.cpp 2013-04-23 09:42:25 +0000
256@@ -17,12 +17,26 @@
257 // Self
258 #include "fake_lens.h"
259
260+#include <dee.h>
261+#include "paths.h"
262+
263+static DeeModel* create_categories_model(unsigned category_count);
264+static DeeModel* create_results_model(unsigned category_count, unsigned result_count);
265+
266 // TODO: Implement remaining pieces
267
268 Lens::Lens(QObject* parent)
269 : QObject(parent),
270- m_visible(false)
271-{}
272+ m_visible(false),
273+ m_categories(new Categories(this)),
274+ m_results(new DeeListModel(this))
275+{
276+ m_categories->setModel(create_categories_model(4));
277+ m_results->setModel(create_results_model(4, 30));
278+
279+ m_categories->setResultModel(m_results);
280+ m_categories->setGlobalResultModel(m_results);
281+}
282
283 Lens::Lens(QString const& id,
284 QString const& name,
285@@ -31,8 +45,16 @@
286 : QObject(parent),
287 m_id(id),
288 m_name(name),
289- m_visible(visible)
290-{}
291+ m_visible(visible),
292+ m_categories(new Categories(this)),
293+ m_results(new DeeListModel(this))
294+{
295+ m_categories->setModel(create_categories_model(4));
296+ m_results->setModel(create_results_model(4, 30));
297+
298+ m_categories->setResultModel(m_results);
299+ m_categories->setGlobalResultModel(m_results);
300+}
301
302 QString Lens::id() const {
303 return m_id;
304@@ -63,3 +85,83 @@
305 bool Lens::visible() const {
306 return m_visible;
307 }
308+
309+Categories* Lens::categories() const {
310+ return m_categories;
311+}
312+
313+static const gchar * categories_model_schema[] = {
314+ "s", // DISPLAY_NAME
315+ "s", // ICON_HINT
316+ "s", // RENDERER_NAME
317+ "a{sv}" // HINTS
318+};
319+
320+
321+DeeModel* create_categories_model(unsigned category_count) {
322+ DeeModel* category_model = dee_sequence_model_new();
323+ dee_model_set_schema_full(category_model, categories_model_schema, G_N_ELEMENTS(categories_model_schema));
324+
325+ GVariantBuilder b;
326+ g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
327+ GVariant *hints = g_variant_builder_end(&b);
328+
329+ for(unsigned i = 0; i < category_count; ++i)
330+ {
331+ dee_model_append(category_model,
332+ ("Category "+std::to_string(i)).c_str(),
333+ "gtk-apply",
334+ "grid",
335+ hints);
336+ }
337+ g_variant_unref(hints);
338+ return category_model;
339+}
340+
341+
342+/* Schema that is used in the DeeModel representing
343+ the results */
344+static const gchar * results_model_schema[] = {
345+ "s", // URI
346+ "s", // ICON_HINT
347+ "u", // CATEGORY
348+ "s", // MIMETYPE
349+ "s", // TITLE
350+ "s", // COMMENT
351+ "s", // DND_URI
352+ "a{sv}" // METADATA
353+};
354+
355+static const gchar * icons[] = {
356+ "Applications.png",
357+ "Home.png",
358+ "Music.png",
359+ "People.png",
360+ "Videos.png",
361+};
362+
363+DeeModel* create_results_model(unsigned category_count, unsigned result_count) {
364+ DeeModel* results_model = dee_sequence_model_new();
365+ dee_model_set_schema_full(results_model, results_model_schema, G_N_ELEMENTS(results_model_schema));
366+
367+ GVariantBuilder b;
368+ g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
369+ GVariant *hints = g_variant_builder_end(&b);
370+
371+ for(unsigned i = 0; i < result_count; ++i)
372+ {
373+ unsigned category = i % category_count;
374+
375+ dee_model_append(results_model,
376+ ("uri://result."+std::to_string(i)).c_str(),
377+ (shellAppDirectory() + "Dash/graphics/lensIcons/" + (icons[i%G_N_ELEMENTS(icons)])).toLatin1().data(),
378+ category,
379+ "application/x-desktop",
380+ ("Title."+std::to_string(i)).c_str(),
381+ ("Comment."+std::to_string(i)).c_str(),
382+ ("uri://result."+std::to_string(i)).c_str(),
383+ hints);
384+ }
385+ g_variant_unref(hints);
386+ return results_model;
387+ }
388
389=== modified file 'tests/qmltests/plugins/Unity/fake_lens.h'
390--- tests/qmltests/plugins/Unity/fake_lens.h 2013-04-19 08:23:18 +0000
391+++ tests/qmltests/plugins/Unity/fake_lens.h 2013-04-23 09:42:25 +0000
392@@ -19,6 +19,7 @@
393
394 // Qt
395 #include <QObject>
396+#include "../../../../../plugins/Unity/categories.h"
397
398 class Lens : public QObject
399 {
400@@ -27,6 +28,7 @@
401 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
402 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
403 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
404+ Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
405
406 public:
407 Lens(QObject* parent = 0);
408@@ -40,17 +42,22 @@
409 void setName(const QString &str);
410 void setSearchQuery(const QString &str);
411
412+ Categories* categories() const;
413+
414 Q_SIGNALS:
415 void idChanged(QString);
416 void nameChanged(QString);
417 void searchQueryChanged(QString);
418 void visibleChanged(bool);
419+ void categoriesChanged();
420
421 private:
422 QString m_id;
423 QString m_name;
424 QString m_searchQuery;
425 bool m_visible;
426+ Categories* m_categories;
427+ DeeListModel* m_results;
428 };
429
430 #endif // FAKE_LENS_H
431
432=== modified file 'tests/qmltests/plugins/Unity/fake_lenses.cpp'
433--- tests/qmltests/plugins/Unity/fake_lenses.cpp 2013-04-19 16:06:36 +0000
434+++ tests/qmltests/plugins/Unity/fake_lenses.cpp 2013-04-23 09:42:25 +0000
435@@ -45,18 +45,16 @@
436
437 Lenses::~Lenses()
438 {
439- qDeleteAll(m_lenses);
440- m_lenses.clear();
441 }
442
443 void Lenses::updateLenses()
444 {
445 clear();
446 addLens(new Lens("MockLens1", "People", true, this));
447- addLens(new Lens("MockLens2", "Music", true, this));
448- addLens(new Lens("MockLens3", "Home", false, this));
449- addLens(new Lens("MockLens4", "Apps", true, this));
450- addLens(new Lens("MockLens5", "Video", true, this));
451+ addLens(new Lens("MockLens2", "Music", false, this));
452+ addLens(new Lens("MockLens3", "Home", true, this));
453+ addLens(new Lens("MockLens4", "Applications", true, this));
454+ addLens(new Lens("MockLens5", "Videos", true, this));
455
456 if (!m_loaded) {
457 m_loaded = true;
458@@ -97,8 +95,6 @@
459
460 QVariant Lenses::data(const QModelIndex& index, int role) const
461 {
462- Q_UNUSED(role)
463-
464 if (!index.isValid() || index.row() >= m_lenses.size()) {
465 return QVariant();
466 }
467
468=== modified file 'tests/qmltests/plugins/Unity/fake_unity_plugin.cpp'
469--- tests/qmltests/plugins/Unity/fake_unity_plugin.cpp 2013-04-19 11:04:55 +0000
470+++ tests/qmltests/plugins/Unity/fake_unity_plugin.cpp 2013-04-23 09:42:25 +0000
471@@ -18,15 +18,26 @@
472
473 // Self
474 #include "fake_unity_plugin.h"
475+
476+// local
477 #include "fake_lenses.h"
478+#include "../../../../../plugins/Unity/categories.h"
479+#include "../../../../../plugins/Unity/categoryfilter.h"
480
481-// Qt
482+// External
483+#include <glib-object.h>
484 #include <QtQml>
485
486 void FakeUnityPlugin::registerTypes(const char *uri)
487 {
488+#ifndef GLIB_VERSION_2_36
489+ g_type_init();
490+#endif
491+
492 Q_ASSERT(uri == QLatin1String("Unity"));
493
494 qmlRegisterType<Lenses>(uri, 0, 1, "Lenses");
495 qmlRegisterType<Lens>(uri, 0, 1, "Lens");
496+ qmlRegisterType<Categories>(uri, 0, 1, "Categories");
497+ qmlRegisterType<CategoryFilter>(uri, 0, 1, "CategoryFilter");
498 }

Subscribers

People subscribed via source and target branches

to all changes: