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
=== modified file 'src/Unity/scope.cpp'
--- src/Unity/scope.cpp 2014-09-25 05:16:02 +0000
+++ src/Unity/scope.cpp 2014-09-30 10:00:42 +0000
@@ -442,6 +442,7 @@
442 Q_FOREACH(DepartmentNode* child, node->childNodes()) {442 Q_FOREACH(DepartmentNode* child, node->childNodes()) {
443 cachedChildrenIds << child->id();443 cachedChildrenIds << child->id();
444 }444 }
445
445 auto subdeps = scopeNode->subdepartments();446 auto subdeps = scopeNode->subdepartments();
446 QMap<QString, scopes::Department::SCPtr> childIdMap;447 QMap<QString, scopes::Department::SCPtr> childIdMap;
447 for (auto it = subdeps.begin(); it != subdeps.end(); ++it) {448 for (auto it = subdeps.begin(); it != subdeps.end(); ++it) {
@@ -471,6 +472,13 @@
471 }472 }
472 }473 }
473474
475 // department has been removed (not reported by scope); make sure it's only treated as such when
476 // we're examining children of *current* department, othwerwise it would break on partial trees when visiting a leaf.
477 if (firstMismatchingChild == nullptr && scopeNode->subdepartments().size() < cachedChildrenIds.size() &&
478 m_currentNavigationId.toStdString() == scopeNode->id()) {
479 return scopeNode;
480 }
481
474 return firstMismatchingChild; // will be nullptr if everything matches482 return firstMismatchingChild; // will be nullptr if everything matches
475}483}
476484
477485
=== modified file 'src/Unity/scope.h'
--- src/Unity/scope.h 2014-09-15 12:03:13 +0000
+++ src/Unity/scope.h 2014-09-30 10:00:42 +0000
@@ -203,7 +203,7 @@
203 void processResultSet(QList<std::shared_ptr<unity::scopes::CategorisedResult>>& result_set);203 void processResultSet(QList<std::shared_ptr<unity::scopes::CategorisedResult>>& result_set);
204204
205 static unity::scopes::Department::SCPtr findDepartmentById(unity::scopes::Department::SCPtr const& root, std::string const& id);205 static unity::scopes::Department::SCPtr findDepartmentById(unity::scopes::Department::SCPtr const& root, std::string const& id);
206 static unity::scopes::Department::SCPtr findUpdateNode(DepartmentNode* node, unity::scopes::Department::SCPtr const& scopeNode);206 unity::scopes::Department::SCPtr findUpdateNode(DepartmentNode* node, unity::scopes::Department::SCPtr const& scopeNode);
207207
208 QUuid m_session_id;208 QUuid m_session_id;
209 int m_query_id;209 int m_query_id;
210210
=== modified file 'tests/data/CMakeLists.txt'
--- tests/data/CMakeLists.txt 2014-08-14 10:14:39 +0000
+++ tests/data/CMakeLists.txt 2014-09-30 10:00:42 +0000
@@ -1,5 +1,6 @@
1add_subdirectory(mock-scope)1add_subdirectory(mock-scope)
2add_subdirectory(mock-scope-departments)2add_subdirectory(mock-scope-departments)
3add_subdirectory(mock-scope-departments-flipflop)
3add_subdirectory(mock-scope-double-nav)4add_subdirectory(mock-scope-double-nav)
4add_subdirectory(mock-scope-info)5add_subdirectory(mock-scope-info)
5add_subdirectory(mock-scope-ttl)6add_subdirectory(mock-scope-ttl)
67
=== added directory 'tests/data/mock-scope-departments-flipflop'
=== added file 'tests/data/mock-scope-departments-flipflop/CMakeLists.txt'
--- tests/data/mock-scope-departments-flipflop/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/data/mock-scope-departments-flipflop/CMakeLists.txt 2014-09-30 10:00:42 +0000
@@ -0,0 +1,16 @@
1include(FindPkgConfig)
2pkg_check_modules(SCOPESLIB REQUIRED libunity-scopes>=0.6.0)
3
4set(SCOPES_BIN_DIR ${SCOPESLIB_LIBDIR})
5
6include_directories(${SCOPESLIB_INCLUDE_DIRS})
7include_directories(${CMAKE_CURRENT_BINARY_DIR})
8
9set(SCOPE_SOURCES
10 mock-scope-departments-flipflop.cpp
11 )
12
13add_library(mock-scope-departments-flipflop MODULE ${SCOPE_SOURCES})
14target_link_libraries(mock-scope-departments-flipflop ${SCOPESLIB_LDFLAGS})
15
16configure_file(mock-scope-departments-flipflop.ini.in mock-scope-departments-flipflop.ini)
017
=== added file 'tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.cpp'
--- tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.cpp 1970-01-01 00:00:00 +0000
+++ tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.cpp 2014-09-30 10:00:42 +0000
@@ -0,0 +1,144 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Pete Woods <pete.woods@canonical.com>
17 */
18
19#include <unity/scopes/CategorisedResult.h>
20#include <unity/scopes/ScopeBase.h>
21#include <unity/scopes/SearchReply.h>
22
23#include <iostream>
24#include <thread>
25#include <atomic>
26#include <sstream>
27
28#define EXPORT __attribute__ ((visibility ("default")))
29
30using namespace std;
31using namespace unity::scopes;
32
33class MyQuery : public SearchQueryBase
34{
35public:
36 MyQuery(CannedQuery const& query, SearchMetadata const& metadata, bool flipflop) :
37 SearchQueryBase(query, metadata),
38 flipflop_(flipflop)
39 {
40 }
41
42 ~MyQuery()
43 {
44 }
45
46 virtual void cancelled() override
47 {
48 }
49
50 Department::SPtr create_root_dep(CannedQuery const& query)
51 {
52 Department::SPtr child_dep;
53 Department::SPtr root_dep;
54 root_dep = Department::create("", query, "All departments");
55
56 child_dep = Department::create("books", query, "Books");
57 child_dep->set_has_subdepartments();
58 root_dep->add_subdepartment(child_dep);
59
60 child_dep = Department::create("movies", query, "Movies, TV, Music");
61 child_dep->set_has_subdepartments();
62 root_dep->add_subdepartment(child_dep);
63
64 if (flipflop_)
65 {
66 child_dep = Department::create("electronics", query, "Electronics");
67 child_dep->set_has_subdepartments();
68 root_dep->add_subdepartment(child_dep);
69 }
70
71 child_dep = Department::create("home", query, "Home, Garden & DIY");
72 child_dep->set_has_subdepartments();
73 root_dep->add_subdepartment(child_dep);
74
75 child_dep = Department::create("toys", query, "Toys, Children & Baby");
76 child_dep->set_has_subdepartments();
77 root_dep->add_subdepartment(child_dep);
78
79 return root_dep;
80 }
81
82 virtual void run(SearchReplyProxy const& reply) override
83 {
84 Department::SPtr child_dep;
85 Department::SPtr root_dep;
86 Department::SPtr active_dep;
87
88 root_dep = create_root_dep(query());
89
90 reply->register_departments(root_dep);
91
92 auto cat1 = reply->register_category("cat1", "Category 1", "");
93 CategorisedResult res1(cat1);
94 res1.set_uri("test:uri");
95 res1.set_title("result for: \"" + query().query_string() + "\"");
96 reply->push(res1);
97 }
98
99protected:
100 bool flipflop_;
101};
102
103class MyScope : public ScopeBase
104{
105public:
106 MyScope()
107 {
108 flipflop_ = false;
109 }
110
111 virtual SearchQueryBase::UPtr search(CannedQuery const& q, SearchMetadata const& metadata) override
112 {
113 flipflop_ = !flipflop_;
114 return SearchQueryBase::UPtr(new MyQuery(q, metadata, flipflop_));
115 }
116
117 virtual PreviewQueryBase::UPtr preview(Result const&, ActionMetadata const&) override
118 {
119 return nullptr;
120 }
121
122 std::atomic<bool> flipflop_;
123};
124
125extern "C"
126{
127
128 EXPORT
129 unity::scopes::ScopeBase*
130 // cppcheck-suppress unusedFunction
131 UNITY_SCOPE_CREATE_FUNCTION()
132 {
133 return new MyScope;
134 }
135
136 EXPORT
137 void
138 // cppcheck-suppress unusedFunction
139 UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base)
140 {
141 delete scope_base;
142 }
143
144}
0145
=== added file 'tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.ini.in'
--- tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.ini.in 1970-01-01 00:00:00 +0000
+++ tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.ini.in 2014-09-30 10:00:42 +0000
@@ -0,0 +1,8 @@
1[ScopeConfig]
2DisplayName = mock-departments-flipflop.DisplayName
3Description = mock-departments-flipflop.Description
4Art = /mock-departments-flipflop.Art
5Icon = /mock-departments-flipflop.Icon
6SearchHint = mock-departments-flipflop.SearchHint
7HotKey = mock-departments-flipflop.HotKey
8Author = mock-departments-flipflop.Author
09
=== modified file 'tests/departmentstest.cpp'
--- tests/departmentstest.cpp 2014-09-02 09:39:41 +0000
+++ tests/departmentstest.cpp 2014-09-30 10:00:42 +0000
@@ -49,6 +49,7 @@
49 QScopedPointer<Scopes> m_scopes;49 QScopedPointer<Scopes> m_scopes;
50 Scope* m_scope;50 Scope* m_scope;
51 Scope* m_scope_navs;51 Scope* m_scope_navs;
52 Scope* m_scope_flipflop;
52 QScopedPointer<RegistrySpawner> m_registry;53 QScopedPointer<RegistrySpawner> m_registry;
5354
54private Q_SLOTS:55private Q_SLOTS:
@@ -65,7 +66,7 @@
65 void init()66 void init()
66 {67 {
67 QStringList favs;68 QStringList favs;
68 favs << "scope://mock-scope-departments" << "scope://mock-scope-double-nav";69 favs << "scope://mock-scope-departments" << "scope://mock-scope-double-nav" << "scope://mock-scope-departments-flipflop";
69 setFavouriteScopes(favs);70 setFavouriteScopes(favs);
7071
71 m_scopes.reset(new Scopes(nullptr));72 m_scopes.reset(new Scopes(nullptr));
@@ -88,8 +89,13 @@
88 QVERIFY(m_scope_navs != nullptr);89 QVERIFY(m_scope_navs != nullptr);
89 m_scope_navs->setActive(true);90 m_scope_navs->setActive(true);
9091
92 m_scope_flipflop = qobject_cast<scopes_ng::Scope*>(m_scopes->getScope(QString("mock-scope-departments-flipflop")));
93 QVERIFY(m_scope_flipflop != nullptr);
94 m_scope_flipflop->setActive(true);
95
91 QTRY_COMPARE(m_scope->searchInProgress(), false);96 QTRY_COMPARE(m_scope->searchInProgress(), false);
92 QTRY_COMPARE(m_scope_navs->searchInProgress(), false);97 QTRY_COMPARE(m_scope_navs->searchInProgress(), false);
98 QTRY_COMPARE(m_scope_flipflop->searchInProgress(), false);
93 }99 }
94100
95 void cleanup()101 void cleanup()
@@ -304,6 +310,47 @@
304 QCOMPARE(sortOrderModel->data(idx, Department::Roles::RoleNavigationId), QVariant(QString("top")));310 QCOMPARE(sortOrderModel->data(idx, Department::Roles::RoleNavigationId), QVariant(QString("top")));
305 QCOMPARE(sortOrderModel->data(idx, Department::Roles::RoleIsActive), QVariant(true));311 QCOMPARE(sortOrderModel->data(idx, Department::Roles::RoleIsActive), QVariant(true));
306 }312 }
313
314 void testDepartmentDissapear()
315 {
316 QCOMPARE(m_scope_flipflop->hasNavigation(), true);
317 QCOMPARE(m_scope_flipflop->hasAltNavigation(), false);
318 QCOMPARE(m_scope_flipflop->currentNavigationId(), QString(""));
319
320 QScopedPointer<NavigationInterface> departmentModel(m_scope_flipflop->getNavigation(m_scope_flipflop->currentNavigationId()));
321 QVERIFY(departmentModel != nullptr);
322
323 QVERIFY(departmentModel->navigationId().isEmpty());
324 QCOMPARE(departmentModel->label(), QString("All departments"));
325 QCOMPARE(departmentModel->allLabel(), QString(""));
326 QCOMPARE(departmentModel->parentNavigationId(), QString());
327 QCOMPARE(departmentModel->parentLabel(), QString());
328 QCOMPARE(departmentModel->loaded(), true);
329 QCOMPARE(departmentModel->isRoot(), true);
330 QCOMPARE(departmentModel->hidden(), false);
331
332 QCOMPARE(departmentModel->rowCount(), 5);
333
334 refreshSearch(m_scope_flipflop);
335
336 // one department removed
337 QCOMPARE(departmentModel->rowCount(), 4);
338
339 QModelIndex idx;
340
341 idx = departmentModel->index(0);
342 QCOMPARE(departmentModel->data(idx, Department::Roles::RoleNavigationId), QVariant(QString("books")));
343 QCOMPARE(departmentModel->data(idx, Department::Roles::RoleLabel), QVariant(QString("Books")));
344 QCOMPARE(departmentModel->data(idx, Department::Roles::RoleHasChildren), QVariant(true));
345 QCOMPARE(departmentModel->data(idx, Department::Roles::RoleIsActive), QVariant(false));
346
347 idx = departmentModel->index(3);
348 QCOMPARE(departmentModel->data(idx, Department::Roles::RoleNavigationId), QVariant(QString("toys")));
349 QCOMPARE(departmentModel->data(idx, Department::Roles::RoleLabel), QVariant(QString("Toys, Children & Baby")));
350 QCOMPARE(departmentModel->data(idx, Department::Roles::RoleHasChildren), QVariant(true));
351 QCOMPARE(departmentModel->data(idx, Department::Roles::RoleIsActive), QVariant(false));
352 }
353
307};354};
308355
309QTEST_GUILESS_MAIN(DepartmentsTest)356QTEST_GUILESS_MAIN(DepartmentsTest)
310357
=== modified file 'tests/test-utils.cpp'
--- tests/test-utils.cpp 2014-09-15 12:03:13 +0000
+++ tests/test-utils.cpp 2014-09-30 10:00:42 +0000
@@ -61,6 +61,20 @@
61 return success;61 return success;
62}62}
6363
64void scopes_ng::refreshSearch(Scope* scope)
65{
66 QCOMPARE(scope->searchInProgress(), false);
67 QSignalSpy spy(scope, SIGNAL(searchInProgressChanged()));
68 // refresh the search
69 scope->refresh();
70 QVERIFY(scope->searchInProgress() || spy.count() > 1);
71 if (scope->searchInProgress()) {
72 // wait for the search to finish
73 QVERIFY(spy.wait());
74 }
75 QCOMPARE(scope->searchInProgress(), false);
76}
77
64void scopes_ng::performSearch(Scope* scope, QString const& searchString)78void scopes_ng::performSearch(Scope* scope, QString const& searchString)
65{79{
66 QCOMPARE(scope->searchInProgress(), false);80 QCOMPARE(scope->searchInProgress(), false);
6781
=== modified file 'tests/test-utils.h'
--- tests/test-utils.h 2014-09-15 12:03:13 +0000
+++ tests/test-utils.h 2014-09-30 10:00:42 +0000
@@ -37,6 +37,9 @@
37bool getFirstResult(Scope* scope, unity::scopes::Result::SPtr& result);37bool getFirstResult(Scope* scope, unity::scopes::Result::SPtr& result);
3838
39Q_DECL_EXPORT39Q_DECL_EXPORT
40void refreshSearch(scopes_ng::Scope*);
41
42Q_DECL_EXPORT
40void performSearch(Scope* scope, QString const& searchString);43void performSearch(Scope* scope, QString const& searchString);
4144
42Q_DECL_EXPORT45Q_DECL_EXPORT

Subscribers

People subscribed via source and target branches

to all changes: