~unity-team/unity-scope-click/devel

« back to all changes in this revision

Viewing changes to scope/tests/test_query.cpp

  • Committer: Tarmac
  • Author(s): Pawel Stolowski
  • Date: 2014-07-16 13:57:55 UTC
  • mfrom: (310.2.13 populate-departments-db)
  • Revision ID: tarmac-20140716135755-bsuqlp22axfwvvd5
Populate departments database in the store scope. Use slugs for unique department ids when parsing. Implemented a tool that initializes or updates departments db.

Approved by Alejandro J. Cura, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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"
40
41
 
41
42
#include <tests/mock_network_access_manager.h>
53
54
 
54
55
namespace
55
56
{
 
57
 
 
58
class MockDepartmentsDb : public click::DepartmentsDb
 
59
{
 
60
public:
 
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
 
56
71
class MockQueryBase : public click::Query {
57
72
public:
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)
62
78
    {
63
79
 
64
80
    }
73
89
public:
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)
78
95
    {
79
96
 
80
97
    }
99
116
public:
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)
104
122
    {
105
123
 
106
124
    }
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);
128
146
 
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, _));
153
171
 
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, _));
182
200
 
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, _));
231
249
 
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, _));
261
279
 
262
280
    scopes::CategoryRenderer renderer("{}");
270
288
    q.wrap_add_available_apps(reply, one_installed_package, FAKE_CATEGORY_TEMPLATE);
271
289
}
272
290
 
 
291
TEST(QueryTest, testDepartmentsDbIsUpdated)
 
292
{
 
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)
 
297
            });
 
298
    DepartmentList init_departments({dept1});
 
299
    auto depts_db = std::make_shared<MockDepartmentsDb>("query-tests.db");
 
300
 
 
301
    EXPECT_CALL(*depts_db, store_department_name(_, _, _)).Times(3);
 
302
    EXPECT_CALL(*depts_db, store_department_mapping(_, _)).Times(2);
 
303
 
 
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"}
 
308
    };
 
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, _));
 
314
 
 
315
    scopes::CategoryRenderer renderer("{}");
 
316
    auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer);
 
317
    EXPECT_CALL(q, register_category(_, _, _, _, _)).Times(2).WillRepeatedly(Return(ptrCat));
 
318
 
 
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);
 
322
}
 
323
 
273
324
class FakeInterface : public click::Interface
274
325
{
275
326
public:
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"}};
291
342
 
292
343
    FakeInterface fake_interface;