Merge lp:~larryprice/libertine-scope/implement-search into lp:libertine-scope

Proposed by Larry Price
Status: Merged
Approved by: Stephen M. Webb
Approved revision: 32
Merged at revision: 33
Proposed branch: lp:~larryprice/libertine-scope/implement-search
Merge into: lp:libertine-scope
Diff against target: 222 lines (+153/-6)
4 files modified
libertine-scope/query.cpp (+10/-5)
po/libertine-scope.pot (+1/-1)
tests/CMakeLists.txt (+3/-0)
tests/test_query.cpp (+139/-0)
To merge this branch: bzr merge lp:~larryprice/libertine-scope/implement-search
Reviewer Review Type Date Requested Status
Stephen M. Webb (community) Approve
Review via email: mp+292047@code.launchpad.net

Commit message

Filter app launchers based on a user-input regular expression.

Description of the change

Filter app launchers based on a user-input regular expression.

To post a comment you must log in.
Revision history for this message
Stephen M. Webb (bregma) wrote :

Works!!!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libertine-scope/query.cpp'
--- libertine-scope/query.cpp 2016-01-19 21:10:09 +0000
+++ libertine-scope/query.cpp 2016-04-15 20:09:21 +0000
@@ -22,6 +22,9 @@
22#include <unity/scopes/CategoryRenderer.h>22#include <unity/scopes/CategoryRenderer.h>
23#include <unity/scopes/QueryBase.h>23#include <unity/scopes/QueryBase.h>
24#include <unity/scopes/SearchReply.h>24#include <unity/scopes/SearchReply.h>
25#include <QString>
26#include <QRegExp>
27
2528
26namespace usc = unity::scopes;29namespace usc = unity::scopes;
2730
@@ -82,26 +85,28 @@
82void Query::85void Query::
83run(usc::SearchReplyProxy const& reply)86run(usc::SearchReplyProxy const& reply)
84{87{
85 usc::CannedQuery const& query(usc::SearchQueryBase::query());88 QRegExp re(QString::fromStdString(query().query_string()), Qt::CaseInsensitive);
86 std::string query_string = query.query_string();
87
88 Libertine::UPtr libertine = libertine_factory_();89 Libertine::UPtr libertine = libertine_factory_();
90
89 for (auto const& container: libertine->get_container_list())91 for (auto const& container: libertine->get_container_list())
90 {92 {
91 auto category = reply->register_category(container->id(),93 auto category = reply->register_category(container->id(),
92 container->name(),94 container->name(),
93 "Application",95 "Application",
94 usc::CategoryRenderer(CATEGORY_APPS_DISPLAY));96 usc::CategoryRenderer(CATEGORY_APPS_DISPLAY));
95
96 for (auto const& app: container->app_launchers())97 for (auto const& app: container->app_launchers())
97 {98 {
98 if (app.no_display())99 if (app.no_display() ||
100 !(re.isEmpty() || QString::fromStdString(app.name()).contains(re)))
101 {
99 continue;102 continue;
103 }
100104
101 usc::CategorisedResult result(category);105 usc::CategorisedResult result(category);
102 result.set_title(app.name());106 result.set_title(app.name());
103 result.set_art(app.icon());107 result.set_art(app.icon());
104 result.set_uri(app_uri(*container, app));108 result.set_uri(app_uri(*container, app));
109
105 if (!reply->push(result))110 if (!reply->push(result))
106 {111 {
107 break;112 break;
108113
=== modified file 'po/libertine-scope.pot'
--- po/libertine-scope.pot 2016-02-27 03:54:52 +0000
+++ po/libertine-scope.pot 2016-04-15 20:09:21 +0000
@@ -8,7 +8,7 @@
8msgstr ""8msgstr ""
9"Project-Id-Version: PACKAGE VERSION\n"9"Project-Id-Version: PACKAGE VERSION\n"
10"Report-Msgid-Bugs-To: \n"10"Report-Msgid-Bugs-To: \n"
11"POT-Creation-Date: 2016-02-26 22:50-0500\n"11"POT-Creation-Date: 2016-04-15 14:36-0400\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"14"Language-Team: LANGUAGE <LL@li.org>\n"
1515
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2016-01-19 00:16:56 +0000
+++ tests/CMakeLists.txt 2016-04-15 20:09:21 +0000
@@ -7,6 +7,7 @@
7 fake_container.cpp7 fake_container.cpp
8 fake_libertine.cpp8 fake_libertine.cpp
9 test_scope.cpp9 test_scope.cpp
10 test_query.cpp
10)11)
1112
12target_link_libraries(libertine_scope_tests13target_link_libraries(libertine_scope_tests
@@ -19,3 +20,5 @@
19add_test(test_scope20add_test(test_scope
20 libertine_scope_tests21 libertine_scope_tests
21)22)
23
24add_test(test_query libertine_scope_tests)
2225
=== added file 'tests/test_query.cpp'
--- tests/test_query.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_query.cpp 2016-04-15 20:09:21 +0000
@@ -0,0 +1,139 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, version 3, as published by the
6 * Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "libertine-scope/query.h"
18#include "tests/fake_libertine.h"
19#include <unity/scopes/SearchMetadata.h>
20#include <unity/scopes/CannedQuery.h>
21#include <unity/scopes/SearchReplyProxyFwd.h>
22#include <unity/scopes/testing/MockSearchReply.h>
23#include <unity/scopes/Category.h>
24#include <vector>
25#include <memory>
26#include <gtest/gtest.h>
27#include <gmock/gmock.h>
28
29namespace
30{
31const std::string LIBERTINE_OUTPUT_WITH_APPS = R"(
32 {
33 "name": "fake-container",
34 "app_launchers": [{
35 "name": "LibreOffice",
36 "no_display": false,
37 "desktop_file_name": "/link/to/libreoffice.desktop"
38 }, {
39 "name": "Linux",
40 "no_display": true,
41 "desktop_file_name": "/link/to/linux.desktop"
42 }, {
43 "name": "Library",
44 "no_display": false,
45 "desktop_file_name": "/link/to/library.desktop"
46 }]
47 }
48)";
49
50
51class FakeCategory : public unity::scopes::Category
52{
53public:
54 FakeCategory(std::string const& id, std::string const& title,
55 std::string const& icon, unity::scopes::CategoryRenderer const& renderer) :
56 unity::scopes::Category(id, title, icon, renderer)
57 {
58 }
59
60};
61
62
63MATCHER_P3(ResultPropertiesMatch, title, art, uri, "")
64{
65 return arg.contains("title") && arg.contains("art") && arg.contains("uri") &&
66 arg["title"] == unity::scopes::Variant(title) &&
67 arg["art"] == unity::scopes::Variant(art) &&
68 arg["uri"] == unity::scopes::Variant(uri);
69}
70
71
72class TestQueryFixture : public ::testing::Test
73{
74public:
75 TestQueryFixture()
76 : metadata("en_US", "phone")
77 , canned_query("libertine-scope")
78 , reply()
79 , proxy(&reply, [](unity::scopes::SearchReply*) {})
80 , category(std::make_shared<FakeCategory>("fake", "fake-container", "Application", unity::scopes::CategoryRenderer()))
81 {
82 }
83
84 void expect_registry()
85 {
86 EXPECT_CALL(reply, register_category("fake", "fake-container", "Application", testing::_)).WillOnce(testing::Return(category));
87 }
88
89 void expect_push(std::string title, std::string art, std::string appId, bool success = true)
90 {
91 EXPECT_CALL(reply, push(testing::Matcher<unity::scopes::CategorisedResult const&>(ResultPropertiesMatch(title, art, appId)))).WillOnce(testing::Return(success));
92 }
93
94 unity::scopes::SearchMetadata metadata;
95 unity::scopes::CannedQuery canned_query;
96 testing::NiceMock<unity::scopes::testing::MockSearchReply> reply;
97 unity::scopes::SearchReplyProxy proxy;
98 std::shared_ptr<FakeCategory> category;
99};
100
101
102TEST_F(TestQueryFixture, returnsAllDisplayableAppsWithoutFilters)
103{
104 expect_registry();
105 expect_push("LibreOffice", "", "appid://fake/libreoffice/0.0");
106 expect_push("Library", "", "appid://fake/library/0.0");
107
108 Query query(canned_query, metadata, []() {
109 return FakeLibertine::make_fake(LIBERTINE_OUTPUT_WITH_APPS);
110 });
111 query.run(proxy);
112}
113
114
115TEST_F(TestQueryFixture, returnsRegularExpressionFilteredListOfApps)
116{
117 expect_registry();
118 expect_push("LibreOffice", "", "appid://fake/libreoffice/0.0");
119 canned_query.set_query_string("li.*office");
120
121 Query query(canned_query, metadata, []() {
122 return FakeLibertine::make_fake(LIBERTINE_OUTPUT_WITH_APPS);
123 });
124 query.run(proxy);
125}
126
127
128TEST_F(TestQueryFixture, haltsFurtherPushesAfterFailedPush)
129{
130 expect_registry();
131 expect_push("LibreOffice", "", "appid://fake/libreoffice/0.0", false);
132
133 Query query(canned_query, metadata, []() {
134 return FakeLibertine::make_fake(LIBERTINE_OUTPUT_WITH_APPS);
135 });
136 query.run(proxy);
137}
138
139} // anonymous namespace

Subscribers

People subscribed via source and target branches