2
* Copyright 2016 Canonical Ltd.
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.
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.
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/>.
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>
26
#include <gtest/gtest.h>
27
#include <gmock/gmock.h>
31
const std::string LIBERTINE_OUTPUT_WITH_APPS = R"(
33
"name": "fake-container",
35
"name": "LibreOffice",
37
"desktop_file_name": "/link/to/libreoffice.desktop"
41
"desktop_file_name": "/link/to/linux.desktop"
45
"desktop_file_name": "/link/to/library.desktop"
51
class FakeCategory : public unity::scopes::Category
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)
63
MATCHER_P3(ResultPropertiesMatch, title, art, uri, "")
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);
72
class TestQueryFixture : public ::testing::Test
76
: metadata("en_US", "phone")
77
, canned_query("libertine-scope")
79
, proxy(&reply, [](unity::scopes::SearchReply*) {})
80
, category(std::make_shared<FakeCategory>("fake", "fake-container", "Application", unity::scopes::CategoryRenderer()))
84
void expect_registry()
86
EXPECT_CALL(reply, register_category("fake", "fake-container", "Application", testing::_)).WillOnce(testing::Return(category));
89
void expect_push(std::string title, std::string art, std::string appId, bool success = true)
91
EXPECT_CALL(reply, push(testing::Matcher<unity::scopes::CategorisedResult const&>(ResultPropertiesMatch(title, art, appId)))).WillOnce(testing::Return(success));
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;
102
TEST_F(TestQueryFixture, returnsAllDisplayableAppsWithoutFilters)
105
expect_push("LibreOffice", "", "appid://fake/libreoffice/0.0");
106
expect_push("Library", "", "appid://fake/library/0.0");
108
Query query(canned_query, metadata, []() {
109
return FakeLibertine::make_fake(LIBERTINE_OUTPUT_WITH_APPS);
115
TEST_F(TestQueryFixture, returnsRegularExpressionFilteredListOfApps)
118
expect_push("LibreOffice", "", "appid://fake/libreoffice/0.0");
119
canned_query.set_query_string("li.*office");
121
Query query(canned_query, metadata, []() {
122
return FakeLibertine::make_fake(LIBERTINE_OUTPUT_WITH_APPS);
128
TEST_F(TestQueryFixture, haltsFurtherPushesAfterFailedPush)
131
expect_push("LibreOffice", "", "appid://fake/libreoffice/0.0", false);
133
Query query(canned_query, metadata, []() {
134
return FakeLibertine::make_fake(LIBERTINE_OUTPUT_WITH_APPS);
139
} // anonymous namespace