mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 11:47:56 +08:00
a7f49d893e
Co-authored-by: antao <antao2002@gmail.com>
58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
#include <drogon/utils/Utilities.h>
|
|
#include <gtest/gtest.h>
|
|
#include <string>
|
|
|
|
TEST(Base64, base64)
|
|
{
|
|
std::string in{"drogon framework"};
|
|
auto out = drogon::utils::base64Encode((const unsigned char *)in.data(),
|
|
in.length());
|
|
auto out2 = drogon::utils::base64Decode(out);
|
|
EXPECT_EQ(out, "ZHJvZ29uIGZyYW1ld29yaw==");
|
|
EXPECT_EQ(out2, in);
|
|
}
|
|
|
|
TEST(Base64, base64_long_string)
|
|
{
|
|
std::string in;
|
|
for (int i = 0; i < 100000; ++i)
|
|
{
|
|
in.append(1, char(i));
|
|
}
|
|
auto out = drogon::utils::base64Encode((const unsigned char *)in.data(),
|
|
in.length());
|
|
auto out2 = drogon::utils::base64Decode(out);
|
|
EXPECT_EQ(out2, in);
|
|
}
|
|
|
|
TEST(Base64, base64_url)
|
|
{
|
|
std::string in{"drogon framework"};
|
|
auto out = drogon::utils::base64Encode((const unsigned char *)in.data(),
|
|
in.length(),
|
|
true);
|
|
auto out2 = drogon::utils::base64Decode(out);
|
|
EXPECT_EQ(out, "ZHJvZ29uIGZyYW1ld29yaw==");
|
|
EXPECT_EQ(out2, in);
|
|
}
|
|
|
|
TEST(Base64, base64_long_string_url)
|
|
{
|
|
std::string in;
|
|
for (int i = 0; i < 100000; ++i)
|
|
{
|
|
in.append(1, char(i));
|
|
}
|
|
auto out = drogon::utils::base64Encode((const unsigned char *)in.data(),
|
|
in.length(),
|
|
true);
|
|
auto out2 = drogon::utils::base64Decode(out);
|
|
EXPECT_EQ(out2, in);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
testing::InitGoogleTest(&argc, argv);
|
|
return RUN_ALL_TESTS();
|
|
}
|