| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include "phoenix_data_stream.h" | ||
| 8 | |||
| 9 | |||
| 10 | namespace ShadokType{ | ||
| 11 | ///Type of the Shadok we want to serialized | ||
| 12 | enum ShadokType{ | ||
| 13 | NONE = 0, //Nothing to do | ||
| 14 | HAUT = 1, //Shadok from the top of the planet | ||
| 15 | BAS = 2 //Shadok from the bottom of the planet | ||
| 16 | }; | ||
| 17 | } | ||
| 18 | |||
| 19 | ///@brief Generic ShadokType deserialisation, load and size function for a ShadokType::ShadokType | ||
| 20 | template<typename Stream> | ||
| 21 | struct DataStream<Stream, DataStreamMode::READ, ShadokType::ShadokType>{ | ||
| 22 | ///Generic function to load/deserialise ShadokType | ||
| 23 | /** @param[out] ds : Stream to be used | ||
| 24 | * @param data : ShadokType to be loaded | ||
| 25 | * @return true on success, false otherwise | ||
| 26 | */ | ||
| 27 | 2 | static bool data_stream(Stream & ds, ShadokType::ShadokType & data){ | |
| 28 | 2 | int value(0); | |
| 29 |
1/1✓ Branch 0 (2→3) taken 2 times.
|
2 | bool b = DataStream<Stream, DataStreamMode::READ, int>::data_stream(ds, value); |
| 30 | 2 | data = (ShadokType::ShadokType)value; | |
| 31 | 2 | return b; | |
| 32 | } | ||
| 33 | }; | ||
| 34 | |||
| 35 | ///@brief Generic ShadokType serialisation, save and size function for a ShadokType::ShadokType | ||
| 36 | template<typename Stream> | ||
| 37 | struct DataStream<Stream, DataStreamMode::WRITE, ShadokType::ShadokType>{ | ||
| 38 | ///Generic function to save/serialise ShadokType | ||
| 39 | /** @param[out] ds : Stream to be used | ||
| 40 | * @param data : ShadokType to be saved | ||
| 41 | * @return true on success, false otherwise | ||
| 42 | */ | ||
| 43 | 4 | static bool data_stream(Stream & ds, ShadokType::ShadokType & data){ | |
| 44 | 4 | int value = (int)data; | |
| 45 |
1/1✓ Branch 0 (2→3) taken 4 times.
|
8 | return DataStream<Stream, DataStreamMode::WRITE, int>::data_stream(ds, value); |
| 46 | } | ||
| 47 | }; | ||
| 48 | |||
| 49 | |||
| 50 | ///Test the Shadok size | ||
| 51 | 1 | void testShadokTypeSize(){ | |
| 52 | 1 | ShadokType::ShadokType type(ShadokType::HAUT); | |
| 53 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | size_t shadokSize(data_size(type)); |
| 54 |
6/6✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (8→9) taken 1 times.
✓ Branch 4 (11→12) taken 1 times.
✓ Branch 6 (14→15) taken 1 times.
✓ Branch 8 (15→16) taken 1 times.
✓ Branch 10 (16→17) taken 1 times.
|
7 | data_stream_assert(checkValue("testShadokTypeSize", shadokSize, 4lu)); |
| 55 | 1 | } | |
| 56 | |||
| 57 | ///Test the Shadok message | ||
| 58 | 1 | void testShadokTypeMessage(){ | |
| 59 | 1 | ShadokType::ShadokType type(ShadokType::BAS); | |
| 60 | |||
| 61 |
2/2✓ Branch 0 (4→5) taken 1 times.
✓ Branch 2 (5→6) taken 1 times.
|
1 | DataStreamMsg messageIn(data_size(type)); |
| 62 | 1 | DataStreamIter iter = (DataStreamIter)messageIn.data(); | |
| 63 |
5/5✓ Branch 0 (10→11) taken 1 times.
✓ Branch 2 (13→14) taken 1 times.
✓ Branch 4 (16→17) taken 1 times.
✓ Branch 6 (17→18) taken 1 times.
✓ Branch 8 (18→19) taken 1 times.
|
5 | data_stream_assert(data_message_save(iter, type)); |
| 64 | |||
| 65 | ///Load shadok from message | ||
| 66 | ShadokType::ShadokType out; | ||
| 67 | 1 | DataStreamIter iterOut = (DataStreamIter)messageIn.data(); | |
| 68 |
5/5✓ Branch 0 (28→29) taken 1 times.
✓ Branch 2 (31→32) taken 1 times.
✓ Branch 4 (34→35) taken 1 times.
✓ Branch 6 (35→36) taken 1 times.
✓ Branch 8 (36→37) taken 1 times.
|
6 | data_stream_assert(data_message_load(iterOut, out)); |
| 69 | |||
| 70 |
6/6✓ Branch 0 (45→46) taken 1 times.
✓ Branch 2 (48→49) taken 1 times.
✓ Branch 4 (51→52) taken 1 times.
✓ Branch 6 (54→55) taken 1 times.
✓ Branch 8 (55→56) taken 1 times.
✓ Branch 10 (56→57) taken 1 times.
|
7 | data_stream_assert(checkValue("testShadokMessage", out, type)); |
| 71 | 1 | } | |
| 72 | |||
| 73 | ///Test the Shadok message | ||
| 74 | 1 | void testShadokTypeFile(){ | |
| 75 | 1 | ShadokType::ShadokType type(ShadokType::BAS); | |
| 76 |
1/1✓ Branch 0 (4→5) taken 1 times.
|
1 | std::string fileName("ShadokType.data"); |
| 77 |
1/1✓ Branch 0 (6→7) taken 1 times.
|
1 | data_save(fileName, type); |
| 78 | |||
| 79 | ///Load shadok from message | ||
| 80 | ShadokType::ShadokType out; | ||
| 81 |
1/1✓ Branch 0 (7→8) taken 1 times.
|
1 | data_load(fileName, out); |
| 82 | |||
| 83 |
6/6✓ Branch 0 (10→11) taken 1 times.
✓ Branch 2 (13→14) taken 1 times.
✓ Branch 4 (16→17) taken 1 times.
✓ Branch 6 (19→20) taken 1 times.
✓ Branch 8 (20→21) taken 1 times.
✓ Branch 10 (21→22) taken 1 times.
|
7 | data_stream_assert(checkValue("testShadokFile", out, type)); |
| 84 | 1 | } | |
| 85 | |||
| 86 | |||
| 87 | 1 | int main(int argc, char** argv){ | |
| 88 | 1 | testShadokTypeSize(); | |
| 89 | 1 | testShadokTypeMessage(); | |
| 90 | 1 | testShadokTypeFile(); | |
| 91 | 1 | return 0; | |
| 92 | } | ||
| 93 | |||
| 94 |