110 lines
2.2 KiB
C++
110 lines
2.2 KiB
C++
|
|
|
|
#include "SimControl/SimControl.hpp"
|
|
|
|
#include "nlohmann/json_fwd.hpp"
|
|
#include <fstream>
|
|
#include <future>
|
|
#include <memory>
|
|
#include <queue>
|
|
#include <string>
|
|
#define CATCH_CONFIG_MAIN
|
|
#include "SimControl/PodList.hpp"
|
|
#include <catch2/catch.hpp>
|
|
#include <loguru.hpp>
|
|
|
|
#include "string.cpp"
|
|
|
|
#include "easywsclient.hpp"
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
int runSimConntrol(bool *running)
|
|
{
|
|
SimControl::SimControl sc(false,"CommandPortChar","5555",SimCore::UtilFunctions::StringToUShort("10000"),"simulator");
|
|
while (*running) {
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
// LOG_S(INFO)<<*running;
|
|
}
|
|
LOG_S(INFO)<<"stopping ";
|
|
sc.stop();
|
|
return 0;
|
|
}
|
|
|
|
std::queue<std::string> msgqueue_in_;
|
|
std::queue<std::string> msgqueue_out_;
|
|
|
|
|
|
|
|
void handle_message(std::string m)
|
|
{
|
|
LOG_S(INFO)<<m;
|
|
msgqueue_in_.push(m);
|
|
|
|
}
|
|
|
|
|
|
void wsFunction(bool *running)
|
|
{
|
|
std::unique_ptr<easywsclient::WebSocket> ws(easywsclient::WebSocket::from_url("ws://localhost:9999/"));
|
|
|
|
|
|
while (*running)
|
|
{
|
|
ws->poll();
|
|
ws->dispatch(handle_message);
|
|
while(msgqueue_out_.size() > 0)
|
|
{
|
|
ws->send(msgqueue_out_.front());
|
|
msgqueue_out_.pop();
|
|
}
|
|
|
|
}
|
|
ws->close();
|
|
|
|
}
|
|
|
|
SCENARIO("Testing the the podlist")
|
|
{
|
|
bool *running = new bool(true);
|
|
std::thread t1(runSimConntrol,running) ;
|
|
// auto res = std::async(std::launch::deferred,runSimConntrol,running);
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
|
std::thread t2(wsFunction,running) ;
|
|
|
|
nlohmann::json j;
|
|
j["Data"] = "TEST";
|
|
|
|
bool gotMessage = false;
|
|
|
|
msgqueue_out_.push(j.dump());
|
|
|
|
|
|
GIVEN("different Attributes for a Track in different forms")
|
|
{
|
|
|
|
WHEN("constructing Track Object with data")
|
|
{
|
|
|
|
THEN("check if Track attributes are correct")
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
LOG_S(INFO)<<"stop";
|
|
*running = false;
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|
|
|
// REQUIRE(t1.joinable());
|
|
auto j = nlohmann::json::parse(msgqueue_in_.front());
|
|
msgqueue_in_.pop();
|
|
REQUIRE(j["Message"] == "Hello world" );
|
|
|
|
t1.join();
|
|
t2.join();
|
|
|
|
|
|
} //THEN
|
|
} // WHEN
|
|
} // GIVEN
|
|
} //SCENARIO
|