Directory: | ./ |
---|---|
File: | TESTS/TEST_DAEMON_PINGPONG/main.cpp |
Date: | 2025-03-14 12:18:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 54 | 54 | 100.0% |
Branches: | 79 | 79 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | |||
2 | /*************************************** | ||
3 | Auteur : Pierre Aubert | ||
4 | Mail : pierre.aubert@lapp.in2p3.fr | ||
5 | Licence : CeCILL-C | ||
6 | ****************************************/ | ||
7 | |||
8 | #include <iostream> | ||
9 | #include "PingPongDaemon.h" | ||
10 | |||
11 | #include "DaemonEmptyBackend.h" | ||
12 | |||
13 | ///Create the mock of the time | ||
14 | /** @param mockName : name of the mock file of the current test | ||
15 | */ | ||
16 | 1 | void createMockTime(const PString & mockName){ | |
17 | //Let's write the mock of the time | ||
18 | |||
19 | 1 | VecTime vecTime; | |
20 | //Let's write all the different time needed by the test | ||
21 |
1/1✓ Branch 1 taken 1 times.
|
1 | vecTime.push_back(0lu); //Call of the clock |
22 |
1/1✓ Branch 1 taken 1 times.
|
1 | vecTime.push_back(1lu); //Call of the clock |
23 |
1/1✓ Branch 1 taken 1 times.
|
1 | vecTime.push_back(2lu); //Call of the clock |
24 |
1/1✓ Branch 1 taken 1 times.
|
1 | vecTime.push_back(3lu); //Call of the clock |
25 | |||
26 |
1/1✓ Branch 1 taken 1 times.
|
1 | phoenix_saveClockMock(vecTime); |
27 | 1 | } | |
28 | |||
29 | ///Create the mock file fo the test Daemon | ||
30 | /** @param mockName : name of the mock file of the current test | ||
31 | */ | ||
32 | 1 | void createMockFileTest(const PString & mockName){ | |
33 | 1 | PVecMockMessage vecOutput; | |
34 | //Let's say, the main Daemon wants to call a function on test | ||
35 |
1/1✓ Branch 1 taken 1 times.
|
1 | Message message; |
36 |
1/1✓ Branch 1 taken 1 times.
|
1 | message.setId(0lu); //Anwser of the PING message |
37 |
1/1✓ Branch 1 taken 1 times.
|
1 | message.setSendTime(0lu); |
38 |
1/1✓ Branch 1 taken 1 times.
|
1 | message.setType(MessageType::PING); |
39 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | message.setSender("main"); |
40 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | message.getVecRecver().push_back("test"); |
41 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(phoenix_addMockMessage(vecOutput, message)); |
42 | |||
43 |
4/4✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
|
1 | std::cout << "createMockFileTest : send time of ping-pong : " << message.getSendTime() << std::endl; |
44 | |||
45 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(phoenix_closeMockSocket(vecOutput, mockName)); |
46 | 1 | } | |
47 | |||
48 | ///Create the mock file to be used by the Daemon | ||
49 | /** @param mockName : name of the mock file of the current test | ||
50 | */ | ||
51 | 1 | void createMockFileMain(const PString & mockName){ | |
52 | 1 | PVecMockMessage vecOutput; | |
53 | |||
54 | 1 | DataStreamMsg emptyMsg; | |
55 |
1/1✓ Branch 1 taken 1 times.
|
1 | vecOutput.push_back(emptyMsg); |
56 | |||
57 | //Let's pretend our Daemon is receiving a PONG message | ||
58 |
1/1✓ Branch 1 taken 1 times.
|
1 | Message message; |
59 |
1/1✓ Branch 1 taken 1 times.
|
1 | message.setId(0lu); |
60 |
1/1✓ Branch 1 taken 1 times.
|
1 | message.setSendTime(0lu); |
61 |
1/1✓ Branch 1 taken 1 times.
|
1 | message.setType(MessageType::PONG); |
62 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | message.setSender("test"); |
63 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | message.getVecRecver().push_back("main"); |
64 | |||
65 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(phoenix_addMockMessage(vecOutput, message)); |
66 | //It should answer a PONG in the test Daemon mock | ||
67 | |||
68 | //Finally we stop the Daemon | ||
69 |
1/1✓ Branch 1 taken 1 times.
|
1 | Message messageStop; |
70 |
1/1✓ Branch 1 taken 1 times.
|
1 | messageStop.setId(0lu); |
71 |
1/1✓ Branch 1 taken 1 times.
|
1 | messageStop.setType(MessageType::STOP); |
72 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(phoenix_addMockMessage(vecOutput, messageStop)); |
73 | |||
74 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(phoenix_closeMockSocket(vecOutput, mockName)); |
75 | 1 | } | |
76 | |||
77 | ///Create and run the Daemon | ||
78 | /** @param fileName : name of the configuration toml file | ||
79 | * @param daemonName : name of the daemon of the current test | ||
80 | */ | ||
81 | 1 | void createDaemon(const PPath & fileName, const PString & daemonName){ | |
82 | //Let's create and start the Daemon | ||
83 |
1/1✓ Branch 1 taken 1 times.
|
1 | PingPongDaemon daemon; |
84 |
1/1✓ Branch 1 taken 1 times.
|
1 | daemon.setSocketMode(PSocketMode::MOCK); |
85 |
1/1✓ Branch 1 taken 1 times.
|
1 | daemon.setClockMode(PClockMode::MOCK); |
86 |
1/1✓ Branch 1 taken 1 times.
|
1 | daemon.load(fileName, daemonName); |
87 |
5/5✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | phoenix_assert(daemon.run()); |
88 | 1 | } | |
89 | |||
90 | ///Test the load configuration of a Daemon | ||
91 | /** @param fileName : name of the configuration toml file | ||
92 | */ | ||
93 | 1 | void testBaseDaemonLoadConfig(const PPath & fileName){ | |
94 |
8/8✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 21 taken 1 times.
✓ Branch 24 taken 1 times.
✓ Branch 27 taken 1 times.
|
1 | phoenix_assert(phoenix_check("Message type name", phoenix_getTypeName<Message>(), "Message")); |
95 | //Let's create the mock file | ||
96 |
1/1✓ Branch 2 taken 1 times.
|
1 | createMockTime("clock.pmockclock"); // need to check this |
97 |
1/1✓ Branch 2 taken 1 times.
|
1 | createMockFileMain("localhost_3390.pmockbackend"); |
98 | //No need to check the output of the messages sent by the Daemon, because the PMockBackend already does it for us | ||
99 |
1/1✓ Branch 2 taken 1 times.
|
1 | createMockFileTest("localhost_3391.pmockbackend"); |
100 | //Let's create and start the Daemon | ||
101 |
1/1✓ Branch 2 taken 1 times.
|
1 | createDaemon(fileName, "main"); |
102 | 1 | } | |
103 | |||
104 | 1 | int main(int argc, char** argv){ | |
105 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK)); |
106 | 1 | return 0; | |
107 | } | ||
108 | |||
109 | |||
110 |