reapack

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

commit dd74b8859ec58d6ce5d38896635b1aa85fb7a368
parent 73d2f3ae0010b382cfe11b10ee2a17dbfdb962a7
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 31 Jan 2016 16:59:45 -0500

centralize index loading and path generation

Diffstat:
Msrc/index.cpp | 10++++++++--
Msrc/index.hpp | 8+++++---
Msrc/transaction.cpp | 6++----
Mtest/index.cpp | 28+++++++++++++++++++++-------
Mtest/index_v1.cpp | 48++++++++++++++++++++++++++++++++++++------------
Rtest/indexes/broken.xml -> test/indexes/ReaPack/broken.xml | 0
Rtest/indexes/future_version.xml -> test/indexes/ReaPack/future_version.xml | 0
Rtest/indexes/invalid_version.xml -> test/indexes/ReaPack/invalid_version.xml | 0
Rtest/indexes/wrong_root.xml -> test/indexes/ReaPack/wrong_root.xml | 0
Rtest/indexes/Новая папка.xml -> test/indexes/ReaPack/Новая папка.xml | 0
Rtest/indexes/v1/anonymous_package.xml -> test/indexes/v1/ReaPack/anonymous_package.xml | 0
Rtest/indexes/v1/changelog.xml -> test/indexes/v1/ReaPack/changelog.xml | 0
Rtest/indexes/v1/missing_platform.xml -> test/indexes/v1/ReaPack/missing_platform.xml | 0
Rtest/indexes/v1/missing_source_file.xml -> test/indexes/v1/ReaPack/missing_source_file.xml | 0
Rtest/indexes/v1/missing_source_url.xml -> test/indexes/v1/ReaPack/missing_source_url.xml | 0
Rtest/indexes/v1/missing_type.xml -> test/indexes/v1/ReaPack/missing_type.xml | 0
Rtest/indexes/v1/missing_version.xml -> test/indexes/v1/ReaPack/missing_version.xml | 0
Rtest/indexes/v1/unnamed_category.xml -> test/indexes/v1/ReaPack/unnamed_category.xml | 0
Rtest/indexes/v1/unnamed_package.xml -> test/indexes/v1/ReaPack/unnamed_package.xml | 0
Rtest/indexes/v1/valid_index.xml -> test/indexes/v1/ReaPack/valid_index.xml | 0
Rtest/indexes/v1/wrong_category_tag.xml -> test/indexes/v1/ReaPack/wrong_category_tag.xml | 0
Rtest/indexes/v1/wrong_package_tag.xml -> test/indexes/v1/ReaPack/wrong_package_tag.xml | 0
Rtest/indexes/v1/wrong_version_tag.xml -> test/indexes/v1/ReaPack/wrong_version_tag.xml | 0
23 files changed, 72 insertions(+), 28 deletions(-)

diff --git a/src/index.cpp b/src/index.cpp @@ -19,6 +19,7 @@ #include "encoding.hpp" #include "errors.hpp" +#include "path.hpp" #include <WDL/tinyxml/tinyxml.h> @@ -35,11 +36,16 @@ static FILE *OpenFile(const char *path) #endif } -RemoteIndex *RemoteIndex::load(const string &name, const char *path) +Path RemoteIndex::pathFor(const string &name) +{ + return Path::prefixCache(name + ".xml"); +} + +RemoteIndex *RemoteIndex::load(const string &name) { TiXmlDocument doc; - FILE *file = OpenFile(path); + FILE *file = OpenFile(pathFor(name).join().c_str()); const bool success = doc.LoadFile(file); diff --git a/src/index.hpp b/src/index.hpp @@ -24,14 +24,16 @@ #include "package.hpp" -class TiXmlElement; - class Category; typedef std::vector<Category *> CategoryList; +class Path; +class TiXmlElement; + class RemoteIndex { public: - static RemoteIndex *load(const std::string &name, const char *url); + static Path pathFor(const std::string &name); + static RemoteIndex *load(const std::string &name); RemoteIndex(const std::string &name); ~RemoteIndex(); diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -72,15 +72,13 @@ void Transaction::synchronize(const Remote &remote, const bool isUserAction) void Transaction::upgradeAll(Download *dl) { - const Path path = Path::prefixCache("remote_" + dl->name() + ".xml"); - - if(!saveFile(dl, path)) + if(!saveFile(dl, RemoteIndex::pathFor(dl->name()))) return; RemoteIndex *ri; try { - ri = RemoteIndex::load(dl->name(), path.join().c_str()); + ri = RemoteIndex::load(dl->name()); m_remoteIndexes.push_back(ri); } catch(const reapack_error &e) { diff --git a/test/index.cpp b/test/index.cpp @@ -13,8 +13,10 @@ using namespace std; static const char *M = "[index]"; TEST_CASE("file not found", M) { + UseRootPath root(RIPATH); + try { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "404.xml"); + RemoteIndex *ri = RemoteIndex::load("404"); RIPTR(ri); FAIL(); } @@ -23,9 +25,11 @@ TEST_CASE("file not found", M) { } } -TEST_CASE("broken xml", M) { +TEST_CASE("broken", M) { + UseRootPath root(RIPATH); + try { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "broken.xml"); + RemoteIndex *ri = RemoteIndex::load("broken"); RIPTR(ri); FAIL(); } @@ -35,8 +39,10 @@ TEST_CASE("broken xml", M) { } TEST_CASE("wrong root tag name", M) { + UseRootPath root(RIPATH); + try { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "wrong_root.xml"); + RemoteIndex *ri = RemoteIndex::load("wrong_root"); RIPTR(ri); FAIL(); } @@ -46,8 +52,10 @@ TEST_CASE("wrong root tag name", M) { } TEST_CASE("invalid version", M) { + UseRootPath root(RIPATH); + try { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "invalid_version.xml"); + RemoteIndex *ri = RemoteIndex::load("invalid_version"); RIPTR(ri); FAIL(); } @@ -57,8 +65,10 @@ TEST_CASE("invalid version", M) { } TEST_CASE("future version", M) { + UseRootPath root(RIPATH); + try { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "future_version.xml"); + RemoteIndex *ri = RemoteIndex::load("future_version"); RIPTR(ri); FAIL(); } @@ -68,8 +78,12 @@ TEST_CASE("future version", M) { } TEST_CASE("unicode index path", M) { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "Новая папка.xml"); + UseRootPath root(RIPATH); + + RemoteIndex *ri = RemoteIndex::load("Новая папка"); RIPTR(ri); + + REQUIRE(ri->name() == "Новая папка"); } TEST_CASE("empty index name", M) { diff --git a/test/index_v1.cpp b/test/index_v1.cpp @@ -14,8 +14,10 @@ using namespace std; static const char *M = "[reapack_v1]"; TEST_CASE("unnamed category", M) { + UseRootPath root(RIPATH); + try { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "unnamed_category.xml"); + RemoteIndex *ri = RemoteIndex::load("unnamed_category"); RIPTR(ri); FAIL(); } @@ -25,22 +27,28 @@ TEST_CASE("unnamed category", M) { } TEST_CASE("invalid category tag", M) { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "wrong_category_tag.xml"); + UseRootPath root(RIPATH); + + RemoteIndex *ri = RemoteIndex::load("wrong_category_tag"); RIPTR(ri); REQUIRE(ri->categories().empty()); } TEST_CASE("invalid package tag", M) { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "wrong_package_tag.xml"); + UseRootPath root(RIPATH); + + RemoteIndex *ri = RemoteIndex::load("wrong_package_tag"); RIPTR(ri); REQUIRE(ri->categories().empty()); } TEST_CASE("null package name", M) { + UseRootPath root(RIPATH); + try { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "unnamed_package.xml"); + RemoteIndex *ri = RemoteIndex::load("unnamed_package"); RIPTR(ri); FAIL(); } @@ -50,8 +58,10 @@ TEST_CASE("null package name", M) { } TEST_CASE("null package type", M) { + UseRootPath root(RIPATH); + try { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "missing_type.xml"); + RemoteIndex *ri = RemoteIndex::load("missing_type"); RIPTR(ri); } catch(const reapack_error &) { @@ -60,15 +70,19 @@ TEST_CASE("null package type", M) { } TEST_CASE("invalid version tag", M) { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "wrong_version_tag.xml"); + UseRootPath root(RIPATH); + + RemoteIndex *ri = RemoteIndex::load("wrong_version_tag"); RIPTR(ri); REQUIRE(ri->categories().empty()); } TEST_CASE("null package version", M) { + UseRootPath root(RIPATH); + try { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "missing_version.xml"); + RemoteIndex *ri = RemoteIndex::load("missing_version"); RIPTR(ri); FAIL(); } @@ -78,8 +92,10 @@ TEST_CASE("null package version", M) { } TEST_CASE("null source url", M) { + UseRootPath root(RIPATH); + try { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "missing_source_url.xml"); + RemoteIndex *ri = RemoteIndex::load("missing_source_url"); RIPTR(ri); FAIL(); } @@ -89,7 +105,9 @@ TEST_CASE("null source url", M) { } TEST_CASE("null source file", M) { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "missing_source_file.xml"); + UseRootPath root(RIPATH); + + RemoteIndex *ri = RemoteIndex::load("missing_source_file"); RIPTR(ri); Package *pkg = ri->category(0)->package(0); @@ -97,7 +115,9 @@ TEST_CASE("null source file", M) { } TEST_CASE("default platform", M) { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "missing_platform.xml"); + UseRootPath root(RIPATH); + + RemoteIndex *ri = RemoteIndex::load("missing_platform"); RIPTR(ri); REQUIRE(ri->category(0)->package(0)->version(0)->source(0)->platform() @@ -105,7 +125,9 @@ TEST_CASE("default platform", M) { } TEST_CASE("version changelog", M) { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "changelog.xml"); + UseRootPath root(RIPATH); + + RemoteIndex *ri = RemoteIndex::load("changelog"); RIPTR(ri); CHECK_FALSE(ri->categories().empty()); @@ -117,7 +139,9 @@ TEST_CASE("version changelog", M) { } TEST_CASE("full index", M) { - RemoteIndex *ri = RemoteIndex::load("a", RIPATH "valid_index.xml"); + UseRootPath root(RIPATH); + + RemoteIndex *ri = RemoteIndex::load("valid_index"); RIPTR(ri); REQUIRE(ri->categories().size() == 1); diff --git a/test/indexes/broken.xml b/test/indexes/ReaPack/broken.xml diff --git a/test/indexes/future_version.xml b/test/indexes/ReaPack/future_version.xml diff --git a/test/indexes/invalid_version.xml b/test/indexes/ReaPack/invalid_version.xml diff --git a/test/indexes/wrong_root.xml b/test/indexes/ReaPack/wrong_root.xml diff --git a/test/indexes/Новая папка.xml b/test/indexes/ReaPack/Новая папка.xml diff --git a/test/indexes/v1/anonymous_package.xml b/test/indexes/v1/ReaPack/anonymous_package.xml diff --git a/test/indexes/v1/changelog.xml b/test/indexes/v1/ReaPack/changelog.xml diff --git a/test/indexes/v1/missing_platform.xml b/test/indexes/v1/ReaPack/missing_platform.xml diff --git a/test/indexes/v1/missing_source_file.xml b/test/indexes/v1/ReaPack/missing_source_file.xml diff --git a/test/indexes/v1/missing_source_url.xml b/test/indexes/v1/ReaPack/missing_source_url.xml diff --git a/test/indexes/v1/missing_type.xml b/test/indexes/v1/ReaPack/missing_type.xml diff --git a/test/indexes/v1/missing_version.xml b/test/indexes/v1/ReaPack/missing_version.xml diff --git a/test/indexes/v1/unnamed_category.xml b/test/indexes/v1/ReaPack/unnamed_category.xml diff --git a/test/indexes/v1/unnamed_package.xml b/test/indexes/v1/ReaPack/unnamed_package.xml diff --git a/test/indexes/v1/valid_index.xml b/test/indexes/v1/ReaPack/valid_index.xml diff --git a/test/indexes/v1/wrong_category_tag.xml b/test/indexes/v1/ReaPack/wrong_category_tag.xml diff --git a/test/indexes/v1/wrong_package_tag.xml b/test/indexes/v1/ReaPack/wrong_package_tag.xml diff --git a/test/indexes/v1/wrong_version_tag.xml b/test/indexes/v1/ReaPack/wrong_version_tag.xml