reapack

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

serializer.cpp (1509B)


      1 #include "helper.hpp"
      2 
      3 #include <serializer.hpp>
      4 
      5 static const char *M = "[serializer]";
      6 
      7 TEST_CASE("read from serialized data", M) {
      8   Serializer s;
      9   REQUIRE(s.userVersion() == 0);
     10   REQUIRE_FALSE(s);
     11 
     12   SECTION("valid") {
     13     const auto &out = s.read("1 1,1 2,3 4,5 6", 1);
     14     REQUIRE(out.size() == 3);
     15     auto it = out.begin();
     16     REQUIRE(*it++ == (Serializer::Record{1,2}));
     17     REQUIRE(*it++ == (Serializer::Record{3,4}));
     18     REQUIRE(*it++ == (Serializer::Record{5,6}));
     19 
     20     REQUIRE(s.userVersion() == 1);
     21     REQUIRE(s);
     22   }
     23 
     24   SECTION("wrong user version") {
     25     const auto &out = s.read("1 1,1 2,3 4,5 6", 2);
     26     REQUIRE(out.empty());
     27     REQUIRE(s.userVersion() == 2);
     28     REQUIRE(s);
     29   }
     30 
     31   SECTION("wrong data version") {
     32     const auto &out = s.read("1 42,1 2,3 4,5 6", 1);
     33     REQUIRE(out.empty());
     34     REQUIRE(s.userVersion() == 1);
     35     REQUIRE(s);
     36   }
     37 
     38   SECTION("not an integer") {
     39     const auto &out = s.read("1 1,1 2,hello world,3 4", 1);
     40     REQUIRE(out.size() == 1);
     41     REQUIRE(out.front() == (Serializer::Record{1,2}));
     42   }
     43 
     44   SECTION("single field") {
     45     const auto &out = s.read("1 1,1 2,3,4 5", 1);
     46     REQUIRE(out.size() == 1);
     47     REQUIRE(out.front() == (Serializer::Record{1,2}));
     48   }
     49 
     50   SECTION("empty string") {
     51     const auto &out = s.read({}, 1);
     52     REQUIRE(out.empty());
     53   }
     54 }
     55 
     56 TEST_CASE("write to string", M) {
     57   Serializer s;
     58   REQUIRE(s.write({{1, 2}}).empty()); // no user version set
     59   s.read({}, 42);
     60 
     61   REQUIRE(s.write({{1, 2}, {3, 4}}) == "42 1,1 2,3 4");
     62 }