Fix IsCompatableWith() logic WRT emptyRouterVersion, add unit tests

pull/1072/head
Stephen Shelton 4 years ago
parent f6813717b5
commit f0571a9f2c
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -44,8 +44,6 @@ namespace llarp
assert(IsEmpty());
}
static const RouterVersion emptyRouterVersion({0, 0, 0}, LLARP_PROTO_VERSION);
bool
RouterVersion::IsEmpty() const
{

@ -61,7 +61,7 @@ namespace llarp
private:
Version_t m_Version = {{0, 0, 0}};
uint64_t m_ProtoVersion = LLARP_PROTO_VERSION;
int64_t m_ProtoVersion = LLARP_PROTO_VERSION;
};
inline std::ostream&
@ -69,6 +69,10 @@ namespace llarp
{
return out << rv.ToString();
}
static constexpr int64_t INVALID_VERSION = -1;
static const RouterVersion emptyRouterVersion({0, 0, 0}, INVALID_VERSION);
} // namespace llarp
#endif

@ -19,6 +19,7 @@ list(APPEND TEST_SRC
link/test_llarp_link.cpp
llarp_test.cpp
net/test_llarp_net.cpp
router/test_llarp_router_version.cpp
routing/llarp_routing_transfer_traffic.cpp
routing/test_llarp_routing_obtainexitmessage.cpp
service/test_llarp_service_address.cpp

@ -0,0 +1,33 @@
#include <gtest/gtest.h>
#include <router_version.hpp>
#include "router/router.hpp"
class TestRouterVersion : public ::testing::Test
{
};
TEST_F(TestRouterVersion, TestCompatibilityWhenProtocolEqual)
{
llarp::RouterVersion v1( {0, 1, 2}, 1);
llarp::RouterVersion v2( {0, 1, 2}, 1);
EXPECT_TRUE(v1.IsCompatableWith(v2));
}
TEST_F(TestRouterVersion, TestCompatibilityWhenProtocolUnequal)
{
llarp::RouterVersion older( {0, 1, 2}, 1);
llarp::RouterVersion newer( {0, 1, 2}, 2);
EXPECT_FALSE(older.IsCompatableWith(newer));
EXPECT_FALSE(newer.IsCompatableWith(older));
}
TEST_F(TestRouterVersion, TestEmptyCompatibility)
{
llarp::RouterVersion v1( {0, 0, 1}, LLARP_PROTO_VERSION);
EXPECT_FALSE(v1.IsCompatableWith(llarp::emptyRouterVersion));
}
Loading…
Cancel
Save