70 lines
2.2 KiB
C++
70 lines
2.2 KiB
C++
#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");
|
|
}
|
|
}
|