GCC Code Coverage Report


Directory: ./
File: TESTS/TEST_DAEMON_SEND_DATA/main.cpp
Date: 2025-03-27 14:50:11
Exec Total Coverage
Lines: 51 51 100.0%
Branches: 64 64 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
10 #include "DaemonEmptyBackend.h"
11 #include "SendDataDaemon.h"
12
13 ///Create the mock of the time
14 /** @param mockName : name of the mock file of the current test
15 */
16 2 void createMockTime(const PString & mockName){
17 //Let's write the mock of the time
18
19 2 VecTime vecTime;
20 //Let's write all the different time needed by the test
21
1/1
✓ Branch 1 taken 2 times.
2 vecTime.push_back(0lu); //Call of the clock
22
1/1
✓ Branch 1 taken 2 times.
2 vecTime.push_back(1lu); //Call of the clock
23
1/1
✓ Branch 1 taken 2 times.
2 vecTime.push_back(2lu); //Call of the clock
24
1/1
✓ Branch 1 taken 2 times.
2 vecTime.push_back(3lu); //Call of the clock
25
26
1/1
✓ Branch 1 taken 2 times.
2 phoenix_saveClockMock(vecTime);
27 2 }
28
29 ///Create the mock file fo the test Daemon
30 /** @param mockName : name of the mock file of the current test
31 */
32 2 void createMockFileTest(const PString & mockName){
33 2 PVecMockMessage vecOutput;
34 //Let's say, the main Daemon wants to call a function on test
35
1/1
✓ Branch 1 taken 2 times.
2 Message message;
36
1/1
✓ Branch 1 taken 2 times.
2 message.setId(1lu); //Anwser of the INT message
37
1/1
✓ Branch 1 taken 2 times.
2 message.setSendTime(0lu);
38
1/1
✓ Branch 1 taken 2 times.
2 message.setIsConfirmationNeeded(true);
39
1/1
✓ Branch 1 taken 2 times.
2 message.setType(MessageType::RESULT_DATA);
40
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 message.setSender("main");
41 2 int data(42);
42
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 message.setData(phoenix_createData(data));
43
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 message.getVecRecver().push_back("test");
44
45
5/5
✓ Branch 2 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
2 phoenix_assert(phoenix_addMockMessage(vecOutput, message));
46
47
5/5
✓ Branch 2 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
2 phoenix_assert(phoenix_closeMockSocket(vecOutput, mockName));
48 2 }
49
50 ///Create the mock file to be used by the Daemon
51 /** @param mockName : name of the mock file of the current test
52 */
53 2 void createMockFileMain(const PString & mockName){
54 2 PVecMockMessage vecOutput;
55
56
1/1
✓ Branch 2 taken 2 times.
2 DataStreamMsg emptyMsg(0lu);
57
1/1
✓ Branch 1 taken 2 times.
2 vecOutput.push_back(emptyMsg);
58
59 //Finally we stop the Daemon
60
1/1
✓ Branch 1 taken 2 times.
2 Message messageStop;
61
1/1
✓ Branch 1 taken 2 times.
2 messageStop.setId(1lu);
62
1/1
✓ Branch 1 taken 2 times.
2 messageStop.setSendTime(0lu);
63
1/1
✓ Branch 1 taken 2 times.
2 messageStop.setType(MessageType::STOP);
64
5/5
✓ Branch 2 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
2 phoenix_assert(phoenix_addMockMessage(vecOutput, messageStop));
65
5/5
✓ Branch 2 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
2 phoenix_assert(phoenix_closeMockSocket(vecOutput, mockName));
66 2 }
67
68 ///Create and run the Daemon
69 /** @param fileName : name of the configuration toml file
70 * @param daemonName : name of the daemon of the current test
71 */
72 2 void createDaemon(const PPath & fileName, const PString & daemonName){
73 //Let's create and start the Daemon
74
1/1
✓ Branch 1 taken 2 times.
2 SendDataDaemon daemon;
75
1/1
✓ Branch 1 taken 2 times.
2 daemon.setSocketMode(PSocketMode::MOCK);
76
1/1
✓ Branch 1 taken 2 times.
2 daemon.setClockMode(PClockMode::MOCK);
77
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 daemon.getLog().setFileName(PPath("Daemon.log"));
78
1/1
✓ Branch 1 taken 2 times.
2 daemon.load(fileName, daemonName);
79
5/5
✓ Branch 2 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
2 phoenix_assert(daemon.run());
80 2 }
81
82 ///Test the load configuration of a Daemon
83 /** @param fileName : name of the configuration toml file
84 */
85 2 void testBaseDaemonLoadConfig(const PPath & fileName){
86 //Let's create the mock file
87
1/1
✓ Branch 2 taken 2 times.
2 createMockTime("clock.pmockclock");
88
1/1
✓ Branch 2 taken 2 times.
2 createMockFileMain("localhost_3390.pmockbackend");
89 //No need to check the output of the messages sent by the Daemon, because the PMockBackend already does it for us
90
1/1
✓ Branch 2 taken 2 times.
2 createMockFileTest("localhost_3391.pmockbackend");
91 //Let's create and start the Daemon
92
1/1
✓ Branch 2 taken 2 times.
2 createDaemon(fileName, "main");
93 2 }
94
95 1 int main(int argc, char** argv){
96
2/2
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK_TOML));
97
2/2
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK_YAML));
98 1 return 0;
99 }
100
101
102