GCC Code Coverage Report


Directory: ./
File: src/PClockMockFile.cpp
Date: 2026-01-26 14:45:44
Exec Total Coverage
Lines: 41 43 95.3%
Functions: 9 11 81.8%
Branches: 18 18 100.0%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7
8 #include "PClockMockFile.h"
9
10 ///Create a mock backend for clock
11 /** @param[out] mock : clock mock backend to be used
12 * @param prefix : prefix of the mock file
13 * @return true on success, false otherwise
14 */
15 2 bool phoenix_createMockBackend(PClockMockFile & mock, const std::string & prefix){
16 2 mock.setMockPrefix(prefix);
17 2 return true;
18 }
19
20 ///Create a clock mock
21 /** @param prefix : prefix where to find the mock file
22 * @param nbTime : number of time values in the mock
23 * @param firstTime : value of the first time
24 * @param timeIncrement : increment between two consecutive times
25 * @return true on success, false otherwise
26 */
27 4 bool phoenix_createClockMock(const std::string & prefix, size_t nbTime, time_t firstTime, time_t timeIncrement){
28
2/2
✓ Branch 0 (2→3) taken 2 times.
✓ Branch 1 (2→9) taken 2 times.
4 if(nbTime < 1000lu){ //For small clock we use a vector and a file otherwise
29
1/1
✓ Branch 0 (3→4) taken 2 times.
2 PClockMock mock;
30
1/1
✓ Branch 0 (4→5) taken 2 times.
2 phoenix_createMockBackend(mock, prefix);
31
1/1
✓ Branch 0 (5→6) taken 2 times.
2 phoenix_fillClockMock(mock, nbTime, firstTime, timeIncrement);
32
1/1
✓ Branch 0 (6→7) taken 2 times.
2 mock.close();
33 2 }else{
34
1/1
✓ Branch 0 (9→10) taken 2 times.
2 PClockMockFile mock;
35
1/1
✓ Branch 0 (10→11) taken 2 times.
2 phoenix_createMockBackend(mock, prefix);
36
1/1
✓ Branch 0 (11→12) taken 2 times.
2 phoenix_fillClockMock(mock, nbTime, firstTime, timeIncrement);
37
1/1
✓ Branch 0 (12→13) taken 2 times.
2 mock.close();
38 2 }
39 4 return true;
40 }
41
42 ///Default constructor of PClockMockFile
43
1/1
✓ Branch 0 (5→6) taken 4 times.
8 PClockMockFile::PClockMockFile(){
44
1/1
✓ Branch 0 (8→9) taken 4 times.
4 initialisationPClockMockFile();
45 4 }
46
47 ///Destructor of PClockMockFile
48 4 PClockMockFile::~PClockMockFile(){
49 4 close();
50 4 }
51
52 ///Get the mocked current time
53 /** @return mocked current time
54 */
55 4 time_t PClockMockFile::now(){
56 4 p_mock.setIsRecord(false);
57 4 time_t currentTime = 0lu;
58
1/1
✓ Branch 0 (3→4) taken 4 times.
4 p_mock.getCurrentValue(currentTime);
59 4 return currentTime;
60 }
61
62 ///Sleep for the given ellapsed time
63 /** @param ellapsedTime : time to sleep
64 */
65 void PClockMockFile::sleep(EllapsedTime ellapsedTime) const {
66 //No real sleep in mock
67 }
68
69 ///Set the current time to be recorded
70 /** @param currentTime : current time to be recorded
71 */
72 4003 void PClockMockFile::setCurrentTime(time_t currentTime){
73 4003 p_mock.setIsRecord(true);
74 //Let's record the given time
75 4003 p_mock.append(currentTime);
76 4003 }
77
78 ///Set the mock directory
79 /** @param mockDirectory : mock directory
80 */
81 4 void PClockMockFile::setMockPrefix(const std::string & mockPrefix){
82
1/1
✓ Branch 0 (2→3) taken 4 times.
4 std::stringstream socketFileName;
83
2/2
✓ Branch 0 (3→4) taken 4 times.
✓ Branch 2 (4→5) taken 4 times.
4 socketFileName << mockPrefix << "clock.pclockmock";
84
2/2
✓ Branch 0 (5→6) taken 4 times.
✓ Branch 2 (6→7) taken 4 times.
4 p_mock.setFileName(socketFileName.str());
85 4 }
86
87 ///Close the PClockMockFile
88 6 void PClockMockFile::close(){
89 6 p_mock.close();
90 6 }
91
92 ///Initialisation function of the class PClockMockFile
93 4 void PClockMockFile::initialisationPClockMockFile(){
94
95 4 }
96
97
98
99
100
101