80 lines
4.0 KiB
C++
80 lines
4.0 KiB
C++
/**
|
|
* @file spitRepoTest.cpp
|
|
* @author Gustice
|
|
* @brief
|
|
*/
|
|
|
|
#include "doctest/doctest.h"
|
|
#include <fmt/core.h>
|
|
#include <iostream>
|
|
|
|
#include "spit_client.hpp"
|
|
|
|
using namespace spit;
|
|
using namespace std;
|
|
|
|
class ClientMock {
|
|
public:
|
|
void onServerEvent(SClient::ServerEvent event, const SadDetectedServer &detectedServer) {
|
|
}
|
|
void onConnectionStatus(string serverID, string serverComputerName, string serverName, int serverStepTime, SClient::Connection connectionStatus, SClient::Connection oldConnectionStatus) {
|
|
}
|
|
void onProjectUpdate(SClient::ProjUpdate state, string projectId) {
|
|
}
|
|
void onSpitType(SClient::ObjectEvent event, bool isRemote, const SType &spitType) {
|
|
}
|
|
void onSpitObject(SClient::ObjectEvent event, bool isRemote, const SType &spitType, const SObject &spitObject) {
|
|
}
|
|
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 &spitType, const SObject &spitObject, uint64_t p_FrameInsideObject, int value) {
|
|
}
|
|
bool onCheckSpitTypeVeto(bool knownType, bool createdByClient) {
|
|
}
|
|
bool onCheckSpitObjectVeto(bool knownType) {
|
|
}
|
|
};
|
|
|
|
class SocketMock : public ISocket {
|
|
public:
|
|
SocketMock(IpAddress ip) : ISocket(ip) {}
|
|
|
|
int sendMessage(const char *message, int length) override {
|
|
}
|
|
int receiveMessage(char *bu1ffer, int bufferLength, string *serverIp) const override {
|
|
}
|
|
void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) override {
|
|
}
|
|
int bindSocket(string clientIp, string clientPort) override {
|
|
}
|
|
int setBroadcast(bool broadcast) const override {
|
|
}
|
|
int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) override {
|
|
}
|
|
};
|
|
|
|
class SpitClientFix {
|
|
protected:
|
|
static ClientMock client;
|
|
ISocket::IpAddress ip{"10.10.0.1", "255.255.255.0"};
|
|
SocketMock socket{ip};
|
|
SClient::Callbacks callbacks{
|
|
.onServerEvent = [&](SClient::ServerEvent event, const SadDetectedServer &detectedServer){client.onServerEvent(event, detectedServer);} ,
|
|
.onConnectionStatus = [&](string serverID, string serverComputerName, string serverName, int serverStepTime, SClient::Connection connectionStatus, SClient::Connection oldConnectionStatus){client.onConnectionStatus(serverID, serverComputerName, serverName, serverStepTime, connectionStatus, oldConnectionStatus);} ,
|
|
.onProjectUpdate = [&](SClient::ProjUpdate state, string projectId){client.onProjectUpdate(state, projectId);} ,
|
|
.onSpitType = [&](SClient::ObjectEvent event, bool isRemote, const SType &spitType){client.onSpitType(event, isRemote, spitType);} ,
|
|
.onSpitObject = [&](SClient::ObjectEvent event, bool isRemote, const SType &spitType, const SObject &spitObject){client.onSpitObject(event, isRemote, spitType, spitObject);} ,
|
|
.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 &spitType, const SObject &spitObject, uint64_t p_FrameInsideObject, int value){client.onPlayRemoteObjectStatus( spitType, spitObject, p_FrameInsideObject, value);} ,
|
|
.onCheckSpitTypeVeto = [&](bool knownType, bool createdByClient){return client.onCheckSpitTypeVeto(knownType, createdByClient);} ,
|
|
.onCheckSpitObjectVeto = [&](bool knownType){return client.onCheckSpitObjectVeto(knownType);}
|
|
};
|
|
SClient sut{"sut", "sutProj", socket, callbacks};
|
|
};
|
|
|
|
TEST_CASE_FIXTURE(SpitClientFix, "Typical use case") {
|
|
}
|