GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/FileParser/TESTS/TEST_DICO_REPLACE_VAR/main.cpp Lines: 177 177 100.0 %
Date: 2023-10-11 10:52:07 Branches: 186 186 100.0 %

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_check.h"
9
#include "dico_replace_var.h"
10
#include "parser_yml.h"
11
12
///Check the embeded dico
13
/**	@return true on success, false otherwise
14
*/
15
1
bool checkReplaceVarDicoEmpty(){
16
1
	std::cout << "\ncheckReplaceVarDicoEmpty :" << std::endl;
17
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");
18
19
2
	std::string ymlFile("test_replace_dico.yml");
20
1
	bool b(true);
21
1
	b &= saveFileContent(ymlFile, fileContent);
22
1
	DicoValue dico;
23
1
	b &= parser_yml(dico, ymlFile);
24
1
	std::cout << "checkCompactDico : output DicoValue :" << std::endl;
25
1
	dico.print();
26
1
	dico_replace_var(dico);
27
1
	std::cout << "checkCompactDico : after var replace DicoValue :" << std::endl;
28
1
	dico.print();
29
1
	phoenix_functionOk("checkReplaceVarDicoEmpty", b);
30
2
	return b;
31
}
32
33
///Check the main dico of the next test
34
/**	@param dicoMain : pointer of DicoValue to be used
35
 * 	@return true on success, false otherwise
36
*/
37
2
bool checkReplaceVarDicoDicoMain(DicoValue * dicoMain){
38
2
	if(dicoMain == NULL){return false;}
39
1
	bool b(true);
40
1
	DicoValue * dicoOtherSubKey = dicoMain->getMap("other_sub_key");
41
1
	std::string valueReplace(dicoOtherSubKey->getValue());
42

1
	std::cout << "other_sub_key = '"<<valueReplace<<"'" << std::endl;
43
1
	b &= valueReplace == "\"some VALUE, in double quotes or VALUE_IN_UPPERCASE\"";
44
1
	return b;
45
}
46
47
///Check the embeded dico
48
/**	@return true on success, false otherwise
49
*/
50
1
bool checkReplaceVarDico(){
51
1
	std::cout << "\ncheckReplaceVarDico :" << std::endl;
52
2
	std::string fileContent("main:\n\tsub_key: VALUE,\n\tother_sub_key: \"some ${sub_key} in double quotes or ${not_in_main_key}\"\n\nnot_in_main_key: VALUE_IN_UPPERCASE\n\n\n");
53
54
2
	std::string ymlFile("checkReplaceVarDico.yml");
55
1
	bool b(true);
56
1
	b &= saveFileContent(ymlFile, fileContent);
57
1
	DicoValue dico;
58
1
	b &= parser_yml(dico, ymlFile);
59
1
	std::cout << "checkReplaceVarDico : output DicoValue :" << std::endl;
60
1
	dico.print();
61
1
	dico_replace_var(dico);
62
1
	std::cout << "checkReplaceVarDico : after var replace DicoValue :" << std::endl;
63
1
	dico.print();
64
1
	DicoValue * dicoMain = dico.getMap("main");
65
1
	b &= checkReplaceVarDicoDicoMain(dicoMain);
66
1
	b &= !checkReplaceVarDicoDicoMain(NULL);
67
68
1
	phoenix_functionOk("checkReplaceVarDico", b);
69
2
	return b;
70
}
71
72
///Check the embeded dico
73
/**	@return true on success, false otherwise
74
*/
75
1
bool checkReplaceVarDicoMultiple(){
76
1
	std::cout << "\ncheckReplaceVarDicoMultiple :" << std::endl;
77
2
	std::string fileContent("varA: \"VALUE and ${varB}\"\nvarB: \"some ${sub_key} in double quotes or ${not_in_main_key}\"\nvarC: \"stack of ${varA}\"\n\n");
78
79
2
	std::string ymlFile("checkReplaceVarDicoMultiple.yml");
80
1
	bool b(true);
81
1
	b &= saveFileContent(ymlFile, fileContent);
82
2
	DicoValue dico;
83
1
	b &= parser_yml(dico, ymlFile);
84
1
	std::cout << "checkReplaceVarDicoMultiple : output DicoValue :" << std::endl;
85
1
	dico.print();
86
1
	dico_replace_var(dico);
87
1
	std::cout << "checkReplaceVarDicoMultiple : after var replace DicoValue :" << std::endl;
88
1
	dico.print();
89
1
	DicoValue * dicoMain = dico.getMap("varC");
90
91
1
	std::string valueReplace(dicoMain->getValue());
92

1
	std::cout << "varC = '"<<valueReplace<<"'" << std::endl;
93
1
	b &= valueReplace == "\"stack of VALUE and some ${sub_key} in double quotes or ${not_in_main_key}\"";
94
95
1
	phoenix_functionOk("checkReplaceVarDicoMultiple", b);
96
2
	return b;
97
}
98
99
///Check the embeded dico
100
/**	@return true on success, false otherwise
101
*/
102
1
bool checkReplaceVarDicoMultipleRevert(){
103
1
	std::cout << "\ncheckReplaceVarDicoMultipleRevert :" << std::endl;
104
2
	std::string fileContent("varJ: \"VALUE and ${varG}\"\nvarG: \"some ${sub_key} in double quotes or ${not_in_main_key}\"\nvarC: \"stack of ${varJ}\"\n\n");
105
106
2
	std::string ymlFile("checkReplaceVarDicoMultipleRevert.yml");
107
1
	bool b(true);
108
1
	b &= saveFileContent(ymlFile, fileContent);
109
2
	DicoValue dico;
110
1
	b &= parser_yml(dico, ymlFile);
111
1
	std::cout << "checkReplaceVarDicoMultipleRevert : output DicoValue :" << std::endl;
112
1
	dico.print();
113
1
	dico_replace_var(dico);
114
1
	std::cout << "checkReplaceVarDicoMultipleRevert : after var replace DicoValue :" << std::endl;
115
1
	dico.print();
116
1
	DicoValue * dicoMain = dico.getMap("varC");
117
118
1
	std::string valueReplace(dicoMain->getValue());
119

1
	std::cout << "varC = '"<<valueReplace<<"'" << std::endl;
120
1
	b &= valueReplace == "\"stack of VALUE and some ${sub_key} in double quotes or ${not_in_main_key}\"";
121
122
1
	phoenix_functionOk("checkReplaceVarDicoMultipleRevert", b);
123
2
	return b;
124
}
125
126
///Check the embeded dico
127
/**	@return true on success, false otherwise
128
*/
129
1
bool checkReplaceVarDicoMultipleList(){
130
1
	std::cout << "\ncheckReplaceVarDicoMultipleList :" << std::endl;
131
2
	std::string fileContent("some_list: [one, two, three]\nmain:\n\t- varA: \"VALUE and ${varB}\"\n\t- varB: \"some ${sub_key} in double quotes or ${not_in_main_key}\"\nvarC: \"stack of ${varA}\"\n\n");
132
133
2
	std::string ymlFile("checkReplaceVarDicoMultipleList.yml");
134
1
	bool b(true);
135
1
	b &= saveFileContent(ymlFile, fileContent);
136
2
	DicoValue dico;
137
1
	b &= parser_yml(dico, ymlFile);
138
1
	std::cout << "checkReplaceVarDicoMultipleList : output DicoValue :" << std::endl;
139
1
	dico.print();
140
1
	dico_replace_var(dico);
141
1
	std::cout << "checkReplaceVarDicoMultipleList : after var replace DicoValue :" << std::endl;
142
1
	dico.print();
143
1
	DicoValue * dicoMain = dico.getMap("varC");
144
145
1
	std::string valueReplace(dicoMain->getValue());
146

1
	std::cout << "varC = '"<<valueReplace<<"'" << std::endl;
147
1
	b &= valueReplace == "\"stack of VALUE and some ${sub_key} in double quotes or ${not_in_main_key}\"";
148
149
1
	phoenix_functionOk("checkReplaceVarDicoMultipleList", b);
150
2
	return b;
151
}
152
153
///Check the embeded dico
154
/**	@param dicoVarC : pointer of DicoValue to be checked
155
 * 	@return true on success, false otherwise
156
*/
157
2
bool checkReplaceVarDicoMultipleNested2DicoVarC(DicoValue * dicoVarC){
158
2
	if(dicoVarC == NULL){return false;}
159
1
	bool b(true);
160
1
	std::string valueReplace(dicoVarC->getValue());
161
1
	b &= phoenix_check("checkReplaceVarDicoMultipleNested2DicoVarC", valueReplace, "\"stack of VALUE and some ${sub_key} in double quotes or ${not_in_main_key}\"");
162
1
	return b;
163
}
164
165
///Check the embeded dico
166
/**	@param dicoFirst : pointer of DicoValue to be checked
167
 * 	@return true on success, false otherwise
168
*/
169
2
bool checkReplaceVarDicoMultipleNested2DicoFirst(DicoValue * dicoFirst){
170
2
	if(dicoFirst == NULL){return false;}
171
1
	bool b(true);
172
1
	DicoValue * dicoVarC = dicoFirst->getMap("varC");
173
1
	b &= checkReplaceVarDicoMultipleNested2DicoVarC(dicoVarC);
174
1
	b &= !checkReplaceVarDicoMultipleNested2DicoVarC(NULL);
175
1
	return b;
176
}
177
178
///Check the embeded dico
179
/**	@return true on success, false otherwise
180
*/
181
1
bool checkReplaceVarDicoMultipleNested2(){
182
1
	std::cout << "\ncheckReplaceVarDicoMultipleNested2 :" << std::endl;
183
2
	std::string fileContent("varA: \"VALUE and ${varB}\"\nvarB: \"some ${sub_key} in double quotes or ${not_in_main_key}\"\nfirst:\n\tvarC: \"stack of ${varA}\"\n\n");
184
185
2
	std::string ymlFile("checkReplaceVarDicoMultipleNested2.yml");
186
1
	bool b(true);
187
1
	b &= saveFileContent(ymlFile, fileContent);
188
1
	DicoValue dico;
189
1
	b &= parser_yml(dico, ymlFile);
190
1
	std::cout << "checkReplaceVarDicoMultipleNested2 : output DicoValue :" << std::endl;
191
1
	dico.print();
192
1
	dico_replace_var(dico);
193
1
	std::cout << "checkReplaceVarDicoMultipleNested2 : after var replace DicoValue :" << std::endl;
194
1
	dico.print();
195
1
	DicoValue * dicoFirst = dico.getMap("first");
196
1
	b &= checkReplaceVarDicoMultipleNested2DicoFirst(dicoFirst);
197
1
	b &= !checkReplaceVarDicoMultipleNested2DicoFirst(NULL);
198
1
	phoenix_functionOk("checkReplaceVarDicoMultipleNested2", b);
199
2
	return b;
200
}
201
202
///Check the embeded dico
203
/**	@param dicoVarC : DicoValue to be used
204
 * 	@return true on success, false otherwise
205
*/
206
2
bool checkReplaceVarDicoMultipleNested3DicoVarC(DicoValue * dicoVarC){
207
2
	if(dicoVarC == NULL){return false;}
208
1
	bool b(true);
209
1
	std::string valueReplace(dicoVarC->getValue());
210
1
	b &= phoenix_check("checkReplaceVarDicoMultipleNested3DicoVarC", valueReplace, "\"stack of VALUE and some ${sub_key} in double quotes or ${not_in_main_key}\"");
211
1
	return b;
212
}
213
214
///Check the embeded dico
215
/**	@param dicoSecond : DicoValue to be used
216
 * 	@return true on success, false otherwise
217
*/
218
2
bool checkReplaceVarDicoMultipleNested3DicoSecond(DicoValue * dicoSecond){
219
2
	if(dicoSecond == NULL){return false;}
220
1
	bool b(true);
221
1
	DicoValue * dicoVarC = dicoSecond->getMap("varC");
222
1
	b &= checkReplaceVarDicoMultipleNested3DicoVarC(dicoVarC);
223
1
	b &= !checkReplaceVarDicoMultipleNested3DicoVarC(NULL);
224
1
	return b;
225
}
226
227
///Check the embeded dico
228
/**	@param dicoFirst : DicoValue to be used
229
 * 	@return true on success, false otherwise
230
*/
231
2
bool checkReplaceVarDicoMultipleNested3DicoFirst(DicoValue * dicoFirst){
232
2
	if(dicoFirst == NULL){return false;}
233
1
	bool b(true);
234
1
	DicoValue * dicoSecond = dicoFirst->getMap("second");
235
1
	b &= checkReplaceVarDicoMultipleNested3DicoSecond(dicoSecond);
236
1
	b &= !checkReplaceVarDicoMultipleNested3DicoSecond(NULL);
237
1
	return b;
238
}
239
240
///Check the embeded dico
241
/**	@return true on success, false otherwise
242
*/
243
1
bool checkReplaceVarDicoMultipleNested3(){
244
1
	std::cout << "\ncheckReplaceVarDicoMultipleNested3 :" << std::endl;
245
2
	std::string fileContent("varA: \"VALUE and ${varB}\"\nvarB: \"some ${sub_key} in double quotes or ${not_in_main_key}\"\nfirst:\n\tsecond:\n\t\tvarC: \"stack of ${varA}\"\n\n");
246
247
2
	std::string ymlFile("checkReplaceVarDicoMultipleNested3.yml");
248
1
	bool b(true);
249
1
	b &= saveFileContent(ymlFile, fileContent);
250
1
	DicoValue dico;
251
1
	b &= parser_yml(dico, ymlFile);
252
1
	std::cout << "checkReplaceVarDicoMultipleNested3 : output DicoValue :" << std::endl;
253
1
	dico.print();
254
1
	dico_replace_var(dico);
255
1
	std::cout << "checkReplaceVarDicoMultipleNested3 : after var replace DicoValue :" << std::endl;
256
1
	dico.print();
257
258
1
	DicoValue * dicoFirst = dico.getMap("first");
259
1
	b &= checkReplaceVarDicoMultipleNested3DicoFirst(dicoFirst);
260
1
	b &= !checkReplaceVarDicoMultipleNested3DicoFirst(NULL);
261
1
	phoenix_functionOk("checkReplaceVarDicoMultipleNested3", b);
262
2
	return b;
263
}
264
265
1
int main(int argc, char** argv){
266
1
	bool b(checkReplaceVarDicoEmpty());
267
1
	b &= checkReplaceVarDico();
268
1
	b &= checkReplaceVarDicoMultiple();
269
1
	b &= checkReplaceVarDicoMultipleRevert();
270
1
	b &= checkReplaceVarDicoMultipleList();
271
1
	b &= checkReplaceVarDicoMultipleNested2();
272
1
	b &= checkReplaceVarDicoMultipleNested3();
273
1
	phoenix_functionOk("final", b);
274
1
	return b - 1;
275
}
276
277