Fix tests

pull/669/head
Michael 5 years ago
parent b51f7d8015
commit 8c2d67f8f1
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -70,8 +70,8 @@ namespace llarp
}
}
llarp::exit::Endpoint*
Context::FindEndpointForPath(const llarp::PathID_t& path) const
exit::Endpoint*
Context::FindEndpointForPath(const PathID_t& path) const
{
auto itr = m_Exits.begin();
while(itr != m_Exits.end())
@ -85,7 +85,7 @@ namespace llarp
}
bool
Context::ObtainNewExit(const llarp::PubKey& pk, const llarp::PathID_t& path,
Context::ObtainNewExit(const PubKey& pk, const PathID_t& path,
bool permitInternet)
{
auto itr = m_Exits.begin();
@ -106,13 +106,13 @@ namespace llarp
auto itr = m_Exits.find(name);
if(itr != m_Exits.end())
{
llarp::LogError("duplicate exit with name ", name);
LogError("duplicate exit with name ", name);
return false;
}
}
std::unique_ptr< llarp::handlers::ExitEndpoint > endpoint;
std::unique_ptr< handlers::ExitEndpoint > endpoint;
// make new endpoint
endpoint.reset(new llarp::handlers::ExitEndpoint(name, m_Router));
endpoint.reset(new handlers::ExitEndpoint(name, m_Router));
// configure
{
auto itr = conf.begin();
@ -120,8 +120,7 @@ namespace llarp
{
if(!endpoint->SetOption(itr->first, itr->second))
{
llarp::LogWarn("Couldn't set option ", itr->first, " to ",
itr->second);
LogWarn("Couldn't set option ", itr->first, " to ", itr->second);
return false;
}
++itr;
@ -130,7 +129,7 @@ namespace llarp
// add endpoint
if(!endpoint->Start())
{
llarp::LogWarn("Couldn't start exit endpoint");
LogWarn("Couldn't start exit endpoint");
return false;
}
m_Exits.emplace(name, std::move(endpoint));

@ -35,11 +35,11 @@ namespace llarp
AddExitEndpoint(const std::string &name, const Config_t &config);
bool
ObtainNewExit(const llarp::PubKey &remote, const llarp::PathID_t &path,
ObtainNewExit(const PubKey &remote, const PathID_t &path,
bool permitInternet);
llarp::exit::Endpoint *
FindEndpointForPath(const llarp::PathID_t &path) const;
exit::Endpoint *
FindEndpointForPath(const PathID_t &path) const;
/// calculate (pk, tx, rx) for all exit traffic
using TrafficStats =
@ -52,9 +52,9 @@ namespace llarp
private:
AbstractRouter *m_Router;
std::unordered_map< std::string,
std::shared_ptr< llarp::handlers::ExitEndpoint > >
std::shared_ptr< handlers::ExitEndpoint > >
m_Exits;
std::list< std::shared_ptr< llarp::handlers::ExitEndpoint > > m_Closed;
std::list< std::shared_ptr< handlers::ExitEndpoint > > m_Closed;
};
} // namespace exit
} // namespace llarp

@ -607,6 +607,7 @@ namespace llarp
pk, path, !wantInternet, ip, this));
m_Paths[path] = pk;
return HasLocalMappedAddrFor(pk);
}

