36
36
#include "click/qtbridge.h"
37
37
#include "clickstore/store-query.h"
38
38
#include "click/application.h"
39
#include "click/departments-db.h"
39
40
#include "test_helpers.h"
41
42
#include <tests/mock_network_access_manager.h>
58
class MockDepartmentsDb : public click::DepartmentsDb
61
MockDepartmentsDb(const std::string& name)
62
: click::DepartmentsDb(name)
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&));
56
71
class MockQueryBase : public click::Query {
58
73
MockQueryBase(const unity::scopes::CannedQuery& query, click::Index& index,
59
74
click::DepartmentLookup& depts,
75
std::shared_ptr<click::DepartmentsDb> depts_db,
60
76
click::HighlightList& highlights,
61
scopes::SearchMetadata const& metadata) : click::Query(query, index, depts, highlights, metadata)
77
scopes::SearchMetadata const& metadata) : click::Query(query, index, depts, depts_db, highlights, metadata)
74
90
MockQuery(const unity::scopes::CannedQuery& query, click::Index& index,
75
91
click::DepartmentLookup& depts,
92
std::shared_ptr<click::DepartmentsDb> depts_db,
76
93
click::HighlightList& highlights,
77
scopes::SearchMetadata const& metadata) : MockQueryBase(query, index, depts, highlights, metadata)
94
scopes::SearchMetadata const& metadata) : MockQueryBase(query, index, depts, depts_db, highlights, metadata)
100
117
MockQueryRun(const unity::scopes::CannedQuery& query, click::Index& index,
101
118
click::DepartmentLookup& depts,
119
std::shared_ptr<click::DepartmentsDb> depts_db,
102
120
click::HighlightList& highlights,
103
scopes::SearchMetadata const& metadata) : MockQueryBase(query, index, depts, highlights, metadata)
121
scopes::SearchMetadata const& metadata) : MockQueryBase(query, index, depts, depts_db, highlights, metadata)
123
141
scopes::SearchMetadata metadata("en_EN", "phone");
124
142
PackageSet no_installed_packages;
125
143
const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
126
MockQuery q(query, mock_index, dept_lookup, highlights, metadata);
144
MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata);
127
145
EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _)).Times(1);
129
147
scopes::testing::MockSearchReply mock_reply;
148
166
scopes::SearchMetadata metadata("en_EN", "phone");
149
167
PackageSet no_installed_packages;
150
168
const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
151
MockQuery q(query, mock_index, dept_lookup, highlights, metadata);
169
MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata);
152
170
EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _));
154
172
scopes::CategoryRenderer renderer("{}");
177
195
scopes::SearchMetadata metadata("en_EN", "phone");
178
196
PackageSet no_installed_packages;
179
197
const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
180
MockQuery q(query, mock_index, dept_lookup, highlights, metadata);
198
MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata);
181
199
EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _));
183
201
scopes::CategoryRenderer renderer("{}");
201
219
scopes::SearchMetadata metadata("en_EN", "phone");
202
220
PackageSet no_installed_packages;
203
221
const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
204
MockQueryRun q(query, mock_index, dept_lookup, highlights, metadata);
222
MockQueryRun q(query, mock_index, dept_lookup, nullptr, highlights, metadata);
205
223
auto reply = scopes::SearchReplyProxy();
206
224
EXPECT_CALL(q, get_installed_packages()).WillOnce(Return(no_installed_packages));
207
225
EXPECT_CALL(q, add_available_apps(reply, no_installed_packages, _));
226
244
click::DepartmentLookup dept_lookup;
227
245
click::HighlightList highlights;
228
246
const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
229
MockQuery q(query, mock_index, dept_lookup, highlights, metadata);
247
MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata);
230
248
EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _));
232
250
scopes::CategoryRenderer renderer("{}");
256
274
click::DepartmentLookup dept_lookup;
257
275
click::HighlightList highlights;
258
276
const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
259
MockQuery q(query, mock_index, dept_lookup, highlights, metadata);
277
MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata);
260
278
EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _));
262
280
scopes::CategoryRenderer renderer("{}");
270
288
q.wrap_add_available_apps(reply, one_installed_package, FAKE_CATEGORY_TEMPLATE);
291
TEST(QueryTest, testDepartmentsDbIsUpdated)
293
auto dept1 = std::make_shared<click::Department>("1", "Department one", "http://one.com", true);
294
dept1->set_subdepartments({
295
std::make_shared<click::Department>("1-1", "Department two", "http://two.com", false),
296
std::make_shared<click::Department>("1-2", "Department three", "http://three.com", false)
298
DepartmentList init_departments({dept1});
299
auto depts_db = std::make_shared<MockDepartmentsDb>("query-tests.db");
301
EXPECT_CALL(*depts_db, store_department_name(_, _, _)).Times(3);
302
EXPECT_CALL(*depts_db, store_department_mapping(_, _)).Times(2);
304
MockIndex mock_index(click::Packages(), click::DepartmentList(), init_departments);
305
scopes::SearchMetadata metadata("en_EN", "phone");
306
PackageSet one_installed_package {
307
{"org.example.app2", "0.2"}
309
click::DepartmentLookup dept_lookup;
310
click::HighlightList highlights;
311
const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
312
MockQuery q(query, mock_index, dept_lookup, depts_db, highlights, metadata);
313
EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _));
315
scopes::CategoryRenderer renderer("{}");
316
auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer);
317
EXPECT_CALL(q, register_category(_, _, _, _, _)).Times(2).WillRepeatedly(Return(ptrCat));
319
scopes::testing::MockSearchReply mock_reply;
320
scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
321
q.wrap_add_available_apps(reply, one_installed_package, FAKE_CATEGORY_TEMPLATE);
273
324
class FakeInterface : public click::Interface
286
337
click::DepartmentLookup dept_lookup;
287
338
click::HighlightList highlights;
288
339
const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
289
MockQuery q(query, mock_index, dept_lookup, highlights, metadata);
340
MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata);
290
341
PackageSet installed_packages{{"package_1", "0.1"}};
292
343
FakeInterface fake_interface;