GCC Code Coverage Report


Directory: ./
File: src/PGenericClock_impl.h
Date: 2026-01-26 14:45:44
Exec Total Coverage
Lines: 32 32 100.0%
Functions: 16 18 88.9%
Branches: 10 13 76.9%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #ifndef __PGENERICCLOCK_H_IMPL__
8 #define __PGENERICCLOCK_H_IMPL__
9
10
11
12 #include "PGenericClock.h"
13
14 ///Default constructor of PGenericClock
15 template<typename _TBackend, typename _TMockBackend>
16
1/1
✓ Branch 0 (3→4) taken 1 times.
2 PGenericClock<_TBackend, _TMockBackend>::PGenericClock(){
17 2 initialisationPGenericClock();
18 2 }
19
20 ///Copy constructor of PGenericClock
21 /** @param other : class to copy
22 */
23 template<typename _TBackend, typename _TMockBackend>
24 PGenericClock<_TBackend, _TMockBackend>::PGenericClock(const PGenericClock<_TBackend, _TMockBackend> & other){
25 copyPGenericClock(other);
26 }
27
28 ///Destructor of PGenericClock
29 template<typename _TBackend, typename _TMockBackend>
30 2 PGenericClock<_TBackend, _TMockBackend>::~PGenericClock(){
31
32 2 }
33
34 ///Definition of equal operator of PGenericClock
35 /** @param other : class to copy
36 * @return copied class
37 */
38 template<typename _TBackend, typename _TMockBackend>
39 PGenericClock<_TBackend, _TMockBackend> & PGenericClock<_TBackend, _TMockBackend>::operator = (const PGenericClock<_TBackend, _TMockBackend> & other){
40 copyPGenericClock(other);
41 return *this;
42 }
43
44 ///Set the mode of the PGenericClock (NO_MOCK, MOCK or MOCK_RECORD)
45 /** @param mode : mode of the PGenericClock
46 */
47 template<typename _TBackend, typename _TMockBackend>
48 8 void PGenericClock<_TBackend, _TMockBackend>::setMode(PClockMode::PClockMode mode){
49 8 p_mode = mode;
50 8 }
51
52 ///Get the mode of the PGenericClock (NO_MOCK, MOCK or MOCK_RECORD)
53 /** @return mode of the PGenericClock
54 */
55 template<typename _TBackend, typename _TMockBackend>
56 PClockMode::PClockMode PGenericClock<_TBackend, _TMockBackend>::getMode() const{
57 return p_mode;
58 }
59
60 ///Get the current time of the clock
61 /** @return current time of the clock (the unit is given by the used backend, second for clock, ns for system_clock, etc)
62 */
63 template<typename _TBackend, typename _TMockBackend>
64 20 time_t PGenericClock<_TBackend, _TMockBackend>::now(){
65
2/2
✓ Branch 0 (2→3) taken 2 times.
✓ Branch 1 (2→5) taken 18 times.
20 if(p_mode == PClockMode::NO_MOCK){
66 2 return p_clockBackend.now();
67
2/2
✓ Branch 0 (5→6) taken 16 times.
✓ Branch 1 (5→8) taken 2 times.
18 }else if(p_mode == PClockMode::MOCK){
68 16 return p_mockBackend.now();
69 }else{
70 2 time_t currentTime = p_clockBackend.now();
71 2 p_mockBackend.setCurrentTime(currentTime);
72 2 return currentTime;
73 }
74 }
75
76 ///Sleep for a given ellapsed time
77 /** @param ellapsedTime : time to sleep (the unit is given by the used backend, second for clock, ns for system_clock, etc)
78 */
79 template<typename _TBackend, typename _TMockBackend>
80 6 void PGenericClock<_TBackend, _TMockBackend>::sleep(EllapsedTime ellapsedTime) const{
81
3/4
✓ Branch 0 (2→3) taken 6 times.
✗ Branch 1 (2→4) not taken.
✓ Branch 2 (3→4) taken 2 times.
✓ Branch 3 (3→5) taken 4 times.
6 if(p_mode == PClockMode::NO_MOCK || p_mode == PClockMode::MOCK_RECORD){
82 2 p_clockBackend.sleep(ellapsedTime);
83
1/2
✓ Branch 0 (5→6) taken 4 times.
✗ Branch 1 (5→7) not taken.
4 }else if(p_mode == PClockMode::MOCK){
84 4 p_mockBackend.sleep(ellapsedTime);
85 }
86 6 }
87
88 ///Set the mock prefix to load and save the mock with a custom file
89 /** @param mockPrefix : mock prefix
90 */
91 template<typename _TBackend, typename _TMockBackend>
92 2 void PGenericClock<_TBackend, _TMockBackend>::setMockPrefix(const std::string & mockPrefix){
93 2 p_mockBackend.setMockPrefix(mockPrefix);
94 2 }
95
96 ///Reset the mock clock to initial state
97 template<typename _TBackend, typename _TMockBackend>
98 2 void PGenericClock<_TBackend, _TMockBackend>::resetMockIndex(){
99
1/2
✓ Branch 0 (2→3) taken 2 times.
✗ Branch 1 (2→4) not taken.
2 if(p_mode == PClockMode::MOCK){
100 2 p_mockBackend.resetIndex();
101 }
102 2 }
103
104 ///Copy function of PGenericClock
105 /** @param other : class to copy
106 */
107 template<typename _TBackend, typename _TMockBackend>
108 void PGenericClock<_TBackend, _TMockBackend>::copyPGenericClock(const PGenericClock<_TBackend, _TMockBackend> & other){
109 p_mode = other.p_mode;
110 }
111
112 ///Initialisation function of the class PGenericClock
113 template<typename _TBackend, typename _TMockBackend>
114 2 void PGenericClock<_TBackend, _TMockBackend>::initialisationPGenericClock(){
115 2 p_mode = PClockMode::NO_MOCK;
116 2 }
117
118
119
120
121
122 #endif
123
124
125
126