GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/FileParser/TESTS/TEST_PFileParser/main.cpp Lines: 282 282 100.0 %
Date: 2024-09-10 03:06:26 Branches: 558 558 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 "PFileParser.h"
11
12
///Test the PFileParser
13
1
void testPFileParserPartern(){
14
2
	PFileParser parser;
15
1
	parser.setFileContent("Les GPUs\\dots{} pour quoi faire ?}\\label{chapGPU}\n");
16
17
2
	std::string res(parser.getUntilKeyWithoutPatern("}"));
18

1
	phoenix_assert(phoenix_check("testPFileParserPartern", res, "Les GPUs\\dots{"));
19
1
}
20
21
///Test the PFileParser
22
1
void testPFileParserParternExclude(){
23
2
	PFileParser parser;
24
1
	parser.setFileContent("Les GPUs\\dots{} pour quoi faire ?}\\label{chapGPU}\n");
25
26
2
	std::string res(parser.getUntilKeyWithoutPaternExclude("}", "{"));
27

1
	phoenix_assert(phoenix_check("testPFileParserParternExclude", res, "Les GPUs\\dots{} pour quoi faire ?"));
28
1
}
29
30
///Test the PFileParser
31
1
void testPFileParserParternRecurse(){
32
2
	PFileParser parser;
33
1
	parser.setFileContent("Les GPUs\\dots{} pour quoi faire ?}\\label{chapGPU}\n");
34
35
2
	std::string res(parser.getUntilKeyWithoutPaternRecurse("}", "{"));
36

1
	phoenix_assert(phoenix_check("testPFileParserParternRecurse", res, "Les GPUs\\dots{} pour quoi faire ?"));
37
1
}
38
39
///Test the PFileParser
40
1
void testPFileParserParternRecurse2(){
41
2
	PFileParser parser;
42
1
	parser.setFileContent("des trucs \"a dire\" et d'autres chose");
43
44
2
	std::string res(parser.getUntilKeyWithoutPaternRecurse("\"", "\""));
45

1
	phoenix_assert(phoenix_check("testPFileParserParternRecurse2", res, "des trucs "));
46
1
}
47
48
///Test the PFileParser
49
1
void testPFileParserParternRecurseAllowChar(){
50
2
	PFileParser parser;
51
1
	parser.setFileContent("Les GPUs\\dots{} pour quoi faire ?}\\label{chapGPU}\n");
52
53

2
	std::string res(parser.getUntilKeyWithoutPaternRecurse("}", "{", "} \\abcdefhijklmnopqrstuvwxyz"));
54

1
	phoenix_assert(phoenix_check("testPFileParserParternRecurseAllowChar", res, "Les GPUs\\dots{} pour quoi faire ?"));
55
1
}
56
57
///Test the PFileParser
58
1
void testPFileParserParternRecurseExcludeEnd(){
59
2
	PFileParser parser;
60
1
	parser.setFileContent("des trucs \\\"a\\\" dire\" et d'autres chose");
61
62

2
	std::string res(parser.getUntilKeyWithoutPaternRecurseExclude("\"", "\"", "\\"));
63

1
	phoenix_assert(phoenix_check("testPFileParserParternRecurseExcludeEnd", res, "des trucs \\\"a\\\" dire"));
64
1
}
65
66
///Test the PFileParser
67
1
void testPFileParserParternRecurseExcludeEnd2(){
68
2
	PFileParser parser;
69
1
	parser.setFileContent("des trucs \"a dire\" et d'autres chose");
70
71

2
	std::string res(parser.getUntilKeyWithoutPaternRecurseExclude("\"", "\"", "\\"));
72

1
	phoenix_assert(phoenix_check("testPFileParserParternRecurseExcludeEnd2", res, "des trucs "));
73
1
}
74
75
///Test the PFileParser
76
1
void testPFileParserSeq(){
77
2
	PParseSeq seq;
78
2
		PParseStep stepBegin;
79
1
		stepBegin.setIsOptional(false);
80
2
			PParseCmd cmdBegin;
81
1
			cmdBegin.setIsMatch(true);
82
1
			cmdBegin.setStr("\\begin");
83
1
		stepBegin.getVecCmd().push_back(cmdBegin);
84
1
	seq.getVecStep().push_back(stepBegin);
85
2
		PParseStep stepOpenBrace;
86
1
			stepOpenBrace.setIsOptional(false);
87
2
			PParseCmd cmdOpenBrace;
88
1
			cmdOpenBrace.setIsMatch(true);
89
1
			cmdOpenBrace.setStr("{");
90
1
		stepOpenBrace.getVecCmd().push_back(cmdOpenBrace);
91
1
	seq.getVecStep().push_back(stepOpenBrace);
92
2
		PParseStep stepEnvName;
93
1
			stepEnvName.setIsOptional(false);
94
2
			PParseCmd cmdEnvName;
95
1
			cmdEnvName.setIsMatch(true);
96
1
			cmdEnvName.setStr("envName");
97
1
		stepEnvName.getVecCmd().push_back(cmdEnvName);
98
1
	seq.getVecStep().push_back(stepEnvName);
99
2
		PParseStep stepEndBrace;
100
1
			stepEndBrace.setIsOptional(false);
101
2
			PParseCmd cmdEndBrace;
102
1
			cmdEndBrace.setIsMatch(true);
103
1
			cmdEndBrace.setStr("}");
104
1
		stepEndBrace.getVecCmd().push_back(cmdEndBrace);
105
1
	seq.getVecStep().push_back(stepEndBrace);
106
107
2
	PFileParser parser;
108
1
	parser.setFileContent("\\begin { envName } des trucs\n");
109
1
	std::string res = parser.isMatch(seq);
110

1
	phoenix_assert(phoenix_check("testPFileParserSeq", res, "\\begin{envName}"));
111
1
}
112
113
///Test the PFileParser
114
1
void testPFileParserMatchSeq(){
115
2
	std::vector<std::string> vecPatern;
116
1
	vecPatern.push_back("\\begin");
117
1
	vecPatern.push_back("{");
118
1
	vecPatern.push_back("envName");
119
1
	vecPatern.push_back("}");
120
121
1
	PFileParser parser;
122
1
	parser.setFileContent("\\begin { envName } des trucs\n");
123

1
	phoenix_assert(parser.isMatchSeq(vecPatern));
124
1
}
125
126
127
///Test the PFileParser
128
1
void testPFileParserSeqOneStep(){
129
2
	PParseSeq seq;
130
2
		PParseStep step;
131
1
		step.setIsOptional(false);
132
2
			PParseCmd cmdBegin;
133
1
			cmdBegin.setIsMatch(true);
134
1
			cmdBegin.setStr("\\begin");
135
1
		step.getVecCmd().push_back(cmdBegin);
136
2
			PParseCmd cmdEnvName;
137
1
			cmdEnvName.setIsMatch(true);
138
1
			cmdEnvName.setStr("envName");
139
1
		step.getVecCmd().push_back(cmdEnvName);
140
2
			PParseCmd cmdEndBrace;
141
1
			cmdEndBrace.setIsMatch(true);
142
1
			cmdEndBrace.setStr("}");
143
1
		step.getVecCmd().push_back(cmdEndBrace);
144
1
	seq.getVecStep().push_back(step);
145
146
2
	PFileParser parser;
147
1
	parser.setFileContent("\\begin { envName } des trucs\n");
148
1
	std::string res = parser.isMatch(seq);
149

1
	phoenix_assert( phoenix_check("testPFileParserSeqOneStep", res, "\\begin"));
150
1
}
151
152
///Test the PFileParser
153
1
void testPFileParserIsMatch(){
154
1
	PFileParser parser;
155
1
	parser.setFileContent(" Les GPUs\\dots{} pour quoi faire ?}\\label{chapGPU}\n");
156

1
	phoenix_assert(!parser.isMatch("Autre"));
157

1
	phoenix_assert(parser.isMatch("Les"));
158

1
	phoenix_assert(parser.isMatch("GPU"));
159
1
}
160
161
///Test the PFileParser
162
/**	@param inputStr : input string
163
 * 	@param search : string to be earched
164
 * 	@param result : expected result
165
 * 	@return true on success, false otherwise
166
*/
167
3
bool testPFileParserGetUntilKey(const std::string & inputStr, const std::string & search, const std::string & result){
168
3
	bool b(true);
169
6
	PFileParser parser2;
170
3
	parser2.setFileContent(inputStr);
171
172
3
	std::string strFound(parser2.getUntilKey(search));
173
// 	std::cout << "testPFileParserGetUntilKey : inputStr = '" << inputStr << "', search = '"<<search<<"', strFound = '" << strFound << "', expectedResult = '" << result << "'" << std::endl;
174
175
3
	b &= phoenix_check("testPFileParserGetUntilKey", strFound, result);
176
// 	phoenix_functionOk("testPFileParserGetUntilKey", b);
177
6
	return b;
178
}
179
180
///Test the PFileParser
181
1
void testPFileParserBase(){
182
1
	PFileParser parser;
183
1
	parser.setFileContent("e :e");
184
1
	parser.setSeparator(":");
185
1
	parser.setWhiteSpace(" ");
186
1
	parser.setLocation(PLocation("fileName", 42, 23));
187
1
	parser.setLine(24);
188
1
	parser.setColumn(2);
189
1
	parser.popPosition();
190
1
	parser.getEscapeChar();
191
1
	parser.getFileName();
192
1
	parser.clear();
193
194

1
	phoenix_assert(!parser.isChSpace());
195

1
	phoenix_assert(!parser.isChSeparator());
196

1
	std::cout << "testPFileParserBase : next char '" << parser.getNextChar() << "'" << std::endl;
197

1
	phoenix_assert(parser.isChSpace());
198

1
	std::cout << "testPFileParserBase : next char '" << parser.getNextChar() << "'" << std::endl;
199

1
	phoenix_assert(parser.isChSeparator());
200

1
	std::cout << "testPFileParserBase : next char '" << parser.getNextChar() << "'" << std::endl;
201

1
	phoenix_assert(!parser.isChSpace());
202

1
	phoenix_assert(!parser.isChSeparator());
203
1
}
204
205
///Check the PFileParser
206
1
void testPFileParserGetCurrentRow(){
207
1
	PFileParser parser;
208
1
	parser.setFileContent("one row\none other row");
209

1
	phoenix_assert(parser.getCurrentRow() == "one row");
210
1
}
211
212
///Check the PFileParser
213
1
void testPFileParserVecIsMatch(){
214
2
	PFileParser parser;
215
1
	parser.setFileContent("one row\none other row");
216
217
1
	std::vector<std::string> vecToken;
218

1
	phoenix_assert(parser.isMatch(vecToken) == "");
219
1
	vecToken.push_back("other");
220

1
	phoenix_assert(parser.isMatch(vecToken) == "");
221
1
	vecToken.push_back("one");
222

1
	phoenix_assert(parser.isMatch(vecToken) == "one");
223
1
}
224
225
///Check the PFileParser
226
1
void testPFileParserListIsMatch(){
227
2
	PFileParser parser;
228
1
	parser.setFileContent("one row\none other row");
229
230
1
	std::list<std::string> vecToken;
231

1
	phoenix_assert(parser.isMatch(vecToken) == "");
232
1
	vecToken.push_back("other");
233

1
	phoenix_assert(parser.isMatch(vecToken) == "");
234
1
	vecToken.push_back("one");
235

1
	phoenix_assert(parser.isMatch(vecToken) == "one");
236
1
}
237
238
///Check the PFileParser
239
1
void testPFileParserVecIsMatchToken(){
240
2
	PFileParser parser;
241
1
	parser.setFileContent("one row\none other row");
242
243
1
	std::vector<std::string> vecToken;
244

1
	phoenix_assert(parser.isMatchToken(vecToken) == "");
245
1
	vecToken.push_back("other");
246

1
	phoenix_assert(parser.isMatchToken(vecToken) == "");
247
1
	vecToken.push_back("one");
248

1
	phoenix_assert(parser.isMatchToken(vecToken) == "one");
249
1
}
250
251
///Check the PFileParser
252
1
void testPFileParserMapIsMatchToken(){
253
2
	PFileParser parser;
254
1
	parser.setFileContent("one row\none other row");
255
256
2
	std::map<std::string, int> mapToken;
257
1
	std::string matchKey("");
258
1
	int matchValue(0);
259

1
	phoenix_assert(!parser.isMatchToken(matchKey, matchValue, mapToken));
260
1
	mapToken["other"] = 23;
261

1
	phoenix_assert(!parser.isMatchToken(matchKey, matchValue, mapToken));
262
263
1
	mapToken["one"] = 1;
264

1
	phoenix_assert(parser.isMatchToken(matchKey, matchValue, mapToken));
265

1
	phoenix_assert(matchKey == "one");
266

1
	phoenix_assert(matchValue == 1);
267
1
}
268
269
///Check the PFileParser
270
1
void testPFileParserListIsMatchToken(){
271
2
	PFileParser parser;
272
1
	parser.setFileContent("one row\none other row");
273
274
1
	std::list<std::string> vecToken;
275

1
	phoenix_assert(parser.isMatchToken(vecToken) == "");
276
1
	vecToken.push_back("other");
277

1
	phoenix_assert(parser.isMatchToken(vecToken) == "");
278
1
	vecToken.push_back("one");
279

1
	phoenix_assert(parser.isMatchToken(vecToken) == "one");
280
1
}
281
282
///Check the PFileParser
283
1
void testPFileParserVecVecIsMatch(){
284
2
	PFileParser parser;
285
1
	parser.setFileContent("one row\none other row");
286
287
2
	std::vector<std::vector<std::string> > patern;
288

1
	phoenix_assert(parser.isMatch(patern) == "");
289
2
	std::vector<std::string> vecPatern;
290
1
	vecPatern.push_back("other");
291
1
	patern.push_back(vecPatern);
292

1
	phoenix_assert(parser.isMatch(patern) == "");
293
1
	vecPatern.push_back("one");
294
1
	patern.push_back(vecPatern);
295

1
	phoenix_assert(parser.isMatch(patern) == "one");
296

1
	phoenix_assert(parser.isWhiteSpace());
297

1
	phoenix_assert(parser.getSeparator() != "");
298

1
	phoenix_assert(parser.getCurrentCh() == 'r');
299

1
	phoenix_assert(parser.getPrevCh() == ' ');
300

1
	phoenix_assert(parser.getLine() == 1lu);
301

1
	phoenix_assert(parser.getCurrentCharIdx() == 4lu);
302
1
	std::cout << parser << std::endl;
303
1
}
304
305
///Test the getNextToken method of the PFileParser
306
1
void testPFileParserGetNextToken(){
307
2
	PFileParser parser;
308
1
	parser.setFileContent("e : e");
309
1
	parser.setWhiteSpace(" ");
310
1
	parser.setSeparator(":");
311
312
2
	std::string token1(parser.getNextToken());
313

1
	phoenix_assert(token1 == "e");
314
// 	std::cout << "testPFileParserGetNextToken : b = " << b << ", token1 = '" << token1 << "'" << std::endl;
315
2
	std::string token2(parser.getNextToken());
316

1
	phoenix_assert(token2 == ":");
317
// 	std::cout << "testPFileParserGetNextToken : b = " << b << ", token2 = '" << token2 << "'" << std::endl;
318
1
	std::string token3(parser.getNextToken());
319

1
	phoenix_assert(token3 == "e");
320
// 	std::cout << "testPFileParserGetNextToken : b = " << b << ", token3 = '" << token3 << "'" << std::endl;
321

1
	phoenix_assert(parser.getNextToken() == "");
322
1
}
323
324
///Test the getNextToken method of the PFileParser
325
1
void testPFileParserGetNextToken2(){
326
2
	PFileParser parser;
327
1
	parser.setFileContent("e : e");
328
1
	parser.setWhiteSpace(" ");
329
1
	parser.setSeparator(":");
330
331
2
	std::string skippedStr("");
332
2
	std::string token1(parser.getNextToken(skippedStr));
333

1
	phoenix_assert(token1 == "e");
334
// 	std::cout << "testPFileParserGetNextToken2 : b = " << b << ", token1 = '" << token1 << "'" << std::endl;
335

1
	phoenix_assert(skippedStr == "");
336
// 	std::cout << "testPFileParserGetNextToken2 : b = " << b << ", skippedStr = '" << skippedStr << "'" << std::endl;
337
338
1
	skippedStr = "";
339
2
	std::string token2(parser.getNextToken(skippedStr));
340

1
	phoenix_assert(token2 == ":");
341
// 	std::cout << "testPFileParserGetNextToken2 : b = " << b << ", token2 = '" << token2 << "'" << std::endl;
342

1
	phoenix_assert(skippedStr == " ");
343
// 	std::cout << "testPFileParserGetNextToken2 : b = " << b << ", skippedStr = '" << skippedStr << "'" << std::endl;
344
345
1
	skippedStr = "";
346
1
	std::string token3(parser.getNextToken(skippedStr));
347

1
	phoenix_assert(token3 == "e");
348
// 	std::cout << "testPFileParserGetNextToken2 : b = " << b << ", token3 = '" << token3 << "'" << std::endl;
349

1
	phoenix_assert(skippedStr == " ");
350
// 	std::cout << "testPFileParserGetNextToken2 : b = " << b << ", skippedStr = '" << skippedStr << "'" << std::endl;
351

1
	phoenix_assert(parser.getNextToken(skippedStr) == "");
352
1
}
353
354
1
int main(int argc, char** argv){
355
1
	testPFileParserPartern();
356
1
	testPFileParserParternExclude();
357
1
	testPFileParserParternRecurse();
358
1
	testPFileParserParternRecurse2();
359
1
	testPFileParserParternRecurseAllowChar();
360
1
	testPFileParserParternRecurseExcludeEnd();
361
1
	testPFileParserParternRecurseExcludeEnd2();
362
1
	testPFileParserSeq();
363
1
	testPFileParserMatchSeq();
364
1
	testPFileParserSeqOneStep();
365
1
	testPFileParserIsMatch();
366
1
	testPFileParserBase();
367
368


1
	phoenix_assert(testPFileParserGetUntilKey("let's test a string", "", ""));
369


1
	phoenix_assert(testPFileParserGetUntilKey("let's test a string", "some", "let's test a stringsome"));
370


1
	phoenix_assert(testPFileParserGetUntilKey("let's test a string", "test", "let's test"));
371
372
1
	testPFileParserGetCurrentRow();
373
1
	testPFileParserVecIsMatch();
374
1
	testPFileParserListIsMatch();
375
1
	testPFileParserVecIsMatchToken();
376
1
	testPFileParserMapIsMatchToken();
377
1
	testPFileParserListIsMatchToken();
378
1
	testPFileParserVecVecIsMatch();
379
1
	testPFileParserGetNextToken();
380
1
	testPFileParserGetNextToken2();
381
1
	return 0;
382
}
383
384