2020-01-31 21:23:48 +01:00
|
|
|
#include <router_version.hpp>
|
|
|
|
#include "router/router.hpp"
|
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
|
|
|
|
using Catch::Matchers::Equals;
|
2020-01-31 21:23:48 +01:00
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
TEST_CASE("Compatibility when protocol equal", "[RouterVersion]")
|
2020-01-31 21:23:48 +01:00
|
|
|
{
|
2021-03-01 22:07:32 +01:00
|
|
|
llarp::RouterVersion v1({0, 1, 2}, 1);
|
|
|
|
llarp::RouterVersion v2({0, 1, 2}, 1);
|
2020-01-31 21:23:48 +01:00
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
CHECK(v1.IsCompatableWith(v2));
|
2020-01-31 21:23:48 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
TEST_CASE("Compatibility when protocol unequal", "[RouterVersion]")
|
2020-01-31 21:23:48 +01:00
|
|
|
{
|
2021-03-01 22:07:32 +01:00
|
|
|
llarp::RouterVersion older({0, 1, 2}, 1);
|
|
|
|
llarp::RouterVersion newer({0, 1, 2}, 2);
|
2020-01-31 21:23:48 +01:00
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
CHECK_FALSE(older.IsCompatableWith(newer));
|
|
|
|
CHECK_FALSE(newer.IsCompatableWith(older));
|
2020-01-31 21:23:48 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
TEST_CASE("Empty compatibility", "[RouterVersion]")
|
2020-01-31 21:23:48 +01:00
|
|
|
{
|
2021-03-01 22:07:32 +01:00
|
|
|
llarp::RouterVersion v1({0, 0, 1}, LLARP_PROTO_VERSION);
|
2020-01-31 21:23:48 +01:00
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
CHECK_FALSE(v1.IsCompatableWith(llarp::emptyRouterVersion));
|
2020-01-31 21:23:48 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
TEST_CASE("IsEmpty", "[RouterVersion]")
|
2020-01-31 21:31:00 +01:00
|
|
|
{
|
2021-03-01 22:07:32 +01:00
|
|
|
llarp::RouterVersion notEmpty({0, 0, 1}, LLARP_PROTO_VERSION);
|
|
|
|
CHECK_FALSE(notEmpty.IsEmpty());
|
2020-01-31 21:31:00 +01:00
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
CHECK(llarp::emptyRouterVersion.IsEmpty());
|
2020-01-31 21:31:00 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
TEST_CASE("Clear", "[RouterVersion]")
|
2020-01-31 21:31:00 +01:00
|
|
|
{
|
2021-03-01 22:07:32 +01:00
|
|
|
llarp::RouterVersion version({0, 0, 1}, LLARP_PROTO_VERSION);
|
|
|
|
CHECK_FALSE(version.IsEmpty());
|
2020-01-31 21:31:00 +01:00
|
|
|
|
|
|
|
version.Clear();
|
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
CHECK(version.IsEmpty());
|
2020-01-31 21:31:00 +01:00
|
|
|
}
|
2020-01-31 21:23:48 +01:00
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
TEST_CASE("BEncode", "[RouterVersion]")
|
2020-01-31 22:48:00 +01:00
|
|
|
{
|
2021-03-01 22:07:32 +01:00
|
|
|
llarp::RouterVersion v1235({1, 2, 3}, 5);
|
2020-01-31 22:48:00 +01:00
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
std::array<byte_t, 128> tmp{};
|
2020-01-31 22:48:00 +01:00
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
CHECK(v1235.BEncode(&buf));
|
2020-01-31 22:48:00 +01:00
|
|
|
|
|
|
|
std::string s((const char*)buf.begin(), (buf.end() - buf.begin()));
|
|
|
|
LogInfo("bencoded: ", buf.begin());
|
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
CHECK_THAT((const char*)buf.begin(), Equals("li5ei1ei2ei3ee"));
|
2020-01-31 22:48:00 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
TEST_CASE("BDecode", "[RouterVersion]")
|
2020-01-31 22:48:00 +01:00
|
|
|
{
|
|
|
|
llarp::RouterVersion version;
|
|
|
|
version.Clear();
|
|
|
|
|
|
|
|
const std::string bString("li9ei3ei2ei1ee");
|
|
|
|
llarp_buffer_t buf(bString.data(), bString.size());
|
2021-03-01 22:07:32 +01:00
|
|
|
CHECK(version.BDecode(&buf));
|
2020-01-31 22:48:00 +01:00
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
llarp::RouterVersion expected({3, 2, 1}, 9);
|
2020-01-31 22:48:00 +01:00
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
CHECK(expected == version);
|
2020-01-31 22:48:00 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 22:07:32 +01:00
|
|
|
TEST_CASE("Decode long version array", "[RouterVersion]")
|
2020-01-31 22:48:00 +01:00
|
|
|
{
|
|
|
|
llarp::RouterVersion version;
|
|
|
|
version.Clear();
|
|
|
|
|
|
|
|
const std::string bString("li9ei3ei2ei1ei2ei3ei4ei5ei6ei7ei8ei9ee");
|
|
|
|
llarp_buffer_t buf(bString.data(), bString.size());
|
2021-03-01 22:07:32 +01:00
|
|
|
CHECK_FALSE(version.BDecode(&buf));
|
2020-01-31 22:48:00 +01:00
|
|
|
}
|