*: begin actually unittesting!
I probably should've a long time ago, but here we are. The aries library now has unit tests written for it, so we can actually (?) ensure it won't break randomly. It's now only 50% cowboy code! Also provides a stub implementation of aries::DecodeBinaryTagData, which will be completed later.
This commit is contained in:
parent
f2c01cf924
commit
a5bf226d11
|
@ -199,3 +199,6 @@
|
||||||
[submodule "third_party/spdlog"]
|
[submodule "third_party/spdlog"]
|
||||||
path = third_party/spdlog
|
path = third_party/spdlog
|
||||||
url = https://github.com/gabime/spdlog
|
url = https://github.com/gabime/spdlog
|
||||||
|
[submodule "third_party/catch2"]
|
||||||
|
path = third_party/catch2
|
||||||
|
url = https://github.com/catchorg/Catch2
|
||||||
|
|
|
@ -15,6 +15,8 @@ include(Policies)
|
||||||
include(ProjectFuncs)
|
include(ProjectFuncs)
|
||||||
include(CompilerFlags)
|
include(CompilerFlags)
|
||||||
|
|
||||||
|
option(LS_BUILD_TESTING "Build unit tests" ON)
|
||||||
|
|
||||||
lobbyserver_set_alternate_linker()
|
lobbyserver_set_alternate_linker()
|
||||||
|
|
||||||
# third party vendor dependencies
|
# third party vendor dependencies
|
||||||
|
|
|
@ -98,4 +98,20 @@ namespace ls::aries {
|
||||||
|
|
||||||
outStr = std::move(tagFieldBuffer);
|
outStr = std::move(tagFieldBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<u8> DecodeBinaryTagData(std::string_view tagData) {
|
||||||
|
// This could be more ergonomic as an optional or something.
|
||||||
|
|
||||||
|
if(tagData.empty())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// Marker for binary data
|
||||||
|
if(tagData[0] != '$')
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// TODO: Implement me fully!
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ls::aries
|
} // namespace ls::aries
|
|
@ -14,4 +14,11 @@ namespace ls::aries {
|
||||||
/// Serializes a TagMap to a string.
|
/// Serializes a TagMap to a string.
|
||||||
void SerializeTagFields(const TagMap& map, std::string& outStr);
|
void SerializeTagFields(const TagMap& map, std::string& outStr);
|
||||||
|
|
||||||
|
/// Decodes a binary tag to binary data.
|
||||||
|
std::vector<u8> DecodeBinaryTagData(std::string_view tagData);
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: Maybe also a in-Aries implementation of "CryptoSSC2"/other dirtysock crypto primitives so that we can rehash
|
||||||
|
// passwords to an actually sane password hash (e.g: argon2di).
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
#include <aries/Tags.hpp>
|
||||||
|
#include <catch2/catch_all.hpp>
|
||||||
|
namespace aries = ls::aries;
|
||||||
|
|
||||||
|
TEST_CASE("Aries tag field serde functions as expected", "[Aries] [TagFields]") {
|
||||||
|
const static aries::TagMap expectedMap = {
|
||||||
|
{ "PROP1", "VAL1" },
|
||||||
|
{ "PROP2", "VAL2" },
|
||||||
|
{ "PROP3", "VAL3" },
|
||||||
|
{ "PROP4", "VAL4" },
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string validTagBuffer;
|
||||||
|
|
||||||
|
SECTION("Serialization works as expected") {
|
||||||
|
// Do the serialization and make sure it's valid
|
||||||
|
aries::SerializeTagFields(expectedMap, validTagBuffer);
|
||||||
|
REQUIRE(validTagBuffer == "PROP4=VAL4\nPROP3=VAL3\nPROP2=VAL2\nPROP1=VAL1\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// For some obscure reason this can't be in a SECTION
|
||||||
|
// (maybe I'll try boost-ext/ut again if this becomes more frequent..)
|
||||||
|
aries::TagMap deserializedMap;
|
||||||
|
REQUIRE(aries::ParseTagFieldsToMap(validTagBuffer, deserializedMap) != false);
|
||||||
|
REQUIRE(deserializedMap == expectedMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("DecodeBinaryTagData() works", "[Aries] [TagFields] [DecodeBinarytagData]") {
|
||||||
|
// should decode to [ 0x12, 0x34, 0x56, 0x78 ]
|
||||||
|
std::string testCorpus = "$12345678";
|
||||||
|
const static std::vector<u8> expectedOutput = { 0x12, 0x34, 0x56, 0x78 };
|
||||||
|
|
||||||
|
REQUIRE(aries::DecodeBinaryTagData(testCorpus) == expectedOutput);
|
||||||
|
}
|
|
@ -21,3 +21,23 @@ target_link_libraries(lobbyserver PRIVATE
|
||||||
Boost::json
|
Boost::json
|
||||||
ls::aries
|
ls::aries
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# == unit test driver ==
|
||||||
|
if(LS_BUILD_TESTING)
|
||||||
|
|
||||||
|
add_executable(testdriver
|
||||||
|
# this is a bit :(
|
||||||
|
../lib/aries/Tags.test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
lobbyserver_target(testdriver)
|
||||||
|
|
||||||
|
target_link_libraries(testdriver
|
||||||
|
Catch2::Catch2WithMain
|
||||||
|
|
||||||
|
ls::aries
|
||||||
|
)
|
||||||
|
|
||||||
|
# TODO: CTest integration
|
||||||
|
|
||||||
|
endif()
|
|
@ -3,3 +3,7 @@ add_subdirectory(tomlplusplus)
|
||||||
|
|
||||||
set(SPDLOG_USE_STD_FORMAT ON)
|
set(SPDLOG_USE_STD_FORMAT ON)
|
||||||
add_subdirectory(spdlog)
|
add_subdirectory(spdlog)
|
||||||
|
|
||||||
|
if(LS_BUILD_TESTING)
|
||||||
|
add_subdirectory(catch2)
|
||||||
|
endif()
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 8ac8190e494a381072c89f5e161b92a08d98b37b
|
Loading…
Reference in New Issue