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 0 (3→4) taken 2 times.
|
2 | vecMockTime.push_back(0l); |
24 |
1/1✓ Branch 0 (4→5) taken 2 times.
|
2 | vecMockTime.push_back(1l); |
25 |
1/1✓ Branch 0 (5→6) taken 2 times.
|
2 | vecMockTime.push_back(2l); |
26 | |||
27 |
5/5✓ Branch 0 (8→9) taken 2 times.
✓ Branch 2 (11→12) taken 2 times.
✓ Branch 4 (14→15) taken 2 times.
✓ Branch 6 (15→16) taken 2 times.
✓ Branch 8 (16→17) taken 2 times.
|
10 | data_stream_assert(phoenix_saveClockMock(vecMockTime)); |
28 | 2 | } | |
29 | |||
30 | template<class _Clock> | ||
31 | 2 | void testSpecialisedClock(){ | |
32 |
1/1✓ Branch 0 (2→3) taken 2 times.
|
2 | testCreateClockMock(); |
33 |
1/1✓ Branch 0 (3→4) taken 2 times.
|
2 | _Clock clock; |
34 | //Let's try in normal mode | ||
35 | 2 | clock.setMode(PClockMode::NO_MOCK); | |
36 |
5/5✓ Branch 0 (7→8) taken 2 times.
✓ Branch 2 (10→11) taken 2 times.
✓ Branch 4 (13→14) taken 2 times.
✓ Branch 6 (14→15) taken 2 times.
✓ Branch 8 (15→16) taken 2 times.
|
10 | data_stream_assert(clock.now() != 0l); |
37 | //Let's play the mock clock | ||
38 | 2 | clock.setMode(PClockMode::MOCK); | |
39 |
5/5✓ Branch 0 (25→26) taken 2 times.
✓ Branch 2 (28→29) taken 2 times.
✓ Branch 4 (31→32) taken 2 times.
✓ Branch 6 (32→33) taken 2 times.
✓ Branch 8 (33→34) taken 2 times.
|
12 | data_stream_assert(clock.now() == 0l); |
40 |
5/5✓ Branch 0 (42→43) taken 2 times.
✓ Branch 2 (45→46) taken 2 times.
✓ Branch 4 (48→49) taken 2 times.
✓ Branch 6 (49→50) taken 2 times.
✓ Branch 8 (50→51) taken 2 times.
|
12 | data_stream_assert(clock.now() == 1l); |
41 |
5/5✓ Branch 0 (59→60) taken 2 times.
✓ Branch 2 (62→63) taken 2 times.
✓ Branch 4 (65→66) taken 2 times.
✓ Branch 6 (66→67) taken 2 times.
✓ Branch 8 (67→68) taken 2 times.
|
10 | data_stream_assert(clock.now() == 2l); |
42 | //Let's record the real clock | ||
43 | 2 | clock.setMode(PClockMode::MOCK_RECORD); | |
44 |
5/5✓ Branch 0 (77→78) taken 2 times.
✓ Branch 2 (80→81) taken 2 times.
✓ Branch 4 (83→84) taken 2 times.
✓ Branch 6 (84→85) taken 2 times.
✓ Branch 8 (85→86) taken 2 times.
|
10 | data_stream_assert(clock.now() != 0l); |
45 | //Let's replay the real clock | ||
46 | 2 | clock.setMode(PClockMode::MOCK); | |
47 |
5/5✓ Branch 0 (95→96) taken 2 times.
✓ Branch 2 (98→99) taken 2 times.
✓ Branch 4 (101→102) taken 2 times.
✓ Branch 6 (102→103) taken 2 times.
✓ Branch 8 (103→104) taken 2 times.
|
10 | data_stream_assert(clock.now() != 0l); |
48 | 2 | } | |
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 |