reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 424648b418ff3136e0514406ea0cb0f98267972b
parent 6094d93f76215e4bcbde5a62aadf670b90c6006c
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Tue, 19 Apr 2016 21:25:42 -0400

refactoring of source construction

Diffstat:
Msrc/index_v1.cpp | 4+++-
Msrc/reapack.cpp | 3+--
Msrc/source.cpp | 5++---
Msrc/source.hpp | 5+++--
Mtest/index.cpp | 4++--
Mtest/package.cpp | 6+++---
Mtest/registry.cpp | 10+++++-----
Mtest/source.cpp | 39+++++++++++++++++++++++++--------------
Mtest/version.cpp | 63++++++++++++++++++++++++++++++++++++---------------------------
9 files changed, 80 insertions(+), 59 deletions(-)

diff --git a/src/index_v1.cpp b/src/index_v1.cpp @@ -149,7 +149,9 @@ void LoadVersionV1(TiXmlElement *verNode, Package *pkg) const char *url = node->GetText(); if(!url) url = ""; - ver->addSource(new Source(Source::ConvertPlatform(platform), file, url, ver)); + Source *src = new Source(file, url, ver); + src->setPlatform(Source::ConvertPlatform(platform)); + ver->addSource(src); node = node->NextSiblingElement("source"); } diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -554,8 +554,7 @@ void ReaPack::registerSelf() Category cat("Extensions", &ri); Package pkg(Package::ExtensionType, "ReaPack.ext", &cat); Version ver(VERSION, &pkg); - ver.addSource(new Source(Source::GenericPlatform, - REAPACK_FILE, "dummy url", &ver)); + ver.addSource(new Source(REAPACK_FILE, "dummy url", &ver)); try { Registry reg(Path::prefixRoot(Path::REGISTRY)); diff --git a/src/source.cpp b/src/source.cpp @@ -43,9 +43,8 @@ Source::Platform Source::ConvertPlatform(const char *platform) return UnknownPlatform; } -Source::Source(const Platform platform, const string &file, - const string &url, const Version *ver) - : m_platform(platform), m_file(file), m_url(url), m_version(ver) +Source::Source(const string &file, const string &url, const Version *ver) + : m_platform(GenericPlatform), m_file(file), m_url(url), m_version(ver) { if(m_url.empty()) throw reapack_error("empty source url"); diff --git a/src/source.hpp b/src/source.hpp @@ -50,9 +50,10 @@ public: static Platform ConvertPlatform(const char *); - Source(const Platform, const std::string &file, - const std::string &url, const Version * = nullptr); + Source(const std::string &file, const std::string &url, + const Version * = nullptr); + void setPlatform(Platform p) { m_platform = p; } Platform platform() const { return m_platform; } bool isMain() const { return m_file.empty(); } diff --git a/test/index.cpp b/test/index.cpp @@ -99,7 +99,7 @@ TEST_CASE("add a category", M) { Category *cat = new Category("a", &ri); Package *pack = new Package(Package::ScriptType, "name", cat); Version *ver = new Version("1", pack); - Source *source = new Source(Source::GenericPlatform, {}, "google.com", ver); + Source *source = new Source({}, "google.com", ver); ver->addSource(source); pack->addVersion(ver); @@ -143,7 +143,7 @@ TEST_CASE("add a package", M) { Category cat("a", &ri); Package *pack = new Package(Package::ScriptType, "name", &cat); Version *ver = new Version("1", pack); - ver->addSource(new Source(Source::GenericPlatform, {}, "google.com", ver)); + ver->addSource(new Source({}, "google.com", ver)); pack->addVersion(ver); CHECK(cat.packages().size() == 0); diff --git a/test/package.cpp b/test/package.cpp @@ -77,10 +77,10 @@ TEST_CASE("package versions are sorted", M) { CHECK(pack.versions().size() == 0); Version *final = new Version("1", &pack); - final->addSource(new Source(Source::GenericPlatform, {}, "google.com", final)); + final->addSource(new Source({}, "google.com", final)); Version *alpha = new Version("0.1", &pack); - alpha->addSource(new Source(Source::GenericPlatform, {}, "google.com", alpha)); + alpha->addSource(new Source({}, "google.com", alpha)); pack.addVersion(final); REQUIRE(final->package() == &pack); @@ -126,7 +126,7 @@ TEST_CASE("find matching version", M) { CHECK(pack.versions().size() == 0); Version *ver = new Version("1", &pack); - ver->addSource(new Source(Source::GenericPlatform, {}, "google.com", ver)); + ver->addSource(new Source({}, "google.com", ver)); REQUIRE(pack.findVersion(Version("1")) == nullptr); REQUIRE(pack.findVersion(Version("2")) == nullptr); diff --git a/test/registry.cpp b/test/registry.cpp @@ -19,7 +19,7 @@ static const char *M = "[registry]"; Package pkg(Package::ScriptType, "Hello", &cat); \ Version *ver = new Version("1.0", &pkg); \ ver->setAuthor("John Doe"); \ - Source *src = new Source(Source::GenericPlatform, "file", "url", ver); \ + Source *src = new Source("file", "url", ver); \ ver->addSource(src); \ pkg.addVersion(ver); @@ -63,7 +63,7 @@ TEST_CASE("bump version", M) { MAKE_PACKAGE Version *ver2 = new Version("2.0", &pkg); - ver2->addSource(new Source(Source::GenericPlatform, "file", "url", ver2)); + ver2->addSource(new Source("file", "url", ver2)); Registry reg; reg.push(ver); @@ -137,8 +137,8 @@ TEST_CASE("file conflicts", M) { Category cat("Category Name", &ri); Package pkg(Package::ScriptType, "Duplicate Package", &cat); Version *ver = new Version("1.0", &pkg); - Source *src1 = new Source(Source::GenericPlatform, "file", "url", ver); - Source *src2 = new Source(Source::GenericPlatform, "file2", "url", ver); + Source *src1 = new Source("file", "url", ver); + Source *src2 = new Source("file2", "url", ver); ver->addSource(src1); ver->addSource(src2); pkg.addVersion(ver); @@ -168,7 +168,7 @@ TEST_CASE("get main file", M) { Registry reg; REQUIRE((reg.getMainFile({})).empty()); - Source *main = new Source(Source::GenericPlatform, {}, "url", ver); + Source *main = new Source({}, "url", ver); ver->addSource(main); const Registry::Entry &entry = reg.push(ver); diff --git a/test/source.cpp b/test/source.cpp @@ -44,8 +44,19 @@ TEST_CASE("convert platforms", M) { } } +TEST_CASE("source platform", M) { + Source src({}, "url"); + REQUIRE(src.platform() == Source::GenericPlatform); + + src.setPlatform(Source::UnknownPlatform); + REQUIRE(src.platform() == Source::UnknownPlatform); + + src.setPlatform(Source::WindowsPlatform); + REQUIRE(src.platform() == Source::WindowsPlatform); +} + TEST_CASE("empty file name and no package", M) { - const Source source(Source::UnknownPlatform, string(), "b"); + const Source source({}, "url"); try { (void)source.file(); @@ -58,19 +69,19 @@ TEST_CASE("empty file name and no package", M) { TEST_CASE("main source", M) { SECTION("with file name") { - const Source source(Source::UnknownPlatform, "a", "b"); + const Source source("filename", "url"); REQUIRE_FALSE(source.isMain()); } SECTION("without file name") { - const Source source(Source::UnknownPlatform, string(), "b"); + const Source source({}, "url"); REQUIRE(source.isMain()); } } TEST_CASE("empty source url", M) { try { - const Source source(Source::UnknownPlatform, "a", string()); + const Source source("filename", {}); FAIL(); } catch(const reapack_error &e) { @@ -79,14 +90,14 @@ TEST_CASE("empty source url", M) { } TEST_CASE("full name without version", M) { - SECTION("with source name") { - const Source source(Source::UnknownPlatform, "path/to/file", "b"); + SECTION("with file name") { + const Source source("path/to/file", "b"); REQUIRE(source.fullName() == "file"); } SECTION("without file name") { try { - const Source source(Source::UnknownPlatform, string(), "b"); + const Source source({}, "b"); (void)source.fullName(); FAIL(); } @@ -97,16 +108,16 @@ TEST_CASE("full name without version", M) { } TEST_CASE("full name with version", M) { - SECTION("with source name") { + SECTION("with file name") { Version ver("1.0"); - const Source source(Source::UnknownPlatform, "path/to/file", "b", &ver); + const Source source("path/to/file", "b", &ver); REQUIRE(source.fullName() == "v1.0 (file)"); } - SECTION("without source name") { + SECTION("without file name") { Version ver("1.0"); - const Source source(Source::UnknownPlatform, string(), "b", &ver); + const Source source({}, "b", &ver); REQUIRE(source.fullName() == ver.fullName()); } @@ -118,7 +129,7 @@ TEST_CASE("source target path", M) { Package pack(Package::ScriptType, "package name", &cat); Version ver("1.0", &pack); - const Source source(Source::GenericPlatform, "file.name", "url", &ver); + const Source source("file.name", "url", &ver); Path expected; expected.append("Scripts"); @@ -135,7 +146,7 @@ TEST_CASE("source target path with parent directory traversal", M) { Package pack(Package::ScriptType, "package name", &cat); Version ver("1.0", &pack); - const Source source(Source::GenericPlatform, "../../../file.name", "url", &ver); + const Source source("../../../file.name", "url", &ver); Path expected; expected.append("Scripts"); @@ -148,7 +159,7 @@ TEST_CASE("source target path with parent directory traversal", M) { TEST_CASE("source target path without package", M) { try { - const Source source(Source::GenericPlatform, "a", "b"); + const Source source("a", "b"); (void)source.targetPath(); FAIL(); } diff --git a/test/version.cpp b/test/version.cpp @@ -16,6 +16,13 @@ using namespace std; Package pkg(Package::ScriptType, "Hello", &cat); \ Version ver("1", &pkg); +static Source *mksource(Source::Platform p, Version *parent) +{ + Source *src = new Source("file", "url", parent); + src->setPlatform(p); + return src; +} + static const char *M = "[version]"; TEST_CASE("invalid", M) { @@ -134,7 +141,7 @@ TEST_CASE("add source", M) { CHECK(ver.sources().size() == 0); - Source *src = new Source(Source::GenericPlatform, "a", "b", &ver); + Source *src = new Source("a", "b", &ver); ver.addSource(src); CHECK(ver.mainSource() == nullptr); @@ -148,7 +155,7 @@ TEST_CASE("add owned source", M) { MAKE_VERSION Version ver2("1"); - Source *src = new Source(Source::GenericPlatform, "a", "b", &ver2); + Source *src = new Source("a", "b", &ver2); try { ver.addSource(src); @@ -163,7 +170,7 @@ TEST_CASE("add owned source", M) { TEST_CASE("add main source", M) { MAKE_VERSION - Source *src = new Source(Source::GenericPlatform, string(), "b", &ver); + Source *src = new Source({}, "b", &ver); ver.addSource(src); REQUIRE(ver.mainSource() == src); @@ -172,7 +179,7 @@ TEST_CASE("add main source", M) { TEST_CASE("list files", M) { MAKE_VERSION - Source *src1 = new Source(Source::GenericPlatform, "file", "url", &ver); + Source *src1 = new Source("file", "url", &ver); ver.addSource(src1); Path path1; @@ -187,7 +194,9 @@ TEST_CASE("list files", M) { TEST_CASE("drop sources for unknown platforms", M) { MAKE_VERSION - ver.addSource(new Source(Source::UnknownPlatform, "a", "b", &ver)); + Source *src = new Source("a", "b", &ver); + src->setPlatform(Source::UnknownPlatform); + ver.addSource(src); REQUIRE(ver.sources().size() == 0); } @@ -334,9 +343,9 @@ TEST_CASE("version operators", M) { TEST_CASE("drop windows sources on os x", M) { MAKE_VERSION - ver.addSource(new Source(Source::WindowsPlatform, "a", "b", &ver)); - ver.addSource(new Source(Source::Win32Platform, "a", "b", &ver)); - ver.addSource(new Source(Source::Win64Platform, "a", "b", &ver)); + ver.addSource(mksource(Source::WindowsPlatform, &ver)); + ver.addSource(mksource(Source::Win32Platform, &ver)); + ver.addSource(mksource(Source::Win64Platform, &ver)); REQUIRE(ver.sources().size() == 0); } @@ -344,7 +353,7 @@ TEST_CASE("drop windows sources on os x", M) { #ifdef __x86_64__ TEST_CASE("drop 32-bit sources on os x 64-bit", M) { MAKE_VERSION - ver.addSource(new Source(Source::Darwin32Platform, "a", "b", &ver)); + ver.addSource(mksource(Source::Darwin32Platform, &ver)); REQUIRE(ver.sources().size() == 0); } @@ -352,16 +361,16 @@ TEST_CASE("drop 32-bit sources on os x 64-bit", M) { TEST_CASE("valid sources for os x 64-bit", M) { MAKE_VERSION - ver.addSource(new Source(Source::GenericPlatform, "a", "b", &ver)); - ver.addSource(new Source(Source::DarwinPlatform, "a", "b", &ver)); - ver.addSource(new Source(Source::Darwin64Platform, "a", "b", &ver)); + ver.addSource(mksource(Source::GenericPlatform, &ver)); + ver.addSource(mksource(Source::DarwinPlatform, &ver)); + ver.addSource(mksource(Source::Darwin64Platform, &ver)); REQUIRE(ver.sources().size() == 3); } #else TEST_CASE("drop 64-bit sources on os x 32-bit", M) { MAKE_VERSION - ver.addSource(new Source(Source::Darwin64Platform, "a", "b", &ver)); + ver.addSource(mksource(Source::Darwin64Platform, &ver)); REQUIRE(ver.sources().size() == 0); } @@ -369,9 +378,9 @@ TEST_CASE("drop 64-bit sources on os x 32-bit", M) { TEST_CASE("valid sources for os x 32-bit", M) { MAKE_VERSION - ver.addSource(new Source(Source::GenericPlatform, "a", "b", &ver)); - ver.addSource(new Source(Source::DarwinPlatform, "a", "b", &ver)); - ver.addSource(new Source(Source::Darwin32Platform, "a", "b", &ver)); + ver.addSource(mksource(Source::GenericPlatform, &ver)); + ver.addSource(mksource(Source::DarwinPlatform, &ver)); + ver.addSource(mksource(Source::Darwin32Platform, &ver)); REQUIRE(ver.sources().size() == 3); } @@ -381,9 +390,9 @@ TEST_CASE("valid sources for os x 32-bit", M) { TEST_CASE("drop os x sources on windows", M) { MAKE_VERSION - ver.addSource(new Source(Source::DarwinPlatform, "a", "b", &ver)); - ver.addSource(new Source(Source::Darwin32Platform, "a", "b", &ver)); - ver.addSource(new Source(Source::Darwin64Platform, "a", "b", &ver)); + ver.addSource(mksource(Source::DarwinPlatform, &ver)); + ver.addSource(mksource(Source::Darwin32Platform, &ver)); + ver.addSource(mksource(Source::Darwin64Platform, &ver)); REQUIRE(ver.sources().size() == 0); } @@ -391,7 +400,7 @@ TEST_CASE("drop os x sources on windows", M) { #ifdef _WIN64 TEST_CASE("drop 32-bit sources on windows 64-bit", M) { MAKE_VERSION - ver.addSource(new Source(Source::Win32Platform, "a", "b", &ver)); + ver.addSource(mksource(Source::Win32Platform, &ver)); REQUIRE(ver.sources().size() == 0); } @@ -399,16 +408,16 @@ TEST_CASE("drop 32-bit sources on windows 64-bit", M) { TEST_CASE("valid sources for windows 64-bit", M) { MAKE_VERSION - ver.addSource(new Source(Source::GenericPlatform, "a", "b", &ver)); - ver.addSource(new Source(Source::WindowsPlatform, "a", "b", &ver)); - ver.addSource(new Source(Source::Win64Platform, "a", "b", &ver)); + ver.addSource(mksource(Source::GenericPlatform, &ver)); + ver.addSource(mksource(Source::WindowsPlatform, &ver)); + ver.addSource(mksource(Source::Win64Platform, &ver)); REQUIRE(ver.sources().size() == 3); } #else TEST_CASE("drop 64-bit sources on windows 32-bit", M) { MAKE_VERSION - ver.addSource(new Source(Source::Win64Platform, "a", "b", &ver)); + ver.addSource(mksource(Source::Win64Platform, &ver)); REQUIRE(ver.sources().size() == 0); } @@ -416,9 +425,9 @@ TEST_CASE("drop 64-bit sources on windows 32-bit", M) { TEST_CASE("valid sources for windows 32-bit", M) { MAKE_VERSION - ver.addSource(new Source(Source::GenericPlatform, "a", "b", &ver)); - ver.addSource(new Source(Source::WindowsPlatform, "a", "b", &ver)); - ver.addSource(new Source(Source::Win32Platform, "a", "b", &ver)); + ver.addSource(mksource(Source::GenericPlatform, &ver)); + ver.addSource(mksource(Source::WindowsPlatform, &ver)); + ver.addSource(mksource(Source::Win32Platform, &ver)); REQUIRE(ver.sources().size() == 3); }