GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixClock/src/PClockMock.cpp
Date: 2025-03-27 14:50:11
Exec Total Coverage
Lines: 27 37 73.0%
Branches: 12 15 80.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 "PClockMock.h"
9
10 ///Save the Clock Mock
11 /** @param vecTime : vector of time to be saved as Mock
12 * @return true on success, false otherwise
13 */
14 9 bool phoenix_saveClockMock(const VecTime & vecTime){
15
2/2
✓ Branch 2 taken 9 times.
✓ Branch 5 taken 9 times.
9 return data_save("clock.clockmock", vecTime);
16 }
17
18 ///Load the Clock Mock
19 /** @param[out] vecTime : vector of time to be loaded from Mock
20 * @return true on success, false otherwise
21 */
22 8 bool phoenix_loadClockMock(VecTime & vecTime){
23
2/2
✓ Branch 2 taken 8 times.
✓ Branch 5 taken 8 times.
8 return data_load("clock.clockmock", vecTime);
24 }
25
26
27 ///Default constructor of PClockMock
28 10 PClockMock::PClockMock(){
29
1/1
✓ Branch 1 taken 10 times.
10 initialisationPClockMock();
30 10 }
31
32 ///Copy constructor of PClockMock
33 /** @param other : class to copy
34 */
35 PClockMock::PClockMock(const PClockMock & other){
36 copyPClockMock(other);
37 }
38
39 ///Destructor of PClockMock
40 20 PClockMock::~PClockMock(){
41
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
20 if(p_isRecordMode){
42 //Let's save the vector of times
43 4 phoenix_saveClockMock(p_vecTime);
44 }
45 }
46
47 ///Definition of equal operator of PClockMock
48 /** @param other : class to copy
49 * @return copied class
50 */
51 PClockMock & PClockMock::operator = (const PClockMock & other){
52 copyPClockMock(other);
53 return *this;
54 }
55
56 ///Get the mocked current time
57 /** @return mocked current time
58 */
59 23 time_t PClockMock::now(){
60 //If we opened the proper mock file
61
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 15 times.
23 if(p_vecTime.size() == 0lu){
62
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 7 times.
8 if(!phoenix_loadClockMock(p_vecTime)){
63 1 std::cerr << "PClockMock::now : cannot load clock mock file 'clock.mock'" << std::endl;
64 1 return 0l;
65 }
66 }
67 //If the current time index is too high, we loop it
68
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
22 if(p_currentTimeIndex >= p_vecTime.size()){
69 p_currentTimeIndex = 0lu;
70 }
71 22 time_t currentTime = p_vecTime[p_currentTimeIndex];
72 //Then we increment the current time index
73 22 ++p_currentTimeIndex;
74 22 return currentTime;
75 }
76
77 ///Set the current time to be recorded
78 /** @param currentTime : current time to be recorded
79 */
80 2 void PClockMock::setCurrentTime(time_t currentTime){
81 2 p_isRecordMode = true;
82 //Let's record the given time
83 2 p_vecTime.push_back(currentTime);
84 2 }
85
86 ///Copy function of PClockMock
87 /** @param other : class to copy
88 */
89 void PClockMock::copyPClockMock(const PClockMock & other){
90 p_isRecordMode = other.p_isRecordMode;
91 p_vecTime = other.p_vecTime;
92 p_currentTimeIndex = other.p_currentTimeIndex;
93 }
94
95 ///Initialisation function of the class PClockMock
96 10 void PClockMock::initialisationPClockMock(){
97 10 p_isRecordMode = false;
98 10 p_currentTimeIndex = 0lu;
99 10 }
100
101
102
103
104
105