| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include "data_stream_assert.h" | ||
| 8 | #include "Shadok.h" | ||
| 9 | |||
| 10 | ///Test the Shadok size | ||
| 11 | 1 | void testShadokSize(){ | |
| 12 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | Shadok s; |
| 13 |
1/1✓ Branch 0 (3→4) taken 1 times.
|
1 | s.setAge(3); |
| 14 |
2/2✓ Branch 0 (6→7) taken 1 times.
✓ Branch 2 (7→8) taken 1 times.
|
1 | s.setName("Shadoko"); |
| 15 | |||
| 16 |
1/1✓ Branch 0 (10→11) taken 1 times.
|
1 | size_t shadokSize(data_size(s)); |
| 17 |
4/4✓ Branch 0 (13→14) taken 1 times.
✓ Branch 2 (16→17) taken 1 times.
✓ Branch 4 (19→20) taken 1 times.
✓ Branch 6 (20→21) taken 1 times.
|
5 | data_stream_assert(shadokSize == 19lu); |
| 18 | 1 | } | |
| 19 | |||
| 20 | ///Test the Shadok message | ||
| 21 | 1 | void testShadokMessage(){ | |
| 22 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | Shadok s; |
| 23 |
1/1✓ Branch 0 (3→4) taken 1 times.
|
1 | s.setAge(3); |
| 24 |
2/2✓ Branch 0 (6→7) taken 1 times.
✓ Branch 2 (7→8) taken 1 times.
|
2 | s.setName("Shadoko"); |
| 25 | |||
| 26 |
2/2✓ Branch 0 (12→13) taken 1 times.
✓ Branch 2 (13→14) taken 1 times.
|
1 | DataStreamMsg messageIn(data_size(s)); |
| 27 | 1 | DataStreamIter iter = (DataStreamIter)messageIn.data(); | |
| 28 |
5/5✓ Branch 0 (18→19) taken 1 times.
✓ Branch 2 (21→22) taken 1 times.
✓ Branch 4 (24→25) taken 1 times.
✓ Branch 6 (25→26) taken 1 times.
✓ Branch 8 (26→27) taken 1 times.
|
5 | data_stream_assert(data_message_save(iter, s)); |
| 29 | |||
| 30 | ///Load shadok from message | ||
| 31 |
1/1✓ Branch 0 (33→34) taken 1 times.
|
1 | Shadok out; |
| 32 | 1 | DataStreamIter iterOut = (DataStreamIter)messageIn.data(); | |
| 33 |
5/5✓ Branch 0 (37→38) taken 1 times.
✓ Branch 2 (40→41) taken 1 times.
✓ Branch 4 (43→44) taken 1 times.
✓ Branch 6 (44→45) taken 1 times.
✓ Branch 8 (45→46) taken 1 times.
|
6 | data_stream_assert(data_message_load(iterOut, out)); |
| 34 | |||
| 35 |
6/6✓ Branch 0 (54→55) taken 1 times.
✓ Branch 2 (57→58) taken 1 times.
✓ Branch 4 (60→61) taken 1 times.
✓ Branch 6 (61→62) taken 1 times.
✓ Branch 8 (62→63) taken 1 times.
✓ Branch 10 (63→64) taken 1 times.
|
6 | data_stream_assert(s.getAge() == out.getAge()); |
| 36 |
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 (82→83) taken 1 times.
|
5 | data_stream_assert(s.getName() == out.getName()); |
| 37 | 1 | } | |
| 38 | |||
| 39 | ///Test the Shadok message | ||
| 40 | 1 | void testShadokFile(){ | |
| 41 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | Shadok s; |
| 42 |
1/1✓ Branch 0 (3→4) taken 1 times.
|
1 | s.setAge(3); |
| 43 |
2/2✓ Branch 0 (6→7) taken 1 times.
✓ Branch 2 (7→8) taken 1 times.
|
2 | s.setName("Shadoko"); |
| 44 | |||
| 45 |
1/1✓ Branch 0 (12→13) taken 1 times.
|
1 | std::string fileName("shadok.data"); |
| 46 |
1/1✓ Branch 0 (14→15) taken 1 times.
|
1 | data_save(fileName, s); |
| 47 | |||
| 48 | ///Load shadok from message | ||
| 49 |
1/1✓ Branch 0 (15→16) taken 1 times.
|
1 | Shadok out; |
| 50 |
1/1✓ Branch 0 (16→17) taken 1 times.
|
1 | data_load(fileName, out); |
| 51 | |||
| 52 |
6/6✓ Branch 0 (19→20) taken 1 times.
✓ Branch 2 (22→23) taken 1 times.
✓ Branch 4 (25→26) taken 1 times.
✓ Branch 6 (26→27) taken 1 times.
✓ Branch 8 (27→28) taken 1 times.
✓ Branch 10 (28→29) taken 1 times.
|
6 | data_stream_assert(s.getAge() == out.getAge()); |
| 53 |
6/6✓ Branch 0 (37→38) taken 1 times.
✓ Branch 2 (40→41) taken 1 times.
✓ Branch 4 (43→44) taken 1 times.
✓ Branch 6 (44→45) taken 1 times.
✓ Branch 8 (45→46) taken 1 times.
✓ Branch 10 (47→48) taken 1 times.
|
5 | data_stream_assert(s.getName() == out.getName()); |
| 54 | 1 | } | |
| 55 | |||
| 56 | ///Check the shadok equality as constant | ||
| 57 | /** @param s1 : Shadok to be checked | ||
| 58 | * @param s2 : Shadok to be checked | ||
| 59 | * @return true if the two Shadok are equal, false otherwise | ||
| 60 | */ | ||
| 61 | 1 | bool checkEqualityConst(const Shadok & s1, const Shadok & s2){ | |
| 62 |
2/4✓ Branch 0 (5→6) taken 1 times.
✗ Branch 1 (5→10) not taken.
✓ Branch 2 (8→9) taken 1 times.
✗ Branch 3 (8→10) not taken.
|
1 | return s1.getName() == s2.getName() && s1.getAge() == s2.getAge(); |
| 63 | } | ||
| 64 | |||
| 65 | ///Some basic Shadok test | ||
| 66 | 1 | void testShadok(){ | |
| 67 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | Shadok s; |
| 68 |
1/1✓ Branch 0 (3→4) taken 1 times.
|
1 | Shadok p(s); |
| 69 |
1/1✓ Branch 0 (4→5) taken 1 times.
|
1 | Shadok q; |
| 70 |
1/1✓ Branch 0 (5→6) taken 1 times.
|
1 | q = s; |
| 71 |
6/6✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (11→12) taken 1 times.
✓ Branch 4 (14→15) taken 1 times.
✓ Branch 6 (15→16) taken 1 times.
✓ Branch 8 (16→17) taken 1 times.
✓ Branch 10 (17→18) taken 1 times.
|
6 | data_stream_assert(s.getAge() == q.getAge()); |
| 72 |
5/5✓ Branch 0 (26→27) taken 1 times.
✓ Branch 2 (29→30) taken 1 times.
✓ Branch 4 (32→33) taken 1 times.
✓ Branch 6 (33→34) taken 1 times.
✓ Branch 8 (34→35) taken 1 times.
|
5 | data_stream_assert(checkEqualityConst(s, q)); |
| 73 | 1 | } | |
| 74 | |||
| 75 | 1 | int main(int argc, char** argv){ | |
| 76 | 1 | testShadokSize(); | |
| 77 | 1 | testShadokMessage(); | |
| 78 | 1 | testShadokFile(); | |
| 79 | 1 | testShadok(); | |
| 80 | 1 | return 0; | |
| 81 | } | ||
| 82 | |||
| 83 |