GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/DataStream/TESTS/TEST_SHADOK/main.cpp Lines: 47 47 100.0 %
Date: 2024-12-09 15:30:52 Branches: 67 69 97.1 %

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
	Shadok s;
13
1
	s.setAge(3);
14
1
	s.setName("Shadoko");
15
16
1
	size_t shadokSize(data_size(s));
17

1
	data_stream_assert(shadokSize == 19lu);
18
1
}
19
20
///Test the Shadok message
21
1
void testShadokMessage(){
22
2
	Shadok s;
23
1
	s.setAge(3);
24
1
	s.setName("Shadoko");
25
26
2
	std::vector<char> messageIn(data_size(s));
27
1
	char* iter = (char*)messageIn.data();
28
1
	data_message_save(iter, s);
29
30
	///Load shadok from message
31
1
	Shadok out;
32
1
	char* iterOut = (char*)messageIn.data();
33
1
	data_message_load(iterOut, out);
34
35

1
	data_stream_assert(s.getAge() == out.getAge());
36

1
	data_stream_assert(s.getName() == out.getName());
37
1
}
38
39
///Test the Shadok message
40
1
void testShadokFile(){
41
2
	Shadok s;
42
1
	s.setAge(3);
43
1
	s.setName("Shadoko");
44
45
2
	std::string fileName("shadok.data");
46
1
	data_save(fileName, s);
47
48
	///Load shadok from message
49
1
	Shadok out;
50
1
	data_load(fileName, out);
51
52

1
	data_stream_assert(s.getAge() == out.getAge());
53

1
	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

1
	return s1.getName() == s2.getName() && s1.getAge() == s2.getAge();
63
}
64
65
///Some basic Shadok test
66
1
void testShadok(){
67
2
	Shadok s;
68
2
	Shadok p(s);
69
1
	Shadok q;
70
1
	q = s;
71

1
	data_stream_assert(s.getAge() == q.getAge());
72

1
	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