GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/FileParser/TESTS/TEST_PCONFIGPARSER/main.cpp Lines: 57 57 100.0 %
Date: 2024-12-09 15:41:43 Branches: 155 165 93.9 %

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