mirror of https://github.com/oxen-io/lokinet
* add path::Path::UniqueEndpointSet_t
* start using check2 for new unit tests * unit test for path::Path::UniqueEndpointSet_t
This commit is contained in:
parent
ffa1012049
commit
e35d17764a
7
Makefile
7
Makefile
|
@ -178,6 +178,8 @@ release-compile: release-configure
|
|||
$(TARGETS): release-compile
|
||||
|
||||
release: $(TARGETS)
|
||||
make -C '$(BUILD_ROOT)' test
|
||||
make -C '$(BUILD_ROOT)' check
|
||||
|
||||
shadow-configure: clean
|
||||
mkdir -p $(BUILD_ROOT)
|
||||
|
@ -214,9 +216,12 @@ testnet:
|
|||
|
||||
$(TEST_EXE): debug
|
||||
|
||||
test: $(TEST_EXE)
|
||||
gtest: $(TEST_EXE)
|
||||
test x$(CROSS) = xOFF && $(TEST_EXE) || test x$(CROSS) = xON
|
||||
|
||||
test: gtest
|
||||
$(MAKE) -C $(BUILD_ROOT) check
|
||||
|
||||
static-configure: $(LIBUV_PREFIX) $(LIBCURL_PREFIX)
|
||||
(test x$(TOOLCHAIN) = x && $(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Release -DSTATIC_LINK=ON -DRELEASE_MOTTO="$(shell cat motto.txt)" -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)' -DLIBUV_ROOT='$(LIBUV_PREFIX)' -DLIBCURL_ROOT='$(LIBCURL_PREFIX)' ) || (test x$(TOOLCHAIN) != x && $(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Release -DSTATIC_LINK=ON -DRELEASE_MOTTO="$(shell cat motto.txt)" -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)' -DLIBUV_ROOT='$(LIBUV_PREFIX)' -DLIBCURL_ROOT='$(LIBCURL_PREFIX)' -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN) -DNATIVE_BUILD=OFF )
|
||||
|
||||
|
|
|
@ -50,7 +50,8 @@ namespace llarp
|
|||
// initialize parts of the introduction
|
||||
intro.router = hops[hsz - 1].rc.pubkey;
|
||||
intro.pathID = hops[hsz - 1].txID;
|
||||
EnterState(ePathBuilding, parent->Now());
|
||||
if(parent)
|
||||
EnterState(ePathBuilding, parent->Now());
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <list>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include <util/decaying_hashset.hpp>
|
||||
|
@ -127,10 +128,11 @@ namespace llarp
|
|||
}
|
||||
};
|
||||
|
||||
/// hash for std::shared_ptr
|
||||
struct Ptr_Hash
|
||||
{
|
||||
size_t
|
||||
operator()(const std::shared_ptr< Path >& p) const
|
||||
operator()(const Path_ptr& p) const
|
||||
{
|
||||
if(p == nullptr)
|
||||
return 0;
|
||||
|
@ -138,6 +140,32 @@ namespace llarp
|
|||
}
|
||||
};
|
||||
|
||||
/// hash for std::shared_ptr by path endpoint
|
||||
struct Endpoint_Hash
|
||||
{
|
||||
size_t
|
||||
operator()(const Path_ptr& p) const
|
||||
{
|
||||
if(p == nullptr)
|
||||
return 0;
|
||||
return RouterID::Hash{}(p->Endpoint());
|
||||
}
|
||||
};
|
||||
|
||||
/// comparision for equal endpoints
|
||||
struct Endpoint_Equals
|
||||
{
|
||||
bool
|
||||
operator()(const Path_ptr& left, const Path_ptr& right) const
|
||||
{
|
||||
return left && right && left->Endpoint() == left->Endpoint();
|
||||
}
|
||||
};
|
||||
|
||||
/// unordered set of paths with unique endpoints
|
||||
using UniqueEndpointSet_t =
|
||||
std::unordered_set< Path_ptr, Endpoint_Hash, Endpoint_Equals >;
|
||||
|
||||
bool
|
||||
operator<(const Path& other) const
|
||||
{
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
set(TEST_EXE testAll)
|
||||
set(CHECK_EXE checkAll)
|
||||
|
||||
|
||||
list(APPEND TEST_SRC
|
||||
config/test_llarp_config_config.cpp
|
||||
|
@ -74,3 +76,12 @@ endif(NOT WIN32)
|
|||
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
target_link_directories(${TEST_EXE} PRIVATE /usr/local/lib)
|
||||
endif()
|
||||
|
||||
add_executable(${CHECK_EXE}
|
||||
path/test_path.cpp
|
||||
check_main.cpp)
|
||||
|
||||
target_link_libraries(${CHECK_EXE} PUBLIC ${STATIC_LIB})
|
||||
target_include_directories(${CHECK_EXE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
add_custom_target(check COMMAND ${CHECK_EXE})
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,2 @@
|
|||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
|
@ -0,0 +1,39 @@
|
|||
#include <path/path.hpp>
|
||||
#include "catch.hpp"
|
||||
|
||||
using Path_t = llarp::path::Path;
|
||||
using Path_ptr = llarp::path::Path_ptr;
|
||||
using Set_t = llarp::path::Path::UniqueEndpointSet_t;
|
||||
using RC_t = llarp::RouterContact;
|
||||
|
||||
static RC_t
|
||||
MakeHop(const char name)
|
||||
{
|
||||
RC_t rc;
|
||||
rc.pubkey.Fill(name);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Path_ptr
|
||||
MakePath(std::vector< char > hops)
|
||||
{
|
||||
std::vector< RC_t > pathHops;
|
||||
for(const auto& hop : hops)
|
||||
pathHops.push_back(MakeHop(hop));
|
||||
return std::make_shared< Path_t >(pathHops, nullptr, 0);
|
||||
}
|
||||
|
||||
TEST_CASE("UniqueEndpointSet_t has unique endpoints", "[path]")
|
||||
{
|
||||
Set_t set;
|
||||
REQUIRE(set.empty());
|
||||
const auto inserted_first =
|
||||
set.emplace(MakePath({'a', 'b', 'c', 'd'})).second;
|
||||
REQUIRE(inserted_first);
|
||||
const auto inserted_again =
|
||||
set.emplace(MakePath({'a', 'b', 'c', 'd'})).second;
|
||||
REQUIRE(not inserted_again);
|
||||
const auto inserted_second =
|
||||
set.emplace(MakePath({'d', 'c', 'b', 'a'})).second;
|
||||
REQUIRE(inserted_second);
|
||||
}
|
Loading…
Reference in New Issue