diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/http/io/compression_ut.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/http/io/compression_ut.cpp')
-rw-r--r-- | library/cpp/http/io/compression_ut.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/library/cpp/http/io/compression_ut.cpp b/library/cpp/http/io/compression_ut.cpp new file mode 100644 index 0000000000..2f3d131f8c --- /dev/null +++ b/library/cpp/http/io/compression_ut.cpp @@ -0,0 +1,60 @@ +#include "stream.h" +#include "compression.h" + +#include <library/cpp/testing/unittest/registar.h> +#include <library/cpp/testing/unittest/tests_data.h> + +#include <util/stream/zlib.h> +#include <util/generic/hash_set.h> + +Y_UNIT_TEST_SUITE(THttpCompressionTest) { + static const TString DATA = "I'm a teapot"; + + Y_UNIT_TEST(TestGetBestCodecs) { + UNIT_ASSERT(TCompressionCodecFactory::Instance().GetBestCodecs().size() > 0); + } + + Y_UNIT_TEST(TestEncoder) { + TStringStream buffer; + + { + auto encoder = TCompressionCodecFactory::Instance().FindEncoder("gzip"); + UNIT_ASSERT(encoder); + + auto encodedStream = (*encoder)(&buffer); + encodedStream->Write(DATA); + } + + TZLibDecompress decompressor(&buffer); + UNIT_ASSERT_EQUAL(decompressor.ReadAll(), DATA); + } + + Y_UNIT_TEST(TestDecoder) { + TStringStream buffer; + + { + TZLibCompress compressor(TZLibCompress::TParams(&buffer).SetType(ZLib::GZip)); + compressor.Write(DATA); + } + + auto decoder = TCompressionCodecFactory::Instance().FindDecoder("gzip"); + UNIT_ASSERT(decoder); + + auto decodedStream = (*decoder)(&buffer); + UNIT_ASSERT_EQUAL(decodedStream->ReadAll(), DATA); + } + + Y_UNIT_TEST(TestChooseBestCompressionScheme) { + THashSet<TString> accepted; + + auto checkAccepted = [&accepted](const TString& v) { + return accepted.contains(v); + }; + + UNIT_ASSERT_VALUES_EQUAL("identity", NHttp::ChooseBestCompressionScheme(checkAccepted, {"gzip", "deflate"})); + accepted.insert("deflate"); + UNIT_ASSERT_VALUES_EQUAL("deflate", NHttp::ChooseBestCompressionScheme(checkAccepted, {"gzip", "deflate"})); + accepted.insert("*"); + UNIT_ASSERT_VALUES_EQUAL("gzip", NHttp::ChooseBestCompressionScheme(checkAccepted, {"gzip", "deflate"})); + } +} // THttpCompressionTest suite |