GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixClock/src/PClockMock.cpp
Date: 2025-03-14 12:18:05
Exec Total Coverage
Lines: 25 37 67.6%
Branches: 11 15 73.3%

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 7 bool phoenix_saveClockMock(const VecTime & vecTime){
15
2/2
✓ Branch 2 taken 7 times.
✓ Branch 5 taken 7 times.
7 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 2 bool phoenix_loadClockMock(VecTime & vecTime){
23
2/2
✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
2 return data_load("clock.clockmock", vecTime);
24 }
25
26
27 ///Default constructor of PClockMock
28 8 PClockMock::PClockMock(){
29
1/1
✓ Branch 1 taken 8 times.
8 initialisationPClockMock();
30 8 }
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 16 PClockMock::~PClockMock(){
41
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
16 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 8 time_t PClockMock::now(){
60 //If we opened the proper mock file
61
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 6 times.
8 if(p_vecTime.size() == 0lu){
62
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if(!phoenix_loadClockMock(p_vecTime)){
63 std::cerr << "PClockMock::now : cannot load clock mock file 'clock.mock'" << std::endl;
64 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 8 times.
8 if(p_currentTimeIndex >= p_vecTime.size()){
69 p_currentTimeIndex = 0lu;
70 }
71 8 time_t currentTime = p_vecTime[p_currentTimeIndex];
72 //Then we increment the current time index
73 8 ++p_currentTimeIndex;
74 8 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 8 void PClockMock::initialisationPClockMock(){
97 8 p_isRecordMode = false;
98 8 p_currentTimeIndex = 0lu;
99 8 }
100
101
102
103
104
105