GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/DataStream/TESTS/TEST_DATA_SIZE/main.cpp Lines: 202 202 100.0 %
Date: 2024-12-09 15:30:52 Branches: 425 426 99.8 %

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_size.h"
9
10
///Check given value compare to the reference size
11
/**	@param testName : name of the current test
12
 * 	@param givenSize : size to be tested
13
 * 	@param referenceSize : reference value
14
 * 	@return true on success, false otherwise
15
*/
16
45
bool checkValue(const std::string & testName, size_t givenSize, size_t referenceSize){
17
// 	std::cout << "checkValue : "<<testName<<" => " << givenSize << ", reference ("<<referenceSize<<")" << std::endl;
18
45
	if(givenSize != referenceSize){std::cerr << "checkValue : "<<testName<<" wrong size givenSize("<<givenSize<<") != referenceSize("<<referenceSize<<")" << std::endl;}
19
45
	return givenSize == referenceSize;
20
}
21
22
///Test if data size is Ok
23
1
void testSimpleDataSize(){
24
1
	long unsigned int dataUint64(42lu);
25
1
	size_t sizeUint64 = data_size(dataUint64);
26

1
	data_stream_assert(checkValue("long unsigned int", sizeUint64, 8lu));
27
28
1
	unsigned int dataUint32(42lu);
29
1
	size_t sizeUint32 = data_size(dataUint32);
30

1
	data_stream_assert(checkValue("unsigned int", sizeUint32, 4lu));
31
32
1
	unsigned short dataUint16(42lu);
33
1
	size_t sizeUint16 = data_size(dataUint16);
34

1
	data_stream_assert(checkValue("unsigned short", sizeUint16, 2lu));
35
36
1
	unsigned char dataUint8(42lu);
37
1
	size_t sizeUint8 = data_size(dataUint8);
38

1
	data_stream_assert(checkValue("unsigned char", sizeUint8, 1lu));
39
40
1
	size_t dataint64(42lu);
41
1
	size_t sizeint64 = data_size(dataint64);
42

1
	data_stream_assert(checkValue("long int", sizeint64, 8lu));
43
44
1
	int dataint32(42lu);
45
1
	size_t sizeint32 = data_size(dataint32);
46

1
	data_stream_assert(checkValue("int", sizeint32, 4lu));
47
48
1
	short dataint16(42lu);
49
1
	size_t sizeint16 = data_size(dataint16);
50

1
	data_stream_assert(checkValue("short", sizeint16, 2lu));
51
52
1
	char dataint8(42lu);
53
1
	size_t sizeint8 = data_size(dataint8);
54

1
	data_stream_assert(checkValue("char", sizeint8, 1lu));
55
1
}
56
57
///Test if data size is Ok
58
1
void testVectorDataSize(){
59
1
	size_t nbValue(10lu);
60
61
2
	std::vector<long unsigned int> vecUInt64;
62
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt64.push_back(i);}
63
1
	size_t sizeVecUint64 = data_size(vecUInt64);
64

1
	data_stream_assert(checkValue("std::vector<long unsigned int>", sizeVecUint64, 8lu*nbValue + 8lu));
65
66
2
	std::vector<unsigned int> vecUInt32;
67
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt32.push_back(i);}
68
1
	size_t sizeVecUint32 = data_size(vecUInt32);
69

1
	data_stream_assert(checkValue("std::vector<unsigned int>", sizeVecUint32, 4lu*nbValue + 8lu));
70
71
2
	std::vector<unsigned short> vecUInt16;
72
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt16.push_back(i);}
73
1
	size_t sizeVecUint16 = data_size(vecUInt16);
74

1
	data_stream_assert(checkValue("std::vector<unsigned short>", sizeVecUint16, 2lu*nbValue + 8lu));
75
76
2
	std::vector<unsigned char> vecUInt8;
77
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt8.push_back(i);}
78
1
	size_t sizeVecUint8 = data_size(vecUInt8);
79

1
	data_stream_assert(checkValue("std::vector<unsigned char>", sizeVecUint8, 1lu*nbValue + 8lu));
80
81
82
2
	std::vector<long int> vecInt64;
83
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt64.push_back(i);}
84
1
	size_t sizeVecInt64 = data_size(vecInt64);
85

1
	data_stream_assert(checkValue("std::vector<long int>", sizeVecInt64, 8lu*nbValue + 8lu));
