GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/FileParser/TESTS/TEST_DICO_REPLACE_VAR/main.cpp Lines: 123 123 100.0 %
Date: 2024-09-10 03:06:26 Branches: 197 197 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_assert.h"
9
#include "phoenix_check.h"
10
#include "dico_replace_var.h"
11
#include "parser_yml.h"
12
13
///Check the embeded dico
14
1
void checkReplaceVarDicoEmpty(){
15
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");
16
17
2
	std::string ymlFile("test_replace_dico.yml");
18

1
	phoenix_assert(saveFileContent(ymlFile, fileContent));
19
1
	DicoValue dico;
20

1
	phoenix_assert(parser_yml(dico, ymlFile));
21
// 	std::cout << "checkCompactDico : output DicoValue :" << std::endl;
22
// 	dico.print();
23
1
	dico_replace_var(dico);
24
// 	std::cout << "checkCompactDico : after var replace DicoValue :" << std::endl;
25
// 	dico.print();
26
1
}
27
28
///Check the main dico of the next test
29
/**	@param dicoMain : pointer of DicoValue to be used
30
 * 	@return true on success, false otherwise
31
*/
32
2
bool checkReplaceVarDicoDicoMain(DicoValue * dicoMain){
33
2
	if(dicoMain == NULL){return false;}
34
1
	bool b(true);
35
1
	DicoValue * dicoOtherSubKey = dicoMain->getMap("other_sub_key");
36
1
	std::string valueReplace(dicoOtherSubKey->getValue());
37
// 	std::cout << "other_sub_key = '"<<valueReplace<<"'" << std::endl;
38
1
	b &= valueReplace == "\"some VALUE, in double quotes or VALUE_IN_UPPERCASE\"";
39
1
	return b;
40
}
41
42
///Check the embeded dico
43
1
void checkReplaceVarDico(){
44
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");
45
46
2
	std::string ymlFile("checkReplaceVarDico.yml");
47

1
	phoenix_assert(saveFileContent(ymlFile, fileContent));
48
1
	DicoValue dico;
49

1
	phoenix_assert(parser_yml(dico, ymlFile));
50
// 	std::cout << "checkReplaceVarDico : output DicoValue :" << std::endl;
51
// 	dico.print();
52
1
	dico_replace_var(dico);
53
// 	std::cout << "checkReplaceVarDico : after var replace DicoValue :" << std::endl;
54
// 	dico.print();
55
1
	DicoValue * dicoMain = dico.getMap("main");
56

1
	phoenix_assert(checkReplaceVarDicoDicoMain(dicoMain));
57

1
	phoenix_assert(!checkReplaceVarDicoDicoMain(NULL));
58
1
}
59
60
///Check the embeded dico
61
1
void checkReplaceVarDicoMultiple(){
62
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");
63
64
2
	std::string ymlFile("checkReplaceVarDicoMultiple.yml");
65

1
	phoenix_assert(saveFileContent(ymlFile, fileContent));
66
2
	DicoValue dico;
67

1
	phoenix_assert(parser_yml(dico, ymlFile));
68
// 	std::cout << "checkReplaceVarDicoMultiple : output DicoValue :" << std::endl;
69
// 	dico.print();
70
1
	dico_replace_var(dico);
71
// 	std::cout << "checkReplaceVarDicoMultiple : after var replace DicoValue :" << std::endl;
72
// 	dico.print();
73
1
	DicoValue * dicoMain = dico.getMap("varC");
74
75
1
	std::string valueReplace(dicoMain->getValue());
76
// 	std::cout << "varC = '"<<valueReplace<<"'" << std::endl;
77

1
	phoenix_assert(valueReplace == "\"stack of VALUE and some ${sub_key} in double quotes or ${not_in_main_key}\"");
78
1
}
79
80
///Check the embeded dico
81
1
void checkReplaceVarDicoMultipleRevert(){
82
// 	std::cout << "\ncheckReplaceVarDicoMultipleRevert :" << std::endl;
83
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");
84
85
2
	std::string ymlFile("checkReplaceVarDicoMultipleRevert.yml");
86

1
	phoenix_assert(saveFileContent(ymlFile, fileContent));
87
2
	DicoValue dico;
88

1
	phoenix_assert(parser_yml(dico, ymlFile));
89
// 	std::cout << "checkReplaceVarDicoMultipleRevert : output DicoValue :" << std::endl;
90
// 	dico.print();
91
1
	dico_replace_var(dico);
92
// 	std::cout << "checkReplaceVarDicoMultipleRevert : after var replace DicoValue :" << std::endl;
93
// 	dico.print();
94
1
	DicoValue * dicoMain = dico.getMap("varC");
95
96
1
	std::string valueReplace(dicoMain->getValue());
97
// 	std::cout << "varC = '"<<valueReplace<<"'" << std::endl;
98

1
	phoenix_assert(valueReplace == "\"stack of VALUE and some ${sub_key} in double quotes or ${not_in_main_key}\"");
99
1
}
100
101
///Check the embeded dico
102
1
void checkReplaceVarDicoMultipleList(){
103
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");
104
105
2
	std::string ymlFile("checkReplaceVarDicoMultipleList.yml");
106

1
	phoenix_assert(saveFileContent(ymlFile, fileContent));
107
2
	DicoValue dico;
108

1
	phoenix_assert(parser_yml(dico, ymlFile));
109
// 	std::cout << "checkReplaceVarDicoMultipleList : output DicoValue :" << std::endl;
110
// 	dico.print();
111
1
	dico_replace_var(dico);
112
// 	std::cout << "checkReplaceVarDicoMultipleList : after var replace DicoValue :" << std::endl;
113
// 	dico.print();
114
1
	DicoValue * dicoMain = dico.getMap("varC");
115
116
1
	std::string valueReplace(dicoMain->getValue());
117
// 	std::cout << "varC = '"<<valueReplace<<"'" << std::endl;
118

1
	phoenix_assert(valueReplace == "\"stack of VALUE and some ${sub_key} in double quotes or ${not_in_main_key}\"");
119
1
}
120
121
///Check the embeded dico
122
/**	@param dicoVarC : pointer of DicoValue to be checked
123
 * 	@return true on success, false otherwise
124
*/
125
2
bool checkReplaceVarDicoMultipleNested2DicoVarC(DicoValue * dicoVarC){
126
2
	if(dicoVarC == NULL){return false;}
127
1
	bool b(true);
128
1
	std::string valueReplace(dicoVarC->getValue());
129
1
	b &= phoenix_check("checkReplaceVarDicoMultipleNested2DicoVarC", valueReplace, "\"stack of VALUE and some ${sub_key} in double quotes or ${not_in_main_key}\"");
130
1
	return b;
131
}
132
133
///Check the embeded dico
134
/**	@param dicoFirst : pointer of DicoValue to be checked
135
 * 	@return true on success, false otherwise
136
*/
137
2
bool checkReplaceVarDicoMultipleNested2DicoFirst(DicoValue * dicoFirst){
138
2
	if(dicoFirst == NULL){return false;}
139
1
	bool b(true);
140
1
	DicoValue * dicoVarC = dicoFirst->getMap("varC");
141
1
	b &= checkReplaceVarDicoMultipleNested2DicoVarC(dicoVarC);
142
1
	b &= !checkReplaceVarDicoMultipleNested2DicoVarC(NULL);
143
1
	return b;
144
}
145
146
///Check the embeded dico
147
1
void checkReplaceVarDicoMultipleNested2(){
148
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");
149
150
2
	std::string ymlFile("checkReplaceVarDicoMultipleNested2.yml");
151

1
	phoenix_assert(saveFileContent(ymlFile, fileContent));
152
1
	DicoValue dico;
153

1
	phoenix_assert(parser_yml(dico, ymlFile));
154
// 	std::cout << "checkReplaceVarDicoMultipleNested2 : output DicoValue :" << std::endl;
155
// 	dico.print();
156
1
	dico_replace_var(dico);
157
// 	std::cout << "checkReplaceVarDicoMultipleNested2 : after var replace DicoValue :" << std::endl;
158
// 	dico.print();
159
1
	DicoValue * dicoFirst = dico.getMap("first");
160

1
	phoenix_assert(checkReplaceVarDicoMultipleNested2DicoFirst(dicoFirst));
161

1
	phoenix_assert(!checkReplaceVarDicoMultipleNested2DicoFirst(NULL));
162
1
}
163
164
///Check the embeded dico
165
/**	@param dicoVarC : DicoValue to be used
166
 * 	@return true on success, false otherwise
167
*/
168
2
bool checkReplaceVarDicoMultipleNested3DicoVarC(DicoValue * dicoVarC){
169
2
	if(dicoVarC == NULL){return false;}
170
1
	bool b(true);
171
1
	std::string valueReplace(dicoVarC->getValue());
172
1
	b &= phoenix_check("checkReplaceVarDicoMultipleNested3DicoVarC", valueReplace, "\"stack of VALUE and some ${sub_key} in double quotes or ${not_in_main_key}\"");
173
1
	return b;
174
}
175
176
///Check the embeded dico
177
/**	@param dicoSecond : DicoValue to be used
178
 * 	@return true on success, false otherwise
179
*/
180
2
bool checkReplaceVarDicoMultipleNested3DicoSecond(DicoValue * dicoSecond){
181
2
	if(dicoSecond == NULL){return false;}
182
1
	bool b(true);
183
1
	DicoValue * dicoVarC = dicoSecond->getMap("varC");
184
1
	b &= checkReplaceVarDicoMultipleNested3DicoVarC(dicoVarC);
185
1
	b &= !checkReplaceVarDicoMultipleNested3DicoVarC(NULL);
186
1
	return b;
187
}
188
189
///Check the embeded dico
190
/**	@param dicoFirst : DicoValue to be used
191
 * 	@return true on success, false otherwise
192
*/
193
2
bool checkReplaceVarDicoMultipleNested3DicoFirst(DicoValue * dicoFirst){
194
2
	if(dicoFirst == NULL){return false;}
195
1
	bool b(true);
196
1
	DicoValue * dicoSecond = dicoFirst->getMap("second");
197
1
	b &= checkReplaceVarDicoMultipleNested3DicoSecond(dicoSecond);
198
1
	b &= !checkReplaceVarDicoMultipleNested3DicoSecond(NULL);
199
1
	return b;
200
}
201
202
///Check the embeded dico
203
1
void checkReplaceVarDicoMultipleNested3(){
204
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");
205
206
2
	std::string ymlFile("checkReplaceVarDicoMultipleNested3.yml");
207

1
	phoenix_assert(saveFileContent(ymlFile, fileContent));
208
1
	DicoValue dico;
209

1
	phoenix_assert(parser_yml(dico, ymlFile));
210
// 	std::cout << "checkReplaceVarDicoMultipleNested3 : output DicoValue :" << std::endl;
211
// 	dico.print();
212
1
	dico_replace_var(dico);
213
// 	std::cout << "checkReplaceVarDicoMultipleNested3 : after var replace DicoValue :" << std::endl;
214
// 	dico.print();
215
216
1
	DicoValue * dicoFirst = dico.getMap("first");
217

1
	phoenix_assert(checkReplaceVarDicoMultipleNested3DicoFirst(dicoFirst));
218

1
	phoenix_assert(!checkReplaceVarDicoMultipleNested3DicoFirst(NULL));
219
1
}
220
221
1
int main(int argc, char** argv){
222
1
	checkReplaceVarDicoEmpty();
223
1
	checkReplaceVarDico();
224
1
	checkReplaceVarDicoMultiple();
225
1
	checkReplaceVarDicoMultipleRevert();
226
1
	checkReplaceVarDicoMultipleList();
227
1
	checkReplaceVarDicoMultipleNested2();
228
1
	checkReplaceVarDicoMultipleNested3();
229
1
	return 0;
230
}
231
232