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