GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/DataStream/TESTS/TEST_DATA_FILE/main.cpp Lines: 210 210 100.0 %
Date: 2024-12-09 15:30:52 Branches: 512 512 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 "data_stream_assert.h"
8
#include "data_stream_check_value.h"
9
10
#include "data_size.h"
11
#include "data_message.h"
12
#include "data_file.h"
13
14
///Abstract check of a value stored in a file
15
/**	@param testName : name of the test
16
 * 	@param referenceValue : reference value
17
 * 	@return true on success, false otherwise
18
*/
19
template<typename T>
20
24
bool testSimpleValue(const std::string & testName, T referenceValue){
21
72
	std::string fileName("value_test.data"), unexistingFileName("someUnexisting/file/in/unexistingDir/file.data");
22
24
	bool b(true);
23
24
	b &= data_save(fileName, referenceValue);
24
2
	T value;
25
24
	b &= data_load(fileName, value);
26
24
	b &= checkValue(testName, value, referenceValue);
27
24
	b &= !data_save(unexistingFileName, referenceValue);
28
24
	b &= !data_load(unexistingFileName, value);
29
48
	return b;
30
}
31
32
///Test if data size is Ok
33
1
void testSimpleDataFile(){
34
1
	long unsigned int dataUInt64(42lu);
35

1
	data_stream_assert(testSimpleValue("long unsigned int", dataUInt64));
36
37
1
	unsigned int dataUInt32(42lu);
38

1
	data_stream_assert(testSimpleValue("unsigned int", dataUInt32));
39
40
1
	unsigned short dataUInt16(42lu);
41

1
	data_stream_assert(testSimpleValue("unsigned short", dataUInt16));
42
43
1
	unsigned char dataUInt8(42lu);
44

1
	data_stream_assert(testSimpleValue("unsigned char", dataUInt8));
45
46
1
	long int dataInt64(42lu);
47

1
	data_stream_assert(testSimpleValue("long int", dataInt64));
48
49
1
	int dataInt32(42lu);
50

1
	data_stream_assert(testSimpleValue("int", dataInt32));
51
52
1
	short dataInt16(42lu);
53

1
	data_stream_assert(testSimpleValue("short", dataInt16));
54
55
1
	char dataInt8(42lu);
56

1
	data_stream_assert(testSimpleValue("char", dataInt8));
57
58
1
	float dataFloat(42.0f);
59

1
	data_stream_assert(testSimpleValue("float", dataFloat));
60
61
1
	float dataDouble(42.0);
62

1
	data_stream_assert(testSimpleValue("double", dataDouble));
63
64
1
	bool dataBool(true);
65

1
	data_stream_assert(testSimpleValue("bool", dataBool));
66
1
}
67
68
///Abstract check of values stored in a file
69
/**	@param testName : name of the test
70
 * 	@param nbValue : number of values to put in the reference vector
71
 * 	@return true on success, false otherwise
72
*/
73
template<typename T>
74
20
bool testSimpleVectorValue(const std::string & testName, size_t nbValue){
75
40
	std::string fileName("value_test.data");
76
77
40
	std::vector<T> vecRef;
78
220
	for(size_t i(0lu); i < nbValue; ++i){vecRef.push_back(i);}
79
20
	bool b(true);
80
20
	b &= data_save(fileName, vecRef);
81
82
20
	std::vector<T> vecValue;
83
20
	b &= data_load(fileName, vecValue);
84
20
	b &= checkValue(testName, vecValue, vecRef);
85
40
	return b;
86
}
87
88
///Test if data size is Ok
89
1
void testVectorDataFile(){
90
1
	size_t nbValue(10lu);
91

1
	data_stream_assert(testSimpleVectorValue<long unsigned int>("std::vector<long unsigned int>", nbValue));
92

1
	data_stream_assert(testSimpleVectorValue<unsigned int>("std::vector<unsigned int>", nbValue));
93

1
	data_stream_assert(testSimpleVectorValue<unsigned short>("std::vector<unsigned short>", nbValue));
94

1
	data_stream_assert(testSimpleVectorValue<unsigned char>("std::vector<unsigned char>", nbValue));
95

1
	data_stream_assert(testSimpleVectorValue<long int>("std::vector<long int>", nbValue));
96

1
	data_stream_assert(testSimpleVectorValue<int>("std::vector<int>", nbValue));
97

1
	data_stream_assert(testSimpleVectorValue<short>("std::vector<short>", nbValue));
98

1
	data_stream_assert(testSimpleVectorValue<char>("std::vector<char>", nbValue));
99

1
	data_stream_assert(testSimpleVectorValue<float>("std::vector<float>", nbValue));
100

1
	data_stream_assert(testSimpleVectorValue<double>("std::vector<double>", nbValue));
101
1
}
102
103
///Abstract check of values stored in a file
104
/**	@param testName : name of the test
105
 * 	@param nbValue : number of values to put in the reference list
106
 * 	@return true on success, false otherwise
107
*/
108
template<typename T>
109
22
bool testSimpleListValue(const std::string & testName, size_t nbValue){
110
44
	std::string fileName("value_test.data");
111
112
44
	std::list<T> vecRef;
113
242
	for(size_t i(0lu); i < nbValue; ++i){vecRef.push_back(i);}
114
22
	bool b(true);
115
22
	b &= data_save(fileName, vecRef);
116
117
22
	std::list<T> vecValue;
118
22
	b &= data_load(fileName, vecValue);
119
22
	b &= checkValue(testName, vecValue, vecRef);
120
44
	return b;
121
}
122
123
///Test if data size is Ok
124
1
void testListDataFile(){
125
1
	size_t nbValue(10lu);
126

1
	data_stream_assert(testSimpleListValue<long unsigned int>("std::list<long unsigned int>", nbValue));
127

1
	data_stream_assert(testSimpleListValue<unsigned int>("std::list<unsigned int>", nbValue));
128

1
	data_stream_assert(testSimpleListValue<unsigned short>("std::list<unsigned short>", nbValue));
129

1
	data_stream_assert(testSimpleListValue<unsigned char>("std::list<unsigned char>", nbValue));
130

1
	data_stream_assert(testSimpleListValue<long int>("std::list<long int>", nbValue));
131

1
	data_stream_assert(testSimpleListValue<int>("std::list<int>", nbValue));
132

1
	data_stream_assert(testSimpleListValue<short>("std::list<short>", nbValue));
133

1
	data_stream_assert(testSimpleListValue<char>("std::list<char>", nbValue));
134

1
	data_stream_assert(testSimpleListValue<float>("std::list<float>", nbValue));
135

1
	data_stream_assert(testSimpleListValue<double>("std::list<double>", nbValue));
136

1
	data_stream_assert(testSimpleListValue<bool>("std::list<bool>", nbValue));
137
1
}
138
139
///Abstract check of values stored in a file
140
/**	@param testName : name of the test
141
 * 	@param nbValue : number of values to put in the reference map
142
 * 	@return true on success, false otherwise
143
*/
144
template<typename T, typename U>
145
242
bool testSimpleMapValue(const std::string & testName, size_t nbValue){
146
484
	std::string fileName("value_test.data");
147
148
484
	std::map<T, U> vecRef;
149

2662
	for(size_t i(0lu); i < nbValue; ++i){vecRef[i] = (U)(2lu*i > nbValue/2lu);}
150
242
	bool b(true);
151
242
	b &= data_save(fileName, vecRef);
152
242
	b &= !data_save("unexistingDir/unexistingFileName.data", vecRef);
153
154
242
	std::map<T, U> vecValue;
155
242
	b &= data_load(fileName, vecValue);
156
242
	b &= checkValue(testName, vecValue, vecRef);
157
242
	b &= !data_load("UnexistingFilename.data", vecValue);
158
484
	return b;
159
}
160
161
///Abstract check of values stored in a file
162
/**	@param firstTypeName : name of the first type
163
 * 	@param nbValue : number of values to put in the reference map
164
 * 	@return true on success, false otherwise
165
*/
166
template<typename T>
167
22
bool testSetMapValue(const std::string & firstTypeName, size_t nbValue){
168
22
	bool b(true);
169
22
	b &= testSimpleMapValue<T, long unsigned int>("std::map<"+firstTypeName+", long unsigned int>", nbValue);
170
22
	b &= testSimpleMapValue<T, unsigned int>("std::map<"+firstTypeName+", unsigned int>", nbValue);
171
22
	b &= testSimpleMapValue<T, unsigned short>("std::map<"+firstTypeName+", unsigned short>", nbValue);
172
22
	b &= testSimpleMapValue<T, unsigned char>("std::map<"+firstTypeName+", unsigned char>", nbValue);
173
174
22
	b &= testSimpleMapValue<T, long int>("std::map<"+firstTypeName+", long int>", nbValue);
175
22
	b &= testSimpleMapValue<T, int>("std::map<"+firstTypeName+", int>", nbValue);
176
22
	b &= testSimpleMapValue<T, short>("std::map<"+firstTypeName+", short>", nbValue);
177
22
	b &= testSimpleMapValue<T, char>("std::map<"+firstTypeName+", char>", nbValue);
178
22
	b &= testSimpleMapValue<T, float>("std::map<"+firstTypeName+", float>", nbValue);
179
22
	b &= testSimpleMapValue<T, double>("std::map<"+firstTypeName+", double>", nbValue);
180
22
	b &= testSimpleMapValue<T, bool>("std::map<"+firstTypeName+", bool>", nbValue);
181
22
	return b;
182
}
183
184
///Test if data size is Ok
185
1
void testMapDataFile(){
186
1
	size_t nbValue(10lu);
187

1
	data_stream_assert(testSetMapValue<long unsigned int>("long unsigned int", nbValue));
188

1
	data_stream_assert(testSetMapValue<unsigned int>("unsigned int", nbValue));
189

1
	data_stream_assert(testSetMapValue<unsigned short>("unsigned short", nbValue));
190

1
	data_stream_assert(testSetMapValue<unsigned char>("unsigned char", nbValue));
191

1
	data_stream_assert(testSetMapValue<long int>("long int", nbValue));
192

1
	data_stream_assert(testSetMapValue<int>("int", nbValue));
193

1
	data_stream_assert(testSetMapValue<short>("short", nbValue));
194

1
	data_stream_assert(testSetMapValue<char>("char", nbValue));
195

1
	data_stream_assert(testSetMapValue<float>("float", nbValue));
196

1
	data_stream_assert(testSetMapValue<double>("double", nbValue));
197

1
	data_stream_assert(testSetMapValue<bool>("bool", nbValue));
198
1
}
199
200
///Abstract check of values stored in a file
201
/**	@param testName : name of the test
202
 * 	@param nbValue : number of values to put in the reference vector
203
 * 	@return true on success, false otherwise
204
*/
205
template<typename T, typename U>
206
242
bool testSimpleVectorPairValue(const std::string & testName, size_t nbValue){
207
484
	std::string fileName("value_test.data");
208
209
484
	std::vector<std::pair<T, U> > vecRef;
210
2662
	for(size_t i(0lu); i < nbValue; ++i){vecRef.push_back(std::pair<T, U>(i,2lu*i));}
211
242
	bool b(true);
212
242
	b &= data_save(fileName, vecRef);
213
214
242
	std::vector<std::pair<T, U> > vecValue;
215
242
	b &= data_load(fileName, vecValue);
216
242
	b &= checkValue(testName, vecValue, vecRef);
217
484
	return b;
218
}
219
220
///Abstract check of values stored in a file
221
/**	@param firstTypeName : name of the first type
222
 * 	@param nbValue : number of values to put in the reference vector
223
 * 	@return true on success, false otherwise
224
*/
225
template<typename T>
226
22
bool testSetVectorPairValue(const std::string & firstTypeName, size_t nbValue){
227
22
	bool b(true);
228
22
	b &= testSimpleVectorPairValue<T, long unsigned int>("std::vector<std::pair<"+firstTypeName+", long unsigned int> >", nbValue);
229
22
	b &= testSimpleVectorPairValue<T, unsigned int>("std::vector<std::pair<"+firstTypeName+", unsigned int> >", nbValue);
230
22
	b &= testSimpleVectorPairValue<T, unsigned short>("std::vector<std::pair<"+firstTypeName+", unsigned short> >", nbValue);
231
22
	b &= testSimpleVectorPairValue<T, unsigned char>("std::vector<std::pair<"+firstTypeName+", unsigned char> >", nbValue);
232
233
22
	b &= testSimpleVectorPairValue<T, long int>("std::vector<std::pair<"+firstTypeName+", long int> >", nbValue);
234
22
	b &= testSimpleVectorPairValue<T, int>("std::vector<std::pair<"+firstTypeName+", int> >", nbValue);
235
22
	b &= testSimpleVectorPairValue<T, short>("std::vector<std::pair<"+firstTypeName+", short> >", nbValue);
236
22
	b &= testSimpleVectorPairValue<T, char>("std::vector<std::pair<"+firstTypeName+", char> >", nbValue);
237
22
	b &= testSimpleVectorPairValue<T, float>("std::vector<std::pair<"+firstTypeName+", float> >", nbValue);
238
22
	b &= testSimpleVectorPairValue<T, double>("std::vector<std::pair<"+firstTypeName+", double> >", nbValue);
239
22
	b &= testSimpleVectorPairValue<T, bool>("std::vector<std::pair<"+firstTypeName+", bool> >", nbValue);
240
22
	return b;
241
}
242
243
///Test if data size is Ok
244
1
void testVectorPairDataFile(){
245
1
	size_t nbValue(10lu);
246

1
	data_stream_assert(testSetVectorPairValue<long unsigned int>("long unsigned int", nbValue));
247

1
	data_stream_assert(testSetVectorPairValue<unsigned int>("unsigned int", nbValue));
248

1
	data_stream_assert(testSetVectorPairValue<unsigned short>("unsigned short", nbValue));
249

1
	data_stream_assert(testSetVectorPairValue<unsigned char>("unsigned char", nbValue));
250

1
	data_stream_assert(testSetVectorPairValue<long int>("long int", nbValue));
251

1
	data_stream_assert(testSetVectorPairValue<int>("int", nbValue));
252

1
	data_stream_assert(testSetVectorPairValue<short>("short", nbValue));
253

1
	data_stream_assert(testSetVectorPairValue<char>("char", nbValue));
254

1
	data_stream_assert(testSetVectorPairValue<float>("float", nbValue));
255

1
	data_stream_assert(testSetVectorPairValue<double>("double", nbValue));
256

1
	data_stream_assert(testSetVectorPairValue<bool>("bool", nbValue));
257
1
}
258
259
///Abstract check of values stored in a file
260
/**	@param testName : name of the test
261
 * 	@param nbValue : number of values to put in the reference list
262
 * 	@return true on success, false otherwise
263
*/
264
template<typename T, typename U>
265
242
bool testSimpleListPairValue(const std::string & testName, size_t nbValue){
266
484
	std::string fileName("value_test.data");
267
268
484
	std::list<std::pair<T, U> > vecRef;
269
2662
	for(size_t i(0lu); i < nbValue; ++i){vecRef.push_back(std::pair<T, U>(i,2lu*i));}
270
242
	bool b(true);
271
242
	b &= data_save(fileName, vecRef);
272
273
242
	std::list<std::pair<T, U> > vecValue;
274
242
	b &= data_load(fileName, vecValue);
275
242
	b &= checkValue(testName, vecValue, vecRef);
276
484
	return b;
277
}
278
279
///Abstract check of values stored in a file
280
/**	@param firstTypeName : name of the first type
281
 * 	@param nbValue : number of values to put in the reference list
282
 * 	@return true on success, false otherwise
283
*/
284
template<typename T>
285
22
bool testSetListPairValue(const std::string & firstTypeName, size_t nbValue){
286
22
	bool b(true);
287
22
	b &= testSimpleListPairValue<T, long unsigned int>("std::list<std::pair<"+firstTypeName+", long unsigned int> >", nbValue);
288
22
	b &= testSimpleListPairValue<T, unsigned int>("std::list<std::pair<"+firstTypeName+", unsigned int> >", nbValue);
289
22
	b &= testSimpleListPairValue<T, unsigned short>("std::list<std::pair<"+firstTypeName+", unsigned short> >", nbValue);
290
22
	b &= testSimpleListPairValue<T, unsigned char>("std::list<std::pair<"+firstTypeName+", unsigned char> >", nbValue);
291
292
22
	b &= testSimpleListPairValue<T, long int>("std::list<std::pair<"+firstTypeName+", long int> >", nbValue);
293
22
	b &= testSimpleListPairValue<T, int>("std::list<std::pair<"+firstTypeName+", int> >", nbValue);
294
22
	b &= testSimpleListPairValue<T, short>("std::list<std::pair<"+firstTypeName+", short> >", nbValue);
295
22
	b &= testSimpleListPairValue<T, char>("std::list<std::pair<"+firstTypeName+", char> >", nbValue);
296
22
	b &= testSimpleListPairValue<T, float>("std::list<std::pair<"+firstTypeName+", float> >", nbValue);
297
22
	b &= testSimpleListPairValue<T, double>("std::list<std::pair<"+firstTypeName+", double> >", nbValue);
298
22
	b &= testSimpleListPairValue<T, bool>("std::list<std::pair<"+firstTypeName+", bool> >", nbValue);
299
22
	return b;
300
}
301
302
///Test if data size is Ok
303
1
void testListPairDataFile(){
304
1
	size_t nbValue(10lu);
305

1
	data_stream_assert(testSetListPairValue<long unsigned int>("long unsigned int", nbValue));
306

1
	data_stream_assert(testSetListPairValue<unsigned int>("unsigned int", nbValue));
307

1
	data_stream_assert(testSetListPairValue<unsigned short>("unsigned short", nbValue));
308

1
	data_stream_assert(testSetListPairValue<unsigned char>("unsigned char", nbValue));
309

1
	data_stream_assert(testSetListPairValue<long int>("long int", nbValue));
310

1
	data_stream_assert(testSetListPairValue<int>("int", nbValue));
311

1
	data_stream_assert(testSetListPairValue<short>("short", nbValue));
312

1
	data_stream_assert(testSetListPairValue<char>("char", nbValue));
313

1
	data_stream_assert(testSetListPairValue<float>("float", nbValue));
314

1
	data_stream_assert(testSetListPairValue<double>("double", nbValue));
315

1
	data_stream_assert(testSetListPairValue<bool>("bool", nbValue));
316
1
}
317
318
///Test if data size is Ok
319
1
void testStringDataFile(){
320
1
	std::string str("One thing to say");
321

1
	data_stream_assert(testSimpleValue("std::string", str));
322
1
}
323
324
1
int main(int argc, char** argv){
325
1
	testSimpleDataFile();
326
1
	testVectorDataFile();
327
1
	testListDataFile();
328
1
	testMapDataFile();
329
1
	testVectorPairDataFile();
330
1
	testListPairDataFile();
331
1
	testStringDataFile();
332
1
	return 0;
333
}
334
335