GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/DataStream/TESTS/TEST_TAB_FILE/main.cpp Lines: 36 36 100.0 %
Date: 2024-12-09 15:30:52 Branches: 91 92 98.9 %

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_file.h"
11
12
///Test the serialisation/deserialisation of table of data in message
13
/**	@param typeNameStr : name of the used type
14
 * 	@param nbElement : number of elements in the table of data
15
 * 	@return true on success, false otherwise
16
*/
17
template<typename T>
18
2156
bool testSimpleTableFile(const std::string & typeNameStr, size_t nbElement){
19
2156
	T * tabData = new T[nbElement];
20
111034
	for(size_t i(0lu); i < nbElement; ++i){
21
108878
		tabData[i] = 2lu*i + 1u;
22
	}
23
4312
	std::string fileName("file.data");
24
2156
	bool b(true);
25
2156
	b &= data_save(fileName, tabData, nbElement);			//Save the message
26
2156
	b &= !data_save("unexistingDirectory/unexistingFile.data", tabData, nbElement);			//Save the message
27
2156
	T * tabLoadedData = new T[nbElement];
28
2156
	b &= data_load(fileName, tabLoadedData, nbElement);		//Load the message
29
30
2156
	std::stringstream str;
31
2156
	str << nbElement;
32

2156
	b &= checkValue(typeNameStr + "("+str.str()+")", tabLoadedData, tabData, nbElement);
33
2156
	b &= !data_load("unexistingFileName.data", tabLoadedData, nbElement);		//Load the message
34
4312
	return b;
35
}
36
37
///Test the serialisation/deserialisation of table of data in message
38
/**	@param typeNameStr : name of the used type
39
 * 	@param nbElementMin : minimum number of elements in the table of data
40
 * 	@param nbElementMax : maximu number of elements in the table of data
41
 * 	@return true on success, false otherwise
42
*/
43
template<typename T>
44
22
bool testMultiSimpleTableFile(const std::string & typeNameStr, size_t nbElementMin, size_t nbElementMax){
45
22
	bool b(true);
46

2178
	for(size_t i(nbElementMin); i < nbElementMax && b; ++i){
47
2156
		b &= testSimpleTableFile<T>(typeNameStr, i);
48
	}
49
22
	return b;
50
}
51
52
///Test if data size is Ok
53
1
void testSimpleTableDataFile(){
54

1
	data_stream_assert(testMultiSimpleTableFile<bool>("bool", 2lu, 100lu));
55

1
	data_stream_assert(testMultiSimpleTableFile<char>("char", 2lu, 100lu));
56

1
	data_stream_assert(testMultiSimpleTableFile<short>("short", 2lu, 100lu));
57

1
	data_stream_assert(testMultiSimpleTableFile<int>("int", 2lu, 100lu));
58

1
	data_stream_assert(testMultiSimpleTableFile<long int>("long int", 2lu, 100lu));
59

1
	data_stream_assert(testMultiSimpleTableFile<unsigned char>("unsigned char", 2lu, 100lu));
60

1
	data_stream_assert(testMultiSimpleTableFile<unsigned short>("unsigned short", 2lu, 100lu));
61

1
	data_stream_assert(testMultiSimpleTableFile<unsigned int>("unsigned int", 2lu, 100lu));
62

1
	data_stream_assert(testMultiSimpleTableFile<long unsigned int>("long unsigned int", 2lu, 100lu));
63

1
	data_stream_assert(testMultiSimpleTableFile<float>("float", 2lu, 100lu));
64

1
	data_stream_assert(testMultiSimpleTableFile<double>("double", 2lu, 100lu));
65
1
}
66
67
1
int main(int argc, char** argv){
68
1
	testSimpleTableDataFile();
69
1
	return 0;
70
}
71