GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
|||
2 |
/*************************************** |
||
3 |
Auteur : Pierre Aubert |
||
4 |
Mail : pierre.aubert@lapp.in2p3.fr |
||
5 |
Licence : CeCILL-C |
||
6 |
****************************************/ |
||
7 |
|||
8 |
#include "parser_yml.h" |
||
9 |
|||
10 |
///Check the value of a DicoValue |
||
11 |
/** @param mapKey : DicoValue to be checked |
||
12 |
* @param expectedValue : expected value |
||
13 |
* @return true if the value matches the expectedValue, false otherwise |
||
14 |
*/ |
||
15 |
13 |
bool checkKeyMapValue(const DicoValue * mapKey, const std::string & expectedValue){ |
|
16 |
✓✓ | 13 |
if(mapKey == NULL){ |
17 |
1 |
std::cout << "checkKeyMapValue : map NULL for expectedValue = '"<<expectedValue<<"'" << std::endl; |
|
18 |
1 |
return expectedValue == ""; |
|
19 |
} |
||
20 |
12 |
std::cout << "checkKeyMapValue : map '"<<mapKey->getKey()<<"' => '"<<mapKey->getValue()<<"', expectedValue = '"<<expectedValue<<"'" << std::endl; |
|
21 |
12 |
bool b(mapKey->getValue() == expectedValue); |
|
22 |
12 |
std::cout << "checkKeyMapValue : b = " << b << std::endl; |
|
23 |
12 |
return b; |
|
24 |
} |
||
25 |
|||
26 |
///Check the value of a DicoValue |
||
27 |
/** @param mapKey : DicoValue to be checked |
||
28 |
* @param expectedValue : expected value |
||
29 |
* @return true if the value matches the expectedValue, false otherwise |
||
30 |
*/ |
||
31 |
5 |
bool checkKeyMapVecValue(const DicoValue * mapKey, const std::vector<std::string> & vecExpectedValue){ |
|
32 |
✓✓ | 5 |
if(mapKey == NULL){ |
33 |
✓✓ | 1 |
std::cout << "checkKeyMapVecValue : map NULL for vecExpectedValue = " << std::endl; |
34 |
✓✓✓ | 1 |
phoenix_print(vecExpectedValue); |
35 |
1 |
return vecExpectedValue.size() == 0lu; |
|
36 |
} |
||
37 |
✓✓✓✓ ✓✓✓✓ |
4 |
std::cout << "checkKeyMapVecValue : map '"<<mapKey->getKey()<<"' => '"<<mapKey->getValue()<<"', vecExpectedValue = " << std::endl; |
38 |
✓✓✓ | 4 |
phoenix_print(vecExpectedValue); |
39 |
4 |
bool b(true); |
|
40 |
✓ | 4 |
const VecDicoValue & vecValue = mapKey->getVecChild(); |
41 |
4 |
b &= vecValue.size() == vecExpectedValue.size(); |
|
42 |
✓✓✓✓ ✓✓✓ |
4 |
std::cout << "checkKeyMapVecValue : vecValue.size() = " << vecValue.size() << ", vecExpectedValue.size() = "<< vecExpectedValue.size() << ", isOk = " << b << std::endl; |
43 |
4 |
VecDicoValue::const_iterator it(vecValue.begin()); |
|
44 |
4 |
std::vector<std::string>::const_iterator itRef(vecExpectedValue.begin()); |
|
45 |
✓✗✓✓ ✓✗✓✓ |
18 |
while(b && it != vecValue.end() && itRef != vecExpectedValue.end()){ |
46 |
✓ | 14 |
b &= it->getValue() == *itRef; |
47 |
✓✓✓✓ ✓✓✓✓ |
14 |
std::cout << "\tvalue = '" << it->getValue() << "', reference = '"<< *itRef << "', isOk = " << b << std::endl; |
48 |
14 |
++it; |
|
49 |
14 |
++itRef; |
|
50 |
} |
||
51 |
✓✓✓ | 4 |
std::cout << "checkKeyMapVecValue : b = " << b << std::endl; |
52 |
4 |
return b; |
|
53 |
} |
||
54 |
|||
55 |
///Call the check value with NULL pointers |
||
56 |
1 |
void testCheckValue(){ |
|
57 |
✓✓ | 1 |
checkKeyMapValue(NULL, ""); |
58 |
2 |
std::vector<std::string> vecNoValue; |
|
59 |
✓ | 1 |
checkKeyMapVecValue(NULL, vecNoValue); |
60 |
1 |
} |
|
61 |
|||
62 |
///Check the YML parser |
||
63 |
/** @return true on success, false otherwise |
||
64 |
*/ |
||
65 |
1 |
bool checkParserYml(){ |
|
66 |
✓✓ | 1 |
std::cout << "\ncheckParserYml :" << std::endl; |
67 |
✓ | 2 |
std::string fileContent("key: value\nother_key: \"some string in double quotes\"\n\nthird_key: 'now we use simple quotes'\n\n\nfourth_key: finally we used nothing to fill the value of this key\n\n\n"); |
68 |
✓ | 2 |
std::string ymlFile("test.yml"); |
69 |
✓✗✓ | 1 |
if(!saveFileContent(ymlFile, fileContent)){return false;} |
70 |
|||
71 |
✓ | 2 |
DicoValue dico; |
72 |
✓✗✓ | 1 |
if(!parser_yml(dico, ymlFile)){return false;} |
73 |
✓✓ | 1 |
std::cout << "checkParserYml : output DicoValue :" << std::endl; |
74 |
✓ | 1 |
dico.print(); |
75 |
1 |
bool b(true); |
|
76 |
|||
77 |
✓✓ | 1 |
DicoValue * mapKey = dico.getMap("key"); |
78 |
1 |
bool isKeyExist = mapKey != NULL; |
|
79 |
✓✓✓ | 1 |
std::cout << "checkParserYml : isKeyExist = " << isKeyExist << std::endl; |
80 |
✓✓ | 1 |
b &= checkKeyMapValue(mapKey, "value"); |
81 |
|||
82 |
✓✓ | 1 |
DicoValue * mapOtherKey = dico.getMap("other_key"); |
83 |
1 |
bool isOtherKeyExist = mapOtherKey != NULL; |
|
84 |
✓✓✓ | 1 |
std::cout << "checkParserYml : isOtherKeyExist = " << isOtherKeyExist << std::endl; |
85 |
✓✓ | 1 |
b &= checkKeyMapValue(mapOtherKey, "\"some string in double quotes\""); |
86 |
|||
87 |
✓✓ | 1 |
DicoValue * mapThirdKey = dico.getMap("third_key"); |
88 |
1 |
bool isThirdKeyExist = mapThirdKey != NULL; |
|
89 |
✓✓✓ | 1 |
std::cout << "checkParserYml : isThirdKeyExist = " << isThirdKeyExist << std::endl; |
90 |
✓✓ | 1 |
b &= checkKeyMapValue(mapThirdKey, "'now we use simple quotes'"); |
91 |
|||
92 |
✓✓ | 1 |
DicoValue * mapFourthKey = dico.getMap("fourth_key"); |
93 |
1 |
bool isFourthKeyExist = mapFourthKey != NULL; |
|
94 |
✓✓✓ | 1 |
std::cout << "checkParserYml : isFourthKeyExist = " << isFourthKeyExist << std::endl; |
95 |
✓✓ | 1 |
b &= checkKeyMapValue(mapFourthKey, "finally we used nothing to fill the value of this key"); |
96 |
|||
97 |
✓✓✓ | 1 |
b &= phoenix_get_string(dico, "key", "default") == "value"; |
98 |
✓✓✓ | 1 |
b &= phoenix_get_string(dico, "unexistingkey", "default") == "default"; |
99 |
|||
100 |
✓✓ | 1 |
b &= phoenix_load_value_from_config<bool>(dico, "key", false) == false; |
101 |
✓✓ | 1 |
b &= phoenix_load_value_from_config<bool>(dico, "unexistingkey", false) == false; |
102 |
|||
103 |
✓✓✓ | 1 |
std::cout << "checkParserYml : b = " << b << std::endl; |
104 |
1 |
return b; |
|
105 |
} |
||
106 |
|||
107 |
///Check the embeded dico |
||
108 |
/** @return true on success, false otherwise |
||
109 |
*/ |
||
110 |
1 |
bool checkEmbededDico(){ |
|
111 |
✓✓ | 1 |
std::cout << "\ncheckEmbededDico :" << std::endl; |
112 |
✓ | 2 |
std::string fileContent("main:\n\tsub_key: VALUE\n\tother_sub_key: \"some string in double quotes\"\n\nnot_in_main_key: VALUE_IN_UPPERCASE\n\n\n"); |
113 |
|||
114 |
✓ | 2 |
std::string ymlFile("test_embeded_dico.yml"); |
115 |
✓✗✓ | 1 |
if(!saveFileContent(ymlFile, fileContent)){return false;} |
116 |
✓ | 2 |
DicoValue dico; |
117 |
✓✗✓ | 1 |
if(!parser_yml(dico, ymlFile)){return false;} |
118 |
✓✓ | 1 |
std::cout << "checkEmbededDico : output DicoValue :" << std::endl; |
119 |
✓ | 1 |
dico.print(); |
120 |
|||
121 |
1 |
bool b(true); |
|
122 |
✓ | 1 |
MapDicoValue & mapChld = dico.getMapChild(); |
123 |
✓✓✓ | 1 |
std::cerr << "checkEmbededDico : nb key = " << mapChld.size() << std::endl; |
124 |
✓✓ | 3 |
for(MapDicoValue::iterator it(mapChld.begin()); it != mapChld.end(); ++it){ |
125 |
✓✓✓✓ |
2 |
std::cerr << "\tkey '"<<it->first<<"'" << std::endl; |
126 |
} |
||
127 |
|||
128 |
✓✓ | 1 |
DicoValue * mapMain = dico.getMap("main"); |
129 |
✓✓✓ | 1 |
std::cout << "checkEmbededDico : mapMain = " << mapMain << std::endl; |
130 |
✓✗ | 1 |
if(mapMain != NULL){ |
131 |
✓✓ | 1 |
DicoValue * mapSubKey = mapMain->getMap("sub_key"); |
132 |
✓✓ | 1 |
b &= checkKeyMapValue(mapSubKey, "VALUE"); |
133 |
✓✓ | 1 |
DicoValue * mapOtherSubKey = mapMain->getMap("other_sub_key"); |
134 |
✓✓ | 1 |
b &= checkKeyMapValue(mapOtherSubKey, "\"some string in double quotes\""); |
135 |
} |
||
136 |
1 |
b &= mapMain != NULL; |
|
137 |
|||
138 |
✓✓ | 1 |
DicoValue * mapNotInMainKey = dico.getMap("not_in_main_key"); |
139 |
1 |
bool isNotInMainKeyExist = mapNotInMainKey != NULL; |
|
140 |
✓✓✓ | 1 |
std::cout << "checkEmbededDico : isNotInMainKeyExist = " << isNotInMainKeyExist << std::endl; |
141 |
✓✓ | 1 |
b &= checkKeyMapValue(mapNotInMainKey, "VALUE_IN_UPPERCASE"); |
142 |
|||
143 |
✓✓✓ | 1 |
std::cout << "checkEmbededDico : b = " << b << std::endl; |
144 |
1 |
return b; |
|
145 |
} |
||
146 |
|||
147 |
///Check the embeded dico |
||
148 |
/** @return true on success, false otherwise |
||
149 |
*/ |
||
150 |
1 |
bool checkCompactList(){ |
|
151 |
✓✓ | 1 |
std::cout << "\ncheckCompactList :" << std::endl; |
152 |
✓ | 2 |
std::string fileContent("some_list: [one, two, three]\nother_key: VALUE_IN_UPPERCASE\nother_list: [\"value in double quotes\",'value in simple quote', \"value 2 in double quotes\", 'value 2 in simple quote']\n\n"); |
153 |
|||
154 |
✓ | 2 |
std::string ymlFile("test_compact_list.yml"); |
155 |
✓✗✓ | 1 |
if(!saveFileContent(ymlFile, fileContent)){return false;} |
156 |
✓ | 2 |
DicoValue dico; |
157 |
✓✗✓ | 1 |
if(!parser_yml(dico, ymlFile)){return false;} |
158 |
✓✓ | 1 |
std::cout << "checkCompactList : output DicoValue :" << std::endl; |
159 |
✓ | 1 |
dico.print(); |
160 |
1 |
bool b(true); |
|
161 |
|||
162 |
✓✓ | 1 |
DicoValue * mapSomeListKey = dico.getMap("some_list"); |
163 |
1 |
bool isSomeListExist = mapSomeListKey != NULL; |
|
164 |
✓✓✓ | 1 |
std::cout << "checkCompactList : isSomeListExist = " << isSomeListExist << std::endl; |
165 |
|||
166 |
2 |
std::vector<std::string> vecExpectedValue; |
|
167 |
✓✓ | 1 |
vecExpectedValue.push_back("one"); |
168 |
✓✓ | 1 |
vecExpectedValue.push_back("two"); |
169 |
✓✓ | 1 |
vecExpectedValue.push_back("three"); |
170 |
✓ | 1 |
b &= checkKeyMapVecValue(mapSomeListKey, vecExpectedValue); |
171 |
|||
172 |
|||
173 |
|||
174 |
✓✓ | 1 |
DicoValue * mapOtherKey = dico.getMap("other_key"); |
175 |
1 |
bool isOtherKeyExist = mapOtherKey != NULL; |
|
176 |
✓✓✓ | 1 |
std::cout << "checkCompactList : isOtherKeyExist = " << isOtherKeyExist << std::endl; |
177 |
✓✓ | 1 |
b &= checkKeyMapValue(mapOtherKey, "VALUE_IN_UPPERCASE"); |
178 |
|||
179 |
✓✓ | 1 |
DicoValue * mapOtherListKey = dico.getMap("other_list"); |
180 |
1 |
bool isOtherListExist = mapOtherListKey != NULL; |
|
181 |
✓✓✓ | 1 |
std::cout << "checkCompactList : isOtherListExist = " << isOtherListExist << std::endl; |
182 |
|||
183 |
1 |
std::vector<std::string> vecOtherExpectedValue; |
|
184 |
✓✓ | 1 |
vecOtherExpectedValue.push_back("\"value in double quotes\""); |
185 |
✓✓ | 1 |
vecOtherExpectedValue.push_back("'value in simple quote'"); |
186 |
✓✓ | 1 |
vecOtherExpectedValue.push_back("\"value 2 in double quotes\""); |
187 |
✓✓ | 1 |
vecOtherExpectedValue.push_back("'value 2 in simple quote'"); |
188 |
✓ | 1 |
b &= checkKeyMapVecValue(mapOtherListKey, vecOtherExpectedValue); |
189 |
|||
190 |
✓✓✓ | 1 |
std::cout << "checkCompactList : b = " << b << std::endl; |
191 |
1 |
return b; |
|
192 |
} |
||
193 |
|||
194 |
///Check the embeded dico |
||
195 |
/** @return true on success, false otherwise |
||
196 |
*/ |
||
197 |
1 |
bool checkDashedList(){ |
|
198 |
✓✓ | 1 |
std::cout << "\ncheckDashedList :" << std::endl; |
199 |
✓ | 2 |
std::string fileContent("some_list:\n\t- one\n\t- two\n\t- three\nother_key: VALUE_IN_UPPERCASE\nother_list:\n\t- \"value in double quotes\"\n\t- 'value in simple quote'\n\t- \"value 2 in double quotes\"\n\t- 'value 2 in simple quote'\n\n"); |
200 |
|||
201 |
✓ | 2 |
std::string ymlFile("test_dashed_list.yml"); |
202 |
✓✗✓ | 1 |
if(!saveFileContent(ymlFile, fileContent)){return false;} |
203 |
✓ | 2 |
DicoValue dico; |
204 |
✓✗✓ | 1 |
if(!parser_yml(dico, ymlFile)){return false;} |
205 |
✓✓ | 1 |
std::cout << "checkDashedList : output DicoValue :" << std::endl; |
206 |
✓ | 1 |
dico.print(); |
207 |
1 |
bool b(true); |
|
208 |
✓✓ | 1 |
DicoValue * mapSomeListKey = dico.getMap("some_list"); |
209 |
1 |
bool isSomeListExist = mapSomeListKey != NULL; |
|
210 |
✓✓✓ | 1 |
std::cout << "checkDashedList : isSomeListExist = " << isSomeListExist << std::endl; |
211 |
|||
212 |
2 |
std::vector<std::string> vecExpectedValue; |
|
213 |
✓✓ | 1 |
vecExpectedValue.push_back("one"); |
214 |
✓✓ | 1 |
vecExpectedValue.push_back("two"); |
215 |
✓✓ | 1 |
vecExpectedValue.push_back("three"); |
216 |
✓ | 1 |
b &= checkKeyMapVecValue(mapSomeListKey, vecExpectedValue); |
217 |
|||
218 |
✓✓ | 1 |
b &= phoenix_get_vecstring(dico, "some_unexisting_list").size() == 0lu; |
219 |
✓✓ | 1 |
b &= phoenix_get_vecstring(dico, "some_list").size() == 3lu; |
220 |
✓✓ | 1 |
b &= phoenix_load_vecValue_from_config<std::string>(dico, "some_list").size() == 3lu; |
221 |
|||
222 |
✓✓ | 1 |
DicoValue * mapOtherKey = dico.getMap("other_key"); |
223 |
1 |
bool isOtherKeyExist = mapOtherKey != NULL; |
|
224 |
✓✓✓ | 1 |
std::cout << "checkDashedList : isOtherKeyExist = " << isOtherKeyExist << std::endl; |
225 |
✓✓ | 1 |
b &= checkKeyMapValue(mapOtherKey, "VALUE_IN_UPPERCASE"); |
226 |
|||
227 |
✓✓ | 1 |
DicoValue * mapOtherListKey = dico.getMap("other_list"); |
228 |
1 |
bool isOtherListExist = mapOtherListKey != NULL; |
|
229 |
✓✓✓ | 1 |
std::cout << "checkDashedList : isOtherListExist = " << isOtherListExist << std::endl; |
230 |
|||
231 |
1 |
std::vector<std::string> vecOtherExpectedValue; |
|
232 |
✓✓ | 1 |
vecOtherExpectedValue.push_back("\"value in double quotes\""); |
233 |
✓✓ | 1 |
vecOtherExpectedValue.push_back("'value in simple quote'"); |
234 |
✓✓ | 1 |
vecOtherExpectedValue.push_back("\"value 2 in double quotes\""); |
235 |
✓✓ | 1 |
vecOtherExpectedValue.push_back("'value 2 in simple quote'"); |
236 |
✓ | 1 |
b &= checkKeyMapVecValue(mapOtherListKey, vecOtherExpectedValue); |
237 |
|||
238 |
✓✓✓ | 1 |
std::cout << "checkDashedList : b = " << b << std::endl; |
239 |
1 |
return b; |
|
240 |
} |
||
241 |
|||
242 |
///Check the embeded dico |
||
243 |
/** @return true on success, false otherwise |
||
244 |
*/ |
||
245 |
1 |
bool checkCompactDico(){ |
|
246 |
✓✓ | 1 |
std::cout << "\ncheckCompactDico :" << std::endl; |
247 |
✓ | 2 |
std::string fileContent("main:{\n\tsub_key: VALUE,\n\tother_sub_key: \"some string in double quotes\"\n}\nnot_in_main_key: VALUE_IN_UPPERCASE\n\n\n"); |
248 |
|||
249 |
✓ | 2 |
std::string ymlFile("test_compact_dico.yml"); |
250 |
✓✗✓ | 1 |
if(!saveFileContent(ymlFile, fileContent)){return false;} |
251 |
✓ | 2 |
DicoValue dico; |
252 |
✓✗✓ | 1 |
if(!parser_yml(dico, ymlFile)){return false;} |
253 |
✓✓ | 1 |
std::cout << "checkCompactDico : output DicoValue :" << std::endl; |
254 |
✓ | 1 |
dico.print(); |
255 |
|||
256 |
1 |
bool b(true); |
|
257 |
✓ | 1 |
MapDicoValue & mapChld = dico.getMapChild(); |
258 |
✓✓✓ | 1 |
std::cerr << "checkCompactDico : nb key = " << mapChld.size() << std::endl; |
259 |
✓✓ | 3 |
for(MapDicoValue::iterator it(mapChld.begin()); it != mapChld.end(); ++it){ |
260 |
✓✓✓✓ |
2 |
std::cerr << "\tkey '"<<it->first<<"'" << std::endl; |
261 |
} |
||
262 |
|||
263 |
✓✓ | 1 |
DicoValue * mapMain = dico.getMap("main"); |
264 |
✓✓✓ | 1 |
std::cout << "checkCompactDico : mapMain = " << mapMain << std::endl; |
265 |
✓✗ | 1 |
if(mapMain != NULL){ |
266 |
✓✓ | 1 |
DicoValue * mapSubKey = mapMain->getMap("sub_key"); |
267 |
✓✓ | 1 |
b &= checkKeyMapValue(mapSubKey, "VALUE"); |
268 |
✓✓ | 1 |
DicoValue * mapOtherSubKey = mapMain->getMap("other_sub_key"); |
269 |
✓✓ | 1 |
b &= checkKeyMapValue(mapOtherSubKey, "\"some string in double quotes\""); |
270 |
} |
||
271 |
1 |
b &= mapMain != NULL; |
|
272 |
|||
273 |
✓✓ | 1 |
DicoValue * mapNotInMainKey = dico.getMap("not_in_main_key"); |
274 |
1 |
bool isNotInMainKeyExist = mapNotInMainKey != NULL; |
|
275 |
✓✓✓ | 1 |
std::cout << "checkCompactDico : isNotInMainKeyExist = " << isNotInMainKeyExist << std::endl; |
276 |
✓✓ | 1 |
b &= checkKeyMapValue(mapNotInMainKey, "VALUE_IN_UPPERCASE"); |
277 |
|||
278 |
✓✓✓ | 1 |
std::cout << "checkCompactDico : b = " << b << std::endl; |
279 |
1 |
return b; |
|
280 |
} |
||
281 |
|||
282 |
1 |
int main(int argc, char** argv){ |
|
283 |
1 |
testCheckValue(); |
|
284 |
1 |
bool b(checkParserYml()); |
|
285 |
1 |
b &= checkEmbededDico(); |
|
286 |
1 |
b &= checkCompactList(); |
|
287 |
1 |
b &= checkDashedList(); |
|
288 |
1 |
b &= checkCompactDico(); |
|
289 |
|||
290 |
1 |
return b - 1; |
|
291 |
} |
||
292 |
|||
293 |
Generated by: GCOVR (Version 4.2) |