177 lines
7.2 KiB
C++
177 lines
7.2 KiB
C++
/**
|
|
* @file spitRepoTest.cpp
|
|
* @author Gustice
|
|
* @brief
|
|
*/
|
|
|
|
#include "doctest/doctest.h"
|
|
#include <fmt/core.h>
|
|
#include <iostream>
|
|
#include <queue>
|
|
|
|
#include "spit_processor.hpp"
|
|
|
|
using namespace spit;
|
|
using namespace std;
|
|
static queue<string> cbEvents;
|
|
|
|
class ClientMock {
|
|
public:
|
|
void onServerEvent(SProcessor::ServerEvent event, const SadDetectedServer &detectedServer) {
|
|
}
|
|
void onConnectionStatus(string serverID, string serverComputerName, string serverName, int serverStepTime, SProcessor::Connection connectionStatus, SProcessor::Connection oldConnectionStatus) {
|
|
}
|
|
void onProjectUpdate(SProcessor::ProjUpdate state, string projectId) {
|
|
}
|
|
void onSpitType(SProcessor::ObjectEvent event, bool isRemote, const SType &sType) {
|
|
cbEvents.push(fmt::format("{}: {} {} {} {}", (int)event, isRemote, sType.getID(), sType.Name.get(), sType.GroupName.get()));
|
|
}
|
|
void onSpitObject(SProcessor::ObjectEvent event, bool isRemote, const SType &sType, const SObject &sObject) {
|
|
cbEvents.push(fmt::format("{}: {} {} {} {} {}", (int)event, isRemote, sType.getID(), sType.Name.get(), sObject.Name.get(), sObject.getID()));
|
|
}
|
|
void onPlay(string playerID, string playerName, char playerType, bool playerIsRunning, uint64_t timeFrames) {
|
|
}
|
|
void onPlaySpitType(string playerID, string spitTypeID, bool playerIsRunning, bool started, bool ended, double value) {
|
|
}
|
|
void onPlayRemoteObjectStatus(const SType &sType, const SObject &sObject, uint64_t p_FrameInsideObject, int value) {
|
|
}
|
|
bool onCheckSpitTypeVeto(bool knownType, bool createdByClient) {
|
|
cbEvents.push(fmt::format("veto check {}/{}", knownType, createdByClient));
|
|
return true;
|
|
}
|
|
bool onCheckSpitObjectVeto(bool knownType) {
|
|
return true;
|
|
}
|
|
};
|
|
|
|
class SpitClientFix {
|
|
protected:
|
|
ClientMock client;
|
|
SProcessor::Callbacks callbacks{
|
|
.onServerEvent = [&](SProcessor::ServerEvent event, const SadDetectedServer &detectedServer) { client.onServerEvent(event, detectedServer); },
|
|
.onConnectionStatus = [&](string serverID, string serverComputerName, string serverName, int serverStepTime, SProcessor::Connection connectionStatus, SProcessor::Connection oldConnectionStatus) { client.onConnectionStatus(serverID, serverComputerName, serverName, serverStepTime, connectionStatus, oldConnectionStatus); },
|
|
.onProjectUpdate = [&](SProcessor::ProjUpdate state, string projectId) { client.onProjectUpdate(state, projectId); },
|
|
.onSpitType = [&](SProcessor::ObjectEvent event, bool isRemote, const SType &t) { client.onSpitType(event, isRemote, t); },
|
|
.onSpitObject = [&](SProcessor::ObjectEvent event, bool isRemote, const SType &t, const SObject &o) { client.onSpitObject(event, isRemote, t, o); },
|
|
.onPlay = [&](string playerID, string playerName, char playerType, bool playerIsRunning, uint64_t timeFrames) { client.onPlay(playerID, playerName, playerType, playerIsRunning, timeFrames); },
|
|
.onPlaySpitType = [&](string playerID, string spitTypeID, bool playerIsRunning, bool started, bool ended, double value) { client.onPlaySpitType(playerID, spitTypeID, playerIsRunning, started, ended, value); },
|
|
.onPlayRemoteObjectStatus = [&](const SType &t, const SObject &o, uint64_t p_FrameInsideObject, int value) { client.onPlayRemoteObjectStatus(t, o, p_FrameInsideObject, value); },
|
|
.onCheckSpitTypeVeto = [&](bool knownType, bool createdByClient) { return client.onCheckSpitTypeVeto(knownType, createdByClient); },
|
|
.onCheckSpitObjectVeto = [&](bool knownType) { return client.onCheckSpitObjectVeto(knownType); }};
|
|
SProcessor::InternalCallbacks intCallbacks {
|
|
.delay = [&](int ms){ return ; },
|
|
.sendMessage = [&](Message::OPPart &msg){ return 0; },
|
|
.sendTypeInternal = [&](SType &sType) { return 0; },
|
|
.sendObjectInternal = [&](SObject *sObject) { return 0; }
|
|
};
|
|
SProcessor sut{"sut", "sutProj", "dev", "##GUID##", callbacks, intCallbacks};
|
|
};
|
|
|
|
TEST_CASE_FIXTURE(SpitClientFix, "Spit types") {
|
|
|
|
{
|
|
Message::ReportType t;
|
|
t.setConfirmed(false);
|
|
t.setID("type1Id#Rem");
|
|
t.setFixed(true);
|
|
t.setServerRemote(true);
|
|
t.setServerProjectIndepended(true);
|
|
t.setGroupName("sGroup");
|
|
t.setName("type1Name");
|
|
t.setDelay(100);
|
|
t.setDuration(200);
|
|
sut.checkParseMessageData(sut.createMessage(t));
|
|
}
|
|
CHECK_MESSAGE(cbEvents.front() == "0: true type1Id#Rem type1Name sGroup", cbEvents.front());
|
|
cbEvents.pop();
|
|
|
|
{
|
|
Message::ReportType t;
|
|
t.setConfirmed(false);
|
|
t.setID("type2Id#Rem");
|
|
t.setFixed(true);
|
|
t.setServerRemote(true);
|
|
t.setServerProjectIndepended(true);
|
|
t.setGroupName("sGroup");
|
|
t.setName("type2Name");
|
|
t.setDelay(100);
|
|
t.setDuration(200);
|
|
sut.checkParseMessageData(sut.createMessage(t));
|
|
}
|
|
CHECK_MESSAGE(cbEvents.front() == "0: true type2Id#Rem type2Name sGroup", cbEvents.front());
|
|
cbEvents.pop();
|
|
|
|
{
|
|
Message::ReportType t;
|
|
t.setConfirmed(false);
|
|
t.setID("type1Id#Rem");
|
|
t.setFixed(true);
|
|
t.setServerRemote(true);
|
|
t.setServerProjectIndepended(true);
|
|
t.setGroupName("sGroup");
|
|
t.setName("type1Name");
|
|
t.setDelay(200);
|
|
t.setDuration(300);
|
|
sut.checkParseMessageData(sut.createMessage(t));
|
|
}
|
|
CHECK_MESSAGE(cbEvents.front() == "1: true type1Id#Rem type1Name sGroup", cbEvents.front());
|
|
cbEvents.pop();
|
|
|
|
CHECK(cbEvents.empty());
|
|
|
|
// Local Objects
|
|
|
|
{
|
|
Message::ReportType t;
|
|
t.setConfirmed(false);
|
|
t.setID("type1Id#Loc");
|
|
t.setFixed(true);
|
|
t.setServerRemote(false);
|
|
t.setServerProjectIndepended(true);
|
|
t.setGroupName("sGroup");
|
|
t.setName("type1Name");
|
|
t.setDelay(100);
|
|
t.setDuration(200);
|
|
sut.checkParseMessageData(sut.createMessage(t));
|
|
}
|
|
CHECK_MESSAGE(cbEvents.front() == "veto check false/false", cbEvents.front());
|
|
cbEvents.pop();
|
|
CHECK_MESSAGE(cbEvents.front() == "0: false type1Id#Loc type1Name sGroup", cbEvents.front());
|
|
cbEvents.pop();
|
|
|
|
{
|
|
Message::ReportType t;
|
|
t.setConfirmed(false);
|
|
t.setID("type2Id#Loc");
|
|
t.setFixed(true);
|
|
t.setServerRemote(false);
|
|
t.setServerProjectIndepended(true);
|
|
t.setGroupName("sGroup");
|
|
t.setName("type2Name");
|
|
t.setDelay(100);
|
|
t.setDuration(200);
|
|
sut.checkParseMessageData(sut.createMessage(t));
|
|
}
|
|
CHECK_MESSAGE(cbEvents.front() == "veto check false/false", cbEvents.front());
|
|
cbEvents.pop();
|
|
CHECK_MESSAGE(cbEvents.front() == "0: false type2Id#Loc type2Name sGroup", cbEvents.front());
|
|
cbEvents.pop();
|
|
|
|
{
|
|
Message::ReportType t;
|
|
t.setConfirmed(false);
|
|
t.setID("type1Id#Loc");
|
|
t.setFixed(true);
|
|
t.setServerRemote(false);
|
|
t.setServerProjectIndepended(true);
|
|
t.setGroupName("sGroup");
|
|
t.setName("type1Name");
|
|
t.setDelay(200);
|
|
t.setDuration(300);
|
|
sut.checkParseMessageData(sut.createMessage(t));
|
|
}
|
|
CHECK_MESSAGE(cbEvents.front() == "1: false type1Id#Loc type1Name sGroup", cbEvents.front());
|
|
cbEvents.pop();
|
|
CHECK(cbEvents.empty());
|
|
}
|