diff --git a/.github/workflows/linux_test.yml b/.github/workflows/linux_test.yml index f2acd49e..e829477c 100644 --- a/.github/workflows/linux_test.yml +++ b/.github/workflows/linux_test.yml @@ -69,4 +69,5 @@ jobs: - name: Run Tests run: | - ./build/bin/TgBot++_test + cd build + ctest diff --git a/.github/workflows/macos_test.yml b/.github/workflows/macos_test.yml index 8131d5e4..f12a3f32 100644 --- a/.github/workflows/macos_test.yml +++ b/.github/workflows/macos_test.yml @@ -35,5 +35,6 @@ jobs: - name: Run Tests run: | - ./build/bin/TgBot++_test + cd build + ctest diff --git a/.github/workflows/windows_msvc.yml b/.github/workflows/windows_msvc.yml.bak similarity index 100% rename from .github/workflows/windows_msvc.yml rename to .github/workflows/windows_msvc.yml.bak diff --git a/.github/workflows/windows_test.yml b/.github/workflows/windows_test.yml index ae86ebc4..90e0f7bd 100644 --- a/.github/workflows/windows_test.yml +++ b/.github/workflows/windows_test.yml @@ -64,4 +64,5 @@ jobs: - name: Run Tests run: | - ./build/bin/TgBot++_test.exe \ No newline at end of file + cd build + ctest \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index d7ab04a9..ed265919 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,7 +223,7 @@ endfunction(add_my_library) function(add_my_executable) cmake_parse_arguments(TGBOT_EXE - "NO_PREFIX;OPTIONAL" # Options + "NO_PREFIX;OPTIONAL;TEST" # Options "NAME" # One-value keywords "SRCS;LIBS;LIBS_WIN32" # Multiple-value keywords ${ARGN} @@ -234,14 +234,22 @@ function(add_my_executable) if (DIRTY_ABSEIL_FIX) list(APPEND TGBOT_EXE_SRCS ${CMAKE_SOURCE_DIR}/src/logging/log_message.cc) endif() + set(TGBOT_EXE_NAME_BAK ${TGBOT_EXE_NAME}) + if (TGBOT_EXE_TEST) + set(TEST_EXT test_) + endif() if (NOT TGBOT_EXE_NO_PREFIX) - set(TGBOT_EXE_NAME ${PROJECT_NAME}_${TGBOT_EXE_NAME}) + set(TGBOT_EXE_NAME ${PROJECT_NAME}_${TEST_EXT}${TGBOT_EXE_NAME}) endif() if (TGBOT_EXE_OPTIONAL) add_executable(${TGBOT_EXE_NAME} EXCLUDE_FROM_ALL ${TGBOT_EXE_SRCS}) else() add_executable(${TGBOT_EXE_NAME} ${TGBOT_EXE_SRCS}) - install(TARGETS ${TGBOT_EXE_NAME} DESTINATION bin) + if (TGBOT_EXE_TEST) + add_test(NAME TestSuite_${TGBOT_EXE_NAME_BAK} COMMAND ${TGBOT_EXE_NAME}) + else() + install(TARGETS ${TGBOT_EXE_NAME} DESTINATION bin) + endif() endif() add_sanitizers(${TGBOT_EXE_NAME}) target_link_libraries(${TGBOT_EXE_NAME} TgBotLogInit absl::log ${TGBOT_EXE_LIBS}) @@ -376,7 +384,7 @@ add_my_library( src/socket/interface/impl/backends/ServerBackend.cpp src/socket/interface/impl/backends/ServerBackend_${TARGET_VARIANT}.cpp LIBS TgBot TgBotUtils TgBotWeb TgBotDBImpl absl::status TgBotRandom TgBot_restartfmt_parser - TgBotPPImpl_shared_deps TgBotStringRes ${CMAKE_DL_LIBS} TgBotSocket JsonCpp::JsonCpp + TgBotPPImpl_shared_deps TgBotStringRes ${CMAKE_DL_LIBS} TgBotSocket JsonCpp::JsonCpp TgBotsighandler STATIC ) ##################################################################### @@ -385,7 +393,7 @@ add_my_library( add_my_executable( NAME main SRCS src/main.cpp - LIBS TgBotPPImpl TgBotDBLoading TgBotsighandler TgBot_restartfmt_parser fruit + LIBS TgBotPPImpl TgBotDBLoading TgBot_restartfmt_parser fruit ) if (UNIX) @@ -408,4 +416,4 @@ set(CPACK_GENERATOR "ZIP;TGZ;NSIS") set(CPACK_PACKAGE_INSTALL_DIRECTORY "TgBot C++ server ${CPACK_PACKAGE_VERSION}") # Include CPack -include(CPack) \ No newline at end of file +include(CPack) diff --git a/src/api/TgBotApiImpl.cpp b/src/api/TgBotApiImpl.cpp index 650045a6..89dbbaa0 100644 --- a/src/api/TgBotApiImpl.cpp +++ b/src/api/TgBotApiImpl.cpp @@ -201,15 +201,16 @@ void TgBotApiImpl::removeInlineQueryKeyboard(const std::string_view key) { } void TgBotApiImpl::startPoll() { - LOG(INFO) << "Bot username: " << getBotUser()->username.value_or("Unknown"); + LOG(INFO) << "Bot username: " << getBotUser()->username.value(); // Deleting webhook getApi().deleteWebhook(); - TgLongPoll longPoll(_bot, 100, 10, - {"message", "inline_query", "callback_query", - "my_chat_member", "chat_member", "chat_join_request"}); + auto* longPoll = _bot.createLongPoll( + 100, 10, + {"message", "inline_query", "callback_query", "my_chat_member", + "chat_member", "chat_join_request"}); while (!SignalHandler::isSignaled()) { - longPoll.start(); + longPoll->start(); } } diff --git a/src/command_modules/alive.cpp b/src/command_modules/alive.cpp index 86ce21bf..9f6fe1d1 100644 --- a/src/command_modules/alive.cpp +++ b/src/command_modules/alive.cpp @@ -35,7 +35,7 @@ DECLARE_COMMAND_HANDLER(alive) { {"_commitid_", data.commitid}, {"_commitmsg_", splitMsg.front()}, {"_botname_", api->getBotUser()->firstName}, - {"_botusername_", api->getBotUser()->username.value()} + {"_botusername_", api->getBotUser()->username.value_or("unknown")} }); }); const auto info = provider->database->queryMediaInfo("alive"); diff --git a/src/include/api/Providers.hpp b/src/include/api/Providers.hpp index b2bd7e9c..202d7034 100644 --- a/src/include/api/Providers.hpp +++ b/src/include/api/Providers.hpp @@ -29,7 +29,7 @@ class Providers { Installable config{}; Installable threads{}; - APPLE_INJECT(Providers(Random *random, ResourceProvider *resource, + APPLE_INJECT(Providers(RandomBase *random, ResourceProvider *resource, DatabaseBase *database, CommandLine *cmd, ConfigManager *configManager, ThreadManager *thread)) { @@ -40,4 +40,4 @@ class Providers { this->config.instance = configManager; this->threads.instance = thread; } -}; \ No newline at end of file +}; diff --git a/src/include/trivial_helpers/_tgbot.h b/src/include/trivial_helpers/_tgbot.h index e8889e53..eff7c83c 100644 --- a/src/include/trivial_helpers/_tgbot.h +++ b/src/include/trivial_helpers/_tgbot.h @@ -24,7 +24,7 @@ constexpr auto fmt::formatter::parse(ParseContext& ctx) { template auto fmt::formatter::format(const User::Ptr& user, FormatContext& ctx) const { - if (!user->lastName.has_value()) { + if (user->lastName.has_value()) { return fmt::format_to(ctx.out(), "{} {} (id: {})", user->firstName, user->lastName.value(), user->id); } diff --git a/src/main.cpp b/src/main.cpp index 4de40a12..ecbf3408 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -354,6 +354,7 @@ getAllComponent(CommandLine cmd) { return fruit::createComponent() .bind() .bind() + .bind() .install(getDatabaseComponent) .install(getTgBotApiImplComponent) .install(getRegexHandlerComponent) diff --git a/src/third-party/tgbot-cpp b/src/third-party/tgbot-cpp index 8ca62261..4aea259b 160000 --- a/src/third-party/tgbot-cpp +++ b/src/third-party/tgbot-cpp @@ -1 +1 @@ -Subproject commit 8ca62261159fabf9b55981988e0465fe8b64e75d +Subproject commit 4aea259b32ecbd1ff28168a75c433168753aa0f4 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ced99cb8..6b92a263 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,7 +2,7 @@ ###################### Creates the test target ###################### add_my_executable( - NAME test + NAME main SRCS TestMain.cpp AuthorizationTest.cpp @@ -20,27 +20,22 @@ add_my_executable( GTest::gtest GTest::gmock TgBotPPImpl fruit - OPTIONAL + TEST ) -# Add the test executable to CTest -add_test(NAME TestSuite COMMAND TgBot++_test) - add_my_executable( - NAME test_database + NAME database SRCS TestMain.cpp DatabaseBackendsTest.cpp LIBS GTest::gtest TgBotDBImpl - OPTIONAL + TEST ) -# Add the test executable to CTest -add_test(NAME TestSuiteDatabase COMMAND TgBot++_test_database) add_my_executable( - NAME test_socketdatahandler + NAME socketdatahandler SRCS TestMain.cpp SocketDataHandlerTest.cpp @@ -49,7 +44,5 @@ add_my_executable( GTest::gmock TgBotPPImpl fruit - OPTIONAL + TEST ) -# Add the test executable to CTest -add_test(NAME TestSuiteSocketDataHandler COMMAND TgBot++_test_socketdatahandler) \ No newline at end of file diff --git a/tests/commands/AliveCmdTest.cpp b/tests/commands/AliveCmdTest.cpp index 282d4ed1..bc15642f 100644 --- a/tests/commands/AliveCmdTest.cpp +++ b/tests/commands/AliveCmdTest.cpp @@ -12,7 +12,8 @@ class AliveCommandTest : public CommandTestBase { TEST_F(AliveCommandTest, hasAliveMediaName) { setCommandExtArgs(); - const auto botUser = std::make_shared(); + auto botUser = std::make_shared(); + botUser->username = "ALALALASL"; // Would call two times for username, nickname ON_CALL(*botApi, getBotUser_impl()).WillByDefault(Return(botUser)); diff --git a/tests/commands/CommandModulesTest.hpp b/tests/commands/CommandModulesTest.hpp index 33a2630f..4ef751d9 100644 --- a/tests/commands/CommandModulesTest.hpp +++ b/tests/commands/CommandModulesTest.hpp @@ -168,13 +168,13 @@ class CommandTestBase : public CommandModulesTest { void setCommandExtArgs( const std::initializer_list& command) { setCommandExtArgs(); - defaultProvidedMessage->text += + (*defaultProvidedMessage->text) += fmt::format("{}", fmt::join(command, " ")); } void setCommandExtArgs() { defaultProvidedMessage->text = "/" + name; defaultProvidedMessage->entities[0]->length = - defaultProvidedMessage->text.size(); + defaultProvidedMessage->text->size(); } void execute() { module->_module->function( diff --git a/tests/commands/DatabaseCmdTest.cpp b/tests/commands/DatabaseCmdTest.cpp index a742d47b..fc9dc0f3 100644 --- a/tests/commands/DatabaseCmdTest.cpp +++ b/tests/commands/DatabaseCmdTest.cpp @@ -5,10 +5,7 @@ #include #include "CommandModulesTest.hpp" -#include "StringResLoader.hpp" #include "api/TgBotApi.hpp" -#include "api/Utils.hpp" -#include "gmock/gmock.h" namespace { void verifyKeyboard(const TgBot::GenericReply::Ptr& reply) { @@ -16,10 +13,10 @@ void verifyKeyboard(const TgBot::GenericReply::Ptr& reply) { std::dynamic_pointer_cast(reply); ASSERT_TRUE(keyboardReply); - EXPECT_TRUE(keyboardReply->resizeKeyboard); - EXPECT_TRUE(keyboardReply->oneTimeKeyboard); - EXPECT_TRUE(keyboardReply->selective); - EXPECT_FALSE(keyboardReply->isPersistent); + EXPECT_TRUE(keyboardReply->resizeKeyboard.value()); + EXPECT_TRUE(keyboardReply->oneTimeKeyboard.value()); + EXPECT_TRUE(keyboardReply->selective.value()); + EXPECT_FALSE(keyboardReply->isPersistent.value()); } } // namespace @@ -119,4 +116,4 @@ TEST_F(DatabaseCommandTest, WithUserAddToBlackList) { TEST_F(DatabaseCommandTest, WithUserRemoveFromBlackList) { test_removeuser(); -} \ No newline at end of file +}