reapack

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

index_v1.cpp (8337B)


      1 #include "helper.hpp"
      2 
      3 #include <index.hpp>
      4 #include <errors.hpp>
      5 
      6 static const char *M = "[reapack_v1]";
      7 static const Path RIPATH("test/indexes/v1");
      8 
      9 TEST_CASE("unnamed category", M) {
     10   UseRootPath root(RIPATH);
     11 
     12   try {
     13     IndexPtr ri = Index::load("unnamed_category");
     14     FAIL();
     15   }
     16   catch(const reapack_error &e) {
     17     REQUIRE(std::string{e.what()} == "empty category name");
     18   }
     19 }
     20 
     21 TEST_CASE("invalid category tag", M) {
     22   UseRootPath root(RIPATH);
     23 
     24   IndexPtr ri = Index::load("wrong_category_tag");
     25 
     26   REQUIRE(ri->categories().empty());
     27 }
     28 
     29 TEST_CASE("invalid package tag", M) {
     30   UseRootPath root(RIPATH);
     31 
     32   IndexPtr ri = Index::load("wrong_package_tag");
     33   REQUIRE(ri->categories().empty());
     34 
     35 }
     36 
     37 TEST_CASE("null package name", M) {
     38   UseRootPath root(RIPATH);
     39 
     40   try {
     41     IndexPtr ri = Index::load("unnamed_package");
     42     FAIL();
     43   }
     44   catch(const reapack_error &e) {
     45     REQUIRE(std::string{e.what()} == "empty package name");
     46   }
     47 }
     48 
     49 TEST_CASE("null package type", M) {
     50   UseRootPath root(RIPATH);
     51 
     52   try {
     53     IndexPtr ri = Index::load("missing_type");
     54   }
     55   catch(const reapack_error &) {
     56     // no segfault -> test passes!
     57   }
     58 }
     59 
     60 TEST_CASE("unsupported package type", M) {
     61   UseRootPath root(RIPATH);
     62 
     63   IndexPtr ri = Index::load("unsupported_type");
     64 }
     65 
     66 TEST_CASE("read version author", M) {
     67   UseRootPath root(RIPATH);
     68 
     69   IndexPtr ri = Index::load("author");
     70 
     71   CHECK(ri->packages().size() == 1);
     72   REQUIRE(ri->category(0)->package(0)->version(0)->author()
     73     == "Watanabe Saki");
     74 }
     75 
     76 TEST_CASE("read version time", M) {
     77   UseRootPath root(RIPATH);
     78 
     79   IndexPtr ri = Index::load("time");
     80   CHECK(ri->packages().size() == 1);
     81 
     82   const Time &time = ri->category(0)->package(0)->version(0)->time();
     83   REQUIRE(time.year() == 2016);
     84   REQUIRE(time.month() == 2);
     85   REQUIRE(time.day() == 12);
     86 }
     87 
     88 TEST_CASE("invalid version tag", M) {
     89   UseRootPath root(RIPATH);
     90 
     91   IndexPtr ri = Index::load("wrong_version_tag");
     92   REQUIRE(ri->categories().empty());
     93 }
     94 
     95 TEST_CASE("null package version", M) {
     96   UseRootPath root(RIPATH);
     97 
     98   try {
     99     IndexPtr ri = Index::load("missing_version");
    100     FAIL();
    101   }
    102   catch(const reapack_error &e) {
    103     REQUIRE(std::string{e.what()} == "invalid version name ''");
    104   }
    105 }
    106 
    107 TEST_CASE("null source url", M) {
    108   UseRootPath root(RIPATH);
    109 
    110   try {
    111     IndexPtr ri = Index::load("missing_source_url");
    112     FAIL();
    113   }
    114   catch(const reapack_error &e) {
    115     REQUIRE(std::string{e.what()} == "empty source url");
    116   }
    117 }
    118 
    119 TEST_CASE("null source file", M) {
    120   UseRootPath root(RIPATH);
    121 
    122   IndexPtr ri = Index::load("missing_source_file");
    123   CHECK(ri->packages().size() == 1);
    124 
    125   const Package *pkg = ri->category(0)->package(0);
    126   REQUIRE(pkg->version(0)->source(0)->file() == pkg->name());
    127 }
    128 
    129 TEST_CASE("default source platform", M) {
    130   UseRootPath root(RIPATH);
    131 
    132   IndexPtr ri = Index::load("missing_platform");
    133 
    134   CHECK(ri->packages().size() == 1);
    135   REQUIRE(ri->category(0)->package(0)->version(0)->source(0)->platform()
    136     == Platform::Generic);
    137 }
    138 
    139 TEST_CASE("version changelog", M) {
    140   UseRootPath root(RIPATH);
    141 
    142   IndexPtr ri = Index::load("changelog");
    143   CHECK(ri->packages().size() == 1);
    144 
    145   REQUIRE(ri->category(0)->package(0)->version(0)->changelog()
    146     == "Hello\nWorld");
    147 }
    148 
    149 TEST_CASE("full index", M) {
    150   UseRootPath root(RIPATH);
    151 
    152   IndexPtr ri = Index::load("valid_index");
    153 
    154   REQUIRE(ri->categories().size() == 1);
    155   const Category *cat = ri->category(0);
    156   REQUIRE(cat->name() == "Category Name");
    157 
    158   REQUIRE(cat->packages().size() == 1);
    159   const Package *pack = cat->package(0);
    160   REQUIRE(pack->type() == Package::ScriptType);
    161   REQUIRE(pack->name() == "Hello World.lua");
    162 
    163   REQUIRE(pack->versions().size() == 1);
    164   const Version *ver = pack->version(0);
    165   REQUIRE(ver->name() == VersionName("1.0"));
    166   REQUIRE(ver->changelog() == "Fixed a division by zero error.");
    167 
    168   REQUIRE(ver->sources().size() == 2);
    169   const Source *source1 = ver->source(0);
    170   REQUIRE(source1->platform() == Platform::Generic);
    171   REQUIRE(source1->file() == "test.lua");
    172   REQUIRE(source1->sections() == Source::MainSection);
    173   REQUIRE(source1->url() == "https://google.com/");
    174 
    175   const Source *source2 = ver->source(1);
    176   REQUIRE(source2->platform() == Platform::Generic);
    177   REQUIRE(source2->file() == "background.png");
    178   REQUIRE_FALSE(source2->sections() == Source::MainSection);
    179   REQUIRE(source2->url() == "http://cfillion.tk/");
    180 }
    181 
    182 TEST_CASE("read index metadata", M) {
    183   UseRootPath root(RIPATH);
    184 
    185   IndexPtr ri = Index::load("metadata");
    186 
    187   SECTION("name (ignored)") {
    188     REQUIRE(ri->name() == "metadata");
    189   }
    190 
    191   SECTION("description") {
    192     REQUIRE(ri->metadata()->about() == "Chunky\nBacon");
    193   }
    194 
    195   SECTION("links") {
    196     REQUIRE(ri->metadata()->links().size() == 5);
    197 
    198     auto link = ri->metadata()->links().begin();
    199     REQUIRE(link->first == Metadata::WebsiteLink);
    200     REQUIRE(link->second.name == "http://cfillion.tk");
    201     REQUIRE(link->second.url == "http://cfillion.tk");
    202 
    203     REQUIRE((++link)->second.name == "https://github.com/cfillion");
    204     REQUIRE(link->second.url == "https://github.com/cfillion");
    205 
    206     REQUIRE((++link)->second.name == "http://twitter.com/cfi30");
    207     REQUIRE(link->second.url == "http://twitter.com/cfi30");
    208 
    209     REQUIRE((++link)->second.name == "http://google.com");
    210     REQUIRE(link->second.url == "http://google.com");
    211 
    212     REQUIRE((++link)->first == Metadata::DonationLink);
    213     REQUIRE(link->second.name == "Donate");
    214     REQUIRE(link->second.url == "http://paypal.com");
    215   }
    216 }
    217 
    218 TEST_CASE("read package metadata", M) {
    219   UseRootPath root(RIPATH);
    220 
    221   IndexPtr ri = Index::load("pkg_metadata");
    222   REQUIRE(ri->packages().size() == 1);
    223 
    224   const Package *pkg = ri->packages()[0];
    225 
    226   SECTION("description") {
    227     REQUIRE(pkg->metadata()->about() == "Chunky\nBacon");
    228   }
    229 
    230   SECTION("links") {
    231     REQUIRE(pkg->metadata()->links().size() == 2);
    232 
    233     auto link = pkg->metadata()->links().begin();
    234     REQUIRE(link->first == Metadata::WebsiteLink);
    235     REQUIRE(link->second.name == "http://cfillion.tk");
    236     REQUIRE(link->second.url == "http://cfillion.tk");
    237 
    238     REQUIRE((++link)->first == Metadata::DonationLink);
    239     REQUIRE(link->second.name == "Donate");
    240     REQUIRE(link->second.url == "http://paypal.com");
    241   }
    242 }
    243 
    244 TEST_CASE("read index name (from raw data only)") {
    245   SECTION("valid") {
    246     IndexPtr ri = Index::load({}, "<index version=\"1\" name=\"Hello World\"/>\n");
    247     REQUIRE(ri->name() == "Hello World");
    248   }
    249 
    250   SECTION("missing") {
    251     IndexPtr ri = Index::load({}, "<index version=\"1\"/>\n");
    252     REQUIRE(ri->name() == "");
    253   }
    254 }
    255 
    256 TEST_CASE("read source platform", M) {
    257   UseRootPath root(RIPATH);
    258 
    259   IndexPtr ri = Index::load("src_platform");
    260 
    261   REQUIRE(ri->packages().size() == 1);
    262 
    263 #ifdef __APPLE__
    264   const auto expected = Platform::Darwin_Any;
    265 #elif _WIN32
    266   const auto expected = Platform::Windows_Any;
    267 #elif __linux__
    268   const auto expected = Platform::Linux_Any;
    269 #endif
    270 
    271   REQUIRE(ri->category(0)->package(0)->version(0)->source(0)->platform()
    272     == expected);
    273 }
    274 
    275 TEST_CASE("read source type override", M) {
    276   UseRootPath root(RIPATH);
    277 
    278   IndexPtr ri = Index::load("src_type");
    279 
    280   CHECK(ri->packages().size() == 1);
    281   REQUIRE(ri->category(0)->package(0)->version(0)->source(0)->typeOverride()
    282     == Package::EffectType);
    283 }
    284 
    285 TEST_CASE("read package description", M) {
    286   UseRootPath root(RIPATH);
    287 
    288   IndexPtr ri = Index::load("pkg_desc");
    289 
    290   CHECK(ri->packages().size() == 1);
    291   REQUIRE(ri->category(0)->package(0)->description() == "From the New World");
    292 }
    293 
    294 TEST_CASE("read multiple sections", M) {
    295   UseRootPath root(RIPATH);
    296 
    297   IndexPtr ri = Index::load("explicit_sections");
    298 
    299   CHECK(ri->packages().size() == 1);
    300   REQUIRE(ri->category(0)->package(0)->version(0)->source(0)->sections()
    301     == (Source::MainSection | Source::MIDIEditorSection));
    302 }
    303 
    304 TEST_CASE("read sha256 checksum", M) {
    305   IndexPtr ri = Index::load({}, R"(
    306 <index version="1">
    307   <category name="catname">
    308     <reapack name="packname" type="script">
    309       <version name="1.0" author="John Doe">
    310         <source hash="12206037d8b51b33934348a2b26e04f0eb7227315b87bb5688ceb6dccb0468b14cce">https://google.com/</source>
    311       </version>
    312     </reapack>
    313   </category>
    314 </index>
    315   )");
    316 
    317   REQUIRE(ri->packages().size() == 1);
    318 
    319   REQUIRE(ri->category(0)->package(0)->version(0)->source(0)->checksum()
    320     == "12206037d8b51b33934348a2b26e04f0eb7227315b87bb5688ceb6dccb0468b14cce");
    321 }