Import Base64 implementation from old repo
This commit is contained in:
parent
e4735e2dfb
commit
f9c6e9e7cb
8 changed files with 266 additions and 1 deletions
17
Tests/Base64/CMakeLists.txt
Normal file
17
Tests/Base64/CMakeLists.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
add_executable(TestBase64)
|
||||
|
||||
target_compile_features(TestBase64
|
||||
PRIVATE
|
||||
cxx_std_20
|
||||
)
|
||||
|
||||
target_link_libraries(TestBase64
|
||||
PRIVATE
|
||||
Garbage
|
||||
Catch2::Catch2WithMain
|
||||
)
|
||||
|
||||
target_sources(TestBase64
|
||||
PRIVATE
|
||||
Tests.cpp
|
||||
)
|
70
Tests/Base64/Tests.cpp
Normal file
70
Tests/Base64/Tests.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <Garbage/Base64.hpp>
|
||||
|
||||
TEST_CASE("Base64 encoding/decoding tests")
|
||||
{
|
||||
SECTION("Empty span")
|
||||
{
|
||||
std::vector<std::uint8_t> data;
|
||||
|
||||
std::string encoded = Garbage::Base64::Encode(data);
|
||||
REQUIRE(encoded.size() == 0);
|
||||
|
||||
std::vector<std::uint8_t> decoded = Garbage::Base64::Decode(encoded);
|
||||
REQUIRE(encoded.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("Encoding short data")
|
||||
{
|
||||
std::string source("Many hands make light work.");
|
||||
std::vector<std::uint8_t> data(source.begin(), source.end());
|
||||
|
||||
std::string encoded = Garbage::Base64::Encode(data);
|
||||
REQUIRE(encoded == "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu");
|
||||
}
|
||||
|
||||
SECTION("Decoding short data")
|
||||
{
|
||||
std::string data("TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu");
|
||||
|
||||
std::vector<std::uint8_t> decoded = Garbage::Base64::Decode(data);
|
||||
std::string destination(decoded.begin(), decoded.end());
|
||||
REQUIRE(destination == "Many hands make light work.");
|
||||
}
|
||||
|
||||
SECTION("Encoding with a padding char")
|
||||
{
|
||||
std::string source("With a padding");
|
||||
std::vector<std::uint8_t> data(source.begin(), source.end());
|
||||
|
||||
std::string encoded = Garbage::Base64::Encode(data);
|
||||
REQUIRE(encoded == "V2l0aCBhIHBhZGRpbmc=");
|
||||
}
|
||||
|
||||
SECTION("Decoding with a padding char")
|
||||
{
|
||||
std::string data("V2l0aCBhIHBhZGRpbmc=");
|
||||
|
||||
std::vector<std::uint8_t> decoded = Garbage::Base64::Decode(data);
|
||||
std::string destination(decoded.begin(), decoded.end());
|
||||
REQUIRE(destination == "With a padding");
|
||||
}
|
||||
|
||||
SECTION("Encoding with two padding chars")
|
||||
{
|
||||
std::string source("With two padding");
|
||||
std::vector<std::uint8_t> data(source.begin(), source.end());
|
||||
|
||||
std::string encoded = Garbage::Base64::Encode(data);
|
||||
REQUIRE(encoded == "V2l0aCB0d28gcGFkZGluZw==");
|
||||
}
|
||||
|
||||
SECTION("Decoding with two padding chars")
|
||||
{
|
||||
std::string data("V2l0aCB0d28gcGFkZGluZw==");
|
||||
|
||||
std::vector<std::uint8_t> decoded = Garbage::Base64::Decode(data);
|
||||
std::string destination(decoded.begin(), decoded.end());
|
||||
REQUIRE(destination == "With two padding");
|
||||
}
|
||||
}
|
3
Tests/CMakeLists.txt
Normal file
3
Tests/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
include(${PROJECT_SOURCE_DIR}/CMake/Catch2.cmake)
|
||||
|
||||
add_subdirectory(Base64)
|
Loading…
Add table
Add a link
Reference in a new issue