Add various testing and building code
This commit is contained in:
@@ -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)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#include "connectors/tgbot-cpp/TgbotCppConnector.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
MBFT::IConnector *c = new MBFT::TgbotCppConnector();
|
||||||
|
|
||||||
|
for ( ; ; )
|
||||||
|
{
|
||||||
|
std::shared_ptr<MBFT::InboundMessage> msg = c->receive();
|
||||||
|
std::shared_ptr<MBFT::OutboundMessage> reply = std::make_shared<MBFT::OutboundMessage>();
|
||||||
|
|
||||||
|
reply->target_chat_id = msg->chat->id;
|
||||||
|
reply->text = std::string("Hello! The message was:\n") + msg->text;
|
||||||
|
|
||||||
|
c->send(reply);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#include "ThreadSafeQueue.h"
|
||||||
|
#include <thread>
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
MBFT::ThreadSafeQueue<int> 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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "connectors/tgbot-cpp/TgbotCppConnector.h"
|
||||||
|
#include "modules/Module.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
std::shared_ptr<MBFT::TgbotCppConnector> c = std::make_shared<MBFT::TgbotCppConnector>();
|
||||||
|
MBFT::ModuleAPI api(*c);
|
||||||
|
|
||||||
|
MBFT::Module m("modules/echo/main.so");
|
||||||
|
|
||||||
|
for ( ; ; )
|
||||||
|
{
|
||||||
|
std::shared_ptr<MBFT::InboundMessage> msg = c->receive();
|
||||||
|
api.set_context(msg.get());
|
||||||
|
|
||||||
|
std::cout << "New message: " << msg.get()->text << "\n";
|
||||||
|
|
||||||
|
m.process(api, *msg);
|
||||||
|
|
||||||
|
/*
|
||||||
|
std::shared_ptr<MBFT::OutboundMessage> reply = std::make_shared<MBFT::OutboundMessage>();
|
||||||
|
|
||||||
|
reply->target_chat_id = msg->chat->id;
|
||||||
|
reply->text = std::string("Hello! The message was:\n") + msg->text;
|
||||||
|
|
||||||
|
c->send(reply);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user