| 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 <iostream> | ||
| 9 | #include "phoenix_assert.h" | ||
| 10 | #include "phoenix_check.h" | ||
| 11 | #include "Daemon.h" | ||
| 12 | #include "DaemonEmptyBackend.h" | ||
| 13 | |||
| 14 | typedef Daemon<DaemonEmptyBackend> TestDaemon; | ||
| 15 | |||
| 16 | ///Test call of a function | ||
| 17 | /** @param arg : argument | ||
| 18 | * @return result | ||
| 19 | */ | ||
| 20 | 1 | int testCallFunction(int arg){ | |
| 21 | 1 | return arg + 2; | |
| 22 | } | ||
| 23 | |||
| 24 | ///Test call of a function | ||
| 25 | /** @param arg : argument | ||
| 26 | */ | ||
| 27 | 1 | void testCallFunctionVoid(int arg){ | |
| 28 | |||
| 29 | 1 | } | |
| 30 | |||
| 31 | ///Test the load configuration of a Daemon | ||
| 32 | /** @param fileName : name of the configuration toml file | ||
| 33 | */ | ||
| 34 | 1 | void testBaseDaemonLoadConfig(const PPath & fileName){ | |
| 35 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | TestDaemon daemon; |
| 36 |
2/2✓ Branch 0 (3→4) taken 1 times.
✓ Branch 2 (4→5) taken 1 times.
|
1 | daemon.load(fileName, "main"); |
| 37 |
1/1✓ Branch 0 (6→7) taken 1 times.
|
1 | daemon.setSocketMode(PSocketMode::MOCK); |
| 38 |
1/1✓ Branch 0 (7→8) taken 1 times.
|
1 | daemon.setClockMode(PClockMode::MOCK); |
| 39 |
4/4✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (9→10) taken 1 times.
✓ Branch 4 (10→11) taken 1 times.
✓ Branch 6 (11→12) taken 1 times.
|
1 | daemon.getLog().setFileName(PPath("Daemon.log")); |
| 40 |
6/6✓ Branch 0 (16→17) taken 1 times.
✓ Branch 2 (19→20) taken 1 times.
✓ Branch 4 (22→23) taken 1 times.
✓ Branch 6 (23→24) taken 1 times.
✓ Branch 8 (24→25) taken 1 times.
✓ Branch 10 (25→26) taken 1 times.
|
6 | phoenix_assert(daemon.getLog().open()); |
| 41 |
6/6✓ Branch 0 (34→35) taken 1 times.
✓ Branch 2 (37→38) taken 1 times.
✓ Branch 4 (40→41) taken 1 times.
✓ Branch 6 (41→42) taken 1 times.
✓ Branch 8 (42→43) taken 1 times.
✓ Branch 10 (43→44) taken 1 times.
|
6 | phoenix_assert(daemon.addCallableMethod(testCallFunction, "testCallFunction")); |
| 42 | //The function is added already | ||
| 43 |
6/6✓ Branch 0 (53→54) taken 1 times.
✓ Branch 2 (56→57) taken 1 times.
✓ Branch 4 (59→60) taken 1 times.
✓ Branch 6 (60→61) taken 1 times.
✓ Branch 8 (61→62) taken 1 times.
✓ Branch 10 (62→63) taken 1 times.
|
6 | phoenix_assert(!daemon.addCallableMethod(testCallFunction, "testCallFunction")); |
| 44 |
6/6✓ Branch 0 (72→73) taken 1 times.
✓ Branch 2 (75→76) taken 1 times.
✓ Branch 4 (78→79) taken 1 times.
✓ Branch 6 (79→80) taken 1 times.
✓ Branch 8 (80→81) taken 1 times.
✓ Branch 10 (81→82) taken 1 times.
|
5 | phoenix_assert(daemon.addCallableMethod(testCallFunctionVoid, "testCallFunctionVoid")); |
| 45 | 1 | int value(42); | |
| 46 |
1/1✓ Branch 0 (89→90) taken 1 times.
|
1 | Data param(phoenix_createData(value)); |
| 47 | |||
| 48 |
1/1✓ Branch 0 (90→91) taken 1 times.
|
1 | Data result; |
| 49 |
2/2✓ Branch 0 (91→92) taken 1 times.
✓ Branch 2 (92→93) taken 1 times.
|
1 | daemon.callMethod(result, "testCallFunction", param); |
| 50 |
1/1✓ Branch 0 (94→95) taken 1 times.
|
1 | int resValue = phoenix_getValueFromData<int>(result); |
| 51 |
6/6✓ Branch 0 (97→98) taken 1 times.
✓ Branch 2 (100→101) taken 1 times.
✓ Branch 4 (103→104) taken 1 times.
✓ Branch 6 (106→107) taken 1 times.
✓ Branch 8 (107→108) taken 1 times.
✓ Branch 10 (108→109) taken 1 times.
|
8 | phoenix_assert(phoenix_check("resValue", resValue, 44)); |
| 52 | |||
| 53 |
6/6✓ Branch 0 (119→120) taken 1 times.
✓ Branch 2 (122→123) taken 1 times.
✓ Branch 4 (125→126) taken 1 times.
✓ Branch 6 (126→127) taken 1 times.
✓ Branch 8 (127→128) taken 1 times.
✓ Branch 10 (128→129) taken 1 times.
|
5 | phoenix_assert(daemon.callMethod(result, "testCallFunctionVoid", param)); |
| 54 | 1 | } | |
| 55 | |||
| 56 | ///@brief Test Daemon access tp private attribute | ||
| 57 | class TestDaemonAccess : public TestDaemon { | ||
| 58 | public: | ||
| 59 | 6 | bool& getFullMock() { return this->p_isFullMock; } | |
| 60 | 6 | bool& getFullMockRecord() { return this->p_isFullMockRecord; } | |
| 61 | }; | ||
| 62 | |||
| 63 | ///Test socket mode | ||
| 64 | 1 | void testSetSocketMode(){ | |
| 65 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | TestDaemonAccess daemon; |
| 66 |
1/1✓ Branch 0 (3→4) taken 1 times.
|
1 | daemon.setSocketMode(PSocketMode::NO_MOCK); |
| 67 |
4/4✓ Branch 0 (6→7) taken 1 times.
✓ Branch 2 (9→10) taken 1 times.
✓ Branch 4 (12→13) taken 1 times.
✓ Branch 6 (14→15) taken 1 times.
|
6 | phoenix_assert(!daemon.getFullMock()); |
| 68 |
4/4✓ Branch 0 (23→24) taken 1 times.
✓ Branch 2 (26→27) taken 1 times.
✓ Branch 4 (29→30) taken 1 times.
✓ Branch 6 (31→32) taken 1 times.
|
5 | phoenix_assert(!daemon.getFullMockRecord()); |
| 69 |
1/1✓ Branch 0 (38→39) taken 1 times.
|
1 | daemon.setSocketMode(PSocketMode::MOCK); |
| 70 |
4/4✓ Branch 0 (41→42) taken 1 times.
✓ Branch 2 (44→45) taken 1 times.
✓ Branch 4 (47→48) taken 1 times.
✓ Branch 6 (49→50) taken 1 times.
|
6 | phoenix_assert(daemon.getFullMock()); |
| 71 |
4/4✓ Branch 0 (58→59) taken 1 times.
✓ Branch 2 (61→62) taken 1 times.
✓ Branch 4 (64→65) taken 1 times.
✓ Branch 6 (66→67) taken 1 times.
|
5 | phoenix_assert(!daemon.getFullMockRecord()); |
| 72 |
1/1✓ Branch 0 (73→74) taken 1 times.
|
1 | daemon.setSocketMode(PSocketMode::MOCK_RECORD); |
| 73 |
4/4✓ Branch 0 (76→77) taken 1 times.
✓ Branch 2 (79→80) taken 1 times.
✓ Branch 4 (82→83) taken 1 times.
✓ Branch 6 (84→85) taken 1 times.
|
6 | phoenix_assert(!daemon.getFullMock()); |
| 74 |
4/4✓ Branch 0 (93→94) taken 1 times.
✓ Branch 2 (96→97) taken 1 times.
✓ Branch 4 (99→100) taken 1 times.
✓ Branch 6 (101→102) taken 1 times.
|
5 | phoenix_assert(daemon.getFullMockRecord()); |
| 75 | 1 | } | |
| 76 | |||
| 77 | ///Test clock mode | ||
| 78 | 1 | void testSetClockMode(){ | |
| 79 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | TestDaemonAccess daemon; |
| 80 |
1/1✓ Branch 0 (3→4) taken 1 times.
|
1 | daemon.setClockMode(PClockMode::NO_MOCK); |
| 81 |
4/4✓ Branch 0 (6→7) taken 1 times.
✓ Branch 2 (9→10) taken 1 times.
✓ Branch 4 (12→13) taken 1 times.
✓ Branch 6 (14→15) taken 1 times.
|
6 | phoenix_assert(!daemon.getFullMock()); |
| 82 |
4/4✓ Branch 0 (23→24) taken 1 times.
✓ Branch 2 (26→27) taken 1 times.
✓ Branch 4 (29→30) taken 1 times.
✓ Branch 6 (31→32) taken 1 times.
|
5 | phoenix_assert(!daemon.getFullMockRecord()); |
| 83 |
1/1✓ Branch 0 (38→39) taken 1 times.
|
1 | daemon.setClockMode(PClockMode::MOCK); |
| 84 |
4/4✓ Branch 0 (41→42) taken 1 times.
✓ Branch 2 (44→45) taken 1 times.
✓ Branch 4 (47→48) taken 1 times.
✓ Branch 6 (49→50) taken 1 times.
|
6 | phoenix_assert(daemon.getFullMock()); |
| 85 |
4/4✓ Branch 0 (58→59) taken 1 times.
✓ Branch 2 (61→62) taken 1 times.
✓ Branch 4 (64→65) taken 1 times.
✓ Branch 6 (66→67) taken 1 times.
|
5 | phoenix_assert(!daemon.getFullMockRecord()); |
| 86 |
1/1✓ Branch 0 (73→74) taken 1 times.
|
1 | daemon.setClockMode(PClockMode::MOCK_RECORD); |
| 87 |
4/4✓ Branch 0 (76→77) taken 1 times.
✓ Branch 2 (79→80) taken 1 times.
✓ Branch 4 (82→83) taken 1 times.
✓ Branch 6 (84→85) taken 1 times.
|
6 | phoenix_assert(!daemon.getFullMock()); |
| 88 |
4/4✓ Branch 0 (93→94) taken 1 times.
✓ Branch 2 (96→97) taken 1 times.
✓ Branch 4 (99→100) taken 1 times.
✓ Branch 6 (101→102) taken 1 times.
|
5 | phoenix_assert(daemon.getFullMockRecord()); |
| 89 | 1 | } | |
| 90 | |||
| 91 | 1 | int main(int argc, char** argv){ | |
| 92 |
3/3✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
✓ Branch 4 (4→5) taken 1 times.
|
1 | testBaseDaemonLoadConfig(PPath(DAEMON_CONFIG_OK)); |
| 93 | 1 | testSetSocketMode(); | |
| 94 | 1 | testSetClockMode(); | |
| 95 | 1 | return 0; | |
| 96 | } | ||
| 97 |