86
87
2
	std::vector<int> vecInt32;
88
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt32.push_back(i);}
89
1
	size_t sizeVecInt32 = data_size(vecInt32);
90

1
	data_stream_assert(checkValue("std::vector<int>", sizeVecInt32, 4lu*nbValue + 8lu));
91
92
2
	std::vector<short> vecInt16;
93
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt16.push_back(i);}
94
1
	size_t sizeVecInt16 = data_size(vecInt16);
95

1
	data_stream_assert(checkValue("std::vector<short>", sizeVecInt16, 2lu*nbValue + 8lu));
96
97
1
	std::vector<char> vecInt8;
98
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt8.push_back(i);}
99
1
	size_t sizeVecInt8 = data_size(vecInt8);
100

1
	data_stream_assert(checkValue("std::vector<char>", sizeVecInt8, 1lu*nbValue + 8lu));
101
1
}
102
103
///Test if data size is Ok
104
1
void testListDataSize(){
105
1
	size_t nbValue(10lu);
106
107
2
	std::list<long unsigned int> vecUInt64;
108
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt64.push_back(i);}
109
1
	size_t sizeVecUint64 = data_size(vecUInt64);
110

1
	data_stream_assert(checkValue("std::list<long unsigned int>", sizeVecUint64, 8lu*nbValue + 8lu));
111
112
2
	std::list<unsigned int> vecUInt32;
113
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt32.push_back(i);}
114
1
	size_t sizeVecUint32 = data_size(vecUInt32);
115

1
	data_stream_assert(checkValue("std::list<unsigned int>", sizeVecUint32, 4lu*nbValue + 8lu));
116
117
2
	std::list<unsigned short> vecUInt16;
118
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt16.push_back(i);}
119
1
	size_t sizeVecUint16 = data_size(vecUInt16);
120

1
	data_stream_assert(checkValue("std::list<unsigned short>", sizeVecUint16, 2lu*nbValue + 8lu));
121
122
2
	std::list<unsigned char> vecUInt8;
123
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt8.push_back(i);}
124
1
	size_t sizeVecUint8 = data_size(vecUInt8);
125

1
	data_stream_assert(checkValue("std::list<unsigned char>", sizeVecUint8, 1lu*nbValue + 8lu));
126
127
128
2
	std::list<long int> vecInt64;
129
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt64.push_back(i);}
130
1
	size_t sizeVecInt64 = data_size(vecInt64);
131

1
	data_stream_assert(checkValue("std::list<long int>", sizeVecInt64, 8lu*nbValue + 8lu));
132
133
2
	std::list<int> vecInt32;
134
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt32.push_back(i);}
135
1
	size_t sizeVecInt32 = data_size(vecInt32);
136

1
	data_stream_assert(checkValue("std::list<int>", sizeVecInt32, 4lu*nbValue + 8lu));
137
138
2
	std::list<short> vecInt16;
139
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt16.push_back(i);}
140
1
	size_t sizeVecInt16 = data_size(vecInt16);
141

1
	data_stream_assert(checkValue("std::list<short>", sizeVecInt16, 2lu*nbValue + 8lu));
142
143
1
	std::list<char> vecInt8;
144
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt8.push_back(i);}
145
1
	size_t sizeVecInt8 = data_size(vecInt8);
146

1
	data_stream_assert(checkValue("std::list<char>", sizeVecInt8, 1lu*nbValue + 8lu));
