PhoenixSerializer  3.0.0
PhoenixSerializer is a framework to save/load/serialize/deserialize data
Loading...
Searching...
No Matches
data_stream_check_value_impl.h
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : LGPL-3.0-only
5****************************************/
6
7#ifndef __DATA_STREAM_CHECK_VALUE_IMPL_H__
8#define __DATA_STREAM_CHECK_VALUE_IMPL_H__
9
10#include <cstdint>
11#include <type_traits>
12
14
16
19template <typename T>
20std::conditional_t<std::is_same_v<T, int8_t> || std::is_same_v<T, uint8_t>, int, T> checkValue_printable(const T & value) {
21 return value;
22}
23
25
30template <typename T>
31bool checkValue(const std::string & testName, const T & givenSize, const T & referenceSize) {
32 // std::cout << "checkValue : "<<testName<<" => " << givenSize << ", reference ("<<referenceSize<<")" << std::endl;
33 if(givenSize != referenceSize) {
34 std::cerr << "checkValue : " << testName << " wrong size givenSize(" << givenSize << ") != referenceSize(" << referenceSize << ")" << std::endl;
35 }
36 return givenSize == referenceSize;
37}
38
40
46template <typename T>
47bool checkValue(const std::string & testName, const T * tabData, const T * tabReferenceData, size_t nbElement) {
48 bool b(true);
49 for(size_t i(0LU); i < nbElement && b; ++i) {
50 std::stringstream str;
51 str << i;
52 b &= checkValue(testName + " element " + str.str(), tabData[i], tabReferenceData[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) the table is given as pointer + nbElement by the public API
53 }
54 return b;
55}
56
58
63template <typename T>
64bool checkValue(const std::string & testName, const std::vector<T> & vecData, const std::vector<T> & vecReferenceData) {
65 if(vecData.size() != vecReferenceData.size()) {
66 std::cout << "checkValue : " << testName << " => vecData.size(" << vecData.size() << ") != vecReferenceData.size(" << vecReferenceData.size() << ")" << std::endl;
67 return false;
68 }
69 bool b(true);
70 for(size_t i(0LU); i < vecData.size() && b; ++i) {
71 b &= vecData[i] == vecReferenceData[i];
72 if(!b) {
73 std::cout << "checkValue : " << testName << " => vecData[" << i << "](" << checkValue_printable(vecData[i]) << ") != vecReferenceData[" << i << "](" << checkValue_printable(vecReferenceData[i]) << ")" << std::endl;
74 }
75 }
76 // if(b){std::cout << "checkValue : "<<testName<<" => Ok"<<std::endl;}
77 // else{std::cout << "checkValue : "<<testName<<" => WRONG!!!!"<<std::endl;}
78 return b;
79}
80
82
87template <typename T>
88bool checkValue(const std::string & testName, const std::list<T> & vecData, const std::list<T> & vecReferenceData) {
89 if(vecData.size() != vecReferenceData.size()) {
90 std::cout << "checkValue : " << testName << " => vecData.size(" << vecData.size() << ") != vecReferenceData.size(" << vecReferenceData.size() << ")" << std::endl;
91 return false;
92 }
93 bool b(true);
94 typename std::list<T>::const_iterator itData = vecData.begin();
95 typename std::list<T>::const_iterator itRef = vecReferenceData.begin();
96 size_t i(0LU);
97 while(itData != vecData.end() && itRef != vecReferenceData.end()) {
98 b &= *itData == *itRef;
99 if(!b) {
100 std::cout << "checkValue : " << testName << " => vecData[" << i << "](" << checkValue_printable(*itData) << ") != vecReferenceData[" << i << "](" << checkValue_printable(*itRef) << ")" << std::endl;
101 }
102 ++i;
103 ++itData;
104 ++itRef;
105 }
106 // if(b){std::cout << "checkValue : "<<testName<<" => Ok"<<std::endl;}
107 // else{std::cout << "checkValue : "<<testName<<" => WRONG!!!!"<<std::endl;}
108 return b;
109}
110
112
117template <typename T, typename U>
118bool checkValue(const std::string & testName, const std::map<T, U> & vecData, const std::map<T, U> & vecReferenceData) {
119 if(vecData.size() != vecReferenceData.size()) {
120 std::cout << "checkValue : " << testName << " => vecData.size(" << vecData.size() << ") != vecReferenceData.size(" << vecReferenceData.size() << ")" << std::endl;
121 return false;
122 }
123 bool b(true);
124 typename std::map<T, U>::const_iterator itData = vecData.begin();
125 typename std::map<T, U>::const_iterator itRef = vecReferenceData.begin();
126 size_t i(0LU);
127 while(itData != vecData.end() && itRef != vecReferenceData.end()) {
128 b &= itData->first == itRef->first;
129 b &= itData->second == itRef->second;
130 if(!b) {
131 std::cout << "checkValue : " << testName << " => vecData[" << i << "](" << checkValue_printable(itData->first) << ", " << checkValue_printable(itData->second) << ") != vecReferenceData[" << i << "](" << checkValue_printable(itRef->first) << "," << checkValue_printable(itRef->second) << ")" << std::endl;
132 }
133 ++i;
134 ++itData;
135 ++itRef;
136 }
137 // if(b){std::cout << "checkValue : "<<testName<<" => Ok"<<std::endl;}
138 // else{std::cout << "checkValue : "<<testName<<" => WRONG!!!!"<<std::endl;}
139 return b;
140}
141
143
148template <typename T, typename U>
149bool checkValue(const std::string & testName, const std::vector<std::pair<T, U>> & vecData, const std::vector<std::pair<T, U>> & vecReferenceData) {
150 if(vecData.size() != vecReferenceData.size()) {
151 std::cout << "checkValue : " << testName << " => vecData.size(" << vecData.size() << ") != vecReferenceData.size(" << vecReferenceData.size() << ")" << std::endl;
152 return false;
153 }
154 bool b(true);
155 for(size_t i(0LU); i < vecData.size() && b; ++i) {
156 b &= vecData[i].first == vecReferenceData[i].first;
157 b &= vecData[i].second == vecReferenceData[i].second;
158 if(!b) {
159 std::cout << "checkValue : " << testName << " => vecData[" << i << "](" << checkValue_printable(vecData[i].first) << ", " << checkValue_printable(vecData[i].second) << ") != vecReferenceData[" << i << "](" << checkValue_printable(vecReferenceData[i].first) << "," << checkValue_printable(vecReferenceData[i].second) << ")" << std::endl;
160 }
161 }
162 // if(b){std::cout << "checkValue : "<<testName<<" => Ok"<<std::endl;}
163 // else{std::cout << "checkValue : "<<testName<<" => WRONG!!!!"<<std::endl;}
164 return b;
165}
166
168
173template <typename T, typename U>
174bool checkValue(const std::string & testName, const std::list<std::pair<T, U>> & vecData, const std::list<std::pair<T, U>> & vecReferenceData) {
175 if(vecData.size() != vecReferenceData.size()) {
176 std::cout << "checkValue : " << testName << " => vecData.size(" << vecData.size() << ") != vecReferenceData.size(" << vecReferenceData.size() << ")" << std::endl;
177 return false;
178 }
179 bool b(true);
180 typename std::list<std::pair<T, U>>::const_iterator itData = vecData.begin();
181 typename std::list<std::pair<T, U>>::const_iterator itRef = vecReferenceData.begin();
182 size_t i(0LU);
183 while(itData != vecData.end() && itRef != vecReferenceData.end()) {
184 b &= itData->first == itRef->first;
185 b &= itData->second == itRef->second;
186 if(!b) {
187 std::cout << "checkValue : " << testName << " => vecData[" << i << "](" << checkValue_printable(itData->first) << ", " << checkValue_printable(itData->second) << ") != vecReferenceData[" << i << "](" << checkValue_printable(itRef->first) << "," << checkValue_printable(itRef->second) << ")" << std::endl;
188 }
189 ++i;
190 ++itData;
191 ++itRef;
192 }
193 // if(b){std::cout << "checkValue : "<<testName<<" => Ok"<<std::endl;}
194 // else{std::cout << "checkValue : "<<testName<<" => WRONG!!!!"<<std::endl;}
195 return b;
196}
197
198#endif
bool checkValue(const std::string &testName, const T &givenSize, const T &referenceSize)
Check given value compare to the reference value.
std::conditional_t< std::is_same_v< T, int8_t >||std::is_same_v< T, uint8_t >, int, T > checkValue_printable(const T &value)
Value to be printed by checkValue : int8_t and uint8_t are printed as numbers instead of characters.