PhoenixSwarm  5.1.1
Library to ease communication between daemons
Loading...
Searching...
No Matches
main.cpp File Reference
#include <iostream>
#include "swarm_mock_daemon.h"
+ Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

void createDaemon (const PPath &fileName, const PString &daemonName)
 Create and run the Daemon.
 
void createMockFileMainRecv (const PString &hostName, size_t port, const PString &prefix)
 Create the mock file to be used by the Daemon.
 
void createMockFileMainSend (const PString &hostName, size_t port, const PString &prefix)
 Create the mock file fo the test Daemon.
 
int main (int argc, char **argv)
 
void testBaseDaemonLoadConfig (const PPath &fileName)
 Test the load configuration of a Daemon.
 

Function Documentation

◆ createDaemon()

void createDaemon ( const PPath & fileName,
const PString & daemonName )

Create and run the Daemon.

Parameters
fileName: name of the configuration toml file
daemonName: name of the daemon of the current test

Definition at line 71 of file main.cpp.

71 {
72 //Let's create and start the Daemon
73 SendDataDaemon daemon;
74 daemon.setSocketMode(PSocketMode::MOCK);
75 daemon.setClockMode(PClockMode::MOCK);
76 daemon.getLog().setFileName(PPath("Daemon.log"));
77 daemon.load(fileName, daemonName);
78 phoenix_assert(daemon.run());
79}

◆ createMockFileMainRecv()

void createMockFileMainRecv ( const PString & hostName,
size_t port,
const PString & prefix )

Create the mock file to be used by the Daemon.

Parameters
hostName: name of the host
port: port to be used
prefix: prefix of the mock file of the current test

Definition at line 56 of file main.cpp.

56 {
57 PMockSocketGenerator::Socket mock;
58 phoenix_assert(phoenix_initializeMockSocket(mock, PSocketParam{hostName, port}, prefix));
59
60 //Finally we stop the Daemon
61 Message messageStop;
62 messageStop.setId(2lu);
63 messageStop.setType(MessageType::STOP);
64 mock.sendData(messageStop);
65}

References MessageType::STOP.

◆ createMockFileMainSend()

void createMockFileMainSend ( const PString & hostName,
size_t port,
const PString & prefix )

Create the mock file fo the test Daemon.

Parameters
hostName: name of the host
port: port to be used
prefix: prefix of the mock file of the current test

Definition at line 34 of file main.cpp.

34 {
35 PMockSocketGenerator::Socket mock;
36 phoenix_assert(phoenix_initializeMockSocket(mock, PSocketParam{hostName, port}, prefix));
37// PVecMockMessage vecOutput;
38 //Let's say, the main Daemon wants to call a function on test
39 Message message;
40 message.setId(1lu); //Anwser of the INT message
41 message.setSendTime(1lu);
42 message.setIsConfirmationNeeded(true);
43 message.setType(MessageType::RESULT_DATA);
44 message.setSender("main");
45 int data(42);
46 message.setData(phoenix_createData(data));
47 message.getVecRecver().push_back("test");
48 mock.sendData(message);
49}
Swarm::Data phoenix_createData(const T &value)
Create a Data from a value.

References phoenix_createData(), and MessageType::RESULT_DATA.

+ Here is the call graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 94 of file main.cpp.

94 {
95 testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK_TOML));
96 testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK_YAML));
97 return 0;
98}
void testBaseDaemonLoadConfig(const PPath &fileName)
Test the load configuration of a Daemon.
Definition main.cpp:84

References testBaseDaemonLoadConfig().

+ Here is the call graph for this function:

◆ testBaseDaemonLoadConfig()

void testBaseDaemonLoadConfig ( const PPath & fileName)

Test the load configuration of a Daemon.

Parameters
fileName: name of the configuration toml file

Definition at line 84 of file main.cpp.

84 {
85 //Let's create the mock file
86 phoenix_createClockMock("main_", 4lu);
87 createMockFileMainRecv("localhost", 3390, "main_");
88 //No need to check the output of the messages sent by the Daemon, because the PMockSocketGenerator already does it for us
89 createMockFileMainSend("localhost", 3391, "main_");
90 //Let's create and start the Daemon
91 createDaemon(fileName, "main");
92}
void createDaemon(const PPath &fileName, const PString &daemonName)
Create a simple Daemon stat manager.
Definition main.cpp:109
void createMockFileMainRecv(const PString &hostName, size_t port, const PString &prefix)
Simulate data to send.
Definition main.cpp:70
void createMockFileMainSend(const PString &hostName, size_t port, const PString &prefix)
Simulate data to send.
Definition main.cpp:44

References createDaemon(), createMockFileMainRecv(), and createMockFileMainSend().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: