60
class MockClickInterface : public click::Interface
63
MockClickInterface() = default;
64
MOCK_METHOD3(find_installed_apps, std::vector<click::Application>(const std::string&, const std::unordered_set<std::string>&, bool));
67
class MockAppsQuery : public click::apps::Query
70
std::shared_ptr<MockClickInterface> click_iface;
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)
80
click::Interface& clickInterfaceInstance() override
59
86
MATCHER_P(HasApplicationTitle, n, "") { return arg["title"].get_string() == n; }
61
88
TEST_F(ResultPusherTest, testPushTopAndLocalResults)
99
126
const unity::scopes::CannedQuery query("foo.scope", "FooBar", "");
100
127
const unity::scopes::CannedQuery query2("foo.scope", "Metallica", "");
102
click::apps::Query q(query, metadata);
103
click::apps::Query q2(query2, metadata);
129
click::apps::Query q(query, nullptr, metadata);
130
click::apps::Query q2(query2, nullptr, metadata);
105
132
scopes::testing::MockSearchReply mock_reply;
106
133
scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
124
151
q2.add_fake_store_app(reply2);
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.
157
MATCHER_P(MatchesDepartments, depts, "") {
158
auto it = depts.begin();
159
if (arg->id() != *it)
161
auto const subdeps = arg->subdepartments();
162
if (subdeps.size() != depts.size() - 1)
164
for (auto const& sub: subdeps)
166
if (sub->id() != *(++it))
172
TEST(Query, Departments)
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>();
178
const scopes::CategoryRenderer renderer("{}");
179
auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer);
180
auto depts_db = std::make_shared<MockDepartmentsDb>(":memory:");
182
const std::list<std::string> expected_locales {"en_EN", "en_US", ""};
184
// query for root of the departments tree
186
const unity::scopes::CannedQuery query("foo.scope", "", "");
188
MockAppsQuery q(query, depts_db, metadata, clickif);
190
scopes::testing::MockSearchReply mock_reply;
191
scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
193
std::list<std::string> expected_departments({{"", "games", "video"}});
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)));
201
EXPECT_CALL(mock_reply, push(Matcher<unity::scopes::CategorisedResult const&>(_))).Times(2).WillRepeatedly(Return(true));
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>({
215
// query for a leaf department
217
const unity::scopes::CannedQuery query("foo.scope", "", "games");
219
MockAppsQuery q(query, depts_db, metadata, clickif);
221
scopes::testing::MockSearchReply mock_reply;
222
scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
224
std::list<std::string> expected_departments({"", "games"});
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)));
231
EXPECT_CALL(mock_reply, push(Matcher<unity::scopes::CategorisedResult const&>(_))).Times(2).WillRepeatedly(Return(true));
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>({})