Skip to content

Commit

Permalink
Adding many round-trip decoding/encoding tests (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgomes28 authored May 4, 2023
1 parent 16d9da3 commit 982db06
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/base64pp_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,32 @@ TEST(Base64RoundTripTests, AllPossibleBytes)
ASSERT_EQ(all_possible_bytes, *decoded_bytes);
}

// NOLINTNEXTLINE
TEST(Base64RoundTripTests, ExhaustiveTests)
{
std::vector<std::string> const base64_strings = {"YW55IGNhcm5hbCBwbGVhcw==", "bGVnYWwgcGFzcw==", "dGVzdCBzdHJpbmc=",
"bGVnYWwgcHJvdmlkZXI=", "ZW5vdWdoIHRoZSBzYW1lIG9mIHRoZSBwbGFjZQ==", "YW5vdGhlciB0aGUgc3RyYWlnaHQ=",
"d2FzIG1lIGFkZHJlc3MgcHJvdmlkZXI=", "YWJvdXQgdGhlIG1hc3RlciBvZiB0aGUgZGFtYWdl",
"ZW50aXJlIHRoYXQgYnJvdWdodCBvZiB0aGUgbW9uZXk=", "bGVnYWwgc2VjdXJpdHk=",
"YmFzaWMgZ29vZCBvZiB0aGUgcGFkIHN0cmluZw==", "ZGVsZXRlIHN0cmluZyBvZiB0aGUgc3RyYWlnaHQ=",
"YnJvdWdodCBvZiB0aGUgcGFkIGZvbGRlciBvZiB0aGUgZGFtYWdl", "aW50ZXJmYWNlIHN0cmluZw==", "Y29uc29sZS1tZS1jb21wYW55",
"aW5mb3JtYXRpb24tbWVkaWE=", "c3RhdHVzLXNlY3VyZQ==", "Y3JlYXRlLWNvbXBhbnktc3RyaW5n", "b3JkZXItbGVhZGVy",
"Y2F0YWxvZy1wcm9maWxl", "dGVzdC1jb25zdWx0aW5n",
"YnJvdWdodC1sZWFkZXI=", "YXNzaWduLW1lY2hhbmlzbQ==", "bGVnYWwtY29udGFpbmVy", "ZW1haWwtY29udGFpbmVy",
"aW5zdGFuY2UtY29udGFpbmVy", "dGVzdC1jb21wYW55LWFuZC1wcm9maWxl", "YmFzZTY0LWJhc2U=", "cGFzc3dvcmQ=", "Zm9vYmFy",
"Y29vbC1iYXNl", "YmFzZTY0LXNlY3VyZQ==", "aW50ZXJ2YWw=", "dGhlLW1hc3Rlci1vZi10aGUtZGFtYWdl",
"c2FtZS1wbGFjZS1vZi10aGUtZGFtYWdl", "aGFzaC1zb21ldGhpbmc="};

for (auto const& b64_string : base64_strings)
{
auto const decoded = base64pp::decode(b64_string);
ASSERT_TRUE(decoded);

auto const encoded_round_trip = base64pp::encode({begin(*decoded), end(*decoded)});
ASSERT_EQ(encoded_round_trip, b64_string);
}
}

int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit 982db06

Please sign in to comment.