GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/FileParser/TESTS/TEST_PARSER_YML/main_full_config.cpp Lines: 60 60 100.0 %
Date: 2023-10-11 10:52:07 Branches: 84 89 94.4 %

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 "parser_yml.h"
9
10
///Check the value of a DicoValue
11
/**	@param mapKey : DicoValue to be checked
12
 * 	@param expectedValue : expected value
13
 * 	@return true if the value matches the expectedValue, false otherwise
14
*/
15
2
bool checkKeyMapValue(const DicoValue * mapKey, const std::string & expectedValue){
16
2
	if(mapKey == NULL){
17
1
		std::cout << "checkKeyMapValue : map NULL for expectedValue = '"<<expectedValue<<"'" << std::endl;
18
1
		return expectedValue == "";
19
	}
20

1
	std::cout << "checkKeyMapValue : map '"<<mapKey->getKey()<<"' => '"<<mapKey->getString()<<"', expectedValue = '"<<expectedValue<<"'"  << std::endl;
21
1
	bool b(mapKey->getString() == expectedValue);
22
1
	std::cout << "checkKeyMapValue : b = " << b << std::endl;
23
1
	return b;
24
}
25
26
///Check the value of a DicoValue
27
/**	@param mapKey : DicoValue to be checked
28
 * 	@param vecExpectedValue : vector of expected values
29
 * 	@return true if the value matches the expectedValue, false otherwise
30
*/
31
2
bool checkKeyMapVecValue(const DicoValue * mapKey, const std::vector<std::string> & vecExpectedValue){
32
2
	if(mapKey == NULL){
33
1
		std::cout << "checkKeyMapVecValue : map NULL for vecExpectedValue = " << std::endl;
34
1
		phoenix_print(vecExpectedValue);
35
1
		return vecExpectedValue.size() == 0lu;
36
	}
37


1
	std::cout << "checkKeyMapVecValue : map '"<<mapKey->getKey()<<"' => '"<<mapKey->getValue()<<"', vecExpectedValue = "  << std::endl;
38
1
	phoenix_print(vecExpectedValue);
39
1
	bool b(true);
40
1
	const VecDicoValue & vecValue = mapKey->getVecChild();
41
1
	b &= vecValue.size() == vecExpectedValue.size();
42

1
	std::cout << "checkKeyMapVecValue : vecValue.size() = " << vecValue.size() << ", vecExpectedValue.size() = "<< vecExpectedValue.size() << ", isOk = " << b << std::endl;
43
1
	VecDicoValue::const_iterator it(vecValue.begin());
44
1
	std::vector<std::string>::const_iterator itRef(vecExpectedValue.begin());
45


3
	while(b && it != vecValue.end() && itRef != vecExpectedValue.end()){
46
2
		b &= it->getValue() == *itRef;
47


2
		std::cout << "\tvalue = '" << it->getValue() << "', reference = '"<< *itRef << "', isOk = " << b << std::endl;
48
2
		++it;
49
2
		++itRef;
50
	}
51
1
	std::cout << "checkKeyMapVecValue : b = " << b << std::endl;
52
1
	return b;
53
}
54
55
///Call the check value with NULL pointers
56
1
void testCheckValue(){
57
1
	checkKeyMapValue(NULL, "");
58
2
	std::vector<std::string> vecNoValue;
59
1
	checkKeyMapVecValue(NULL, vecNoValue);
60
1
}
61
62
///Check the YML parser
63
/**	@return true on success, false otherwise
64
*/
65
1
bool checkParserYml(){
66
2
	std::string ymlFile(FULL_YML_CONFIG);
67
2
	DicoValue dico;
68
1
	if(!parser_yml(dico, ymlFile)){return false;}
69
1
	std::cout << "checkParserYml : output DicoValue :" << std::endl;
70
1
	dico.print();
71
1
	bool b(true);
72
73
1
	const DicoValue * mapJob = dico.getMap("job");
74
1
	b &= mapJob != NULL;
75
1
	std::cout << "checkParserYml : mapJob exist : b = " << b << std::endl;
76
1
	if(mapJob != NULL){
77
1
		const DicoValue * mapJobArgument = mapJob->getMap("job_argument");
78
1
		b &= checkKeyMapValue(mapJobArgument, "-A aswg -p short");
79
80
1
		const DicoValue * mapRmDL1 = mapJob->getMap("rmdl1");
81
1
		b &= mapRmDL1 != NULL;
82
1
		if(mapRmDL1 != NULL){
83
1
			const DicoValue * mapDemendencies = mapRmDL1->getMap("depdendencies");
84
85
1
			std::vector<std::string> vecExpectedValue;
86
1
			vecExpectedValue.push_back("dl1dl2");
87
1
			vecExpectedValue.push_back("plotdl1");
88
1
			b &= checkKeyMapVecValue(mapDemendencies, vecExpectedValue);
89
		}
90
	}
91
1
	std::cout << "checkParserYml : b = " << b << std::endl;
92
1
	return b;
93
}
94
95
1
int main(int argc, char** argv){
96
1
	testCheckValue();
97
1
	bool b(checkParserYml());
98
1
	return b - 1;
99
}
100
101