Merge lp:~stolowski/unity-scope-click/use-local-departments into lp:unity-scope-click/devel
- use-local-departments
- Merge into devel
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 |
Related bugs: |
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.
- 322. By Paweł Stołowski
-
Merged partent branch.
PS Jenkins bot (ps-jenkins) wrote : | # |
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.
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.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:324
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
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(
TEST_F(
Alejandro J. Cura (alecu) wrote : | # |
Here's a branch to split the test as suggested above: https:/
Preview Diff
1 | === modified file 'libclickscope/click/interface.cpp' |
2 | --- libclickscope/click/interface.cpp 2014-06-16 15:38:49 +0000 |
3 | +++ libclickscope/click/interface.cpp 2014-07-16 13:16:39 +0000 |
4 | @@ -228,13 +228,15 @@ |
5 | * |
6 | * Find all of the installed apps matching @search_query in a timeout. |
7 | */ |
8 | -std::vector<click::Application> Interface::find_installed_apps(const std::string& search_query) |
9 | +std::vector<click::Application> Interface::find_installed_apps(const std::string& search_query, |
10 | + const std::unordered_set<std::string>& packages_in_department, |
11 | + bool department_filter) |
12 | { |
13 | std::vector<Application> result; |
14 | |
15 | bool include_desktop_results = show_desktop_apps(); |
16 | |
17 | - auto enumerator = [&result, this, search_query, include_desktop_results] |
18 | + auto enumerator = [&result, this, search_query, packages_in_department, department_filter, include_desktop_results] |
19 | (const unity::util::IniParser& keyFile, const std::string& filename) |
20 | { |
21 | if (keyFile.has_group(DESKTOP_FILE_GROUP) == false) { |
22 | @@ -250,6 +252,21 @@ |
23 | || Interface::is_non_click_app(QString::fromStdString(filename))) { |
24 | auto app = load_app_from_desktop(keyFile, filename); |
25 | |
26 | + // check if apps is present in current department |
27 | + if (department_filter) |
28 | + { |
29 | + if (!app.name.empty()) // app from click package |
30 | + { |
31 | + if (packages_in_department.find(app.name) == packages_in_department.end()) |
32 | + return; |
33 | + } |
34 | + else // non-click app, match on desktop file name |
35 | + { |
36 | + if (packages_in_department.find(filename) == packages_in_department.end()) |
37 | + return; |
38 | + } |
39 | + } |
40 | + |
41 | if (search_query.empty()) { |
42 | result.push_back(app); |
43 | } else { |
44 | |
45 | === modified file 'libclickscope/click/interface.h' |
46 | --- libclickscope/click/interface.h 2014-07-16 13:16:39 +0000 |
47 | +++ libclickscope/click/interface.h 2014-07-16 13:16:39 +0000 |
48 | @@ -91,7 +91,9 @@ |
49 | virtual Application load_app_from_desktop(const unity::util::IniParser& keyFile, |
50 | const std::string& filename); |
51 | static std::vector<Application> sort_apps(const std::vector<Application>& apps); |
52 | - virtual std::vector<Application> find_installed_apps(const std::string& search_query); |
53 | + virtual std::vector<Application> find_installed_apps(const std::string& search_query, |
54 | + const std::unordered_set<std::string>& packages_in_department = std::unordered_set<std::string>(), |
55 | + bool department_filter = false); |
56 | |
57 | static bool is_non_click_app(const QString& filename); |
58 | |
59 | |
60 | === modified file 'scope/clickapps/CMakeLists.txt' |
61 | --- scope/clickapps/CMakeLists.txt 2014-06-04 14:45:48 +0000 |
62 | +++ scope/clickapps/CMakeLists.txt 2014-07-16 13:16:39 +0000 |
63 | @@ -1,6 +1,7 @@ |
64 | SET (CMAKE_INCLUDE_CURRENT_DIR ON) |
65 | SET (CMAKE_AUTOMOC ON) |
66 | find_package (Qt5Core REQUIRED) |
67 | +find_package (Qt5Sql REQUIRED) |
68 | pkg_check_modules(JSON_CPP REQUIRED jsoncpp) |
69 | |
70 | add_definitions( |
71 | @@ -20,7 +21,7 @@ |
72 | ${JSON_CPP_INCLUDE_DIRS} |
73 | ) |
74 | |
75 | -qt5_use_modules (${APPS_LIB_UNVERSIONED} Network) |
76 | +qt5_use_modules (${APPS_LIB_UNVERSIONED} Network Sql) |
77 | |
78 | target_link_libraries (${APPS_LIB_UNVERSIONED} |
79 | ${SCOPE_LIB_NAME} |
80 | |
81 | === modified file 'scope/clickapps/apps-query.cpp' |
82 | --- scope/clickapps/apps-query.cpp 2014-07-14 12:44:48 +0000 |
83 | +++ scope/clickapps/apps-query.cpp 2014-07-16 13:16:39 +0000 |
84 | @@ -28,7 +28,7 @@ |
85 | */ |
86 | |
87 | #include <click/application.h> |
88 | -#include <click/interface.h> |
89 | +#include <click/departments-db.h> |
90 | |
91 | #include <click/key_file_locator.h> |
92 | |
93 | @@ -37,6 +37,7 @@ |
94 | #include <unity/scopes/CannedQuery.h> |
95 | #include <unity/scopes/SearchReply.h> |
96 | #include <unity/scopes/SearchMetadata.h> |
97 | +#include <unity/scopes/Department.h> |
98 | |
99 | #include <vector> |
100 | |
101 | @@ -199,17 +200,21 @@ |
102 | |
103 | struct click::apps::Query::Private |
104 | { |
105 | - Private(const scopes::SearchMetadata& metadata) |
106 | - : meta(metadata) |
107 | + Private(std::shared_ptr<click::DepartmentsDb> depts_db, const scopes::SearchMetadata& metadata) |
108 | + : depts_db(depts_db), |
109 | + meta(metadata) |
110 | { |
111 | } |
112 | + |
113 | + std::shared_ptr<click::DepartmentsDb> depts_db; |
114 | scopes::SearchMetadata meta; |
115 | click::Configuration configuration; |
116 | }; |
117 | |
118 | -click::apps::Query::Query(unity::scopes::CannedQuery const& query, scopes::SearchMetadata const& metadata) |
119 | +click::apps::Query::Query(unity::scopes::CannedQuery const& query, std::shared_ptr<DepartmentsDb> depts_db, |
120 | + scopes::SearchMetadata const& metadata) |
121 | : unity::scopes::SearchQueryBase(query, metadata), |
122 | - impl(new Private(metadata)) |
123 | + impl(new Private(depts_db, metadata)) |
124 | { |
125 | } |
126 | |
127 | @@ -223,9 +228,7 @@ |
128 | qDebug() << "destroying search"; |
129 | } |
130 | |
131 | -namespace |
132 | -{ |
133 | -click::Interface& clickInterfaceInstance() |
134 | +click::Interface& click::apps::Query::clickInterfaceInstance() |
135 | { |
136 | static QSharedPointer<click::KeyFileLocator> keyFileLocator(new click::KeyFileLocator()); |
137 | static click::Interface iface(keyFileLocator); |
138 | @@ -233,8 +236,6 @@ |
139 | return iface; |
140 | } |
141 | |
142 | -} |
143 | - |
144 | void click::apps::Query::add_fake_store_app(scopes::SearchReplyProxy const& searchReply) |
145 | { |
146 | static const std::string title = _("Ubuntu Store"); |
147 | @@ -267,15 +268,89 @@ |
148 | searchReply->push(res); |
149 | } |
150 | |
151 | +void click::apps::Query::push_local_departments(scopes::SearchReplyProxy const& replyProxy) |
152 | +{ |
153 | + auto const current_dep_id = query().department_id(); |
154 | + const std::list<std::string> locales = { search_metadata().locale(), "en_US", "" }; |
155 | + |
156 | + unity::scopes::Department::SPtr root; |
157 | + |
158 | + try |
159 | + { |
160 | + static const std::string all_dept_name = _("All departments"); |
161 | + |
162 | + // create node for current department |
163 | + auto name = current_dep_id == "" ? all_dept_name : impl->depts_db->get_department_name(current_dep_id, locales); |
164 | + unity::scopes::Department::SPtr current = unity::scopes::Department::create(current_dep_id, query(), name); |
165 | + |
166 | + // attach subdepartments to it |
167 | + for (auto const& subdep: impl->depts_db->get_children_departments(current_dep_id)) |
168 | + { |
169 | + name = impl->depts_db->get_department_name(subdep.id, locales); |
170 | + unity::scopes::Department::SPtr dep = unity::scopes::Department::create(subdep.id, query(), name); |
171 | + dep->set_has_subdepartments(subdep.has_children); |
172 | + current->add_subdepartment(dep); |
173 | + } |
174 | + |
175 | + // if current is not the top, then gets its parent |
176 | + if (current_dep_id != "") |
177 | + { |
178 | + auto const parent_dep_id = impl->depts_db->get_parent_department_id(current_dep_id); |
179 | + root = unity::scopes::Department::create(parent_dep_id, query(), parent_dep_id == "" ? all_dept_name : |
180 | + impl->depts_db->get_department_name(parent_dep_id, locales)); |
181 | + root->add_subdepartment(current); |
182 | + } |
183 | + else |
184 | + { |
185 | + root = current; |
186 | + } |
187 | + |
188 | + replyProxy->register_departments(root); |
189 | + } |
190 | + catch (const std::exception& e) |
191 | + { |
192 | + qWarning() << "Failed to push departments: " << QString::fromStdString(e.what()); |
193 | + } |
194 | +} |
195 | + |
196 | void click::apps::Query::run(scopes::SearchReplyProxy const& searchReply) |
197 | { |
198 | const std::string categoryTemplate = CATEGORY_APPS_DISPLAY; |
199 | - auto querystr = query().query_string(); |
200 | - |
201 | - ResultPusher pusher(searchReply, querystr.empty() ? impl->configuration.get_core_apps() : std::vector<std::string>()); |
202 | - auto localResults = clickInterfaceInstance().find_installed_apps(querystr); |
203 | + auto const current_dept = query().department_id(); |
204 | + auto const querystr = query().query_string(); |
205 | + |
206 | + // |
207 | + // get the set of packages that belong to current deparment; |
208 | + // only apply department filtering if not in root of all departments. |
209 | + bool apply_department_filter = (querystr.empty() && !current_dept.empty()); |
210 | + std::unordered_set<std::string> pkgs_in_department; |
211 | + if (impl->depts_db && apply_department_filter) |
212 | + { |
213 | + try |
214 | + { |
215 | + pkgs_in_department = impl->depts_db->get_packages_for_department(current_dept); |
216 | + } |
217 | + catch (const std::exception& e) |
218 | + { |
219 | + qWarning() << "Failed to get packages of department" << QString::fromStdString(current_dept); |
220 | + apply_department_filter = false; // disable so that we are not loosing any apps if something goes wrong |
221 | + } |
222 | + } |
223 | + |
224 | + const bool show_top_apps = querystr.empty() && current_dept.empty(); |
225 | + ResultPusher pusher(searchReply, show_top_apps ? impl->configuration.get_core_apps() : std::vector<std::string>()); |
226 | + auto const localResults = clickInterfaceInstance().find_installed_apps( |
227 | + querystr, pkgs_in_department, apply_department_filter); |
228 | |
229 | if (querystr.empty()) { |
230 | + if (impl->depts_db) |
231 | + { |
232 | + push_local_departments(searchReply); |
233 | + } |
234 | + } |
235 | + |
236 | + if (show_top_apps) |
237 | + { |
238 | pusher.push_top_results(localResults, categoryTemplate); |
239 | } |
240 | |
241 | |
242 | === modified file 'scope/clickapps/apps-query.h' |
243 | --- scope/clickapps/apps-query.h 2014-07-11 16:49:05 +0000 |
244 | +++ scope/clickapps/apps-query.h 2014-07-16 13:16:39 +0000 |
245 | @@ -38,14 +38,14 @@ |
246 | #include <QSharedPointer> |
247 | #include <set> |
248 | #include <unordered_set> |
249 | - |
250 | +#include <click/interface.h> |
251 | |
252 | namespace click |
253 | { |
254 | |
255 | class Application; |
256 | class Configuration; |
257 | -class Index; |
258 | +class DepartmentsDb; |
259 | |
260 | namespace apps |
261 | { |
262 | @@ -65,7 +65,7 @@ |
263 | constexpr static const char* VERSION{"version"}; |
264 | }; |
265 | |
266 | - Query(unity::scopes::CannedQuery const& query, scopes::SearchMetadata const& metadata); |
267 | + Query(unity::scopes::CannedQuery const& query, std::shared_ptr<DepartmentsDb> depts_db, scopes::SearchMetadata const& metadata); |
268 | virtual ~Query(); |
269 | |
270 | virtual void cancelled() override; |
271 | @@ -73,6 +73,12 @@ |
272 | virtual void run(scopes::SearchReplyProxy const& reply) override; |
273 | |
274 | virtual void add_fake_store_app(scopes::SearchReplyProxy const &replyProxy); |
275 | + |
276 | + virtual void push_local_departments(scopes::SearchReplyProxy const& replyProxy); |
277 | + |
278 | +protected: |
279 | + virtual click::Interface& clickInterfaceInstance(); |
280 | + |
281 | private: |
282 | struct Private; |
283 | QSharedPointer<Private> impl; |
284 | |
285 | === modified file 'scope/clickapps/apps-scope.cpp' |
286 | --- scope/clickapps/apps-scope.cpp 2014-07-16 13:16:39 +0000 |
287 | +++ scope/clickapps/apps-scope.cpp 2014-07-16 13:16:39 +0000 |
288 | @@ -31,6 +31,7 @@ |
289 | #include <click/preview.h> |
290 | #include <click/interface.h> |
291 | #include <click/scope_activation.h> |
292 | +#include <click/departments-db.h> |
293 | |
294 | #include <QSharedPointer> |
295 | |
296 | @@ -49,6 +50,14 @@ |
297 | nam.reset(new click::network::AccessManager()); |
298 | client.reset(new click::web::Client(nam)); |
299 | index.reset(new click::Index(client)); |
300 | + try |
301 | + { |
302 | + depts_db = click::DepartmentsDb::create_db(); |
303 | + } |
304 | + catch (const std::runtime_error& e) |
305 | + { |
306 | + std::cerr << "Failed to get cache directory" << std::endl; |
307 | + } |
308 | } |
309 | |
310 | click::Scope::~Scope() |
311 | @@ -79,14 +88,14 @@ |
312 | |
313 | scopes::SearchQueryBase::UPtr click::Scope::search(unity::scopes::CannedQuery const& q, scopes::SearchMetadata const& metadata) |
314 | { |
315 | - return scopes::SearchQueryBase::UPtr(new click::apps::Query(q, metadata)); |
316 | + return scopes::SearchQueryBase::UPtr(new click::apps::Query(q, depts_db, metadata)); |
317 | } |
318 | |
319 | |
320 | unity::scopes::PreviewQueryBase::UPtr click::Scope::preview(const unity::scopes::Result& result, |
321 | const unity::scopes::ActionMetadata& metadata) { |
322 | qDebug() << "Scope::preview() called."; |
323 | - return scopes::PreviewQueryBase::UPtr{new click::Preview(result, metadata, client, nam, nullptr)}; |
324 | + return scopes::PreviewQueryBase::UPtr{new click::Preview(result, metadata, client, nam, depts_db)}; |
325 | } |
326 | |
327 | |
328 | |
329 | === modified file 'scope/clickapps/apps-scope.h' |
330 | --- scope/clickapps/apps-scope.h 2014-06-18 14:42:47 +0000 |
331 | +++ scope/clickapps/apps-scope.h 2014-07-16 13:16:39 +0000 |
332 | @@ -43,6 +43,9 @@ |
333 | |
334 | namespace click |
335 | { |
336 | + |
337 | +class DepartmentsDb; |
338 | + |
339 | class Scope : public scopes::ScopeBase |
340 | { |
341 | public: |
342 | @@ -64,6 +67,7 @@ |
343 | QSharedPointer<click::network::AccessManager> nam; |
344 | QSharedPointer<click::web::Client> client; |
345 | QSharedPointer<click::Index> index; |
346 | + std::shared_ptr<click::DepartmentsDb> depts_db; |
347 | |
348 | std::string installApplication(unity::scopes::Result const& result); |
349 | }; |
350 | |
351 | === modified file 'scope/tests/test_apps_query.cpp' |
352 | --- scope/tests/test_apps_query.cpp 2014-07-14 12:44:48 +0000 |
353 | +++ scope/tests/test_apps_query.cpp 2014-07-16 13:16:39 +0000 |
354 | @@ -34,6 +34,7 @@ |
355 | #include <gmock/gmock.h> |
356 | |
357 | #include <clickapps/apps-query.h> |
358 | +#include <click/departments-db.h> |
359 | |
360 | #include <unity/scopes/SearchReply.h> |
361 | #include <unity/scopes/SearchMetadata.h> |
362 | @@ -56,6 +57,32 @@ |
363 | } |
364 | }; |
365 | |
366 | +class MockClickInterface : public click::Interface |
367 | +{ |
368 | +public: |
369 | + MockClickInterface() = default; |
370 | + MOCK_METHOD3(find_installed_apps, std::vector<click::Application>(const std::string&, const std::unordered_set<std::string>&, bool)); |
371 | +}; |
372 | + |
373 | +class MockAppsQuery : public click::apps::Query |
374 | +{ |
375 | +private: |
376 | + std::shared_ptr<MockClickInterface> click_iface; |
377 | + |
378 | +public: |
379 | + MockAppsQuery(unity::scopes::CannedQuery const& query, std::shared_ptr<click::DepartmentsDb> depts_db, scopes::SearchMetadata const& metadata, |
380 | + const std::shared_ptr<MockClickInterface>& click_iface) |
381 | + : click::apps::Query(query, depts_db, metadata), |
382 | + click_iface(click_iface) |
383 | + { |
384 | + } |
385 | + |
386 | + click::Interface& clickInterfaceInstance() override |
387 | + { |
388 | + return *click_iface; |
389 | + } |
390 | +}; |
391 | + |
392 | MATCHER_P(HasApplicationTitle, n, "") { return arg["title"].get_string() == n; } |
393 | |
394 | TEST_F(ResultPusherTest, testPushTopAndLocalResults) |
395 | @@ -99,8 +126,8 @@ |
396 | const unity::scopes::CannedQuery query("foo.scope", "FooBar", ""); |
397 | const unity::scopes::CannedQuery query2("foo.scope", "Metallica", ""); |
398 | |
399 | - click::apps::Query q(query, metadata); |
400 | - click::apps::Query q2(query2, metadata); |
401 | + click::apps::Query q(query, nullptr, metadata); |
402 | + click::apps::Query q2(query2, nullptr, metadata); |
403 | |
404 | scopes::testing::MockSearchReply mock_reply; |
405 | scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); |
406 | @@ -124,3 +151,92 @@ |
407 | q2.add_fake_store_app(reply2); |
408 | } |
409 | |
410 | +// this matcher expects a list of department ids in depts: |
411 | +// first on the list is the root, followed by children ids. |
412 | +// the arg of the matcher is unity::scopes::Department ptr. |
413 | +MATCHER_P(MatchesDepartments, depts, "") { |
414 | + auto it = depts.begin(); |
415 | + if (arg->id() != *it) |
416 | + return false; |
417 | + auto const subdeps = arg->subdepartments(); |
418 | + if (subdeps.size() != depts.size() - 1) |
419 | + return false; |
420 | + for (auto const& sub: subdeps) |
421 | + { |
422 | + if (sub->id() != *(++it)) |
423 | + return false; |
424 | + } |
425 | + return true; |
426 | +} |
427 | + |
428 | +TEST(Query, Departments) |
429 | +{ |
430 | + const std::vector<click::Application> installed_apps = {{"app1", "App1", 0.0f, "icon", "url", "descr", "scrshot"}}; |
431 | + const scopes::SearchMetadata metadata("en_EN", "phone"); |
432 | + auto clickif = std::make_shared<MockClickInterface>(); |
433 | + |
434 | + const scopes::CategoryRenderer renderer("{}"); |
435 | + auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
436 | + auto depts_db = std::make_shared<MockDepartmentsDb>(":memory:"); |
437 | + |
438 | + const std::list<std::string> expected_locales {"en_EN", "en_US", ""}; |
439 | + |
440 | + // query for root of the departments tree |
441 | + { |
442 | + const unity::scopes::CannedQuery query("foo.scope", "", ""); |
443 | + |
444 | + MockAppsQuery q(query, depts_db, metadata, clickif); |
445 | + |
446 | + scopes::testing::MockSearchReply mock_reply; |
447 | + scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); |
448 | + |
449 | + std::list<std::string> expected_departments({{"", "games", "video"}}); |
450 | + |
451 | + EXPECT_CALL(*clickif, find_installed_apps(_, _, _)).WillOnce(Return(installed_apps)); |
452 | + EXPECT_CALL(mock_reply, register_category("predefined", _, _, _)).WillOnce(Return(ptrCat)); |
453 | + EXPECT_CALL(mock_reply, register_category("local", _, _, _)).WillOnce(Return(ptrCat)); |
454 | + EXPECT_CALL(mock_reply, register_category("store", _, _, _)).WillOnce(Return(ptrCat)); |
455 | + EXPECT_CALL(mock_reply, register_departments(MatchesDepartments(expected_departments))); |
456 | + |
457 | + EXPECT_CALL(mock_reply, push(Matcher<unity::scopes::CategorisedResult const&>(_))).Times(2).WillRepeatedly(Return(true)); |
458 | + |
459 | + EXPECT_CALL(*depts_db, get_department_name("games", expected_locales)).WillOnce(Return("Games")); |
460 | + EXPECT_CALL(*depts_db, get_department_name("video", expected_locales)).WillOnce(Return("Video")); |
461 | + EXPECT_CALL(*depts_db, get_children_departments("")).WillOnce(Return( |
462 | + std::list<click::DepartmentsDb::DepartmentInfo>({ |
463 | + {"games", false}, |
464 | + {"video", true} |
465 | + })) |
466 | + ); |
467 | + |
468 | + q.run(reply); |
469 | + } |
470 | + |
471 | + // query for a leaf department |
472 | + { |
473 | + const unity::scopes::CannedQuery query("foo.scope", "", "games"); |
474 | + |
475 | + MockAppsQuery q(query, depts_db, metadata, clickif); |
476 | + |
477 | + scopes::testing::MockSearchReply mock_reply; |
478 | + scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){}); |
479 | + |
480 | + std::list<std::string> expected_departments({"", "games"}); |
481 | + |
482 | + EXPECT_CALL(*clickif, find_installed_apps(_, _, _)).WillOnce(Return(installed_apps)); |
483 | + EXPECT_CALL(mock_reply, register_category("local", _, _, _)).WillOnce(Return(ptrCat)); |
484 | + EXPECT_CALL(mock_reply, register_category("store", _, _, _)).WillOnce(Return(ptrCat)); |
485 | + EXPECT_CALL(mock_reply, register_departments(MatchesDepartments(expected_departments))); |
486 | + |
487 | + EXPECT_CALL(mock_reply, push(Matcher<unity::scopes::CategorisedResult const&>(_))).Times(2).WillRepeatedly(Return(true)); |
488 | + |
489 | + EXPECT_CALL(*depts_db, get_parent_department_id("games")).WillOnce(Return("")); |
490 | + EXPECT_CALL(*depts_db, get_department_name("games", expected_locales)).WillOnce(Return("Games")); |
491 | + EXPECT_CALL(*depts_db, get_children_departments("games")).WillOnce(Return( |
492 | + std::list<click::DepartmentsDb::DepartmentInfo>({}) |
493 | + )); |
494 | + |
495 | + q.run(reply); |
496 | + } |
497 | +} |
498 | + |
499 | |
500 | === modified file 'scope/tests/test_helpers.h' |
501 | --- scope/tests/test_helpers.h 2014-07-03 14:58:53 +0000 |
502 | +++ scope/tests/test_helpers.h 2014-07-16 13:16:39 +0000 |
503 | @@ -53,6 +53,23 @@ |
504 | std::function<void(click::Packages, click::Packages)>)); |
505 | }; |
506 | |
507 | +class MockDepartmentsDb : public click::DepartmentsDb |
508 | +{ |
509 | +public: |
510 | + MockDepartmentsDb(const std::string& name) |
511 | + : click::DepartmentsDb(name) |
512 | + { |
513 | + } |
514 | + |
515 | + MOCK_METHOD2(get_department_name, std::string(const std::string&, const std::list<std::string>&)); |
516 | + MOCK_METHOD2(get_packages_for_department, std::unordered_set<std::string>(const std::string&, bool)); |
517 | + MOCK_METHOD1(get_parent_department_id, std::string(const std::string&)); |
518 | + MOCK_METHOD1(get_children_departments, std::list<click::DepartmentsDb::DepartmentInfo>(const std::string&)); |
519 | + |
520 | + MOCK_METHOD2(store_package_mapping, void(const std::string&, const std::string&)); |
521 | + MOCK_METHOD2(store_department_mapping, void(const std::string&, const std::string&)); |
522 | + MOCK_METHOD3(store_department_name, void(const std::string&, const std::string&, const std::string&)); |
523 | +}; |
524 | |
525 | class FakeCategory : public scopes::Category |
526 | { |
527 | |
528 | === modified file 'scope/tests/test_query.cpp' |
529 | --- scope/tests/test_query.cpp 2014-07-16 13:16:39 +0000 |
530 | +++ scope/tests/test_query.cpp 2014-07-16 13:16:39 +0000 |
531 | @@ -55,19 +55,6 @@ |
532 | namespace |
533 | { |
534 | |
535 | -class MockDepartmentsDb : public click::DepartmentsDb |
536 | -{ |
537 | -public: |
538 | - MockDepartmentsDb(const std::string& name) |
539 | - : click::DepartmentsDb(name) |
540 | - { |
541 | - } |
542 | - |
543 | - MOCK_METHOD2(store_package_mapping, void(const std::string&, const std::string&)); |
544 | - MOCK_METHOD2(store_department_mapping, void(const std::string&, const std::string&)); |
545 | - MOCK_METHOD3(store_department_name, void(const std::string&, const std::string&, const std::string&)); |
546 | -}; |
547 | - |
548 | class MockQueryBase : public click::Query { |
549 | public: |
550 | MockQueryBase(const unity::scopes::CannedQuery& query, click::Index& index, |
551 | @@ -296,7 +283,7 @@ |
552 | std::make_shared<click::Department>("1-2", "Department three", "http://three.com", false) |
553 | }); |
554 | DepartmentList init_departments({dept1}); |
555 | - auto depts_db = std::make_shared<MockDepartmentsDb>("query-tests.db"); |
556 | + auto depts_db = std::make_shared<MockDepartmentsDb>(":memory:"); |
557 | |
558 | EXPECT_CALL(*depts_db, store_department_name(_, _, _)).Times(3); |
559 | EXPECT_CALL(*depts_db, store_department_mapping(_, _)).Times(2); |
PASSED: Continuous integration, rev:322 jenkins. qa.ubuntu. com/job/ unity-team- unity-scope- click-devel- ci/199/ jenkins. qa.ubuntu. com/job/ unity-team- unity-scope- click-devel- utopic- amd64-ci/ 174 jenkins. qa.ubuntu. com/job/ unity-team- unity-scope- click-devel- utopic- armhf-ci/ 173 jenkins. qa.ubuntu. com/job/ unity-team- unity-scope- click-devel- utopic- armhf-ci/ 173/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ unity-team- unity-scope- click-devel- utopic- i386-ci/ 173
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- team-unity- scope-click- devel-ci/ 199/rebuild
http://