GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixDataStream/TESTS/TEST_ENUM/main.cpp
Date: 2025-03-14 12:18:05
Exec Total Coverage
Lines: 34 34 100.0%
Branches: 36 36 100.0%

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 4 static bool data_stream(Stream & ds, ShadokType::ShadokType & data){
28 4 int value(0);
29
1/1
✓ Branch 1 taken 2 times.
4 bool b = DataStream<Stream, DataStreamMode::READ, int>::data_stream(ds, value);
30 4 data = (ShadokType::ShadokType)value;
31 4 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 8 static bool data_stream(Stream & ds, ShadokType::ShadokType & data){
44 8 int value = (int)data;
45
1/1
✓ Branch 1 taken 4 times.
16 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 1 taken 1 times.
1 size_t shadokSize(data_size(type));
54
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 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 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 DataStreamMsg messageIn(data_size(type));
62 1 DataStreamIter iter = (DataStreamIter)messageIn.data();
63
5/5
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 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 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
1 data_stream_assert(data_message_load(iterOut, out));
69
70
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 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 2 taken 1 times.
1 std::string fileName("ShadokType.data");
77
1/1
✓ Branch 1 taken 1 times.
1 data_save(fileName, type);
78
79 ///Load shadok from message
80 ShadokType::ShadokType out;
81
1/1
✓ Branch 1 taken 1 times.
1 data_load(fileName, out);
82
83
6/6
✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 20 taken 1 times.
1 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