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, double rating)
32
QVariantMap attributes;
33
attributes["name"] = name;
34
attributes["summary"] = summary;
35
attributes["rating"] = rating;
36
attributes["description"] = description;
37
attributes["icon"] = icon;
38
attributes["publisher"] = publisher;
39
attributes["website"] = website;
40
attributes["license"] = license;
41
attributes["id"] = id;
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, double rating)
51
EXPECT_EQ(name, actual.name);
52
EXPECT_EQ(summary, actual.summary);
53
EXPECT_EQ(rating, actual.rating);
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);
63
TEST(PackageTest, FromMapCreatesSinglePackage)
65
auto attributeMap = attribute_map("Harry", "The Philosopher's Stone",
66
"Boy with head injury seeks magic rock",
67
"harry.png", "JK", "pottermore.com", "Private",
68
"com.pottermore.harry", 3.4);
69
auto package = Package::from_map(attributeMap);
70
package_matches_attributes(package, "Harry", "The Philosopher's Stone",
71
"Boy with head injury seeks magic rock",
72
"harry.png", "JK", "pottermore.com", "Private",
73
"com.pottermore.harry", 3.4);
77
TEST(PackageTest, FromMapCreatesListOfPackages)
79
auto attributePkg1Map = attribute_map("Harry", "The Philosopher's Stone",
80
"Boy with head injury seeks magic rock",
81
"harry.png", "JK", "pottermore.com", "Private",
82
"com.pottermore.harry", 3.4);
83
auto attributePkg2Map = attribute_map("Dune", "Classic science fiction",
84
"The spice must flow", "worms.png",
85
"Herbert", "dunebook.net", "Other",
86
"net.dunebook.dune", 4.1);
87
auto packages = Package::from_map(QList<QVariantMap>{attributePkg1Map, attributePkg2Map});
88
ASSERT_EQ(2, packages.size());
89
package_matches_attributes(packages[0], "Harry", "The Philosopher's Stone",
90
"Boy with head injury seeks magic rock",
91
"harry.png", "JK", "pottermore.com", "Private",
92
"com.pottermore.harry", 3.4);
93
package_matches_attributes(packages[1], "Dune", "Classic science fiction",
94
"The spice must flow", "worms.png",
95
"Herbert", "dunebook.net", "Other",
96
"net.dunebook.dune", 4.1);
100
TEST(PackageTest, RenderRatingReturnsMinimum0EmptyStars)
104
EXPECT_EQ("☆☆☆☆☆", p.render_rating());
108
TEST(PackageTest, RenderRatingReturnsMaximum5FilledStars)
112
EXPECT_EQ("★★★★★", p.render_rating());
116
TEST(PackageTest, RenderRatingReturnsRoundedUpStars)
120
EXPECT_EQ("★★★☆☆", p.render_rating());
124
TEST(PackageTest, RenderRatingReturnsRoundedDownStars)
128
EXPECT_EQ("★★★★☆", p.render_rating());