147
1
}
148
149
///Test if data size is Ok
150
1
void testMapDataSize(){
151
1
	size_t nbValue(10lu);
152
153
2
	std::map<long unsigned int, long unsigned int> mapUInt64UInt64;
154
11
	for(size_t i(0lu); i < nbValue; ++i){mapUInt64UInt64[i] = i;}
155
1
	size_t sizeMapUint64Uint64 = data_size(mapUInt64UInt64);
156

1
	data_stream_assert(checkValue("std::map<long unsigned int, long unsigned int>", sizeMapUint64Uint64, 8lu*nbValue + 8lu*nbValue + 8lu));
157
158
2
	std::map<unsigned short, unsigned int> mapUInt16UInt32;
159
11
	for(size_t i(0lu); i < nbValue; ++i){mapUInt16UInt32[i] = i;}
160
1
	size_t sizeMapUint16Uint32 = data_size(mapUInt16UInt32);
161

1
	data_stream_assert(checkValue("std::map<unsigned short, unsigned int>", sizeMapUint16Uint32, 2lu*nbValue + 4lu*nbValue + 8lu));
162
163
2
	std::map<long int, long int> mapInt64Int64;
164
11
	for(size_t i(0lu); i < nbValue; ++i){mapInt64Int64[i] = i;}
165
1
	size_t sizeMapInt64Int64 = data_size(mapInt64Int64);
166

1
	data_stream_assert(checkValue("std::map<long int, long int>", sizeMapInt64Int64, 8lu*nbValue + 8lu*nbValue + 8lu));
167
168
1
	std::map<short, int> mapInt16Int32;
169
11
	for(size_t i(0lu); i < nbValue; ++i){mapInt16Int32[i] = i;}
170
1
	size_t sizeMapInt16Int32 = data_size(mapInt16Int32);
171

1
	data_stream_assert(checkValue("std::map<short, int>", sizeMapInt16Int32, 2lu*nbValue + 4lu*nbValue + 8lu));
172
1
}
173
174
///Test if data size is Ok
175
1
void testVectorPairDataSize(){
176
1
	size_t nbValue(10lu);
177
178
2
	std::vector<std::pair<long unsigned int, long unsigned int> > vecUInt64;
179
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt64.push_back(std::pair<long unsigned int, long unsigned int>(i,i));}
180
1
	size_t sizeVecUint64 = data_size(vecUInt64);
181

1
	data_stream_assert(checkValue("std::vector<std::pair<long unsigned int, long unsigned int> >", sizeVecUint64, 2lu*8lu*nbValue + 8lu));
182
183
2
	std::vector<std::pair<unsigned int, unsigned int> > vecUInt32;
184
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt32.push_back(std::pair<unsigned int, unsigned int>(i,i));}
185
1
	size_t sizeVecUint32 = data_size(vecUInt32);
186

1
	data_stream_assert(checkValue("std::vector<std::pair<unsigned int, unsigned int> >", sizeVecUint32, 2lu*4lu*nbValue + 8lu));
187
188
2
	std::vector<std::pair<unsigned short, unsigned short> > vecUInt16;
189
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt16.push_back(std::pair<unsigned short, unsigned short>(i,i));}
190
1
	size_t sizeVecUint16 = data_size(vecUInt16);
191

1
	data_stream_assert(checkValue("std::vector<std::pair<unsigned short, unsigned short> >", sizeVecUint16, 2lu*2lu*nbValue + 8lu));
192
193
2
	std::vector<std::pair<unsigned char, unsigned char> > vecUInt8;
194
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt8.push_back(std::pair<unsigned char, unsigned char>(i,i));}
195
1
	size_t sizeVecUint8 = data_size(vecUInt8);
196

1
	data_stream_assert(checkValue("std::vector<std::pair<unsigned char, unsigned char> >", sizeVecUint8, 2lu*1lu*nbValue + 8lu));
197
198
199
2
	std::vector<std::pair<long int, long int> > vecInt64;
200
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt64.push_back(std::pair<long int, long int>(i,i));}
201
1
	size_t sizeVecInt64 = data_size(vecInt64);
202

1
	data_stream_assert(checkValue("std::vector<std::pair<long int, long int> >", sizeVecInt64, 2lu*8lu*nbValue + 8lu));
203
204
2
	std::vector<std::pair<int,int> > vecInt32;
205
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt32.push_back(std::pair<int,int>(i,i));}
206
1
	size_t sizeVecInt32 = data_size(vecInt32);
207

1
	data_stream_assert(checkValue("std::vector<std::pair<int,int> >", sizeVecInt32, 2lu*4lu*nbValue + 8lu));
208
209
2
	std::vector<std::pair<short, short> > vecInt16;
210
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt16.push_back(std::pair<short, short>(i,i));}
211
1
	size_t sizeVecInt16 = data_size(vecInt16);
212

1
	data_stream_assert(checkValue("std::vector<std::pair<short, short> >", sizeVecInt16, 2lu*2lu*nbValue + 8lu));
213
214
1
	std::vector<std::pair<char, char> > vecInt8;
215
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt8.push_back(std::pair<char, char>(i,i));}
216
1
	size_t sizeVecInt8 = data_size(vecInt8);
