Merge lp:~stolowski/unity-scope-click/use-local-departments into lp:unity-scope-click/devel

Proposed by Paweł Stołowski
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 324
Merged at revision: 336
Proposed branch: lp:~stolowski/unity-scope-click/use-local-departments
Merge into: lp:unity-scope-click/devel
Prerequisite: lp:~stolowski/unity-scope-click/populate-departments-db
Diff against target: 559 lines (+273/-39)
10 files modified
libclickscope/click/interface.cpp (+19/-2)
libclickscope/click/interface.h (+3/-1)
scope/clickapps/CMakeLists.txt (+2/-1)
scope/clickapps/apps-query.cpp (+89/-14)
scope/clickapps/apps-query.h (+9/-3)
scope/clickapps/apps-scope.cpp (+11/-2)
scope/clickapps/apps-scope.h (+4/-0)
scope/tests/test_apps_query.cpp (+118/-2)
scope/tests/test_helpers.h (+17/-0)
scope/tests/test_query.cpp (+1/-14)
To merge this branch: bzr merge lp:~stolowski/unity-scope-click/use-local-departments
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+225435@code.launchpad.net

Commit message

Make use of departments db if available to provide departments for installed apps.

Description of the change

Make use of departments db if available to provide departments for installed apps.

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

Merged partent branch.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

On a first look, this branch seems to be lacking a bit more tests.
I'll take a better look tomorrow, to see if I'm missing something.

review: Abstain
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Ok, I'm adding a test; this requires some extra work as it's touching stuff we haven't mocked before, but I should have something soon.

323. By Paweł Stołowski

Added test for departments.

324. By Paweł Stołowski

Added one more test case.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Branch looks mostly fine. One small comment, that we can fix in a following branch:

The big test function in:
TEST(Query, Departments)

Does not follow the naming convention for tests, and should perhaps be split into two test functions sharing a common class, like:

