Merge lp:~unity-api-team/unity-scopes-shell/department-doesnt-go-away into lp:unity-scopes-shell

Proposed by Pete Woods
Status: Merged
Approved by: Marcus Tomlinson
Approved revision: 150
Merged at revision: 150
Proposed branch: lp:~unity-api-team/unity-scopes-shell/department-doesnt-go-away
Merge into: lp:unity-scopes-shell
Diff against target: 355 lines (+243/-2)
9 files modified
src/Unity/scope.cpp (+8/-0)
src/Unity/scope.h (+1/-1)
tests/data/CMakeLists.txt (+1/-0)
tests/data/mock-scope-departments-flipflop/CMakeLists.txt (+16/-0)
tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.cpp (+144/-0)
tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.ini.in (+8/-0)
tests/departmentstest.cpp (+48/-1)
tests/test-utils.cpp (+14/-0)
tests/test-utils.h (+3/-0)
To merge this branch: bzr merge lp:~unity-api-team/unity-scopes-shell/department-doesnt-go-away
Reviewer Review Type Date Requested Status
Marcus Tomlinson (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+231774@code.launchpad.net

Commit message

Remove missing departments

Description of the change

Remove missing departments

To post a comment you must log in.
150. By Paweł Stołowski

Merged trunk

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

Looks sane & works for me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Unity/scope.cpp'
2--- src/Unity/scope.cpp 2014-09-25 05:16:02 +0000
3+++ src/Unity/scope.cpp 2014-09-30 10:00:42 +0000
4@@ -442,6 +442,7 @@
5 Q_FOREACH(DepartmentNode* child, node->childNodes()) {
6 cachedChildrenIds << child->id();
7 }
8+
9 auto subdeps = scopeNode->subdepartments();
10 QMap<QString, scopes::Department::SCPtr> childIdMap;
11 for (auto it = subdeps.begin(); it != subdeps.end(); ++it) {
12@@ -471,6 +472,13 @@
13 }
14 }
15
16+ // department has been removed (not reported by scope); make sure it's only treated as such when
17+ // we're examining children of *current* department, othwerwise it would break on partial trees when visiting a leaf.
18+ if (firstMismatchingChild == nullptr && scopeNode->subdepartments().size() < cachedChildrenIds.size() &&
19+ m_currentNavigationId.toStdString() == scopeNode->id()) {
20+ return scopeNode;
21+ }
22+
23 return firstMismatchingChild; // will be nullptr if everything matches
24 }
25
26
27=== modified file 'src/Unity/scope.h'
28--- src/Unity/scope.h 2014-09-15 12:03:13 +0000
29+++ src/Unity/scope.h 2014-09-30 10:00:42 +0000
30@@ -203,7 +203,7 @@
31 void processResultSet(QList<std::shared_ptr<unity::scopes::CategorisedResult>>& result_set);
32
33 static unity::scopes::Department::SCPtr findDepartmentById(unity::scopes::Department::SCPtr const& root, std::string const& id);
34- static unity::scopes::Department::SCPtr findUpdateNode(DepartmentNode* node, unity::scopes::Department::SCPtr const& scopeNode);
35+ unity::scopes::Department::SCPtr findUpdateNode(DepartmentNode* node, unity::scopes::Department::SCPtr const& scopeNode);
36
37 QUuid m_session_id;
38 int m_query_id;
39
40=== modified file 'tests/data/CMakeLists.txt'
41--- tests/data/CMakeLists.txt 2014-08-14 10:14:39 +0000
42+++ tests/data/CMakeLists.txt 2014-09-30 10:00:42 +0000
43@@ -1,5 +1,6 @@
44 add_subdirectory(mock-scope)
45 add_subdirectory(mock-scope-departments)
46+add_subdirectory(mock-scope-departments-flipflop)
47 add_subdirectory(mock-scope-double-nav)
48 add_subdirectory(mock-scope-info)
49 add_subdirectory(mock-scope-ttl)
50
51=== added directory 'tests/data/mock-scope-departments-flipflop'
52=== added file 'tests/data/mock-scope-departments-flipflop/CMakeLists.txt'
53--- tests/data/mock-scope-departments-flipflop/CMakeLists.txt 1970-01-01 00:00:00 +0000
54+++ tests/data/mock-scope-departments-flipflop/CMakeLists.txt 2014-09-30 10:00:42 +0000
55@@ -0,0 +1,16 @@
56+include(FindPkgConfig)
57+pkg_check_modules(SCOPESLIB REQUIRED libunity-scopes>=0.6.0)
58+
59+set(SCOPES_BIN_DIR ${SCOPESLIB_LIBDIR})
60+
61+include_directories(${SCOPESLIB_INCLUDE_DIRS})
62+include_directories(${CMAKE_CURRENT_BINARY_DIR})
63+
64+set(SCOPE_SOURCES
65+ mock-scope-departments-flipflop.cpp
66+ )
67+
68+add_library(mock-scope-departments-flipflop MODULE ${SCOPE_SOURCES})
69+target_link_libraries(mock-scope-departments-flipflop ${SCOPESLIB_LDFLAGS})
70+
71+configure_file(mock-scope-departments-flipflop.ini.in mock-scope-departments-flipflop.ini)
72
73=== added file 'tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.cpp'
74--- tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.cpp 1970-01-01 00:00:00 +0000
75+++ tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.cpp 2014-09-30 10:00:42 +0000
76@@ -0,0 +1,144 @@
77+/*
78+ * Copyright (C) 2014 Canonical Ltd
79+ *
80+ * This program is free software: you can redistribute it and/or modify
81+ * it under the terms of the GNU Lesser General Public License version 3 as
82+ * published by the Free Software Foundation.
83+ *
84+ * This program is distributed in the hope that it will be useful,
85+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
86+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87+ * GNU Lesser General Public License for more details.
88+ *
89+ * You should have received a copy of the GNU Lesser General Public License
90+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
91+ *
92+ * Authored by: Pete Woods <pete.woods@canonical.com>
93+ */
94+
95+#include <unity/scopes/CategorisedResult.h>
96+#include <unity/scopes/ScopeBase.h>
97+#include <unity/scopes/SearchReply.h>
98+
99+#include <iostream>
100+#include <thread>
101+#include <atomic>
102+#include <sstream>
103+
104+#define EXPORT __attribute__ ((visibility ("default")))
105+
106+using namespace std;
107+using namespace unity::scopes;
108+
109+class MyQuery : public SearchQueryBase
110+{
111+public:
112+ MyQuery(CannedQuery const& query, SearchMetadata const& metadata, bool flipflop) :
113+ SearchQueryBase(query, metadata),
114+ flipflop_(flipflop)
115+ {
116+ }
117+
118+ ~MyQuery()
119+ {
120+ }
121+
122+ virtual void cancelled() override
123+ {
124+ }
125+
126+ Department::SPtr create_root_dep(CannedQuery const& query)
127+ {
128+ Department::SPtr child_dep;
129+ Department::SPtr root_dep;
130+ root_dep = Department::create("", query, "All departments");
131+
132+ child_dep = Department::create("books", query, "Books");
133+ child_dep->set_has_subdepartments();
134+ root_dep->add_subdepartment(child_dep);
135+
136+ child_dep = Department::create("movies", query, "Movies, TV, Music");
137+ child_dep->set_has_subdepartments();
138+ root_dep->add_subdepartment(child_dep);
139+
140+ if (flipflop_)
141+ {
142+ child_dep = Department::create("electronics", query, "Electronics");
143+ child_dep->set_has_subdepartments();
144+ root_dep->add_subdepartment(child_dep);
145+ }
146+
147+ child_dep = Department::create("home", query, "Home, Garden & DIY");
148+ child_dep->set_has_subdepartments();
149+ root_dep->add_subdepartment(child_dep);
150+
151+ child_dep = Department::create("toys", query, "Toys, Children & Baby");
152+ child_dep->set_has_subdepartments();
153+ root_dep->add_subdepartment(child_dep);
154+
155+ return root_dep;
156+ }
157+
158+ virtual void run(SearchReplyProxy const& reply) override
159+ {
160+ Department::SPtr child_dep;
161+ Department::SPtr root_dep;
162+ Department::SPtr active_dep;
163+
164+ root_dep = create_root_dep(query());
165+
166+ reply->register_departments(root_dep);
167+
168+ auto cat1 = reply->register_category("cat1", "Category 1", "");
169+ CategorisedResult res1(cat1);
170+ res1.set_uri("test:uri");
171+ res1.set_title("result for: \"" + query().query_string() + "\"");
172+ reply->push(res1);
173+ }
174+
175+protected:
176+ bool flipflop_;
177+};
178+
179+class MyScope : public ScopeBase
180+{
181+public:
182+ MyScope()
183+ {
184+ flipflop_ = false;
185+ }
186+
187+ virtual SearchQueryBase::UPtr search(CannedQuery const& q, SearchMetadata const& metadata) override
188+ {
189+ flipflop_ = !flipflop_;
190+ return SearchQueryBase::UPtr(new MyQuery(q, metadata, flipflop_));
191+ }
192+
193+ virtual PreviewQueryBase::UPtr preview(Result const&, ActionMetadata const&) override
194+ {
195+ return nullptr;
196+ }
197+
198+ std::atomic<bool> flipflop_;
199+};
200+
201+extern "C"
202+{
203+
204+ EXPORT
205+ unity::scopes::ScopeBase*
206+ // cppcheck-suppress unusedFunction
207+ UNITY_SCOPE_CREATE_FUNCTION()
208+ {
209+ return new MyScope;
210+ }
211+
212+ EXPORT
213+ void
214+ // cppcheck-suppress unusedFunction
215+ UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
216+ {
217+ delete scope_base;
218+ }
219+
220+}
221
222=== added file 'tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.ini.in'
223--- tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.ini.in 1970-01-01 00:00:00 +0000
224+++ tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.ini.in 2014-09-30 10:00:42 +0000
225@@ -0,0 +1,8 @@
226+[ScopeConfig]
227+DisplayName = mock-departments-flipflop.DisplayName
228+Description = mock-departments-flipflop.Description
229+Art = /mock-departments-flipflop.Art
230+Icon = /mock-departments-flipflop.Icon
231+SearchHint = mock-departments-flipflop.SearchHint
232+HotKey = mock-departments-flipflop.HotKey
233+Author = mock-departments-flipflop.Author
234
235=== modified file 'tests/departmentstest.cpp'
236--- tests/departmentstest.cpp 2014-09-02 09:39:41 +0000
237+++ tests/departmentstest.cpp 2014-09-30 10:00:42 +0000
238@@ -49,6 +49,7 @@
239 QScopedPointer<Scopes> m_scopes;
240 Scope* m_scope;
241 Scope* m_scope_navs;
242+ Scope* m_scope_flipflop;
243 QScopedPointer<RegistrySpawner> m_registry;
244
245 private Q_SLOTS:
246@@ -65,7 +66,7 @@
247 void init()
248 {
249 QStringList favs;
250- favs << "scope://mock-scope-departments" << "scope://mock-scope-double-nav";
251+ favs << "scope://mock-scope-departments" << "scope://mock-scope-double-nav" << "scope://mock-scope-departments-flipflop";
252 setFavouriteScopes(favs);
253
254 m_scopes.reset(new Scopes(nullptr));
255@@ -88,8 +89,13 @@
256 QVERIFY(m_scope_navs != nullptr);
257 m_scope_navs->setActive(true);
258
259+ m_scope_flipflop = qobject_cast<scopes_ng::Scope*>(m_scopes->getScope(QString("mock-scope-departments-flipflop")));
260+ QVERIFY(m_scope_flipflop != nullptr);
261+ m_scope_flipflop->setActive(true);
262+
263 QTRY_COMPARE(m_scope->searchInProgress(), false);
264 QTRY_COMPARE(m_scope_navs->searchInProgress(), false);
265+ QTRY_COMPARE(m_scope_flipflop->searchInProgress(), false);
266 }
267
268 void cleanup()
269@@ -304,6 +310,47 @@
270 QCOMPARE(sortOrderModel->data(idx, Department::Roles::RoleNavigationId), QVariant(QString("top")));
271 QCOMPARE(sortOrderModel->data(idx, Department::Roles::RoleIsActive), QVariant(true));
272 }
273+
274+ void testDepartmentDissapear()
275+ {
276+ QCOMPARE(m_scope_flipflop->hasNavigation(), true);
277+ QCOMPARE(m_scope_flipflop->hasAltNavigation(), false);
278+ QCOMPARE(m_scope_flipflop->currentNavigationId(), QString(""));
279+
280+ QScopedPointer<NavigationInterface> departmentModel(m_scope_flipflop->getNavigation(m_scope_flipflop->currentNavigationId()));
281+ QVERIFY(departmentModel != nullptr);
282+
283+ QVERIFY(departmentModel->navigationId().isEmpty());
284+ QCOMPARE(departmentModel->label(), QString("All departments"));
285+ QCOMPARE(departmentModel->allLabel(), QString(""));
286+ QCOMPARE(departmentModel->parentNavigationId(), QString());
287+ QCOMPARE(departmentModel->parentLabel(), QString());
288+ QCOMPARE(departmentModel->loaded(), true);
289+ QCOMPARE(departmentModel->isRoot(), true);
290+ QCOMPARE(departmentModel->hidden(), false);
291+
292+ QCOMPARE(departmentModel->rowCount(), 5);
293+
294+ refreshSearch(m_scope_flipflop);
295+
296+ // one department removed
297+ QCOMPARE(departmentModel->rowCount(), 4);
298+
299+ QModelIndex idx;
300+
301+ idx = departmentModel->index(0);
302+ QCOMPARE(departmentModel->data(idx, Department::Roles::RoleNavigationId), QVariant(QString("books")));
303+ QCOMPARE(departmentModel->data(idx, Department::Roles::RoleLabel), QVariant(QString("Books")));
304+ QCOMPARE(departmentModel->data(idx, Department::Roles::RoleHasChildren), QVariant(true));
305+ QCOMPARE(departmentModel->data(idx, Department::Roles::RoleIsActive), QVariant(false));
306+
307+ idx = departmentModel->index(3);
308+ QCOMPARE(departmentModel->data(idx, Department::Roles::RoleNavigationId), QVariant(QString("toys")));
309+ QCOMPARE(departmentModel->data(idx, Department::Roles::RoleLabel), QVariant(QString("Toys, Children & Baby")));
310+ QCOMPARE(departmentModel->data(idx, Department::Roles::RoleHasChildren), QVariant(true));
311+ QCOMPARE(departmentModel->data(idx, Department::Roles::RoleIsActive), QVariant(false));
312+ }
313+
314 };
315
316 QTEST_GUILESS_MAIN(DepartmentsTest)
317
318=== modified file 'tests/test-utils.cpp'
319--- tests/test-utils.cpp 2014-09-15 12:03:13 +0000
320+++ tests/test-utils.cpp 2014-09-30 10:00:42 +0000
321@@ -61,6 +61,20 @@
322 return success;
323 }
324
325+void scopes_ng::refreshSearch(Scope* scope)
326+{
327+ QCOMPARE(scope->searchInProgress(), false);
328+ QSignalSpy spy(scope, SIGNAL(searchInProgressChanged()));
329+ // refresh the search
330+ scope->refresh();
331+ QVERIFY(scope->searchInProgress() || spy.count() > 1);
332+ if (scope->searchInProgress()) {
333+ // wait for the search to finish
334+ QVERIFY(spy.wait());
335+ }
336+ QCOMPARE(scope->searchInProgress(), false);
337+}
338+
339 void scopes_ng::performSearch(Scope* scope, QString const& searchString)
340 {
341 QCOMPARE(scope->searchInProgress(), false);
342
343=== modified file 'tests/test-utils.h'
344--- tests/test-utils.h 2014-09-15 12:03:13 +0000
345+++ tests/test-utils.h 2014-09-30 10:00:42 +0000
346@@ -37,6 +37,9 @@
347 bool getFirstResult(Scope* scope, unity::scopes::Result::SPtr& result);
348
349 Q_DECL_EXPORT
350+void refreshSearch(scopes_ng::Scope*);
351+
352+Q_DECL_EXPORT
353 void performSearch(Scope* scope, QString const& searchString);
354
355 Q_DECL_EXPORT

Subscribers

People subscribed via source and target branches

to all changes: