reapack

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

commit a2d8dd75cdfd063a9bbc995445d1bc804b760eb2
parent 73534ade0dbf10568935a636c8ab530dc15011f3
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu, 10 Dec 2015 23:54:31 -0500

split the source class to its own file and mild refactoring

Diffstat:
Msrc/database_v1.cpp | 4++--
Msrc/package.cpp | 2+-
Msrc/package.hpp | 2+-
Asrc/source.cpp | 30++++++++++++++++++++++++++++++
Asrc/source.hpp | 39+++++++++++++++++++++++++++++++++++++++
Msrc/version.cpp | 27---------------------------
Msrc/version.hpp | 33+--------------------------------
Mtest/database.cpp | 10----------
Mtest/package.cpp | 10++++++++++
Atest/source.cpp | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/version.cpp | 48+-----------------------------------------------
11 files changed, 139 insertions(+), 120 deletions(-)

diff --git a/src/database_v1.cpp b/src/database_v1.cpp @@ -60,7 +60,7 @@ 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); unique_ptr<Package> ptr(pack); TiXmlElement *verNode = packNode->FirstChildElement("version"); @@ -92,7 +92,7 @@ Version *LoadVersionV1(TiXmlElement *verNode) const char *url = node->GetText(); if(!url) url = ""; - ver->addSource(new Source(Source::convertPlatform(platform), url)); + ver->addSource(new Source(Source::ConvertPlatform(platform), url)); node = node->NextSiblingElement("source"); } diff --git a/src/package.cpp b/src/package.cpp @@ -7,7 +7,7 @@ using namespace std; -Package::Type Package::convertType(const char *type) +Package::Type Package::ConvertType(const char *type) { if(!strcmp(type, "script")) return ScriptType; diff --git a/src/package.hpp b/src/package.hpp @@ -16,7 +16,7 @@ public: ScriptType, }; - static Type convertType(const char *); + static Type ConvertType(const char *); Package(const Type, const std::string &name); ~Package(); diff --git a/src/source.cpp b/src/source.cpp @@ -0,0 +1,30 @@ +#include "source.hpp" + +#include "errors.hpp" + +Source::Platform Source::ConvertPlatform(const char *platform) +{ + if(!strcmp(platform, "all")) + return GenericPlatform; + else if(!strcmp(platform, "windows")) + return WindowsPlatform; + else if(!strcmp(platform, "win32")) + return Win32Platform; + else if(!strcmp(platform, "win64")) + return Win64Platform; + else if(!strcmp(platform, "darwin")) + return DarwinPlatform; + else if(!strcmp(platform, "darwin32")) + return Darwin32Platform; + else if(!strcmp(platform, "darwin64")) + return Darwin64Platform; + else + return UnknownPlatform; +} + +Source::Source(const Platform platform, const std::string &url) + : m_platform(platform), m_url(url) +{ + if(m_url.empty()) + throw reapack_error("empty source url"); +} diff --git a/src/source.hpp b/src/source.hpp @@ -0,0 +1,39 @@ +#ifndef REAPACK_SOURCE_HPP +#define REAPACK_SOURCE_HPP + +#include <string> +#include <vector> + +class Source; +typedef std::vector<Source *> SourceList; + +class Source { +public: + enum Platform { + UnknownPlatform, + GenericPlatform, + + // windows + WindowsPlatform, + Win32Platform, + Win64Platform, + + // os x + DarwinPlatform, + Darwin32Platform, + Darwin64Platform, + }; + + static Platform ConvertPlatform(const char *); + + Source(const Platform, const std::string &source); + + Platform platform() const { return m_platform; } + const std::string &url() const { return m_url; } + +private: + Platform m_platform; + std::string m_url; +}; + +#endif diff --git a/src/version.cpp b/src/version.cpp @@ -87,30 +87,3 @@ bool Version::operator<(const Version &o) const { return m_code < o.code(); } - -Source::Platform Source::convertPlatform(const char *platform) -{ - if(!strcmp(platform, "all")) - return GenericPlatform; - else if(!strcmp(platform, "windows")) - return WindowsPlatform; - else if(!strcmp(platform, "win32")) - return Win32Platform; - else if(!strcmp(platform, "win64")) - return Win64Platform; - else if(!strcmp(platform, "darwin")) - return DarwinPlatform; - else if(!strcmp(platform, "darwin32")) - return Darwin32Platform; - else if(!strcmp(platform, "darwin64")) - return Darwin64Platform; - else - return UnknownPlatform; -} - -Source::Source(const Platform platform, const std::string &url) - : m_platform(platform), m_url(url) -{ - if(m_url.empty()) - throw reapack_error("empty source url"); -} diff --git a/src/version.hpp b/src/version.hpp @@ -3,10 +3,8 @@ #include <set> #include <string> -#include <vector> -class Source; -typedef std::vector<Source *> SourceList; +#include "source.hpp" class Package; @@ -51,33 +49,4 @@ public: typedef std::set<Version *, VersionCompare> VersionSet; -class Source { -public: - enum Platform { - UnknownPlatform, - GenericPlatform, - - // windows - WindowsPlatform, - Win32Platform, - Win64Platform, - - // os x - DarwinPlatform, - Darwin32Platform, - Darwin64Platform, - }; - - static Platform convertPlatform(const char *); - - Source(const Platform, const std::string &source); - - Platform platform() const { return m_platform; } - const std::string &url() const { return m_url; } - -private: - Platform m_platform; - std::string m_url; -}; - #endif diff --git a/test/database.cpp b/test/database.cpp @@ -123,16 +123,6 @@ TEST_CASE("drop unknown package", M) { REQUIRE(cat.packages().size() == 0); } -TEST_CASE("package type from string", M) { - SECTION("unknown") { - REQUIRE(Package::convertType("yoyo") == Package::UnknownType); - } - - SECTION("script") { - REQUIRE(Package::convertType("script") == Package::ScriptType); - } -} - TEST_CASE("empty category name", M) { try { Category cat{string()}; diff --git a/test/package.cpp b/test/package.cpp @@ -12,6 +12,16 @@ using namespace std; static const char *M = "[package]"; +TEST_CASE("package type from string", M) { + SECTION("unknown") { + REQUIRE(Package::ConvertType("yoyo") == Package::UnknownType); + } + + SECTION("script") { + REQUIRE(Package::ConvertType("script") == Package::ScriptType); + } +} + TEST_CASE("empty package name", M) { try { Package pack(Package::ScriptType, string()); diff --git a/test/source.cpp b/test/source.cpp @@ -0,0 +1,54 @@ +#include <catch.hpp> + +#include <source.hpp> + +#include <errors.hpp> + +using namespace std; + +static const char *M = "[source]"; + +TEST_CASE("convert platforms", M) { + SECTION("unknown") { + REQUIRE(Source::ConvertPlatform("hello") == Source::UnknownPlatform); + } + + SECTION("generic") { + REQUIRE(Source::ConvertPlatform("all") == Source::GenericPlatform); + } + + SECTION("generic windows") { + REQUIRE(Source::ConvertPlatform("windows") == Source::WindowsPlatform); + } + + SECTION("windows 32-bit") { + REQUIRE(Source::ConvertPlatform("win32") == Source::Win32Platform); + } + + SECTION("windows 64-bit") { + REQUIRE(Source::ConvertPlatform("win64") == Source::Win64Platform); + } + + SECTION("generic os x") { + REQUIRE(Source::ConvertPlatform("darwin") == Source::DarwinPlatform); + } + + SECTION("os x 32-bit") { + REQUIRE(Source::ConvertPlatform("darwin32") == Source::Darwin32Platform); + } + + SECTION("os x 64-bit") { + REQUIRE(Source::ConvertPlatform("darwin64") == Source::Darwin64Platform); + } +} + +TEST_CASE("empty source url", M) { + try { + Source source(Source::UnknownPlatform, string()); + FAIL(); + } + catch(const reapack_error &e) { + REQUIRE(string(e.what()) == "empty source url"); + } +} + diff --git a/test/version.cpp b/test/version.cpp @@ -6,8 +6,6 @@ #include <errors.hpp> #include <package.hpp> -#include <string> - using namespace std; static const char *M = "[version]"; @@ -97,51 +95,7 @@ TEST_CASE("version full name", M) { REQUIRE(ver.fullName() == "Database Name/Category Name/file.name v1.0"); } -TEST_CASE("convert platforms", M) { - SECTION("unknown") { - REQUIRE(Source::convertPlatform("hello") == Source::UnknownPlatform); - } - - SECTION("generic") { - REQUIRE(Source::convertPlatform("all") == Source::GenericPlatform); - } - - SECTION("generic windows") { - REQUIRE(Source::convertPlatform("windows") == Source::WindowsPlatform); - } - - SECTION("windows 32-bit") { - REQUIRE(Source::convertPlatform("win32") == Source::Win32Platform); - } - - SECTION("windows 64-bit") { - REQUIRE(Source::convertPlatform("win64") == Source::Win64Platform); - } - - SECTION("generic os x") { - REQUIRE(Source::convertPlatform("darwin") == Source::DarwinPlatform); - } - - SECTION("os x 32-bit") { - REQUIRE(Source::convertPlatform("darwin32") == Source::Darwin32Platform); - } - - SECTION("os x 64-bit") { - REQUIRE(Source::convertPlatform("darwin64") == Source::Darwin64Platform); - } -} - -TEST_CASE("empty source url", M) { - try { - Source source(Source::UnknownPlatform, string()); - FAIL(); - } - catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "empty source url"); - } -} - -TEST_CASE("drow sources for unknown platforms") { +TEST_CASE("drop sources for unknown platforms") { Version ver("1"); ver.addSource(new Source(Source::UnknownPlatform, "a"));