/
farado
/
farado-binara
Обзор
Документация
Войти
/
farado
/
farado-binara
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
develop
tests/api/test_api_set_element.cpp
83 строки
2 KB
Ostapenko Alexey
[common][datenaro][retejo][tests] Убраны лишние include, местами в пользу forward declaration.
13 янв 2024, 16:03
13 янв 2024, 16:03
f1e4442
Код
Авторство
О чём код?
#define BOOST_TEST_MODULE testSetElement #include <memory> #include <thread> #include <boost/test/unit_test.hpp> #include <crow.h> #include "common/api/client.h" #include "common/api/result.hpp" #include "common/api/server.h" #include "common/api/server_helper.hpp" #include "common/elements/element_type.hpp" #include "common/elements/item.h" #include "common/elements/user.h" #include "common/more/uuid.h" class Server final { public: Server() : m_crowApplication(new crow::SimpleApp) { ADD_CROW_ROUTE_SET_ELEMENT( (*m_crowApplication), [this]( const Uuids::Uuid& sessionUuid, std::shared_ptr<Elements::Element> element ) -> bool { if (sessionUuid.is_nil()) return false; return (Elements::ElementType::User == element->elementType()); } ); m_runThread.reset(new std::thread( [this]() { m_crowApplication->port(8080).multithreaded().run(); } )); m_stopThread.reset(new std::thread( [this]() { stop(); } )); } ~Server() { m_stopThread->join(); m_runThread->join(); } private: std::unique_ptr<crow::SimpleApp> m_crowApplication; std::unique_ptr<std::thread> m_runThread; std::unique_ptr<std::thread> m_stopThread; void stop() { std::this_thread::sleep_for(std::chrono::seconds(2)); m_crowApplication->stop(); } }; Server server; Api::Client client("http://127.0.0.1:8080"); BOOST_AUTO_TEST_CASE(testCorrectSetElement) { const auto uuid = Uuids::newUuid(); const auto element = std::make_shared<Elements::User>(); BOOST_CHECK(client.setElement(uuid, element).m_isSuccess); } BOOST_AUTO_TEST_CASE(testNonCorrectSetElement) { const auto uuid = Uuids::newUuid(); const auto element = std::make_shared<Elements::Item>(); BOOST_CHECK(!client.setElement(uuid, element).m_isSuccess); }