~larryprice/libertine-scope/libertine-store-create-container

« back to all changes in this revision

Viewing changes to tests/scope/store/test_package.cpp

  • Committer: Larry Price
  • Date: 2016-09-16 14:13:09 UTC
  • mfrom: (75.1.30 preview-2)
  • Revision ID: larry.price@canonical.com-20160916141309-ifq55kdzk2pq64bx
Create Preview pane with base information

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "scope/store/package.h"
 
17
 
 
18
#include <gtest/gtest.h>
 
19
#include <gmock/gmock.h>
 
20
 
 
21
 
 
22
namespace
 
23
{
 
24
using namespace Libertine::Store;
 
25
 
 
26
 
 
27
static QVariantMap
 
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)
 
31
{
 
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;
 
42
  return attributes;
 
43
}
 
44
 
 
45
 
 
46
static void
 
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)
 
51
{
 
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);
 
60
 
 
61
  ASSERT_EQ(actual.screenshots.size(), screenshots.size());
 
62
  for (auto i = 0u; i < actual.screenshots.size(); ++i)
 
63
  {
 
64
    EXPECT_EQ(screenshots[i], QString::fromStdString(actual.screenshots[i]));
 
65
  }
 
66
}
 
67
 
 
68
 
 
69
TEST(PackageTest, FromMapCreatesSinglePackage)
 
70
{
 
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);
 
81
}
 
82
 
 
83
 
 
84
TEST(PackageTest, FromMapCreatesListOfPackages)
 
85
{
 
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);
 
106
}
 
107
}