diff options
Diffstat (limited to 'src/base64_test.cpp')
-rw-r--r-- | src/base64_test.cpp | 92 |
1 files changed, 44 insertions, 48 deletions
diff --git a/src/base64_test.cpp b/src/base64_test.cpp index 3484976034..2758dfa80f 100644 --- a/src/base64_test.cpp +++ b/src/base64_test.cpp @@ -1,62 +1,58 @@ #include "base64.hpp" -#include "gtest/gtest.h" #include "big_list_of_naughty_strings.hpp" +#include "gtest/gtest.h" // Tests that Base64 basic strings work -TEST(Base64, EncodeBasicString) -{ - std::string output; - EXPECT_TRUE(base64::base64_encode("Foo", output)); +TEST(Base64, EncodeBasicString) { + std::string output; + EXPECT_TRUE(base64::base64_encode("Foo", output)); } // Tests the test vectors available in the base64 spec -TEST(Base64, EncodeRFC4648) -{ - std::string output; - EXPECT_TRUE(base64::base64_encode("", output)); - EXPECT_EQ(output, ""); - EXPECT_TRUE(base64::base64_encode("f", output)); - EXPECT_EQ(output, "Zg=="); - EXPECT_TRUE(base64::base64_encode("fo", output)); - EXPECT_EQ(output, "Zm8="); - EXPECT_TRUE(base64::base64_encode("foo", output)); - EXPECT_EQ(output, "Zm9v"); - EXPECT_TRUE(base64::base64_encode("foob", output)); - EXPECT_EQ(output, "Zm9vYg=="); - EXPECT_TRUE(base64::base64_encode("fooba", output)); - EXPECT_EQ(output, "Zm9vYmE="); - EXPECT_TRUE(base64::base64_encode("foobar", output)); - EXPECT_EQ(output, "Zm9vYmFy"); +TEST(Base64, EncodeRFC4648) { + std::string output; + EXPECT_TRUE(base64::base64_encode("", output)); + EXPECT_EQ(output, ""); + EXPECT_TRUE(base64::base64_encode("f", output)); + EXPECT_EQ(output, "Zg=="); + EXPECT_TRUE(base64::base64_encode("fo", output)); + EXPECT_EQ(output, "Zm8="); + EXPECT_TRUE(base64::base64_encode("foo", output)); + EXPECT_EQ(output, "Zm9v"); + EXPECT_TRUE(base64::base64_encode("foob", output)); + EXPECT_EQ(output, "Zm9vYg=="); + EXPECT_TRUE(base64::base64_encode("fooba", output)); + EXPECT_EQ(output, "Zm9vYmE="); + EXPECT_TRUE(base64::base64_encode("foobar", output)); + EXPECT_EQ(output, "Zm9vYmFy"); } // Tests the test vectors available in the base64 spec -TEST(Base64, DecodeRFC4648) -{ - std::string output; - EXPECT_TRUE(base64::base64_decode("", output)); - EXPECT_EQ(output, ""); - EXPECT_TRUE(base64::base64_decode("Zg==", output)); - EXPECT_EQ(output, "f"); - EXPECT_TRUE(base64::base64_decode("Zm8=", output)); - EXPECT_EQ(output, "fo"); - EXPECT_TRUE(base64::base64_decode("Zm9v", output)); - EXPECT_EQ(output, "foo"); - EXPECT_TRUE(base64::base64_decode("Zm9vYg==", output)); - EXPECT_EQ(output, "foob"); - EXPECT_TRUE(base64::base64_decode("Zm9vYmE=", output)); - EXPECT_EQ(output, "fooba"); - EXPECT_TRUE(base64::base64_decode("Zm9vYmFy", output)); - EXPECT_EQ(output, "foobar"); +TEST(Base64, DecodeRFC4648) { + std::string output; + EXPECT_TRUE(base64::base64_decode("", output)); + EXPECT_EQ(output, ""); + EXPECT_TRUE(base64::base64_decode("Zg==", output)); + EXPECT_EQ(output, "f"); + EXPECT_TRUE(base64::base64_decode("Zm8=", output)); + EXPECT_EQ(output, "fo"); + EXPECT_TRUE(base64::base64_decode("Zm9v", output)); + EXPECT_EQ(output, "foo"); + EXPECT_TRUE(base64::base64_decode("Zm9vYg==", output)); + EXPECT_EQ(output, "foob"); + EXPECT_TRUE(base64::base64_decode("Zm9vYmE=", output)); + EXPECT_EQ(output, "fooba"); + EXPECT_TRUE(base64::base64_decode("Zm9vYmFy", output)); + EXPECT_EQ(output, "foobar"); } // Tests using pathalogical cases for all escapings -TEST(Base64, NaugtyStrings){ - std::string base64_string; - std::string decoded_string; - for (auto& str: naughty_strings){ - EXPECT_TRUE(base64::base64_encode(str, base64_string)); - EXPECT_TRUE(base64::base64_decode(base64_string, decoded_string)); - EXPECT_EQ(str, decoded_string); - } +TEST(Base64, NaugtyStrings) { + std::string base64_string; + std::string decoded_string; + for (auto& str : naughty_strings) { + EXPECT_TRUE(base64::base64_encode(str, base64_string)); + EXPECT_TRUE(base64::base64_decode(base64_string, decoded_string)); + EXPECT_EQ(str, decoded_string); + } } - |