217

1
	data_stream_assert(checkValue("std::vector<std::pair<char, char> >", sizeVecInt8, 2lu*1lu*nbValue + 8lu));
218
1
}
219
220
///Test if data size is Ok
221
1
void testListPairDataSize(){
222
1
	size_t nbValue(10lu);
223
224
2
	std::list<std::pair<long unsigned int, long unsigned int> > vecUInt64;
225
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt64.push_back(std::pair<long unsigned int, long unsigned int>(i,i));}
226
1
	size_t sizeVecUint64 = data_size(vecUInt64);
227

1
	data_stream_assert(checkValue("std::list<std::pair<long unsigned int, long unsigned int> >", sizeVecUint64, 2lu*8lu*nbValue + 8lu));
228
229
2
	std::list<std::pair<unsigned int, unsigned int> > vecUInt32;
230
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt32.push_back(std::pair<unsigned int, unsigned int>(i,i));}
231
1
	size_t sizeVecUint32 = data_size(vecUInt32);
232

1
	data_stream_assert(checkValue("std::list<std::pair<unsigned int, unsigned int> >", sizeVecUint32, 2lu*4lu*nbValue + 8lu));
233
234
2
	std::list<std::pair<unsigned short, unsigned short> > vecUInt16;
235
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt16.push_back(std::pair<unsigned short, unsigned short>(i,i));}
236
1
	size_t sizeVecUint16 = data_size(vecUInt16);
237

1
	data_stream_assert(checkValue("std::list<std::pair<unsigned short, unsigned short> >", sizeVecUint16, 2lu*2lu*nbValue + 8lu));
238
239
2
	std::list<std::pair<unsigned char, unsigned char> > vecUInt8;
240
11
	for(size_t i(0lu); i < nbValue; ++i){vecUInt8.push_back(std::pair<unsigned char, unsigned char>(i,i));}
241
1
	size_t sizeVecUint8 = data_size(vecUInt8);
242

1
	data_stream_assert(checkValue("std::list<std::pair<unsigned char, unsigned char> >", sizeVecUint8, 2lu*1lu*nbValue + 8lu));
243
244
245
2
	std::list<std::pair<long int, long int> > vecInt64;
246
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt64.push_back(std::pair<long int, long int>(i,i));}
247
1
	size_t sizeVecInt64 = data_size(vecInt64);
248

1
	data_stream_assert(checkValue("std::list<std::pair<long int, long int> >", sizeVecInt64, 2lu*8lu*nbValue + 8lu));
249
250
2
	std::list<std::pair<int,int> > vecInt32;
251
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt32.push_back(std::pair<int,int>(i,i));}
252
1
	size_t sizeVecInt32 = data_size(vecInt32);
253

1
	data_stream_assert(checkValue("std::list<std::pair<int,int> >", sizeVecInt32, 2lu*4lu*nbValue + 8lu));
254
255
2
	std::list<std::pair<short, short> > vecInt16;
256
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt16.push_back(std::pair<short, short>(i,i));}
257
1
	size_t sizeVecInt16 = data_size(vecInt16);
258

1
	data_stream_assert(checkValue("std::list<std::pair<short, short> >", sizeVecInt16, 2lu*2lu*nbValue + 8lu));
259
260
1
	std::list<std::pair<char, char> > vecInt8;
261
11
	for(size_t i(0lu); i < nbValue; ++i){vecInt8.push_back(std::pair<char, char>(i,i));}
262
1
	size_t sizeVecInt8 = data_size(vecInt8);
263

1
	data_stream_assert(checkValue("std::list<std::pair<char, char> >", sizeVecInt8, 2lu*1lu*nbValue + 8lu));
264
1
}
265
266
///Test if data size is Ok
267
1
void testStringDataSize(){
268
1
	std::string str("One thing to say");
269
1
	size_t sizeStr = data_size(str);
270

1
	data_stream_assert(checkValue("std::string", sizeStr, 16lu + 8lu));
271
1
}
272
273
1
int main(int argc, char** argv){
274
1
	testSimpleDataSize();
275
1
	testVectorDataSize();
276
1
	testListDataSize();
277
1
	testMapDataSize();
278
1
	testVectorPairDataSize();
279
1
	testListPairDataSize();
280
1
	testStringDataSize();
281
1
	return 0;
282
}
283