@ -7,40 +7,36 @@
namespace llarp
{
struct CaselessCmp
bool
CaselessCmp::operator()(string_view lhs, string_view rhs) const
{
bool
operator()(string_view lhs, string_view rhs) const
if(lhs.size() < rhs.size())
{
if(lhs.size() < rhs.size())
{
return true;
}
else if(lhs.size() > rhs.size())
{
return false;
}
else
return true;
}
else if(lhs.size() > rhs.size())
{
return false;
}
else
{
for(size_t i = 0; i < lhs.size(); ++i)
{
for(size_t i = 0; i < lhs.size(); ++i)
{
auto l = std::tolower(lhs[i]);
auto r = std::tolower(rhs[i]);
auto l = std::tolower(lhs[i]);
auto r = std::tolower(rhs[i]);
if(l < r)
{
return true;
}
else if(l > r)
{
return false;
}
if(l < r)
{
return true;
}
else if(l > r)
{
return false;
}
}
return true;
return false;
}
};
}
bool
IsFalseValue(string_view str)

@ -11,6 +11,12 @@ namespace llarp
bool
IsFalseValue(string_view str);
struct CaselessCmp
{
bool
operator()(string_view lhs, string_view rhs) const;
};
bool
IsTrueValue(string_view str);

@ -48,6 +48,7 @@ list(APPEND TEST_SRC
util/test_llarp_util_timerqueue.cpp
util/test_llarp_util_traits.cpp
util/test_llarp_utils_scheduler.cpp
util/test_llarp_utils_str.cpp
)
add_executable(${TEST_EXE}

@ -1,15 +1,18 @@
#include <exit/context.hpp>
#include <router/router.hpp>
#include <exit/context.hpp>
#include <gtest/gtest.h>
struct ExitTest : public ::testing::Test
{
ExitTest() : r(nullptr, nullptr, nullptr)
ExitTest() : r(nullptr, nullptr, nullptr), context(&r)
{
}
llarp::Router r;
llarp::exit::Context context;
};
TEST_F(ExitTest, AddMultipleIP)
@ -23,9 +26,10 @@ TEST_F(ExitTest, AddMultipleIP)
conf.emplace("exit", "true");
conf.emplace("type", "null");
conf.emplace("ifaddr", "10.0.0.1/24");
ASSERT_TRUE(r.exitContext().AddExitEndpoint("test-exit", conf));
ASSERT_TRUE(r.exitContext().ObtainNewExit(pk, firstPath, true));
ASSERT_TRUE(r.exitContext().ObtainNewExit(pk, secondPath, true));
ASSERT_TRUE(r.exitContext().FindEndpointForPath(firstPath)->LocalIP()
== r.exitContext().FindEndpointForPath(secondPath)->LocalIP());
ASSERT_TRUE(context.AddExitEndpoint("test-exit", conf));
ASSERT_TRUE(context.ObtainNewExit(pk, firstPath, true));
ASSERT_TRUE(context.ObtainNewExit(pk, secondPath, true));
ASSERT_TRUE(context.FindEndpointForPath(firstPath)->LocalIP()
== context.FindEndpointForPath(secondPath)->LocalIP());
}

@ -0,0 +1,68 @@
#include <util/str.hpp>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using namespace llarp;
using namespace ::testing;
struct CmpTestData
{
bool lt;
std::string lhs;
std::string rhs;
};
class CaselessCmpTest : public ::testing::TestWithParam< CmpTestData >
{
};
TEST_P(CaselessCmpTest, test)
{
CaselessCmp cmp;
auto d = GetParam();
ASSERT_EQ(d.lt, cmp(d.lhs, d.rhs));
}
std::vector< CmpTestData > CMPTESTDATA{
{true, "", "1"}, {false, "1", ""}, {true, "abc", "abcd"},
{true, "abc", "abd"}, {false, "11", "1"}, {false, "a", "A"},
{false, "abc", "aBc"}, {false, "ABC", "abc"}};
INSTANTIATE_TEST_SUITE_P(TestStr, CaselessCmpTest, ValuesIn(CMPTESTDATA));
using TestData = std::pair< bool, std::string >;
class TestIsFalseValue : public ::testing::TestWithParam< TestData >
{
};
TEST_P(TestIsFalseValue, test)
{
ASSERT_EQ(GetParam().first, IsFalseValue(GetParam().second));
}
std::vector< TestData > FALSE_DATA{
{true, "false"}, {true, "FaLsE"}, {true, "no"}, {true, "nO"},
{true, "No"}, {true, "NO"}, {true, "NO"}, {true, "0"},
{true, "off"}, {true, "oFF"}, {false, "false y"}, {false, "true"},
{false, "tRue"}, {false, "on"}};
INSTANTIATE_TEST_SUITE_P(TestStr, TestIsFalseValue, ValuesIn(FALSE_DATA));
class TestIsTrueValue : public ::testing::TestWithParam< TestData >
{
};
TEST_P(TestIsTrueValue, test)
{
ASSERT_EQ(GetParam().first, IsTrueValue(GetParam().second));
}
std::vector< TestData > TRUE_DATA{
{true, "true"}, {true, "TruE"}, {true, "yes"}, {true, "yeS"},
{true, "yES"}, {true, "YES"}, {true, "1"}, {false, "0"},
{true, "on"}, {true, "oN"}, {false, "false y"}, {false, "truth"},
{false, "false"}, {false, "off"}};
INSTANTIATE_TEST_SUITE_P(TestStr, TestIsTrueValue, ValuesIn(TRUE_DATA));
Loading…
Cancel
Save