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/>.
16
#include "scope/store/package.h"
18
#include <gtest/gtest.h>
19
#include <gmock/gmock.h>
24
using namespace Libertine::Store;
28
attribute_map(QString const& name, QString const& summary, QString const& description,
29
QString const& icon, QString const& publisher, QString const& website,
30
QString const& license, QString const& id, QStringList screenshots)
32
QVariantMap attributes;
33
attributes["name"] = name;
34
attributes["summary"] = summary;
35
attributes["description"] = description;
36
attributes["icon"] = icon;
37
attributes["publisher"] = publisher;
38
attributes["website"] = website;
39
attributes["license"] = license;
40
attributes["id"] = id;
41
attributes["screenshots"] = screenshots;
47
package_matches_attributes(Package actual, std::string const& name, std::string const& summary,
48
std::string const& description, std::string const& icon, std::string const& publisher,
49
std::string const& website, std::string const& license, std::string const& id,
50
QStringList screenshots)
52
EXPECT_EQ(name, actual.name);
53
EXPECT_EQ(summary, actual.summary);
54
EXPECT_EQ(description, actual.description);
55
EXPECT_EQ(icon, actual.icon);
56
EXPECT_EQ(publisher, actual.publisher);
57
EXPECT_EQ(website, actual.website);
58
EXPECT_EQ(license, actual.license);
59
EXPECT_EQ(id, actual.id);
61
ASSERT_EQ(actual.screenshots.size(), screenshots.size());
62
for (auto i = 0u; i < actual.screenshots.size(); ++i)
64
EXPECT_EQ(screenshots[i], QString::fromStdString(actual.screenshots[i]));
69
TEST(PackageTest, FromMapCreatesSinglePackage)
71
QStringList screenshots{"file:///some/image.png", "file:///some/other/image.jpg"};
72
auto attributeMap = attribute_map("Harry", "The Philosopher's Stone",
73
"Boy with head injury seeks magic rock",
74
"harry.png", "JK", "pottermore.com", "Private",
75
"com.pottermore.harry", screenshots);
76
auto package = Package::from_map(attributeMap);
77
package_matches_attributes(package, "Harry", "The Philosopher's Stone",
78
"Boy with head injury seeks magic rock",
79
"harry.png", "JK", "pottermore.com", "Private",
80
"com.pottermore.harry", screenshots);
84
TEST(PackageTest, FromMapCreatesListOfPackages)
86
QStringList screenshots{"file:///some/image.png", "file:///some/other/image.jpg"};
87
auto attributePkg1Map = attribute_map("Harry", "The Philosopher's Stone",
88
"Boy with head injury seeks magic rock",
89
"harry.png", "JK", "pottermore.com", "Private",
90
"com.pottermore.harry", screenshots);
91
QStringList screenshots2{"file://imageFor2.png"};
92
auto attributePkg2Map = attribute_map("Dune", "Classic science fiction",
93
"The spice must flow", "worms.png",
94
"Herbert", "dunebook.net", "Other",
95
"net.dunebook.dune", screenshots2);
96
auto packages = Package::from_map(QList<QVariantMap>{attributePkg1Map, attributePkg2Map});
97
ASSERT_EQ(2, packages.size());
98
package_matches_attributes(packages[0], "Harry", "The Philosopher's Stone",
99
"Boy with head injury seeks magic rock",
100
"harry.png", "JK", "pottermore.com", "Private",
101
"com.pottermore.harry", screenshots);
102
package_matches_attributes(packages[1], "Dune", "Classic science fiction",
103
"The spice must flow", "worms.png",
104
"Herbert", "dunebook.net", "Other",
105
"net.dunebook.dune", screenshots2);