Debian Codegraph @

tests/src/utility/test_Base64.cpp

raw
1 #include <pbcopper/utility/Base64.h>
2
3 #include <gtest/gtest.h>
4
5 // Adapted from: https://github.com/ReneNyffenegger/cpp-base64/blob/master/test-google.cpp
6
7 using namespace PacBio;
8
9 namespace Base64Tests {
10
11 void Roundtrip(const std::string& input, const std::string& expectedEncoded)
12 {
13 const auto encoded = Utility::Base64::Encode(input);
14 const auto decoded = Utility::Base64::Decode(encoded);
15 EXPECT_EQ(expectedEncoded, encoded);
16 EXPECT_EQ(input, decoded);
17 }
18
19 } // namespace Base64Tests
20
21 TEST(Utility_Base64, can_roundtrip_with_no_fill_bytes)
22 {
23 const std::string input{"abc"};
24 const std::string encoded{"YWJj"};
25 Base64Tests::Roundtrip(input, encoded);
26 }
27
28 TEST(Utility_Base64, can_roundtrip_with_one_fill_byte)
29 {
30 const std::string input{"abcde"};
31 const std::string encoded{"YWJjZGU="};
32 Base64Tests::Roundtrip(input, encoded);
33 }
34
35 TEST(Utility_Base64, can_roundtrip_with_two_fill_bytes)
36 {
37 const std::string input{"abcd"};
38 const std::string encoded{"YWJjZA=="};
39 Base64Tests::Roundtrip(input, encoded);
40 }