summaryrefslogtreecommitdiff
path: root/libs/tdlib/td/tdutils/test/gzip.cpp
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2018-04-27 21:33:17 +0300
committeraunsane <aunsane@gmail.com>2018-04-27 21:33:17 +0300
commite1ec72eab6d00b3ba38e5932bc88920f103b6e4a (patch)
tree999de2725a83e30fbbf6576200525d4ef0c5fe38 /libs/tdlib/td/tdutils/test/gzip.cpp
parentb9ce1d4d98525490ca1a38e2d9fd4f3369adb3e0 (diff)
Telegram: initial commit
- tdlib moved to telegram dir
Diffstat (limited to 'libs/tdlib/td/tdutils/test/gzip.cpp')
-rw-r--r--libs/tdlib/td/tdutils/test/gzip.cpp113
1 files changed, 0 insertions, 113 deletions
diff --git a/libs/tdlib/td/tdutils/test/gzip.cpp b/libs/tdlib/td/tdutils/test/gzip.cpp
deleted file mode 100644
index e4bd81eb0d..0000000000
--- a/libs/tdlib/td/tdutils/test/gzip.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-//
-// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
-//
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
-// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-#include "td/utils/buffer.h"
-#include "td/utils/ByteFlow.h"
-#include "td/utils/Gzip.h"
-#include "td/utils/GzipByteFlow.h"
-#include "td/utils/logging.h"
-#include "td/utils/Status.h"
-#include "td/utils/tests.h"
-
-static void encode_decode(td::string s) {
- auto r = td::gzencode(s, 2);
- ASSERT_TRUE(!r.empty());
- if (r.empty()) {
- return;
- }
- auto new_s = td::gzdecode(r.as_slice());
- ASSERT_TRUE(!new_s.empty());
- if (new_s.empty()) {
- return;
- }
- ASSERT_EQ(s, new_s.as_slice().str());
-}
-
-TEST(Gzip, gzencode_gzdecode) {
- auto str = td::rand_string(0, 127, 1000);
- encode_decode(str);
- str = td::rand_string('a', 'z', 1000000);
- encode_decode(str);
- str = td::string(1000000, 'a');
- encode_decode(str);
-}
-
-TEST(Gzip, flow) {
- auto str = td::rand_string('a', 'z', 1000000);
- auto parts = td::rand_split(str);
-
- auto input_writer = td::ChainBufferWriter::create_empty();
- auto input = input_writer.extract_reader();
- td::ByteFlowSource source(&input);
- td::GzipByteFlow gzip_flow(td::Gzip::Encode);
- gzip_flow = td::GzipByteFlow(td::Gzip::Encode);
- td::ByteFlowSink sink;
-
- source >> gzip_flow >> sink;
-
- ASSERT_TRUE(!sink.is_ready());
- for (auto &part : parts) {
- input_writer.append(part);
- source.wakeup();
- }
- ASSERT_TRUE(!sink.is_ready());
- source.close_input(td::Status::OK());
- ASSERT_TRUE(sink.is_ready());
- ASSERT_TRUE(sink.status().is_ok());
- auto res = sink.result()->move_as_buffer_slice().as_slice().str();
- ASSERT_TRUE(!res.empty());
- ASSERT_EQ(td::gzencode(str, 2).as_slice().str(), res);
-}
-TEST(Gzip, flow_error) {
- auto str = td::rand_string('a', 'z', 1000000);
- auto zip = td::gzencode(str).as_slice().str();
- zip.resize(zip.size() - 1);
- auto parts = td::rand_split(zip);
-
- auto input_writer = td::ChainBufferWriter();
- auto input = input_writer.extract_reader();
- td::ByteFlowSource source(&input);
- td::GzipByteFlow gzip_flow(td::Gzip::Decode);
- td::ByteFlowSink sink;
-
- source >> gzip_flow >> sink;
-
- ASSERT_TRUE(!sink.is_ready());
- for (auto &part : parts) {
- input_writer.append(part);
- source.wakeup();
- }
- ASSERT_TRUE(!sink.is_ready());
- source.close_input(td::Status::OK());
- ASSERT_TRUE(sink.is_ready());
- ASSERT_TRUE(!sink.status().is_ok());
-}
-
-TEST(Gzip, encode_decode_flow) {
- auto str = td::rand_string('a', 'z', 1000000);
- auto parts = td::rand_split(str);
- auto input_writer = td::ChainBufferWriter::create_empty();
- auto input = input_writer.extract_reader();
- td::ByteFlowSource source(&input);
- td::GzipByteFlow gzip_encode_flow(td::Gzip::Encode);
- td::GzipByteFlow gzip_decode_flow(td::Gzip::Decode);
- td::GzipByteFlow gzip_encode_flow2(td::Gzip::Encode);
- td::GzipByteFlow gzip_decode_flow2(td::Gzip::Decode);
- td::ByteFlowSink sink;
- source >> gzip_encode_flow >> gzip_decode_flow >> gzip_encode_flow2 >> gzip_decode_flow2 >> sink;
-
- ASSERT_TRUE(!sink.is_ready());
- for (auto &part : parts) {
- input_writer.append(part);
- source.wakeup();
- }
- ASSERT_TRUE(!sink.is_ready());
- source.close_input(td::Status::OK());
- ASSERT_TRUE(sink.is_ready());
- LOG_IF(ERROR, sink.status().is_error()) << sink.status();
- ASSERT_TRUE(sink.status().is_ok());
- ASSERT_EQ(str, sink.result()->move_as_buffer_slice().as_slice().str());
-}