commit 9b0fe4248b2c92756de56152ed9aa1b1ff48ebe6
parent e5acedbe6c0395bbdeae33debd9d523c837ec398
Author: cfillion <cfillion@users.noreply.github.com>
Date: Fri, 18 Dec 2015 18:24:42 -0500
handle duplicate sources gracefully
Diffstat:
18 files changed, 177 insertions(+), 148 deletions(-)
diff --git a/src/database.cpp b/src/database.cpp
@@ -23,7 +23,7 @@
using namespace std;
-Database *Database::load(const char *file)
+Database *Database::load(const string &name, const char *file)
{
TiXmlDocument doc(file);
@@ -44,12 +44,19 @@ Database *Database::load(const char *file)
switch(version) {
case 1:
- return loadV1(root);
+ return loadV1(root, name);
default:
throw reapack_error("unsupported version");
}
}
+Database::Database(const string &name)
+ : m_name(name)
+{
+ if(m_name.empty())
+ throw reapack_error("empty database name");
+}
+
Database::~Database()
{
for(Category *cat : m_categories)
@@ -68,8 +75,8 @@ void Database::addCategory(Category *cat)
cat->packages().begin(), cat->packages().end());
}
-Category::Category(const string &name)
- : m_database(nullptr), m_name(name)
+Category::Category(const string &name, Database *db)
+ : m_database(db), m_name(name)
{
if(m_name.empty())
throw reapack_error("empty category name");
diff --git a/src/database.hpp b/src/database.hpp
@@ -34,11 +34,11 @@ typedef std::vector<Category *> CategoryList;
class Database {
public:
- static Database *load(const char *);
+ static Database *load(const std::string &name, const char *url);
+ Database(const std::string &name);
~Database();
- void setName(const std::string &name) { m_name = name; }
const std::string &name() const { return m_name; }
void addCategory(Category *cat);
@@ -48,7 +48,7 @@ public:
const PackageList &packages() const { return m_packages; }
private:
- static Database *loadV1(TiXmlElement *);
+ static Database *loadV1(TiXmlElement *, const std::string &);
std::string m_name;
CategoryList m_categories;
@@ -57,7 +57,7 @@ private:
class Category {
public:
- Category(const std::string &name);
+ Category(const std::string &name, Database * = nullptr);
~Category();
const std::string &name() const { return m_name; }
diff --git a/src/database_v1.cpp b/src/database_v1.cpp
@@ -25,13 +25,13 @@
using namespace std;
-static Category *LoadCategoryV1(TiXmlElement *);
-static Package *LoadPackageV1(TiXmlElement *);
-static Version *LoadVersionV1(TiXmlElement *);
+static void LoadCategoryV1(TiXmlElement *, Database *db);
+static void LoadPackageV1(TiXmlElement *, Category *cat);
+static void LoadVersionV1(TiXmlElement *, Package *pkg);
-Database *Database::loadV1(TiXmlElement *root)
+Database *Database::loadV1(TiXmlElement *root, const string &name)
{
- Database *db = new Database;
+ Database *db = new Database(name);
// ensure the memory is released if an exception is
// thrown during the loading process
@@ -40,7 +40,7 @@ Database *Database::loadV1(TiXmlElement *root)
TiXmlElement *catNode = root->FirstChildElement("category");
while(catNode) {
- db->addCategory(LoadCategoryV1(catNode));
+ LoadCategoryV1(catNode, db);
catNode = catNode->NextSiblingElement("category");
}
@@ -49,27 +49,28 @@ Database *Database::loadV1(TiXmlElement *root)
return db;
}
-Category *LoadCategoryV1(TiXmlElement *catNode)
+void LoadCategoryV1(TiXmlElement *catNode, Database *db)
{
const char *name = catNode->Attribute("name");
if(!name) name = "";
- Category *cat = new Category(name);
+ Category *cat = new Category(name, db);
unique_ptr<Category> ptr(cat);
TiXmlElement *packNode = catNode->FirstChildElement("reapack");
while(packNode) {
- cat->addPackage(LoadPackageV1(packNode));
+ LoadPackageV1(packNode, cat);
packNode = packNode->NextSiblingElement("reapack");
}
+ db->addCategory(cat);
+
ptr.release();
- return cat;
}
-Package *LoadPackageV1(TiXmlElement *packNode)
+void LoadPackageV1(TiXmlElement *packNode, Category *cat)
{
const char *type = packNode->Attribute("type");
if(!type) type = "";
@@ -77,27 +78,28 @@ Package *LoadPackageV1(TiXmlElement *packNode)
const char *name = packNode->Attribute("name");
if(!name) name = "";
- Package *pack = new Package(Package::ConvertType(type), name);
+ Package *pack = new Package(Package::ConvertType(type), name, cat);
unique_ptr<Package> ptr(pack);
TiXmlElement *verNode = packNode->FirstChildElement("version");
while(verNode) {
- pack->addVersion(LoadVersionV1(verNode));
+ LoadVersionV1(verNode, pack);
verNode = verNode->NextSiblingElement("version");
}
+ cat->addPackage(pack);
+
ptr.release();
- return pack;
}
-Version *LoadVersionV1(TiXmlElement *verNode)
+void LoadVersionV1(TiXmlElement *verNode, Package *pkg)
{
const char *name = verNode->Attribute("name");
if(!name) name = "";
- Version *ver = new Version(name);
+ Version *ver = new Version(name, pkg);
unique_ptr<Version> ptr(ver);
TiXmlElement *node = verNode->FirstChildElement("source");
@@ -126,6 +128,7 @@ Version *LoadVersionV1(TiXmlElement *verNode)
ver->setChangelog(changelog);
}
+ pkg->addVersion(ver);
+
ptr.release();
- return ver;
}
diff --git a/src/package.cpp b/src/package.cpp
@@ -32,8 +32,8 @@ Package::Type Package::ConvertType(const char *type)
return UnknownType;
}
-Package::Package(const Type type, const string &name)
- : m_category(nullptr), m_type(type), m_name(name)
+Package::Package(const Type type, const string &name, Category *cat)
+ : m_category(cat), m_type(type), m_name(name)
{
if(m_name.empty())
throw reapack_error("empty package name");
diff --git a/src/package.hpp b/src/package.hpp
@@ -35,7 +35,7 @@ public:
static Type ConvertType(const char *);
- Package(const Type, const std::string &name);
+ Package(const Type, const std::string &name, Category * = nullptr);
~Package();
void setCategory(Category *cat) { m_category = cat; }
diff --git a/src/path.cpp b/src/path.cpp
@@ -81,6 +81,11 @@ bool Path::operator!=(const Path &o) const
return !(*this == o);
}
+bool Path::operator<(const Path &o) const
+{
+ return m_parts < o.m_parts;
+}
+
Path Path::operator+(const string &part) const
{
Path path(*this);
diff --git a/src/path.hpp b/src/path.hpp
@@ -36,6 +36,7 @@ public:
bool operator==(const Path &) const;
bool operator!=(const Path &) const;
+ bool operator<(const Path &) const;
Path operator+(const std::string &) const;
Path operator+(const Path &) const;
std::string &operator[](const size_t index);
diff --git a/src/pkgtransaction.cpp b/src/pkgtransaction.cpp
@@ -33,10 +33,11 @@ PackageTransaction::PackageTransaction(Transaction *transaction)
void PackageTransaction::install(Version *ver)
{
- const size_t sourcesSize = ver->sources().size();
+ const auto &sources = ver->sources();
- for(size_t i = 0; i < sourcesSize; i++) {
- Source *src = ver->source(i);
+ for(auto it = sources.begin(); it != sources.end();) {
+ const Path &path = it->first;
+ Source *src = it->second;
Download *dl = new Download(src->fullName(), src->url());
dl->onFinish(bind(&PackageTransaction::saveSource, this, dl, src));
@@ -47,6 +48,9 @@ void PackageTransaction::install(Version *ver)
// executing finish after the download is deleted
// prevents the download queue from being deleted before the download is
dl->onFinish(bind(&PackageTransaction::finish, this));
+
+ // skip duplicate files
+ do { it++; } while(it != sources.end() && path == it->first);
}
}
diff --git a/src/transaction.cpp b/src/transaction.cpp
@@ -70,8 +70,7 @@ void Transaction::saveDatabase(Download *dl)
return;
try {
- Database *db = Database::load(path.join().c_str());
- db->setName(dl->name());
+ Database *db = Database::load(dl->name(), path.join().c_str());
m_databases.push_back(db);
}
@@ -89,7 +88,7 @@ void Transaction::prepare()
for(Package *pkg : db->packages()) {
Registry::QueryResult entry = m_registry->query(pkg);
- vector<Path> files = pkg->lastVersion()->files();
+ set<Path> files = pkg->lastVersion()->files();
registerFiles(files);
if(entry.status == Registry::UpToDate && allFilesExists(files))
@@ -191,7 +190,7 @@ Path Transaction::prefixPath(const Path &input) const
return m_root + input;
}
-bool Transaction::allFilesExists(const vector<Path> &list) const
+bool Transaction::allFilesExists(const set<Path> &list) const
{
for(const Path &path : list) {
if(!file_exists(prefixPath(path).join().c_str()))
@@ -201,24 +200,17 @@ bool Transaction::allFilesExists(const vector<Path> &list) const
return true;
}
-void Transaction::registerFiles(const vector<Path> &list)
+void Transaction::registerFiles(const set<Path> &list)
{
- m_files.insert(m_files.end(), list.begin(), list.end());
-
- const auto dupBegin = unique(m_files.begin(), m_files.end());
-
- if(dupBegin == m_files.end())
- return;
-
- auto it = dupBegin;
+ for(const Path &path : list) {
+ if(!m_files.count(path))
+ continue;
- do {
addError("Conflict: This file is owned by more than one package",
- it->join());
+ path.join());
- it++;
- } while(it != m_files.end());
+ m_hasConflicts = true;
+ }
- m_files.erase(dupBegin, m_files.end());
- m_hasConflicts = true;
+ m_files.insert(list.begin(), list.end());
}
diff --git a/src/transaction.hpp b/src/transaction.hpp
@@ -72,8 +72,8 @@ private:
bool saveFile(Download *, const Path &);
void addError(const std::string &msg, const std::string &title);
Path prefixPath(const Path &) const;
- bool allFilesExists(const std::vector<Path> &) const;
- void registerFiles(const std::vector<Path> &);
+ bool allFilesExists(const std::set<Path> &) const;
+ void registerFiles(const std::set<Path> &);
Registry *m_registry;
@@ -89,7 +89,7 @@ private:
ErrorList m_errors;
std::vector<PackageTransaction *> m_transactions;
- std::vector<Path> m_files;
+ std::set<Path> m_files;
bool m_hasConflicts;
Signal m_onReady;
diff --git a/src/version.cpp b/src/version.cpp
@@ -26,8 +26,8 @@
using namespace std;
-Version::Version(const std::string &str)
- : m_name(str), m_code(0), m_package(nullptr)
+Version::Version(const std::string &str, Package *pkg)
+ : m_name(str), m_code(0), m_package(pkg)
{
static const regex pattern("(\\d+)");
@@ -54,8 +54,8 @@ Version::Version(const std::string &str)
Version::~Version()
{
- for(Source *source : m_sources)
- delete source;
+ for(auto pair : m_sources)
+ delete pair.second;
}
string Version::fullName() const
@@ -94,7 +94,10 @@ void Version::addSource(Source *source)
#endif
source->setVersion(this);
- m_sources.push_back(source);
+
+ const Path path = source->targetPath();
+ m_files.insert(path);
+ m_sources.insert({path, source});
}
void Version::setChangelog(const std::string &changelog)
@@ -102,16 +105,14 @@ void Version::setChangelog(const std::string &changelog)
m_changelog = changelog;
}
-vector<Path> Version::files() const
+Source *Version::source(const size_t index) const
{
- const size_t size = m_sources.size();
-
- vector<Path> list(size);
+ auto it = m_sources.begin();
- for(size_t i = 0; i < size; i++)
- list[i] = m_sources[i]->targetPath();
+ for(size_t i = 0; i < index; i++)
+ it++;
- return list;
+ return it->second;
}
bool Version::operator<(const Version &o) const
diff --git a/src/version.hpp b/src/version.hpp
@@ -19,6 +19,7 @@
#define REAPACK_VERSION_HPP
#include <cstdint>
+#include <map>
#include <set>
#include <string>
@@ -28,7 +29,7 @@ class Package;
class Version {
public:
- Version(const std::string &);
+ Version(const std::string &, Package * = nullptr);
~Version();
const std::string &name() const { return m_name; }
@@ -42,10 +43,10 @@ public:
const std::string &changelog() const { return m_changelog; }
void addSource(Source *source);
- const SourceList &sources() const { return m_sources; }
- Source *source(const size_t i) const { return m_sources[i]; }
+ const std::multimap<Path, Source *> &sources() const { return m_sources; }
+ Source *source(const size_t) const;
- std::vector<Path> files() const;
+ const std::set<Path> &files() const { return m_files; }
bool operator<(const Version &) const;
@@ -56,7 +57,8 @@ private:
Package *m_package;
std::string m_changelog;
- SourceList m_sources;
+ std::multimap<Path, Source *> m_sources;
+ std::set<Path> m_files;
};
class VersionCompare {
diff --git a/test/database.cpp b/test/database.cpp
@@ -14,7 +14,7 @@ static const char *M = "[database]";
TEST_CASE("file not found", M) {
try {
- Database *db = Database::load(DBPATH "404.xml");
+ Database *db = Database::load("a", DBPATH "404.xml");
DBPTR(db);
FAIL();
}
@@ -25,7 +25,7 @@ TEST_CASE("file not found", M) {
TEST_CASE("broken xml", M) {
try {
- Database *db = Database::load(DBPATH "broken.xml");
+ Database *db = Database::load("a", DBPATH "broken.xml");
DBPTR(db);
FAIL();
}
@@ -36,7 +36,7 @@ TEST_CASE("broken xml", M) {
TEST_CASE("wrong root tag name", M) {
try {
- Database *db = Database::load(DBPATH "wrong_root.xml");
+ Database *db = Database::load("a", DBPATH "wrong_root.xml");
DBPTR(db);
FAIL();
}
@@ -47,7 +47,7 @@ TEST_CASE("wrong root tag name", M) {
TEST_CASE("invalid version", M) {
try {
- Database *db = Database::load(DBPATH "invalid_version.xml");
+ Database *db = Database::load("a", DBPATH "invalid_version.xml");
DBPTR(db);
FAIL();
}
@@ -58,7 +58,7 @@ TEST_CASE("invalid version", M) {
TEST_CASE("future version", M) {
try {
- Database *db = Database::load(DBPATH "future_version.xml");
+ Database *db = Database::load("a", DBPATH "future_version.xml");
DBPTR(db);
FAIL();
}
@@ -66,17 +66,28 @@ TEST_CASE("future version", M) {
REQUIRE(string(e.what()) == "unsupported version");
}
}
+
+TEST_CASE("empty database name", M) {
+ try {
+ Database cat{string()};
+ FAIL();
+ }
+ catch(const reapack_error &e) {
+ REQUIRE(string(e.what()) == "empty database name");
+ }
+}
+
TEST_CASE("add category", M) {
- Version *ver = new Version("1");
- ver->addSource(new Source(Source::GenericPlatform, string(), "google.com"));
+ Database db("a");
+ Category *cat = new Category("a", &db);
+ Package *pack = new Package(Package::ScriptType, "name", cat);
+ Source *source = new Source(Source::GenericPlatform, string(), "google.com");
+ Version *ver = new Version("1", pack);
- Package *pack = new Package(Package::ScriptType, "name");
+ ver->addSource(source);
pack->addVersion(ver);
-
- Category *cat = new Category("a");
cat->addPackage(pack);
- Database db;
CHECK(db.categories().size() == 0);
db.addCategory(cat);
@@ -86,27 +97,29 @@ TEST_CASE("add category", M) {
}
TEST_CASE("drop empty category", M) {
- Database db;
+ Database db("a");
db.addCategory(new Category("a"));
REQUIRE(db.categories().empty());
}
TEST_CASE("add a package", M) {
- Version *ver = new Version("1");
+ Database db("a");
+ Category cat1("a", &db);
+ Package *pack = new Package(Package::ScriptType, "name", &cat1);
+ Version *ver = new Version("1", pack);
ver->addSource(new Source(Source::GenericPlatform, string(), "google.com"));
-
- Package *pack = new Package(Package::ScriptType, "name");
pack->addVersion(ver);
- Category cat("a");
- CHECK(cat.packages().size() == 0);
- CHECK_FALSE(pack->category());
+ CHECK(pack->category() == &cat1);
+
+ Category cat2("b");
+ CHECK(cat2.packages().size() == 0);
- cat.addPackage(pack);
+ cat2.addPackage(pack);
- REQUIRE(cat.packages().size() == 1);
- REQUIRE(pack->category() == &cat);
+ REQUIRE(cat2.packages().size() == 1);
+ REQUIRE(pack->category() == &cat2);
}
TEST_CASE("drop empty package", M) {
@@ -137,8 +150,7 @@ TEST_CASE("category full name", M) {
Category cat("Category Name");
REQUIRE(cat.fullName() == "Category Name");
- Database db;
- db.setName("Database Name");
+ Database db("Database Name");
cat.setDatabase(&db);
REQUIRE(cat.fullName() == "Database Name/Category Name");
}
diff --git a/test/database_v1.cpp b/test/database_v1.cpp
@@ -15,7 +15,7 @@ static const char *M = "[reapack_v1]";
TEST_CASE("unnamed category", M) {
try {
- Database *db = Database::load(DBPATH "unnamed_category.xml");
+ Database *db = Database::load("a", DBPATH "unnamed_category.xml");
DBPTR(db);
FAIL();
}
@@ -25,14 +25,14 @@ TEST_CASE("unnamed category", M) {
}
TEST_CASE("invalid category tag", M) {
- Database *db = Database::load(DBPATH "wrong_category_tag.xml");
+ Database *db = Database::load("a", DBPATH "wrong_category_tag.xml");
DBPTR(db);
REQUIRE(db->categories().empty());
}
TEST_CASE("invalid package tag", M) {
- Database *db = Database::load(DBPATH "wrong_package_tag.xml");
+ Database *db = Database::load("a", DBPATH "wrong_package_tag.xml");
DBPTR(db);
REQUIRE(db->categories().empty());
@@ -40,7 +40,7 @@ TEST_CASE("invalid package tag", M) {
TEST_CASE("null package name", M) {
try {
- Database *db = Database::load(DBPATH "unnamed_package.xml");
+ Database *db = Database::load("a", DBPATH "unnamed_package.xml");
DBPTR(db);
FAIL();
}
@@ -51,7 +51,7 @@ TEST_CASE("null package name", M) {
TEST_CASE("null package type", M) {
try {
- Database *db = Database::load(DBPATH "missing_type.xml");
+ Database *db = Database::load("a", DBPATH "missing_type.xml");
DBPTR(db);
}
catch(const reapack_error &) {
@@ -60,7 +60,7 @@ TEST_CASE("null package type", M) {
}
TEST_CASE("invalid version tag", M) {
- Database *db = Database::load(DBPATH "wrong_version_tag.xml");
+ Database *db = Database::load("a", DBPATH "wrong_version_tag.xml");
DBPTR(db);
REQUIRE(db->categories().empty());
@@ -68,7 +68,7 @@ TEST_CASE("invalid version tag", M) {
TEST_CASE("null package version", M) {
try {
- Database *db = Database::load(DBPATH "missing_version.xml");
+ Database *db = Database::load("a", DBPATH "missing_version.xml");
DBPTR(db);
FAIL();
}
@@ -79,7 +79,7 @@ TEST_CASE("null package version", M) {
TEST_CASE("null source url", M) {
try {
- Database *db = Database::load(DBPATH "missing_source_url.xml");
+ Database *db = Database::load("a", DBPATH "missing_source_url.xml");
DBPTR(db);
FAIL();
}
@@ -89,7 +89,7 @@ TEST_CASE("null source url", M) {
}
TEST_CASE("null source file", M) {
- Database *db = Database::load(DBPATH "missing_source_file.xml");
+ Database *db = Database::load("a", DBPATH "missing_source_file.xml");
DBPTR(db);
Package *pkg = db->category(0)->package(0);
@@ -97,7 +97,7 @@ TEST_CASE("null source file", M) {
}
TEST_CASE("default platform", M) {
- Database *db = Database::load(DBPATH "missing_platform.xml");
+ Database *db = Database::load("a", DBPATH "missing_platform.xml");
DBPTR(db);
REQUIRE(db->category(0)->package(0)->version(0)->source(0)->platform()
@@ -105,7 +105,7 @@ TEST_CASE("default platform", M) {
}
TEST_CASE("version changelog", M) {
- Database *db = Database::load(DBPATH "changelog.xml");
+ Database *db = Database::load("a", DBPATH "changelog.xml");
DBPTR(db);
CHECK_FALSE(db->categories().empty());
@@ -117,7 +117,7 @@ TEST_CASE("version changelog", M) {
}
TEST_CASE("full database", M) {
- Database *db = Database::load(DBPATH "full_database.xml");
+ Database *db = Database::load("a", DBPATH "full_database.xml");
DBPTR(db);
REQUIRE(db->categories().size() == 1);
diff --git a/test/package.cpp b/test/package.cpp
@@ -33,16 +33,19 @@ TEST_CASE("empty package name", M) {
}
TEST_CASE("package versions are sorted", M) {
- Package pack(Package::ScriptType, "a");
+ Database db("Database Name");
+ Category cat("Category Name", &db);
+
+ Package pack(Package::ScriptType, "a", &cat);
CHECK(pack.versions().size() == 0);
Source *sourceA = new Source(Source::GenericPlatform, string(), "google.com");
Source *sourceB = new Source(Source::GenericPlatform, string(), "google.com");
- Version *final = new Version("1");
+ Version *final = new Version("1", &pack);
final->addSource(sourceA);
- Version *alpha = new Version("0.1");
+ Version *alpha = new Version("0.1", &pack);
alpha->addSource(sourceB);
pack.addVersion(final);
@@ -66,7 +69,7 @@ TEST_CASE("drop empty version", M) {
}
TEST_CASE("unknown target path", M) {
- Database db;
+ Database db("name");
Category cat("name");
cat.setDatabase(&db);
@@ -83,8 +86,7 @@ TEST_CASE("unknown target path", M) {
}
TEST_CASE("script target path", M) {
- Database db;
- db.setName("Database Name");
+ Database db("Database Name");
Category cat("Category Name");
cat.setDatabase(&db);
@@ -113,8 +115,7 @@ TEST_CASE("script target path without category", M) {
}
TEST_CASE("full name", M) {
- Database db;
- db.setName("Database Name");
+ Database db("Database Name");
Category cat("Category Name");
diff --git a/test/registry.cpp b/test/registry.cpp
@@ -9,13 +9,11 @@ using namespace std;
static const char *M = "[registry]";
#define MAKE_PACKAGE \
- Database db; \
- db.setName("Hello"); \
+ Database db("Hello"); \
Category cat("Hello"); \
cat.setDatabase(&db); \
- Package pkg(Package::ScriptType, "Hello"); \
- pkg.setCategory(&cat); \
- Version *ver = new Version("1.0"); \
+ Package pkg(Package::ScriptType, "Hello", &cat); \
+ Version *ver = new Version("1.0", &pkg); \
Source *src = new Source(Source::GenericPlatform, "file", "url"); \
ver->addSource(src); \
pkg.addVersion(ver);
@@ -45,6 +43,7 @@ TEST_CASE("bump version", M) {
MAKE_PACKAGE
Version *ver2 = new Version("2.0");
+ ver2->setPackage(&pkg);
ver2->addSource(new Source(Source::GenericPlatform, "file", "url"));
Registry reg;
diff --git a/test/source.cpp b/test/source.cpp
@@ -103,8 +103,7 @@ TEST_CASE("full name with version", M) {
}
TEST_CASE("source target path", M) {
- Database db;
- db.setName("Database Name");
+ Database db("Database Name");
Category cat("Category Name");
cat.setDatabase(&db);
diff --git a/test/version.cpp b/test/version.cpp
@@ -8,6 +8,12 @@
using namespace std;
+#define MAKE_VERSION \
+ Database db("Database Name"); \
+ Category cat("Category Name", &db); \
+ Package pkg(Package::ScriptType, "Hello", &cat); \
+ Version ver("1", &pkg);
+
static const char *M = "[version]";
TEST_CASE("invalid", M) {
@@ -89,18 +95,19 @@ TEST_CASE("version full name", M) {
pkg.setCategory(&cat);
REQUIRE(ver.fullName() == "Category Name/file.name v1.0");
- Database db;
- db.setName("Database Name");
+ Database db("Database Name");
cat.setDatabase(&db);
REQUIRE(ver.fullName() == "Database Name/Category Name/file.name v1.0");
}
TEST_CASE("add source", M) {
- Source *src = new Source(Source::GenericPlatform, "a", "b");
+ MAKE_VERSION
- Version ver("1");
CHECK(ver.sources().size() == 0);
+
+ Source *src = new Source(Source::GenericPlatform, "a", "b");
ver.addSource(src);
+
CHECK(ver.sources().size() == 1);
REQUIRE(src->version() == &ver);
@@ -108,33 +115,23 @@ TEST_CASE("add source", M) {
}
TEST_CASE("list files", M) {
- Source *src1 = new Source(Source::GenericPlatform, "file", "url");
+ MAKE_VERSION
- Version ver("1");
+ Source *src1 = new Source(Source::GenericPlatform, "file", "url");
ver.addSource(src1);
- Package pkg(Package::ScriptType, "name");
- ver.setPackage(&pkg);
-
- Category cat("Category Name");
- pkg.setCategory(&cat);
-
- Database db;
- db.setName("Database Name");
- cat.setDatabase(&db);
-
Path path1;
path1.append("Scripts");
path1.append("Database Name");
path1.append("Category Name");
path1.append("file");
- const vector<Path> expected{path1};
+ const set<Path> expected{path1};
REQUIRE(ver.files() == expected);
}
TEST_CASE("drop sources for unknown platforms", M) {
- Version ver("1");
+ MAKE_VERSION
ver.addSource(new Source(Source::UnknownPlatform, "a", "b"));
REQUIRE(ver.sources().size() == 0);
@@ -142,7 +139,8 @@ TEST_CASE("drop sources for unknown platforms", M) {
#ifdef __APPLE__
TEST_CASE("drop windows sources on os x", M) {
- Version ver("1");
+ MAKE_VERSION
+
ver.addSource(new Source(Source::WindowsPlatform, "a", "b"));
ver.addSource(new Source(Source::Win32Platform, "a", "b"));
ver.addSource(new Source(Source::Win64Platform, "a", "b"));
@@ -152,14 +150,15 @@ TEST_CASE("drop windows sources on os x", M) {
#ifdef __x86_64__
TEST_CASE("drop 32-bit sources on os x 64-bit", M) {
- Version ver("1");
+ MAKE_VERSION
ver.addSource(new Source(Source::Darwin32Platform, "a", "b"));
REQUIRE(ver.sources().size() == 0);
}
TEST_CASE("valid sources for os x 64-bit", M) {
- Version ver("1");
+ MAKE_VERSION
+
ver.addSource(new Source(Source::GenericPlatform, "a", "b"));
ver.addSource(new Source(Source::DarwinPlatform, "a", "b"));
ver.addSource(new Source(Source::Darwin64Platform, "a", "b"));
@@ -168,14 +167,15 @@ TEST_CASE("valid sources for os x 64-bit", M) {
}
#else
TEST_CASE("drop 64-bit sources on os x 32-bit", M) {
- Version ver("1");
+ MAKE_VERSION
ver.addSource(new Source(Source::Darwin64Platform, "a", "b"));
REQUIRE(ver.sources().size() == 0);
}
TEST_CASE("valid sources for os x 32-bit", M) {
- Version ver("1");
+ MAKE_VERSION
+
ver.addSource(new Source(Source::GenericPlatform, "a", "b"));
ver.addSource(new Source(Source::DarwinPlatform, "a", "b"));
ver.addSource(new Source(Source::Darwin32Platform, "a", "b"));
@@ -186,7 +186,8 @@ TEST_CASE("valid sources for os x 32-bit", M) {
#elif _WIN32
TEST_CASE("drop os x sources on windows", M) {
- Version ver("1");
+ MAKE_VERSION
+
ver.addSource(new Source(Source::DarwinPlatform, "a", "b"));
ver.addSource(new Source(Source::Darwin32Platform, "a", "b"));
ver.addSource(new Source(Source::Darwin64Platform, "a", "b"));
@@ -196,14 +197,15 @@ TEST_CASE("drop os x sources on windows", M) {
#ifdef _WIN64
TEST_CASE("drop 32-bit sources on windows 64-bit", M) {
- Version ver("1");
+ MAKE_VERSION
ver.addSource(new Source(Source::Win32Platform, "a", "b"));
REQUIRE(ver.sources().size() == 0);
}
TEST_CASE("valid sources for windows 64-bit", M) {
- Version ver("1");
+ MAKE_VERSION
+
ver.addSource(new Source(Source::GenericPlatform, "a", "b"));
ver.addSource(new Source(Source::WindowsPlatform, "a", "b"));
ver.addSource(new Source(Source::Win64Platform, "a", "b"));
@@ -212,14 +214,15 @@ TEST_CASE("valid sources for windows 64-bit", M) {
}
#else
TEST_CASE("drop 64-bit sources on windows 32-bit", M) {
- Version ver("1");
+ MAKE_VERSION
ver.addSource(new Source(Source::Win64Platform, "a", "b"));
REQUIRE(ver.sources().size() == 0);
}
TEST_CASE("valid sources for windows 32-bit", M) {
- Version ver("1");
+ MAKE_VERSION
+
ver.addSource(new Source(Source::GenericPlatform, "a", "b"));
ver.addSource(new Source(Source::WindowsPlatform, "a", "b"));
ver.addSource(new Source(Source::Win32Platform, "a", "b"));