RoboidControl-cpp/test/thing_test.cc
Pascal Serrarens f2f942d084 Refactoring
2025-02-28 15:01:23 +01:00

98 lines
2.4 KiB
C++

#if GTEST
// #include <gmock/gmock.h>
// not supported using Visual Studio 2022 compiler...
#include <gtest/gtest.h>
#include <chrono>
#include <thread>
// #include <ws2tcpip.h>
#include "Participant.h"
#include "SiteServer.h"
#include "Thing.h"
using namespace RoboidControl;
// Function to get the current time in milliseconds as unsigned long
unsigned long get_time_ms() {
auto now = std::chrono::steady_clock::now();
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
now.time_since_epoch());
return static_cast<unsigned long>(ms.count());
}
class ControlCoreSuite : public ::testing::Test {
protected:
// SetUp and TearDown can be used to set up and clean up before/after each
// test
void SetUp() override {
// Initialize test data here
}
void TearDown() override {
// Clean up test data here
}
};
TEST_F(ControlCoreSuite, LocalParticipant) {
LocalParticipant participant = LocalParticipant("127.0.0.1", 7681);
unsigned long milliseconds = get_time_ms();
unsigned long startTime = milliseconds;
while (milliseconds < startTime + 1000) {
participant.Update(milliseconds);
milliseconds = get_time_ms();
}
ASSERT_EQ(1, 1);
}
TEST_F(ControlCoreSuite, SiteServer) {
SiteServer site = SiteServer(7681);
unsigned long milliseconds = get_time_ms();
unsigned long startTime = milliseconds;
while (milliseconds < startTime + 1000) {
site.Update(milliseconds);
milliseconds = get_time_ms();
}
ASSERT_EQ(1, 1);
}
TEST_F(ControlCoreSuite, SiteParticipant) {
SiteServer site = SiteServer(7681);
LocalParticipant participant = LocalParticipant("127.0.0.1", 7681);
unsigned long milliseconds = get_time_ms();
unsigned long startTime = milliseconds;
while (milliseconds < startTime + 1000) {
site.Update(milliseconds);
participant.Update(milliseconds);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
milliseconds = get_time_ms();
}
ASSERT_EQ(1, 1);
}
TEST_F(ControlCoreSuite, Thing) {
SiteServer site = SiteServer(7681);
LocalParticipant participant = LocalParticipant("127.0.0.1", 7681);
Thing thing = Thing(&participant);
unsigned long milliseconds = get_time_ms();
unsigned long startTime = milliseconds;
while (milliseconds < startTime + 1000) {
site.Update(milliseconds);
participant.Update(milliseconds);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
milliseconds = get_time_ms();
}
ASSERT_EQ(1, 1);
}
#endif