/
farado
/
farado-binara
Обзор
Документация
Войти
/
farado
/
farado-binara
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
develop
tests/api/test_api_del_element.cpp
85 строк
2 KB
Ostapenko Alexey
[common][datenaro][retejo][tests] Убраны лишние include, местами в пользу forward declaration.
13 янв 2024, 16:03
13 янв 2024, 16:03
f1e4442
Код
Авторство
О чём код?
#define BOOST_TEST_MODULE testDelElement #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/more/uuid.h" class Server final { public: Server() : m_crowApplication(new crow::SimpleApp) { ADD_CROW_ROUTE_DEL_ELEMENT( (*m_crowApplication), [this]( const Uuids::Uuid& sessionUuid, Elements::ElementType type, unsigned id ) -> bool { return bool( Uuids::nilUuid() != sessionUuid && Elements::ElementType::User == type && 9 == id ); } ); 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(testCorrectDelElement) { const auto uuid = Uuids::newUuid(); const auto type = Elements::ElementType::User; const unsigned id = 9; BOOST_CHECK(client.delElement(uuid, type, id).m_isSuccess); } BOOST_AUTO_TEST_CASE(testNonCorrectDelElement) { const auto uuid = Uuids::nilUuid(); const auto type = Elements::ElementType::Item; const unsigned id = 0; BOOST_CHECK(!client.delElement(uuid, type, id).m_isSuccess); }