From 4f6e7ad05379d2fb25dcd6726aca2d72ab4698c9 Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Wed, 15 Jul 2026 17:53:54 +0300 Subject: [PATCH] Add various testing and building code --- CMakeLists.txt | 24 ++++++++++++++++++++++++ connectors/test.cpp | 17 +++++++++++++++++ core/src/test.cpp | 34 ++++++++++++++++++++++++++++++++++ modules/test.cpp | 31 +++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 connectors/test.cpp create mode 100644 core/src/test.cpp create mode 100644 modules/test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c94dbaa --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.23) + +project(mbft-cpp) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_subdirectory("external/tgbot-cpp") + +add_executable(test) + +file(GLOB ${PROJECT_NAME}_SRC_LIST connectors/**/*.cpp connectors/test.cpp connectors/BotToken.cpp) + +target_sources(test PRIVATE ${${PROJECT_NAME}_SRC_LIST}) +target_sources(test PRIVATE FILE_SET h1 TYPE HEADERS BASE_DIRS .) +target_link_libraries(test PRIVATE TgBot) + +add_executable(test2) + +file(GLOB test2_src connectors/**/*.cpp modules/*.cpp connectors/BotToken.cpp) +target_sources(test2 PRIVATE ${test2_src}) +target_sources(test2 PRIVATE FILE_SET h1 TYPE HEADERS BASE_DIRS .) +target_link_libraries(test2 PRIVATE TgBot) +set_property(TARGET test2 PROPERTY ENABLE_EXPORTS ON) diff --git a/connectors/test.cpp b/connectors/test.cpp new file mode 100644 index 0000000..fd5951a --- /dev/null +++ b/connectors/test.cpp @@ -0,0 +1,17 @@ +#include "connectors/tgbot-cpp/TgbotCppConnector.h" + +int main(void) +{ + MBFT::IConnector *c = new MBFT::TgbotCppConnector(); + + for ( ; ; ) + { + std::shared_ptr msg = c->receive(); + std::shared_ptr reply = std::make_shared(); + + reply->target_chat_id = msg->chat->id; + reply->text = std::string("Hello! The message was:\n") + msg->text; + + c->send(reply); + } +} diff --git a/core/src/test.cpp b/core/src/test.cpp new file mode 100644 index 0000000..68b6323 --- /dev/null +++ b/core/src/test.cpp @@ -0,0 +1,34 @@ +#include "ThreadSafeQueue.h" +#include +#include +#include + +MBFT::ThreadSafeQueue q; + +void a(void) +{ + for (int i = 0; i < 10000; i++) + { + q.push(i); + + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } +} + +void b(void) +{ + for (int i = 0; i < 10000; i++) + { + std::cout << q.pop() << "\n"; + } +} + +int main(void) +{ + std::thread t1(a), t2(b); + + t1.join(); + t2.join(); + + return 0; +} diff --git a/modules/test.cpp b/modules/test.cpp new file mode 100644 index 0000000..e050c04 --- /dev/null +++ b/modules/test.cpp @@ -0,0 +1,31 @@ +#include + +#include "connectors/tgbot-cpp/TgbotCppConnector.h" +#include "modules/Module.h" + +int main(void) +{ + std::shared_ptr c = std::make_shared(); + MBFT::ModuleAPI api(*c); + + MBFT::Module m("modules/echo/main.so"); + + for ( ; ; ) + { + std::shared_ptr msg = c->receive(); + api.set_context(msg.get()); + + std::cout << "New message: " << msg.get()->text << "\n"; + + m.process(api, *msg); + + /* + std::shared_ptr reply = std::make_shared(); + + reply->target_chat_id = msg->chat->id; + reply->text = std::string("Hello! The message was:\n") + msg->text; + + c->send(reply); + */ + } +}