GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixClock/TESTS/TEST_GENERIC_CLOCK/main.cpp
Date: 2025-03-14 12:18:05
Exec Total Coverage
Lines: 28 28 100.0%
Branches: 40 40 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 <unistd.h>
9 #include <iomanip>
10 #include <iostream>
11 #include "data_stream_assert.h"
12 #include "phoenix_clock.h"
13
14 ///Definition of the test clock
15 typedef PGenericClock<PClockBackend, PClockMock> ClockSecond;
16
17 ///Definition of the test clock for more precise time
18 typedef PGenericClock<PClockNsBackend, PClockMock> ClockNanoSecond;
19
20 ///Create a ClockMock ready to use
21 2 void testCreateClockMock(){
22 2 VecTime vecMockTime;
23
1/1
✓ Branch 1 taken 2 times.
2 vecMockTime.push_back(0l);
24
1/1
✓ Branch 1 taken 2 times.
2 vecMockTime.push_back(1l);
25
1/1
✓ Branch 1 taken 2 times.
2 vecMockTime.push_back(2l);
26
27
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 data_stream_assert(phoenix_saveClockMock(vecMockTime));
28 2 }
29
30 template<class _Clock>
31 4 void testSpecialisedClock(){
32
1/1
✓ Branch 1 taken 2 times.
4 testCreateClockMock();
33
1/1
✓ Branch 1 taken 2 times.
4 _Clock clock;
34 //Let's try in normal mode
35 4 clock.setMode(PClockMode::NO_MOCK);
36
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.
4 data_stream_assert(clock.now() != 0l);
37 //Let's play the mock clock
38 4 clock.setMode(PClockMode::MOCK);
39
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.
4 data_stream_assert(clock.now() == 0l);
40
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.
4 data_stream_assert(clock.now() == 1l);
41
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.
4 data_stream_assert(clock.now() == 2l);
42 //Let's record the real clock
43 4 clock.setMode(PClockMode::MOCK_RECORD);
44
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.
4 data_stream_assert(clock.now() != 0l);
45 //Let's replay the real clock
46 4 clock.setMode(PClockMode::MOCK);
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.
4 data_stream_assert(clock.now() != 0l);
48 4 }
49
50 ///Test the PGenericClock
51 1 void testGenericClock(){
52 1 testSpecialisedClock<ClockSecond>();
53 1 testSpecialisedClock<ClockNanoSecond>();
54 1 }
55
56 1 int main(int argc, char** argv){
57 1 testGenericClock();
58 1 return 0;
59 }
60
61
62