drogon/lib/tests/unittests/BrotliTest.cc

31 lines
858 B
C++
Raw Normal View History

2021-05-27 12:09:57 +00:00
#include <drogon/utils/Utilities.h>
#include <drogon/drogon_test.h>
#include <string>
#include <iostream>
using namespace drogon::utils;
2021-05-27 12:09:57 +00:00
DROGON_TEST(BrotliTest)
{
SUBSECTION(shortText)
{
std::string source{"123中文顶替要枯械"};
auto compressed = brotliCompress(source.data(), source.length());
auto decompressed =
brotliDecompress(compressed.data(), compressed.length());
CHECK(source == decompressed);
}
SUBSECTION(longText)
{
std::string source;
for (size_t i = 0; i < 100000; i++)
{
source.append(std::to_string(i));
}
auto compressed = brotliCompress(source.data(), source.length());
auto decompressed =
brotliDecompress(compressed.data(), compressed.length());
CHECK(source == decompressed);
}
}