diff --git a/td/mtproto/TcpTransport.cpp b/td/mtproto/TcpTransport.cpp index 9eec19fe3..81a29e743 100644 --- a/td/mtproto/TcpTransport.cpp +++ b/td/mtproto/TcpTransport.cpp @@ -168,7 +168,7 @@ void ObfuscatedTransport::init(ChainBufferReader *input, ChainBufferWriter *outp string rheader = header; std::reverse(rheader.begin(), rheader.end()); - auto key = as(rheader.data() + 8); + UInt256 key = as(rheader.data() + 8); if (secret_.size() == 17) { secret_ = secret_.substr(1); } diff --git a/td/mtproto/Transport.cpp b/td/mtproto/Transport.cpp index dfd363123..f9d10a844 100644 --- a/td/mtproto/Transport.cpp +++ b/td/mtproto/Transport.cpp @@ -19,7 +19,6 @@ namespace td { namespace mtproto { - // mtproto v1.0 template std::tuple Transport::calc_message_ack_and_key(const HeaderT &head, size_t data_size) { @@ -80,10 +79,9 @@ Status Transport::read_no_crypto(MutableSlice message, PacketInfo *info, Mutable return Status::Error(PSLICE() << "Invalid mtproto message: too small [message.size()=" << message.size() << "] < [sizeof(NoCryptoHeader) = " << sizeof(NoCryptoHeader) << "]"); } - auto &header = as(message.begin()); size_t data_size = message.size() - sizeof(NoCryptoHeader); CHECK(message.size() == calc_no_crypto_size(data_size)); - *data = MutableSlice(header.data, data_size); + *data = MutableSlice(message.begin() + sizeof(NoCryptoHeader), data_size); return Status::OK(); } @@ -94,7 +92,8 @@ Status Transport::read_crypto_impl(int X, MutableSlice message, const AuthKey &a return Status::Error(PSLICE() << "Invalid mtproto message: too small [message.size()=" << message.size() << "] < [sizeof(HeaderT) = " << sizeof(HeaderT) << "]"); } - auto *header = &as(message.begin()); + //FIXME: rewrite without reinterpret cast + auto *header = reinterpret_cast(message.begin()); *header_ptr = header; auto to_decrypt = MutableSlice(header->encrypt_begin(), message.uend()); to_decrypt = to_decrypt.truncate(to_decrypt.size() & ~15); @@ -123,7 +122,8 @@ Status Transport::read_crypto_impl(int X, MutableSlice message, const AuthKey &a if (tail_size < sizeof(PrefixT)) { return Status::Error("Too small encrypted part"); } - auto *prefix = &as(header->data); + //FIXME: rewrite without reinterpret cast + auto *prefix = reinterpret_cast(header->data); *prefix_ptr = prefix; size_t data_size = prefix->message_data_length + sizeof(PrefixT); bool is_length_ok = prefix->message_data_length % 4 == 0; @@ -191,9 +191,9 @@ size_t Transport::write_no_crypto(const Storer &storer, PacketInfo *info, Mutabl if (size > dest.size()) { return size; } - auto &header = as(dest.begin()); - header.auth_key_id = 0; - auto real_size = storer.store(header.data); + // NoCryptoHeader + as(dest.begin()) = uint64(0); + auto real_size = storer.store(dest.ubegin() + sizeof(uint64)); CHECK(real_size == storer.size()); return size; } @@ -249,7 +249,8 @@ size_t Transport::write_crypto(const Storer &storer, const AuthKey &auth_key, Pa return size; } - auto &header = as(dest.begin()); + //FIXME: rewrite without reinterpret cast + auto &header = *reinterpret_cast(dest.begin()); header.auth_key_id = auth_key.id(); header.salt = info->salt; header.session_id = info->session_id; @@ -271,7 +272,8 @@ size_t Transport::write_e2e_crypto(const Storer &storer, const AuthKey &auth_key return size; } - auto &header = as(dest.begin()); + //FIXME: rewrite without reinterpret cast + auto &header = *reinterpret_cast(dest.begin()); header.auth_key_id = auth_key.id(); write_crypto_impl(info->is_creator || info->version == 1 ? 0 : 8, storer, auth_key, info, &header, data_size); diff --git a/td/telegram/files/FileDownloader.cpp b/td/telegram/files/FileDownloader.cpp index 73c0f5ced..1ea8a905a 100644 --- a/td/telegram/files/FileDownloader.cpp +++ b/td/telegram/files/FileDownloader.cpp @@ -312,7 +312,7 @@ Result FileDownloader::process_part(Part part, NetQueryPtr net_query) { // Encryption if (need_cdn_decrypt) { - auto iv = as(cdn_encryption_iv_.c_str()); + UInt128 iv = as(cdn_encryption_iv_.c_str()); CHECK(part.offset % 16 == 0); auto offset = narrow_cast(part.offset / 16); offset = diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fb76e51f6..8169b723e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,11 +9,6 @@ set(TD_TEST_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/secret.cpp ${CMAKE_CURRENT_SOURCE_DIR}/secure_storage.cpp ${CMAKE_CURRENT_SOURCE_DIR}/string_cleaning.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/TestsRunner.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/tests_runner.cpp - - ${CMAKE_CURRENT_SOURCE_DIR}/TestsRunner.h - ${CMAKE_CURRENT_SOURCE_DIR}/tests_runner.h ${CMAKE_CURRENT_SOURCE_DIR}/data.cpp ${CMAKE_CURRENT_SOURCE_DIR}/data.h diff --git a/test/TestsRunner.cpp b/test/TestsRunner.cpp deleted file mode 100644 index 72b1290fe..000000000 --- a/test/TestsRunner.cpp +++ /dev/null @@ -1,63 +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 "test/TestsRunner.h" - -#include "td/utils/common.h" -#include "td/utils/FileLog.h" -#include "td/utils/format.h" -#include "td/utils/logging.h" -#include "td/utils/port/path.h" -#include "td/utils/tests.h" - -#include - -DESC_TESTS(string_cleaning); -DESC_TESTS(message_entities); -DESC_TESTS(variant); -DESC_TESTS(secret); -DESC_TESTS(actors_main); -DESC_TESTS(actors_simple); -DESC_TESTS(actors_workers); -DESC_TESTS(db); -DESC_TESTS(json); -DESC_TESTS(http); -DESC_TESTS(heap); -DESC_TESTS(pq); -DESC_TESTS(mtproto); - -namespace td { - -void TestsRunner::run_all_tests() { - LOAD_TESTS(string_cleaning); - LOAD_TESTS(message_entities); - LOAD_TESTS(variant); - LOAD_TESTS(secret); - LOAD_TESTS(actors_main); - LOAD_TESTS(actors_simple); - LOAD_TESTS(actors_workers); - LOAD_TESTS(db); - LOAD_TESTS(json); - LOAD_TESTS(http); - LOAD_TESTS(heap); - LOAD_TESTS(pq); - LOAD_TESTS(mtproto); - Test::run_all(); -} - -static FileLog file_log; -static TsLog ts_log(&file_log); - -void TestsRunner::init(string dir) { - SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR)); - chdir(dir).ensure(); - LOG(WARNING) << "Redirect log into " << tag("file", dir + TD_DIR_SLASH + "log.txt"); - if (file_log.init("log.txt", std::numeric_limits::max()).is_ok()) { - log_interface = &ts_log; - } -} - -} // namespace td diff --git a/test/TestsRunner.h b/test/TestsRunner.h deleted file mode 100644 index a5bc66d85..000000000 --- a/test/TestsRunner.h +++ /dev/null @@ -1,19 +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) -// -#pragma once - -#include "td/utils/common.h" - -namespace td { - -class TestsRunner { - public: - static void init(string dir); - static void run_all_tests(); -}; - -} // namespace td diff --git a/test/main.cpp b/test/main.cpp index 68b0e3cd1..bc316bd3a 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -16,26 +16,27 @@ int main(int argc, char **argv) { // TODO port OptionsParser to Windows + td::TestsRunner &runner = td::TestsRunner::get_default(); SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR)); for (int i = 1; i < argc; i++) { if (!std::strcmp(argv[i], "--filter")) { CHECK(i + 1 < argc); - td::Test::add_substr_filter(argv[++i]); + runner.add_substr_filter(argv[++i]); } if (!std::strcmp(argv[i], "--stress")) { - td::Test::set_stress_flag(true); + runner.set_stress_flag(true); } } #if TD_EMSCRIPTEN emscripten_set_main_loop( [] { - if (!td::Test::run_all_step()) { + if (!runner.run_all_step()) { emscripten_cancel_main_loop(); } }, 10, 0); #else - td::Test::run_all(); + runner.run_all(); #endif return 0; } diff --git a/test/mtproto.cpp b/test/mtproto.cpp index 674f4fda5..ee33728eb 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -163,7 +163,7 @@ class Mtproto_ping : public td::Test { ConcurrentScheduler sched_; Status result_; }; -Mtproto_ping mtproto_ping("Mtproto_ping"); +RegisterTest mtproto_ping("Mtproto_ping"); class HandshakeContext : public mtproto::AuthKeyHandshakeContext { public: @@ -296,7 +296,7 @@ class Mtproto_handshake : public td::Test { ConcurrentScheduler sched_; Status result_; }; -Mtproto_handshake mtproto_handshake("Mtproto_handshake"); +RegisterTest mtproto_handshake("Mtproto_handshake"); class Socks5TestActor : public Actor { public: diff --git a/test/tests_runner.cpp b/test/tests_runner.cpp deleted file mode 100644 index 0edb186f0..000000000 --- a/test/tests_runner.cpp +++ /dev/null @@ -1,18 +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 "test/tests_runner.h" - -#include "test/TestsRunner.h" - -extern "C" { -void tests_runner_init(const char *dir) { - td::TestsRunner::init(dir); -} -void run_all_tests() { - td::TestsRunner::run_all_tests(); -} -} diff --git a/test/tests_runner.h b/test/tests_runner.h deleted file mode 100644 index 3de566858..000000000 --- a/test/tests_runner.h +++ /dev/null @@ -1,18 +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) -// -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -void tests_runner_init(const char *dir); -void run_all_tests(); - -#ifdef __cplusplus -} -#endif