diff --git a/.clang-format b/.clang-format index 2f75c24a1..8a51b957e 100644 --- a/.clang-format +++ b/.clang-format @@ -3,16 +3,20 @@ Language: Cpp # BasedOnStyle: Google AccessModifierOffset: -1 AlignAfterOpenBracket: Align +AlignConsecutiveMacros: false AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false AlignEscapedNewlines: Left AlignOperands: true AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false +AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: None # All -AllowShortIfStatementsOnASingleLine: false # true +AllowShortIfStatementsOnASingleLine: Never # WithoutElse +AllowShortLambdasOnASingleLine: Inline # All AllowShortLoopsOnASingleLine: false # true AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None @@ -21,6 +25,7 @@ AlwaysBreakTemplateDeclarations: Yes BinPackArguments: true BinPackParameters: true BraceWrapping: + AfterCaseLabel: false AfterClass: false AfterControlStatement: false AfterEnum: false @@ -60,6 +65,7 @@ ForEachMacros: - Q_FOREACH_THIS_LIST_MUST_BE_NON_EMPTY IncludeBlocks: Preserve IndentCaseLabels: true +IndentGotoLabels: true IndentPPDirectives: None IndentWidth: 2 IndentWrappedFunctionNames: false @@ -87,6 +93,7 @@ ReflowComments: false # true SortIncludes: false # disabled, because we need case insensitive sort SortUsingDeclarations: false # true SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true SpaceBeforeCpp11BracedList: false @@ -94,6 +101,7 @@ SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 SpacesInAngles: false diff --git a/benchmark/bench_misc.cpp b/benchmark/bench_misc.cpp index 52b5b19de..2cc3c9ba5 100644 --- a/benchmark/bench_misc.cpp +++ b/benchmark/bench_misc.cpp @@ -222,15 +222,13 @@ class CreateFileBench : public Benchmark { } } void tear_down() override { - td::walk_path("A/", - [&](CSlice path, auto type) { - if (type == td::WalkPath::Type::ExitDir) { - rmdir(path).ignore(); - } else if (type == td::WalkPath::Type::NotDir) { - unlink(path).ignore(); - } - }) - .ignore(); + td::walk_path("A/", [&](CSlice path, auto type) { + if (type == td::WalkPath::Type::ExitDir) { + rmdir(path).ignore(); + } else if (type == td::WalkPath::Type::NotDir) { + unlink(path).ignore(); + } + }).ignore(); } }; @@ -246,26 +244,22 @@ class WalkPathBench : public Benchmark { } void run(int n) override { int cnt = 0; - td::walk_path("A/", - [&](CSlice path, auto type) { - if (type == td::WalkPath::Type::EnterDir) { - return; - } - stat(path).ok(); - cnt++; - }) - .ignore(); + td::walk_path("A/", [&](CSlice path, auto type) { + if (type == td::WalkPath::Type::EnterDir) { + return; + } + stat(path).ok(); + cnt++; + }).ignore(); } void tear_down() override { - td::walk_path("A/", - [&](CSlice path, auto type) { - if (type == td::WalkPath::Type::ExitDir) { - rmdir(path).ignore(); - } else if (type == td::WalkPath::Type::NotDir) { - unlink(path).ignore(); - } - }) - .ignore(); + td::walk_path("A/", [&](CSlice path, auto type) { + if (type == td::WalkPath::Type::ExitDir) { + rmdir(path).ignore(); + } else if (type == td::WalkPath::Type::NotDir) { + unlink(path).ignore(); + } + }).ignore(); } }; diff --git a/benchmark/check_tls.cpp b/benchmark/check_tls.cpp index 7ff1a1466..c2ac3c565 100644 --- a/benchmark/check_tls.cpp +++ b/benchmark/check_tls.cpp @@ -53,7 +53,9 @@ td::Result test_tls(const td::string &url) { td::string request; - auto add_string = [&](td::Slice data) { request.append(data.data(), data.size()); }; + auto add_string = [&](td::Slice data) { + request.append(data.data(), data.size()); + }; auto add_random = [&](size_t length) { while (length-- > 0) { request += static_cast(td::Random::secure_int32()); diff --git a/memprof/memprof.cpp b/memprof/memprof.cpp index 5025b6a2b..7ce971f4d 100644 --- a/memprof/memprof.cpp +++ b/memprof/memprof.cpp @@ -41,9 +41,9 @@ extern void *__libc_stack_end; static void *get_bp() { void *bp; #if defined(__i386__) - __asm__ volatile("movl %%ebp, %[r]" : [r] "=r"(bp)); + __asm__ volatile("movl %%ebp, %[r]" : [ r ] "=r"(bp)); #elif defined(__x86_64__) - __asm__ volatile("movq %%rbp, %[r]" : [r] "=r"(bp)); + __asm__ volatile("movq %%rbp, %[r]" : [ r ] "=r"(bp)); #endif return bp; } diff --git a/td/mtproto/SessionConnection.h b/td/mtproto/SessionConnection.h index 430cd3863..b28844029 100644 --- a/td/mtproto/SessionConnection.h +++ b/td/mtproto/SessionConnection.h @@ -202,7 +202,9 @@ class SessionConnection auto set_buffer_slice(BufferSlice *buffer_slice) TD_WARN_UNUSED_RESULT { auto old_buffer_slice = current_buffer_slice_; current_buffer_slice_ = buffer_slice; - return ScopeExit() + [&to = current_buffer_slice_, from = old_buffer_slice] { to = from; }; + return ScopeExit() + [&to = current_buffer_slice_, from = old_buffer_slice] { + to = from; + }; } Status parse_message(TlParser &parser, MsgInfo *info, Slice *packet, bool crypto_flag = true) TD_WARN_UNUSED_RESULT; diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index e15cf1c51..97603c173 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -987,7 +987,9 @@ void ConfigManager::process_config(tl_object_ptr config) { shared_config.set_option_string("photo_search_bot_username", config->img_search_username_); } - auto fix_timeout_ms = [](int32 timeout_ms) { return clamp(timeout_ms, 1000, 86400 * 1000); }; + auto fix_timeout_ms = [](int32 timeout_ms) { + return clamp(timeout_ms, 1000, 86400 * 1000); + }; shared_config.set_option_integer("online_update_period_ms", fix_timeout_ms(config->online_update_period_ms_)); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 959674046..2f738429a 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -27065,13 +27065,17 @@ void MessagesManager::suffix_load_add_query(Dialog *d, void MessagesManager::suffix_load_till_date(Dialog *d, int32 date, Promise<> promise) { LOG(INFO) << "Load suffix of " << d->dialog_id << " till date " << date; - auto condition = [date](const Message *m) { return m != nullptr && m->date < date; }; + auto condition = [date](const Message *m) { + return m != nullptr && m->date < date; + }; suffix_load_add_query(d, std::make_pair(std::move(promise), std::move(condition))); } void MessagesManager::suffix_load_till_message_id(Dialog *d, MessageId message_id, Promise<> promise) { LOG(INFO) << "Load suffix of " << d->dialog_id << " till " << message_id; - auto condition = [message_id](const Message *m) { return m != nullptr && m->message_id.get() < message_id.get(); }; + auto condition = [message_id](const Message *m) { + return m != nullptr && m->message_id.get() < message_id.get(); + }; suffix_load_add_query(d, std::make_pair(std::move(promise), std::move(condition))); } diff --git a/td/telegram/SecretChatActor.cpp b/td/telegram/SecretChatActor.cpp index 67f669cb0..8d2ed44ee 100644 --- a/td/telegram/SecretChatActor.cpp +++ b/td/telegram/SecretChatActor.cpp @@ -1662,7 +1662,9 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise [&](telegram_api::encryptedFileEmpty &) { state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file( telegram_api::inputEncryptedFileEmpty()); - get_file = [] { return telegram_api::make_object(); }; + get_file = [] { + return telegram_api::make_object(); + }; }, [&](telegram_api::encryptedFile &file) { state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file( diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index b8a3ce1a4..122993a6a 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1551,7 +1551,9 @@ int32 UpdatesManager::get_short_update_date() const { tl_object_ptr UpdatesManager::convert_send_message_action( tl_object_ptr action) { - auto fix_progress = [](int32 progress) { return progress <= 0 || progress > 100 ? 0 : progress; }; + auto fix_progress = [](int32 progress) { + return progress <= 0 || progress > 100 ? 0 : progress; + }; switch (action->get_id()) { case telegram_api::sendMessageCancelAction::ID: diff --git a/td/telegram/files/FileStatsWorker.cpp b/td/telegram/files/FileStatsWorker.cpp index 9313ed1ff..4ce7ee993 100644 --- a/td/telegram/files/FileStatsWorker.cpp +++ b/td/telegram/files/FileStatsWorker.cpp @@ -106,35 +106,33 @@ void scan_fs(CancellationToken &token, CallbackT &&callback) { continue; } auto files_dir = get_files_dir(file_type); - walk_path(files_dir, - [&](CSlice path, WalkPath::Type type) { - if (token) { - return WalkPath::Action::Abort; - } - if (type != WalkPath::Type::NotDir) { - return WalkPath::Action::Continue; - } - auto r_stat = stat(path); - if (r_stat.is_error()) { - LOG(WARNING) << "Stat in files gc failed: " << r_stat.error(); - return WalkPath::Action::Continue; - } - auto stat = r_stat.move_as_ok(); - if (ends_with(path, "/.nomedia") && stat.size_ == 0) { - // skip .nomedia file - return WalkPath::Action::Continue; - } + walk_path(files_dir, [&](CSlice path, WalkPath::Type type) { + if (token) { + return WalkPath::Action::Abort; + } + if (type != WalkPath::Type::NotDir) { + return WalkPath::Action::Continue; + } + auto r_stat = stat(path); + if (r_stat.is_error()) { + LOG(WARNING) << "Stat in files gc failed: " << r_stat.error(); + return WalkPath::Action::Continue; + } + auto stat = r_stat.move_as_ok(); + if (ends_with(path, "/.nomedia") && stat.size_ == 0) { + // skip .nomedia file + return WalkPath::Action::Continue; + } - FsFileInfo info; - info.path = path.str(); - info.size = stat.size_; - info.file_type = file_type; - info.atime_nsec = stat.atime_nsec_; - info.mtime_nsec = stat.mtime_nsec_; - callback(info); - return WalkPath::Action::Continue; - }) - .ignore(); + FsFileInfo info; + info.path = path.str(); + info.size = stat.size_; + info.file_type = file_type; + info.atime_nsec = stat.atime_nsec_; + info.mtime_nsec = stat.mtime_nsec_; + callback(info); + return WalkPath::Action::Continue; + }).ignore(); } } } // namespace diff --git a/td/telegram/files/PartsManager.cpp b/td/telegram/files/PartsManager.cpp index 40fcad935..5706a08f0 100644 --- a/td/telegram/files/PartsManager.cpp +++ b/td/telegram/files/PartsManager.cpp @@ -228,7 +228,9 @@ bool PartsManager::is_part_in_streaming_limit(int part_i) const { return true; } - auto is_intersect_with = [&](int64 begin, int64 end) { return max(begin, offset_begin) < min(end, offset_end); }; + auto is_intersect_with = [&](int64 begin, int64 end) { + return max(begin, offset_begin) < min(end, offset_end); + }; auto streaming_begin = streaming_offset_; auto streaming_end = streaming_offset_ + streaming_limit_; diff --git a/td/telegram/net/DcOptionsSet.cpp b/td/telegram/net/DcOptionsSet.cpp index 470c62508..c031ac933 100644 --- a/td/telegram/net/DcOptionsSet.cpp +++ b/td/telegram/net/DcOptionsSet.cpp @@ -135,11 +135,9 @@ Result DcOptionsSet::find_connection(DcId dc_id, b << tag("prefer_ipv6", prefer_ipv6)); } - auto last_error_at = std::min_element(options.begin(), options.end(), - [](const auto &a_option, const auto &b_option) { - return a_option.stat->error_at > b_option.stat->error_at; - }) - ->stat->error_at; + auto last_error_at = std::min_element(options.begin(), options.end(), [](const auto &a_option, const auto &b_option) { + return a_option.stat->error_at > b_option.stat->error_at; + })->stat->error_at; auto result = *std::min_element(options.begin(), options.end(), [](const auto &a_option, const auto &b_option) { auto &a = *a_option.stat; diff --git a/tdactor/td/actor/impl/Scheduler.h b/tdactor/td/actor/impl/Scheduler.h index 7adf451eb..0dd5ea1d2 100644 --- a/tdactor/td/actor/impl/Scheduler.h +++ b/tdactor/td/actor/impl/Scheduler.h @@ -229,37 +229,40 @@ void Scheduler::send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, c template void Scheduler::send_lambda(ActorRef actor_ref, EventT &&lambda) { - return send_impl(actor_ref.get(), - [&](ActorInfo *actor_info) { - event_context_ptr_->link_token = actor_ref.token(); - lambda(); - }, - [&]() { - auto event = Event::lambda(std::forward(lambda)); - event.set_link_token(actor_ref.token()); - return event; - }); + return send_impl( + actor_ref.get(), + [&](ActorInfo *actor_info) { + event_context_ptr_->link_token = actor_ref.token(); + lambda(); + }, + [&]() { + auto event = Event::lambda(std::forward(lambda)); + event.set_link_token(actor_ref.token()); + return event; + }); } template void Scheduler::send_closure(ActorRef actor_ref, EventT &&closure) { - return send_impl(actor_ref.get(), - [&](ActorInfo *actor_info) { - event_context_ptr_->link_token = actor_ref.token(); - closure.run(static_cast(actor_info->get_actor_unsafe())); - }, - [&]() { - auto event = Event::immediate_closure(std::forward(closure)); - event.set_link_token(actor_ref.token()); - return event; - }); + return send_impl( + actor_ref.get(), + [&](ActorInfo *actor_info) { + event_context_ptr_->link_token = actor_ref.token(); + closure.run(static_cast(actor_info->get_actor_unsafe())); + }, + [&]() { + auto event = Event::immediate_closure(std::forward(closure)); + event.set_link_token(actor_ref.token()); + return event; + }); } template void Scheduler::send(ActorRef actor_ref, Event &&event) { event.set_link_token(actor_ref.token()); - return send_impl(actor_ref.get(), [&](ActorInfo *actor_info) { do_event(actor_info, std::move(event)); }, - [&]() { return std::move(event); }); + return send_impl( + actor_ref.get(), [&](ActorInfo *actor_info) { do_event(actor_info, std::move(event)); }, + [&]() { return std::move(event); }); } inline void Scheduler::subscribe(PollableFd fd, PollFlags flags) { diff --git a/tddb/td/db/BinlogKeyValue.h b/tddb/td/db/BinlogKeyValue.h index 970e57ab0..8649e7ba0 100644 --- a/tddb/td/db/BinlogKeyValue.h +++ b/tddb/td/db/BinlogKeyValue.h @@ -77,13 +77,14 @@ class BinlogKeyValue : public KeyValueSyncInterface { } binlog_ = std::make_shared(); - TRY_STATUS(binlog_->init(name, - [&](const BinlogEvent &binlog_event) { - Event event; - event.parse(TlParser(binlog_event.data_)); - map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_)); - }, - std::move(db_key), DbKey::empty(), scheduler_id)); + TRY_STATUS(binlog_->init( + name, + [&](const BinlogEvent &binlog_event) { + Event event; + event.parse(TlParser(binlog_event.data_)); + map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_)); + }, + std::move(db_key), DbKey::empty(), scheduler_id)); return Status::OK(); } diff --git a/tddb/td/db/SqliteKeyValue.cpp b/tddb/td/db/SqliteKeyValue.cpp index 9f96c6301..cfe0a234b 100644 --- a/tddb/td/db/SqliteKeyValue.cpp +++ b/tddb/td/db/SqliteKeyValue.cpp @@ -24,7 +24,9 @@ Result SqliteKeyValue::init(string path) { } Status SqliteKeyValue::init_with_connection(SqliteDb connection, string table_name) { - auto init_guard = ScopeExit() + [&]() { close(); }; + auto init_guard = ScopeExit() + [&]() { + close(); + }; db_ = std::move(connection); table_name_ = std::move(table_name); TRY_STATUS(init(db_, table_name_)); diff --git a/tddb/td/db/SqliteStatement.h b/tddb/td/db/SqliteStatement.h index 9c3885dcc..ecbac9e78 100644 --- a/tddb/td/db/SqliteStatement.h +++ b/tddb/td/db/SqliteStatement.h @@ -56,7 +56,9 @@ class SqliteStatement { void reset(); auto guard() { - return ScopeExit{} + [this] { this->reset(); }; + return ScopeExit{} + [this] { + this->reset(); + }; } // TODO get row diff --git a/tddb/td/db/binlog/binlog_dump.cpp b/tddb/td/db/binlog/binlog_dump.cpp index 3b8dedffe..50c1407dd 100644 --- a/tddb/td/db/binlog/binlog_dump.cpp +++ b/tddb/td/db/binlog/binlog_dump.cpp @@ -28,19 +28,20 @@ int main(int argc, char *argv[]) { SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR)); td::Binlog binlog; binlog - .init(argv[1], - [&](auto &event) { - info[0].compressed_size += event.raw_event_.size(); - info[event.type_].compressed_size += event.raw_event_.size(); - }, - td::DbKey::raw_key("cucumber"), td::DbKey::empty(), -1, - [&](auto &event) mutable { - info[0].full_size += event.raw_event_.size(); - info[event.type_].full_size += event.raw_event_.size(); - LOG(PLAIN) << "LogEvent[" << td::tag("id", td::format::as_hex(event.id_)) << td::tag("type", event.type_) - << td::tag("flags", event.flags_) << td::tag("size", event.data_.size()) - << td::tag("data", td::format::escaped(event.data_)) << "]\n"; - }) + .init( + argv[1], + [&](auto &event) { + info[0].compressed_size += event.raw_event_.size(); + info[event.type_].compressed_size += event.raw_event_.size(); + }, + td::DbKey::raw_key("cucumber"), td::DbKey::empty(), -1, + [&](auto &event) mutable { + info[0].full_size += event.raw_event_.size(); + info[event.type_].full_size += event.raw_event_.size(); + LOG(PLAIN) << "LogEvent[" << td::tag("id", td::format::as_hex(event.id_)) << td::tag("type", event.type_) + << td::tag("flags", event.flags_) << td::tag("size", event.data_.size()) + << td::tag("data", td::format::escaped(event.data_)) << "]\n"; + }) .ensure(); for (auto &it : info) { diff --git a/tdnet/td/net/SslStream.cpp b/tdnet/td/net/SslStream.cpp index 23dff44e8..388d4248b 100644 --- a/tdnet/td/net/SslStream.cpp +++ b/tdnet/td/net/SslStream.cpp @@ -224,7 +224,9 @@ class SslStreamImpl { if (ssl_ctx == nullptr) { return create_openssl_error(-7, "Failed to create an SSL context"); } - auto ssl_ctx_guard = ScopeExit() + [&]() { SSL_CTX_free(ssl_ctx); }; + auto ssl_ctx_guard = ScopeExit() + [&]() { + SSL_CTX_free(ssl_ctx); + }; long options = 0; #ifdef SSL_OP_NO_SSLv2 options |= SSL_OP_NO_SSLv2; diff --git a/tdutils/td/utils/port/StdStreams.cpp b/tdutils/td/utils/port/StdStreams.cpp index 799baed81..388bcf148 100644 --- a/tdutils/td/utils/port/StdStreams.cpp +++ b/tdutils/td/utils/port/StdStreams.cpp @@ -22,7 +22,9 @@ namespace td { template static FileFd &get_file_fd() { static FileFd result = FileFd::from_native_fd(NativeFd(id, true)); - static auto guard = ScopeExit() + [&] { result.move_as_native_fd().release(); }; + static auto guard = ScopeExit() + [&] { + result.move_as_native_fd().release(); + }; return result; } @@ -42,7 +44,9 @@ static FileFd &get_file_fd() { static auto handle = GetStdHandle(id); LOG_IF(FATAL, handle == INVALID_HANDLE_VALUE) << "Failed to GetStdHandle " << id; static FileFd result = FileFd::from_native_fd(NativeFd(handle, true)); - static auto guard = ScopeExit() + [&] { result.move_as_native_fd().release(); }; + static auto guard = ScopeExit() + [&] { + result.move_as_native_fd().release(); + }; #else static FileFd result; #endif diff --git a/tdutils/td/utils/port/detail/ThreadPthread.h b/tdutils/td/utils/port/detail/ThreadPthread.h index 3d9677eaa..6d35ae210 100644 --- a/tdutils/td/utils/port/detail/ThreadPthread.h +++ b/tdutils/td/utils/port/detail/ThreadPthread.h @@ -31,9 +31,7 @@ class ThreadPthread { ThreadPthread() = default; ThreadPthread(const ThreadPthread &other) = delete; ThreadPthread &operator=(const ThreadPthread &other) = delete; - ThreadPthread(ThreadPthread &&other) noexcept - : is_inited_(std::move(other.is_inited_)) - , thread_(other.thread_) { + ThreadPthread(ThreadPthread &&other) noexcept : is_inited_(std::move(other.is_inited_)), thread_(other.thread_) { } ThreadPthread &operator=(ThreadPthread &&other) { join(); diff --git a/tdutils/test/misc.cpp b/tdutils/test/misc.cpp index 4d560fd70..69ee77e18 100644 --- a/tdutils/test/misc.cpp +++ b/tdutils/test/misc.cpp @@ -153,7 +153,8 @@ TEST(Misc, get_last_argument) { } TEST(Misc, call_n_arguments) { - auto f = [](int, int) {}; + auto f = [](int, int) { + }; call_n_arguments<2>(f, 1, 3, 4); } @@ -757,8 +758,12 @@ TEST(Misc, uint128) { static_cast(std::numeric_limits::min()) - 1}; #if TD_HAVE_INT128 - auto to_intrinsic = [](uint128_emulated num) { return uint128_intrinsic(num.hi(), num.lo()); }; - auto eq = [](uint128_emulated a, uint128_intrinsic b) { return a.hi() == b.hi() && a.lo() == b.lo(); }; + auto to_intrinsic = [](uint128_emulated num) { + return uint128_intrinsic(num.hi(), num.lo()); + }; + auto eq = [](uint128_emulated a, uint128_intrinsic b) { + return a.hi() == b.hi() && a.lo() == b.lo(); + }; auto ensure_eq = [&](uint128_emulated a, uint128_intrinsic b) { if (!eq(a, b)) { LOG(FATAL) << "[" << a.hi() << ";" << a.lo() << "] vs [" << b.hi() << ";" << b.lo() << "]"; diff --git a/tdutils/test/port.cpp b/tdutils/test/port.cpp index a051ab8c2..1055c94d5 100644 --- a/tdutils/test/port.cpp +++ b/tdutils/test/port.cpp @@ -41,44 +41,38 @@ TEST(Port, files) { int cnt = 0; const int ITER_COUNT = 1000; for (int i = 0; i < ITER_COUNT; i++) { - walk_path(main_dir, - [&](CSlice name, WalkPath::Type type) { - if (type == WalkPath::Type::NotDir) { - ASSERT_TRUE(name == fd_path || name == fd2_path); - } - cnt++; - }) - .ensure(); + walk_path(main_dir, [&](CSlice name, WalkPath::Type type) { + if (type == WalkPath::Type::NotDir) { + ASSERT_TRUE(name == fd_path || name == fd2_path); + } + cnt++; + }).ensure(); } ASSERT_EQ((5 * 2 + 2) * ITER_COUNT, cnt); bool was_abort = false; - walk_path(main_dir, - [&](CSlice name, WalkPath::Type type) { - CHECK(!was_abort); - if (type == WalkPath::Type::EnterDir && ends_with(name, PSLICE() << TD_DIR_SLASH << "B")) { - was_abort = true; - return WalkPath::Action::Abort; - } - return WalkPath::Action::Continue; - }) - .ensure(); + walk_path(main_dir, [&](CSlice name, WalkPath::Type type) { + CHECK(!was_abort); + if (type == WalkPath::Type::EnterDir && ends_with(name, PSLICE() << TD_DIR_SLASH << "B")) { + was_abort = true; + return WalkPath::Action::Abort; + } + return WalkPath::Action::Continue; + }).ensure(); CHECK(was_abort); cnt = 0; bool is_first_dir = true; - walk_path(main_dir, - [&](CSlice name, WalkPath::Type type) { - cnt++; - if (type == WalkPath::Type::EnterDir) { - if (is_first_dir) { - is_first_dir = false; - } else { - return WalkPath::Action::SkipDir; - } - } - return WalkPath::Action::Continue; - }) - .ensure(); + walk_path(main_dir, [&](CSlice name, WalkPath::Type type) { + cnt++; + if (type == WalkPath::Type::EnterDir) { + if (is_first_dir) { + is_first_dir = false; + } else { + return WalkPath::Action::SkipDir; + } + } + return WalkPath::Action::Continue; + }).ensure(); ASSERT_EQ(6, cnt); ASSERT_EQ(0u, fd.get_size().move_as_ok()); diff --git a/test/db.cpp b/test/db.cpp index 962ba4891..69687bb0c 100644 --- a/test/db.cpp +++ b/test/db.cpp @@ -47,11 +47,17 @@ TEST(DB, binlog_encryption_bug) { auto empty = DbKey::empty(); { Binlog binlog; - binlog.init(binlog_name.str(), [&](const BinlogEvent &x) {}, cucumber).ensure(); + binlog + .init( + binlog_name.str(), [&](const BinlogEvent &x) {}, cucumber) + .ensure(); } { Binlog binlog; - binlog.init(binlog_name.str(), [&](const BinlogEvent &x) {}, cucumber).ensure(); + binlog + .init( + binlog_name.str(), [&](const BinlogEvent &x) {}, cucumber) + .ensure(); } } @@ -92,7 +98,10 @@ TEST(DB, binlog_encryption) { std::vector v; LOG(INFO) << "RESTART"; Binlog binlog; - binlog.init(binlog_name.str(), [&](const BinlogEvent &x) { v.push_back(x.data_.str()); }, hello).ensure(); + binlog + .init( + binlog_name.str(), [&](const BinlogEvent &x) { v.push_back(x.data_.str()); }, hello) + .ensure(); CHECK(v == std::vector({"AAAA", "BBBB", long_data, "CCCC"})); } @@ -102,7 +111,8 @@ TEST(DB, binlog_encryption) { std::vector v; LOG(INFO) << "RESTART"; Binlog binlog; - auto status = binlog.init(binlog_name.str(), [&](const BinlogEvent &x) { v.push_back(x.data_.str()); }, cucumber); + auto status = binlog.init( + binlog_name.str(), [&](const BinlogEvent &x) { v.push_back(x.data_.str()); }, cucumber); CHECK(status.is_error()); } @@ -112,8 +122,8 @@ TEST(DB, binlog_encryption) { std::vector v; LOG(INFO) << "RESTART"; Binlog binlog; - auto status = - binlog.init(binlog_name.str(), [&](const BinlogEvent &x) { v.push_back(x.data_.str()); }, cucumber, hello); + auto status = binlog.init( + binlog_name.str(), [&](const BinlogEvent &x) { v.push_back(x.data_.str()); }, cucumber, hello); CHECK(v == std::vector({"AAAA", "BBBB", long_data, "CCCC"})); } };