/** * @file test_mean.cpp * @author Gustice * @brief Hardware bound unit-Test example device */ #include "spit_client.hpp" #include "unity.h" #include #include #include using namespace spit; using namespace std; queue callbackEvents; 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) { return true; } bool onCheckSpitObjectVeto(bool knownType) { return true; } }; class SocketMock : public ISocket { public: SocketMock(IpAddress ip) : ISocket(ip) {} int sendMessage(const char *message, int length) override { return 0; } int receiveMessage(char *bu1ffer, int bufferLength, string *serverIp) const override { return 0; } void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) override { } int bindSocket(string clientIp, string clientPort) override { return 0; } int setBroadcast(bool broadcast) const override { return 0; } int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) override { return 0; } }; // 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("Full Connect precedure", "[spit][init]") { 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}; // tood connect - Response - Request project // Transfer items liveSHOW -> Device { Message::ReportType t1; t1.setConfirmed(false); t1.setID("type1Id#"); t1.setFixed(true); t1.setServerRemote("serverId"); t1.setServerProjectIndepended(true); t1.setGroupName("sGroup"); t1.setName("type1Name"); t1.setDelay(100); t1.setDuration(200); socket. } }