TEST_F(DepartmentsTest, testRootDepartment)
TEST_F(DepartmentsTest, testLeafDepartment)

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libclickscope/click/interface.cpp'
--- libclickscope/click/interface.cpp 2014-06-16 15:38:49 +0000
+++ libclickscope/click/interface.cpp 2014-07-16 13:16:39 +0000
@@ -228,13 +228,15 @@
228 *228 *
229 * Find all of the installed apps matching @search_query in a timeout.229 * Find all of the installed apps matching @search_query in a timeout.
230 */230 */
231std::vector<click::Application> Interface::find_installed_apps(const std::string& search_query)231std::vector<click::Application> Interface::find_installed_apps(const std::string& search_query,
232 const std::unordered_set<std::string>& packages_in_department,
233 bool department_filter)
232{234{
233 std::vector<Application> result;235 std::vector<Application> result;
234236
235 bool include_desktop_results = show_desktop_apps();237 bool include_desktop_results = show_desktop_apps();
236238
237 auto enumerator = [&result, this, search_query, include_desktop_results]239 auto enumerator = [&result, this, search_query, packages_in_department, department_filter, include_desktop_results]
238 (const unity::util::IniParser& keyFile, const std::string& filename)240 (const unity::util::IniParser& keyFile, const std::string& filename)
239 {241 {
240 if (keyFile.has_group(DESKTOP_FILE_GROUP) == false) {242 if (keyFile.has_group(DESKTOP_FILE_GROUP) == false) {
@@ -250,6 +252,21 @@
250 || Interface::is_non_click_app(QString::fromStdString(filename))) {252 || Interface::is_non_click_app(QString::fromStdString(filename))) {
251 auto app = load_app_from_desktop(keyFile, filename);253 auto app = load_app_from_desktop(keyFile, filename);
252254
255 // check if apps is present in current department
256 if (department_filter)
257 {
258 if (!app.name.empty()) // app from click package
259 {
260 if (packages_in_department.find(app.name) == packages_in_department.end())
261 return;
262 }
263 else // non-click app, match on desktop file name
264 {
265 if (packages_in_department.find(filename) == packages_in_department.end())
266 return;
267 }
268 }
269
253 if (search_query.empty()) {270 if (search_query.empty()) {
254 result.push_back(app);271 result.push_back(app);
255 } else {272 } else {
256273
=== modified file 'libclickscope/click/interface.h'
--- libclickscope/click/interface.h 2014-07-16 13:16:39 +0000
+++ libclickscope/click/interface.h 2014-07-16 13:16:39 +0000
@@ -91,7 +91,9 @@
91 virtual Application load_app_from_desktop(const unity::util::IniParser& keyFile,91 virtual Application load_app_from_desktop(const unity::util::IniParser& keyFile,
92 const std::string& filename);92 const std::string& filename);
93 static std::vector<Application> sort_apps(const std::vector<Application>& apps);93 static std::vector<Application> sort_apps(const std::vector<Application>& apps);
94 virtual std::vector<Application> find_installed_apps(const std::string& search_query);94 virtual std::vector<Application> find_installed_apps(const std::string& search_query,
95 const std::unordered_set<std::string>& packages_in_department = std::unordered_set<std::string>(),
96 bool department_filter = false);
9597
96 static bool is_non_click_app(const QString& filename);98 static bool is_non_click_app(const QString& filename);
9799
98100
=== modified file 'scope/clickapps/CMakeLists.txt'
--- scope/clickapps/CMakeLists.txt 2014-06-04 14:45:48 +0000
+++ scope/clickapps/CMakeLists.txt 2014-07-16 13:16:39 +0000
@@ -1,6 +1,7 @@
1SET (CMAKE_INCLUDE_CURRENT_DIR ON)1SET (CMAKE_INCLUDE_CURRENT_DIR ON)
2SET (CMAKE_AUTOMOC ON)2SET (CMAKE_AUTOMOC ON)
3find_package (Qt5Core REQUIRED)3find_package (Qt5Core REQUIRED)
4find_package (Qt5Sql REQUIRED)
4pkg_check_modules(JSON_CPP REQUIRED jsoncpp)5pkg_check_modules(JSON_CPP REQUIRED jsoncpp)
56
6add_definitions(7add_definitions(
@@ -20,7 +21,7 @@
20 ${JSON_CPP_INCLUDE_DIRS}21 ${JSON_CPP_INCLUDE_DIRS}
21)22)
2223
23qt5_use_modules (${APPS_LIB_UNVERSIONED} Network)24qt5_use_modules (${APPS_LIB_UNVERSIONED} Network Sql)
2425
25target_link_libraries (${APPS_LIB_UNVERSIONED}26target_link_libraries (${APPS_LIB_UNVERSIONED}
26 ${SCOPE_LIB_NAME}27 ${SCOPE_LIB_NAME}
2728
=== modified file 'scope/clickapps/apps-query.cpp'
--- scope/clickapps/apps-query.cpp 2014-07-14 12:44:48 +0000
+++ scope/clickapps/apps-query.cpp 2014-07-16 13:16:39 +0000
@@ -28,7 +28,7 @@
28 */28 */
2929
30#include <click/application.h>30#include <click/application.h>
31#include <click/interface.h>31#include <click/departments-db.h>
3232
33#include <click/key_file_locator.h>33#include <click/key_file_locator.h>
3434
@@ -37,6 +37,7 @@
37#include <unity/scopes/CannedQuery.h>37#include <unity/scopes/CannedQuery.h>
38#include <unity/scopes/SearchReply.h>38#include <unity/scopes/SearchReply.h>
39#include <unity/scopes/SearchMetadata.h>39#include <unity/scopes/SearchMetadata.h>
40#include <unity/scopes/Department.h>
4041
41#include <vector>42#include <vector>
4243
@@ -199,17 +200,21 @@
199200
200struct click::apps::Query::Private201struct click::apps::Query::Private
201{202{
202 Private(const scopes::SearchMetadata& metadata)203 Private(std::shared_ptr<click::DepartmentsDb> depts_db, const scopes::SearchMetadata& metadata)
203 : meta(metadata)204 : depts_db(depts_db),
205 meta(metadata)
204 {206 {
205 }207 }
208
209 std::shared_ptr<click::DepartmentsDb> depts_db;
206 scopes::SearchMetadata meta;210 scopes::SearchMetadata meta;
207 click::Configuration configuration;211 click::Configuration configuration;
208};212};
209213
210click::apps::Query::Query(unity::scopes::CannedQuery const& query, scopes::SearchMetadata const& metadata)214click::apps::Query::Query(unity::scopes::CannedQuery const& query, std::shared_ptr<DepartmentsDb> depts_db,
215 scopes::SearchMetadata const& metadata)
211 : unity::scopes::SearchQueryBase(query, metadata),216 : unity::scopes::SearchQueryBase(query, metadata),
212 impl(new Private(metadata))217 impl(new Private(depts_db, metadata))
213{218{
214}219}
215220
@@ -223,9 +228,7 @@
223 qDebug() << "destroying search";228 qDebug() << "destroying search";
224}229}
225230
226namespace231click::Interface& click::apps::Query::clickInterfaceInstance()
227{
228click::Interface& clickInterfaceInstance()
229{232{
230 static QSharedPointer<click::KeyFileLocator> keyFileLocator(new click::KeyFileLocator());233 static QSharedPointer<click::KeyFileLocator> keyFileLocator(new click::KeyFileLocator());
231 static click::Interface iface(keyFileLocator);234 static click::Interface iface(keyFileLocator);
@@ -233,8 +236,6 @@
233 return iface;236 return iface;
234}237}
235238
236}
237
238void click::apps::Query::add_fake_store_app(scopes::SearchReplyProxy const& searchReply)239void click::apps::Query::add_fake_store_app(scopes::SearchReplyProxy const& searchReply)
239{240{
240 static const std::string title = _("Ubuntu Store");241 static const std::string title = _("Ubuntu Store");
@@ -267,15 +268,89 @@
267 searchReply->push(res);268 searchReply->push(res);
268}269}
269270
271void click::apps::Query::push_local_departments(scopes::SearchReplyProxy const& replyProxy)
272{
273 auto const current_dep_id = query().department_id();
274 const std::list<std::string> locales = { search_metadata().locale(), "en_US", "" };
275
276 unity::scopes::Department::SPtr root;
277
278 try
279 {
280 static const std::string all_dept_name = _("All departments");
281
282 // create node for current department
283 auto name = current_dep_id == "" ? all_dept_name : impl->depts_db->get_department_name(current_dep_id, locales);
284 unity::scopes::Department::SPtr current = unity::scopes::Department::create(current_dep_id, query(), name);
285
286 // attach subdepartments to it
287 for (auto const& subdep: impl->depts_db->get_children_departments(current_dep_id))
288 {
289 name = impl->depts_db->get_department_name(subdep.id, locales);
290 unity::scopes::Department::SPtr dep = unity::scopes::Department::create(subdep.id, query(), name);
291 dep->set_has_subdepartments(subdep.has_children);
292 current->add_subdepartment(dep);
293 }
294
295 // if current is not the top, then gets its parent
296 if (current_dep_id != "")
297 {
298 auto const parent_dep_id = impl->depts_db->get_parent_department_id(current_dep_id);
299 root = unity::scopes::Department::create(parent_dep_id, query(), parent_dep_id == "" ? all_dept_name :
300 impl->depts_db->get_department_name(parent_dep_id, locales));
301 root->add_subdepartment(current);
302 }
303 else
304 {
305 root = current;
306 }
307
308 replyProxy->register_departments(root);
309 }
310 catch (const std::exception& e)
311 {
312 qWarning() << "Failed to push departments: " << QString::fromStdString(e.what());
313 }
314}
315
270void click::apps::Query::run(scopes::SearchReplyProxy const& searchReply)316void click::apps::Query::run(scopes::SearchReplyProxy const& searchReply)
271{317{
272 const std::string categoryTemplate = CATEGORY_APPS_DISPLAY;318 const std::string categoryTemplate = CATEGORY_APPS_DISPLAY;
273 auto querystr = query().query_string();319 auto const current_dept = query().department_id();
274320 auto const querystr = query().query_string();
275 ResultPusher pusher(searchReply, querystr.empty() ? impl->configuration.get_core_apps() : std::vector<std::string>());321
276 auto localResults = clickInterfaceInstance().find_installed_apps(querystr);322 //
323 // get the set of packages that belong to current deparment;
324 // only apply department filtering if not in root of all departments.
325 bool apply_department_filter = (querystr.empty() && !current_dept.empty());
326 std::unordered_set<std::string> pkgs_in_department;
327 if (impl->depts_db && apply_department_filter)
328 {
329 try
330 {
331 pkgs_in_department = impl->depts_db->get_packages_for_department(current_dept);
332 }
333 catch (const std::exception& e)
334 {
335 qWarning() << "Failed to get packages of department" << QString::fromStdString(current_dept);
336 apply_department_filter = false; // disable so that we are not loosing any apps if something goes wrong
337 }
338 }
339
340 const bool show_top_apps = querystr.empty() && current_dept.empty();
341 ResultPusher pusher(searchReply, show_top_apps ? impl->configuration.get_core_apps() : std::vector<std::string>());
342 auto const localResults = clickInterfaceInstance().find_installed_apps(
343 querystr, pkgs_in_department, apply_department_filter);
277344
278 if (querystr.empty()) {345 if (querystr.empty()) {
346 if (impl->depts_db)
347 {
348 push_local_departments(searchReply);
349 }
350 }
351
352 if (show_top_apps)
353 {
279 pusher.push_top_results(localResults, categoryTemplate);354 pusher.push_top_results(localResults, categoryTemplate);
280 }355 }
281356
282357
=== modified file 'scope/clickapps/apps-query.h'
--- scope/clickapps/apps-query.h 2014-07-11 16:49:05 +0000
+++ scope/clickapps/apps-query.h 2014-07-16 13:16:39 +0000
@@ -38,14 +38,14 @@
38#include <QSharedPointer>38#include <QSharedPointer>
39#include <set>39#include <set>
40#include <unordered_set>40#include <unordered_set>
4141#include <click/interface.h>
4242
43namespace click43namespace click
44{44{
4545
46class Application;46class Application;
47class Configuration;47class Configuration;
48class Index;48class DepartmentsDb;
4949
50namespace apps50namespace apps
51{51{
@@ -65,7 +65,7 @@
65 constexpr static const char* VERSION{"version"};65 constexpr static const char* VERSION{"version"};
66 };66 };
6767
68 Query(unity::scopes::CannedQuery const& query, scopes::SearchMetadata const& metadata);68 Query(unity::scopes::CannedQuery const& query, std::shared_ptr<DepartmentsDb> depts_db, scopes::SearchMetadata const& metadata);
69 virtual ~Query();69 virtual ~Query();
7070
71 virtual void cancelled() override;71 virtual void cancelled() override;
@@ -73,6 +73,12 @@
73 virtual void run(scopes::SearchReplyProxy const& reply) override;73 virtual void run(scopes::SearchReplyProxy const& reply) override;
7474
75 virtual void add_fake_store_app(scopes::SearchReplyProxy const &replyProxy);75 virtual void add_fake_store_app(scopes::SearchReplyProxy const &replyProxy);
76
77 virtual void push_local_departments(scopes::SearchReplyProxy const& replyProxy);
78
79protected:
80 virtual click::Interface& clickInterfaceInstance();
81
76private:82private:
77 struct Private;83 struct Private;
78 QSharedPointer<Private> impl;84 QSharedPointer<Private> impl;
7985
=== modified file 'scope/clickapps/apps-scope.cpp'
--- scope/clickapps/apps-scope.cpp 2014-07-16 13:16:39 +0000
+++ scope/clickapps/apps-scope.cpp 2014-07-16 13:16:39 +0000
@@ -31,6 +31,7 @@
31#include <click/preview.h>31#include <click/preview.h>
32#include <click/interface.h>32#include <click/interface.h>
33#include <click/scope_activation.h>33#include <click/scope_activation.h>
34#include <click/departments-db.h>
3435
35#include <QSharedPointer>36#include <QSharedPointer>
3637
@@ -49,6 +50,14 @@
49 nam.reset(new click::network::AccessManager());50 nam.reset(new click::network::AccessManager());
50 client.reset(new click::web::Client(nam));51 client.reset(new click::web::Client(nam));
51 index.reset(new click::Index(client));52 index.reset(new click::Index(client));
53 try
54 {
55 depts_db = click::DepartmentsDb::create_db();
56 }
57 catch (const std::runtime_error& e)
58 {
59 std::cerr << "Failed to get cache directory" << std::endl;
60 }
52}61}
5362
54click::Scope::~Scope()63click::Scope::~Scope()
@@ -79,14 +88,14 @@
7988
80scopes::SearchQueryBase::UPtr click::Scope::search(unity::scopes::CannedQuery const& q, scopes::SearchMetadata const& metadata)89scopes::SearchQueryBase::UPtr click::Scope::search(unity::scopes::CannedQuery const& q, scopes::SearchMetadata const& metadata)
81{90{
82 return scopes::SearchQueryBase::UPtr(new click::apps::Query(q, metadata));91 return scopes::SearchQueryBase::UPtr(new click::apps::Query(q, depts_db, metadata));
83}92}
8493
8594
86unity::scopes::PreviewQueryBase::UPtr click::Scope::preview(const unity::scopes::Result& result,95unity::scopes::PreviewQueryBase::UPtr click::Scope::preview(const unity::scopes::Result& result,
87 const unity::scopes::ActionMetadata& metadata) {96 const unity::scopes::ActionMetadata& metadata) {
88 qDebug() << "Scope::preview() called.";97 qDebug() << "Scope::preview() called.";
89 return scopes::PreviewQueryBase::UPtr{new click::Preview(result, metadata, client, nam, nullptr)};98 return scopes::PreviewQueryBase::UPtr{new click::Preview(result, metadata, client, nam, depts_db)};
90}99}
91100
92101
93102
=== modified file 'scope/clickapps/apps-scope.h'
--- scope/clickapps/apps-scope.h 2014-06-18 14:42:47 +0000
+++ scope/clickapps/apps-scope.h 2014-07-16 13:16:39 +0000
@@ -43,6 +43,9 @@
4343
44namespace click44namespace click
45{45{
46
47class DepartmentsDb;
48
46class Scope : public scopes::ScopeBase49class Scope : public scopes::ScopeBase
47{50{
48public:51public:
@@ -64,6 +67,7 @@
64 QSharedPointer<click::network::AccessManager> nam;67 QSharedPointer<click::network::AccessManager> nam;
65 QSharedPointer<click::web::Client> client;68 QSharedPointer<click::web::Client> client;
66 QSharedPointer<click::Index> index;69 QSharedPointer<click::Index> index;
70 std::shared_ptr<click::DepartmentsDb> depts_db;
6771
68 std::string installApplication(unity::scopes::Result const& result);72 std::string installApplication(unity::scopes::Result const& result);
69};73};
7074
=== modified file 'scope/tests/test_apps_query.cpp'
--- scope/tests/test_apps_query.cpp 2014-07-14 12:44:48 +0000
+++ scope/tests/test_apps_query.cpp 2014-07-16 13:16:39 +0000
@@ -34,6 +34,7 @@
34#include <gmock/gmock.h>34#include <gmock/gmock.h>
3535
36#include <clickapps/apps-query.h>36#include <clickapps/apps-query.h>
37#include <click/departments-db.h>
3738
38#include <unity/scopes/SearchReply.h>39#include <unity/scopes/SearchReply.h>
39#include <unity/scopes/SearchMetadata.h>40#include <unity/scopes/SearchMetadata.h>
@@ -56,6 +57,32 @@
56 }57 }
57};58};
5859
60class MockClickInterface : public click::Interface
61{
62public:
63 MockClickInterface() = default;
64 MOCK_METHOD3(find_installed_apps, std::vector<click::Application>(const std::string&, const std::unordered_set<std::string>&, bool));
65};
66
67class MockAppsQuery : public click::apps::Query
68{
69private:
70 std::shared_ptr<MockClickInterface> click_iface;
71
72public:
73 MockAppsQuery(unity::scopes::CannedQuery const& query, std::shared_ptr<click::DepartmentsDb> depts_db, scopes::SearchMetadata const& metadata,
74 const std::shared_ptr<MockClickInterface>& click_iface)
75 : click::apps::Query(query, depts_db, metadata),
76 click_iface(click_iface)
77 {
78 }
79
80 click::Interface& clickInterfaceInstance() override
81 {
82 return *click_iface;
83 }
84};
85
59MATCHER_P(HasApplicationTitle, n, "") { return arg["title"].get_string() == n; }86MATCHER_P(HasApplicationTitle, n, "") { return arg["title"].get_string() == n; }
6087
61TEST_F(ResultPusherTest, testPushTopAndLocalResults)88TEST_F(ResultPusherTest, testPushTopAndLocalResults)
@@ -99,8 +126,8 @@
99 const unity::scopes::CannedQuery query("foo.scope", "FooBar", "");126 const unity::scopes::CannedQuery query("foo.scope", "FooBar", "");
100 const unity::scopes::CannedQuery query2("foo.scope", "Metallica", "");127 const unity::scopes::CannedQuery query2("foo.scope", "Metallica", "");
101128
102 click::apps::Query q(query, metadata);129 click::apps::Query q(query, nullptr, metadata);
103 click::apps::Query q2(query2, metadata);130 click::apps::Query q2(query2, nullptr, metadata);
104131
105 scopes::testing::MockSearchReply mock_reply;132 scopes::testing::MockSearchReply mock_reply;
106 scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});133 scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
@@ -124,3 +151,92 @@
124 q2.add_fake_store_app(reply2);151 q2.add_fake_store_app(reply2);
125}152}
126153
154// this matcher expects a list of department ids in depts:
155// first on the list is the root, followed by children ids.
156// the arg of the matcher is unity::scopes::Department ptr.
157MATCHER_P(MatchesDepartments, depts, "") {
158 auto it = depts.begin();
159 if (arg->id() != *it)
160 return false;
161 auto const subdeps = arg->subdepartments();
162 if (subdeps.size() != depts.size() - 1)
163 return false;
164 for (auto const& sub: subdeps)
165 {
166 if (sub->id() != *(++it))
167 return false;
168 }
169 return true;
170}
171
172TEST(Query, Departments)
173{
174 const std::vector<click::Application> installed_apps = {{"app1", "App1", 0.0f, "icon", "url", "descr", "scrshot"}};
175 const scopes::SearchMetadata metadata("en_EN", "phone");
176 auto clickif = std::make_shared<MockClickInterface>();
177
178 const scopes::CategoryRenderer renderer("{}");
179 auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer);
180 auto depts_db = std::make_shared<MockDepartmentsDb>(":memory:");
181
182 const std::list<std::string> expected_locales {"en_EN", "en_US", ""};
183
184 // query for root of the departments tree
185 {
186 const unity::scopes::CannedQuery query("foo.scope", "", "");
187
188 MockAppsQuery q(query, depts_db, metadata, clickif);
189
190 scopes::testing::MockSearchReply mock_reply;
191 scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
192
193 std::list<std::string> expected_departments({{"", "games", "video"}});
194
195 EXPECT_CALL(*clickif, find_installed_apps(_, _, _)).WillOnce(Return(installed_apps));
196 EXPECT_CALL(mock_reply, register_category("predefined", _, _, _)).WillOnce(Return(ptrCat));
197 EXPECT_CALL(mock_reply, register_category("local", _, _, _)).WillOnce(Return(ptrCat));
198 EXPECT_CALL(mock_reply, register_category("store", _, _, _)).WillOnce(Return(ptrCat));
199 EXPECT_CALL(mock_reply, register_departments(MatchesDepartments(expected_departments)));
200
201 EXPECT_CALL(mock_reply, push(Matcher<unity::scopes::CategorisedResult const&>(_))).Times(2).WillRepeatedly(Return(true));
202
203 EXPECT_CALL(*depts_db, get_department_name("games", expected_locales)).WillOnce(Return("Games"));
204 EXPECT_CALL(*depts_db, get_department_name("video", expected_locales)).WillOnce(Return("Video"));
205 EXPECT_CALL(*depts_db, get_children_departments("")).WillOnce(Return(
206 std::list<click::DepartmentsDb::DepartmentInfo>({
207 {"games", false},
208 {"video", true}
209 }))
210 );
211
212 q.run(reply);
213 }
214
215 // query for a leaf department
216 {
217 const unity::scopes::CannedQuery query("foo.scope", "", "games");
218
219 MockAppsQuery q(query, depts_db, metadata, clickif);
220
221 scopes::testing::MockSearchReply mock_reply;
222 scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
223
224 std::list<std::string> expected_departments({"", "games"});
225
226 EXPECT_CALL(*clickif, find_installed_apps(_, _, _)).WillOnce(Return(installed_apps));
227 EXPECT_CALL(mock_reply, register_category("local", _, _, _)).WillOnce(Return(ptrCat));
228 EXPECT_CALL(mock_reply, register_category("store", _, _, _)).WillOnce(Return(ptrCat));
229 EXPECT_CALL(mock_reply, register_departments(MatchesDepartments(expected_departments)));
230
231 EXPECT_CALL(mock_reply, push(Matcher<unity::scopes::CategorisedResult const&>(_))).Times(2).WillRepeatedly(Return(true));
232
233 EXPECT_CALL(*depts_db, get_parent_department_id("games")).WillOnce(Return(""));
234 EXPECT_CALL(*depts_db, get_department_name("games", expected_locales)).WillOnce(Return("Games"));
235 EXPECT_CALL(*depts_db, get_children_departments("games")).WillOnce(Return(
236 std::list<click::DepartmentsDb::DepartmentInfo>({})
237 ));
238
239 q.run(reply);
240 }
241}
242
127243
=== modified file 'scope/tests/test_helpers.h'
--- scope/tests/test_helpers.h 2014-07-03 14:58:53 +0000
+++ scope/tests/test_helpers.h 2014-07-16 13:16:39 +0000
@@ -53,6 +53,23 @@
53 std::function<void(click::Packages, click::Packages)>));53 std::function<void(click::Packages, click::Packages)>));
54};54};
5555
56class MockDepartmentsDb : public click::DepartmentsDb
57{
58public:
59 MockDepartmentsDb(const std::string& name)
60 : click::DepartmentsDb(name)
61 {
62 }
63
64 MOCK_METHOD2(get_department_name, std::string(const std::string&, const std::list<std::string>&));
65 MOCK_METHOD2(get_packages_for_department, std::unordered_set<std::string>(const std::string&, bool));
66 MOCK_METHOD1(get_parent_department_id, std::string(const std::string&));
67 MOCK_METHOD1(get_children_departments, std::list<click::DepartmentsDb::DepartmentInfo>(const std::string&));
68
69 MOCK_METHOD2(store_package_mapping, void(const std::string&, const std::string&));
70 MOCK_METHOD2(store_department_mapping, void(const std::string&, const std::string&));
71 MOCK_METHOD3(store_department_name, void(const std::string&, const std::string&, const std::string&));
72};
5673
57class FakeCategory : public scopes::Category74class FakeCategory : public scopes::Category
58{75{
5976
=== modified file 'scope/tests/test_query.cpp'
--- scope/tests/test_query.cpp 2014-07-16 13:16:39 +0000
+++ scope/tests/test_query.cpp 2014-07-16 13:16:39 +0000
@@ -55,19 +55,6 @@
55namespace55namespace
56{56{
5757
58class MockDepartmentsDb : public click::DepartmentsDb
59{
60public:
61 MockDepartmentsDb(const std::string& name)
62 : click::DepartmentsDb(name)
63 {
64 }
65
66 MOCK_METHOD2(store_package_mapping, void(const std::string&, const std::string&));
67 MOCK_METHOD2(store_department_mapping, void(const std::string&, const std::string&));
68 MOCK_METHOD3(store_department_name, void(const std::string&, const std::string&, const std::string&));
69};
70
71class MockQueryBase : public click::Query {58class MockQueryBase : public click::Query {
72public:59public:
73 MockQueryBase(const unity::scopes::CannedQuery& query, click::Index& index,60 MockQueryBase(const unity::scopes::CannedQuery& query, click::Index& index,
@@ -296,7 +283,7 @@
296 std::make_shared<click::Department>("1-2", "Department three", "http://three.com", false)283 std::make_shared<click::Department>("1-2", "Department three", "http://three.com", false)
297 });284 });
298 DepartmentList init_departments({dept1});285 DepartmentList init_departments({dept1});
299 auto depts_db = std::make_shared<MockDepartmentsDb>("query-tests.db");286 auto depts_db = std::make_shared<MockDepartmentsDb>(":memory:");
300287
301 EXPECT_CALL(*depts_db, store_department_name(_, _, _)).Times(3);288 EXPECT_CALL(*depts_db, store_department_name(_, _, _)).Times(3);
302 EXPECT_CALL(*depts_db, store_department_mapping(_, _)).Times(2);289 EXPECT_CALL(*depts_db, store_department_mapping(_, _)).Times(2);

Subscribers

People subscribed via source and target branches

to all changes: