GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/FileParser/TESTS/TEST_PCONFIGPARSER/main.cpp Lines: 66 66 100.0 %
Date: 2023-10-11 10:52:07 Branches: 70 74 94.6 %

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 "file_utils.h"
10
#include "ConfigParser.h"
11
12
///Test the ConfigBase
13
/**	@return true on success, false otherwise
14
*/
15
1
bool testConfigBase(){
16
1
	ConfigBase * cb = new ConfigTemplate<int>();
17
1
	cb->setName("value");
18
1
	cb->setDocumentation("some doc");
19
20
1
	bool b(true);
21
1
	b &= cb->getName() == "value";
22
1
	b &= cb->getDocumentation() == "some doc";
23
24
1
	delete cb;
25
1
	phoenix_functionOk("testConfigBase", b);
26
1
	return b;
27
}
28
29
///Check the file utils
30
/**	@return true on success, false otherwise
31
*/
32
1
bool testPConfigParser(){
33
1
	bool b(true);
34
2
	std::string configFileName("config.txt");
35
1
	b &= saveFileContent(configFileName, "{\n\tvalue = 23;\n}\n");
36
37
1
	int value = 42;
38
39
2
	ConfigParser parser;
40
1
	parser.addVariable(value, "value", "Testing value");
41
1
	b &= parser.save("configDefault.txt");
42
43
1
	b &= parser.load(configFileName);
44
1
	std::cout << "testPConfigParser : load " << b << std::endl;
45
1
	std::cout << "testPConfigParser : value = " << value << std::endl;
46
1
	b &= value == 23;
47
48
1
	b &= parser.save("configSave.txt");
49
1
	b &= !parser.save("");
50
1
	b &= !parser.save("unexistingDir/unexistingFile.txt");
51
52
1
	b &= parser.load("configDefault.txt");
53
1
	b &= value == 42;
54
55
1
	b &= !parser.load("");
56
1
	b &= !parser.load("unexistingFile");
57
58
2
	std::string configFileNameWrongName("configWrongName.txt");
59
1
	b &= saveFileContent(configFileNameWrongName, "{\n\tvar = 23;\n}\n");
60
1
	b &= !parser.load(configFileNameWrongName);
61
62
63
2
	std::string configFileNameRepeat("configRepeat.txt");
64
1
	b &= saveFileContent(configFileNameRepeat, "{\n\tvalue = 23;\n\tvalue = 42;\n}\n");
65
66
	try{
67
1
		b &= parser.load(configFileNameRepeat);
68
1
	}catch(std::runtime_error & e){
69
		//We exptect an error because the value is given twice
70
1
		b &= true;
71
	}
72
73
2
	std::string configFileNameMissingEqual("configMissingEqual.txt");
74
1
	b &= saveFileContent(configFileNameMissingEqual, "{\n\tvalue 23;\n");
75
76
	try{
77
1
		b &= parser.load(configFileNameMissingEqual);
78
1
	}catch(std::runtime_error & e){
79
		//We exptect an error because the value is given twice
80
1
		b &= true;
81
	}
82
83
1
	std::string configFileNameMissingSemicol("configMissingSemicol.txt");
84
1
	b &= saveFileContent(configFileNameMissingSemicol, "{\n\tvalue = 23\n");
85
86
	try{
87
1
		b &= parser.load(configFileNameMissingSemicol);
88
1
	}catch(std::runtime_error & e){
89
		//We exptect an error because the value is given twice
90
1
		b &= true;
91
	}
92
1
	phoenix_functionOk("testPConfigParser", b);
93
2
	return b;
94
}
95
96
///Check some partial parsing of the ConfigParser
97
/**	@param fileContent : file content to be checked
98
 * 	@return true on success, false otherwise
99
*/
100
2
bool checkPartConfigParser(const std::string & fileContent){
101
4
	std::string fileName("config.txt");
102
2
	bool b(saveFileContent(fileName, fileContent));
103
104
2
	ConfigParser parser;
105
2
	int value = 42;
106
2
	parser.addVariable(value, "value", "Testing value");
107
108
2
	b &= parser.load(fileName);
109

2
	std::cout << "checkPartConfigParser('"<<fileContent<<"')" << std::endl;
110
2
	phoenix_functionOk("checkPartConfigParser", b);
111
4
	return b;
112
}
113
114
1
int main(int argc, char** argv){
115
1
	bool b(testConfigBase());
116
1
	b &= testPConfigParser();
117
118
1
	b &= !checkPartConfigParser("");
119
1
	b &= !checkPartConfigParser("some wrong thing");
120
121
1
	phoenix_functionOk("final", b);
122
1
	return b - 1;
123
}
124
125