GCC Code Coverage Report


Directory: ./
File: src/BackEnd/generator_class_cpp.cpp
Date: 2025-12-15 11:32:44
Exec Total Coverage
Lines: 254 304 83.6%
Functions: 19 19 100.0%
Branches: 438 633 69.2%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "phoenix_color.h"
8 #include "openFileStream.h"
9 #include "header_generator.h"
10 #include "cmakelist_generator.h"
11 #include "generator_class_cpp.h"
12
13 ///Check if the given type is a pointer or not
14 /** @param varType : type to be checked
15 * @return true if the given type is a pointer, false otherwise
16 */
17 11 bool class_getIsPointer(const PString & varType){
18
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 11 times.
11 if(varType.size() == 0lu){return false;}
19
1/4
✗ Branch 0 (6→7) not taken.
✓ Branch 1 (6→10) taken 11 times.
✗ Branch 2 (8→9) not taken.
✗ Branch 3 (8→10) not taken.
11 return varType.find('*') && varType.back() == '*';
20 }
21
22 ///Get the template call in the class declaration
23 /** @param listTemplate : list of template def
24 * @return template definition in the class declaration (< T, U, .... >)
25 */
26 13 PString class_getClassDefTemplate(const PVecString & listTemplate){
27
3/3
✓ Branch 0 (3→4) taken 11 times.
✓ Branch 1 (3→6) taken 2 times.
✓ Branch 2 (4→5) taken 11 times.
13 if(listTemplate.size() == 0lu){return "";}
28
2/2
✓ Branch 0 (6→7) taken 2 times.
✓ Branch 2 (7→8) taken 2 times.
2 PString defTemplate("<"), comma("");
29
2/2
✓ Branch 0 (30→9) taken 3 times.
✓ Branch 1 (30→31) taken 2 times.
10 for(PVecString::const_iterator it(listTemplate.begin()); it != listTemplate.end(); ++it){
30
1/1
✓ Branch 0 (11→12) taken 3 times.
3 PVecString vecPart = it->split(' ');
31
1/2
✓ Branch 0 (13→14) taken 3 times.
✗ Branch 1 (13→19) not taken.
3 if(vecPart.size() != 0lu){
32
2/2
✓ Branch 0 (15→16) taken 3 times.
✓ Branch 2 (16→17) taken 3 times.
3 defTemplate += comma + vecPart.back();
33
1/1
✓ Branch 0 (18→19) taken 3 times.
3 comma = ", ";
34 }
35 3 }
36
1/1
✓ Branch 0 (31→32) taken 2 times.
2 defTemplate += ">";
37
1/1
✓ Branch 0 (32→33) taken 2 times.
2 return defTemplate;
38 2 }
39
40 ///Get the template definition in the class declaration
41 /** @param listTemplate : list of template def
42 * @return template definition in the class declaration (template< .... >)
43 */
44 11 PString class_getClassDeclTempalteDef(const PVecString & listTemplate){
45
2/3
✓ Branch 0 (3→4) taken 11 times.
✗ Branch 1 (3→6) not taken.
✓ Branch 2 (4→5) taken 11 times.
11 if(listTemplate.size() == 0lu){return "";}
46 PString templateDef("template<");
47 PString comma("");
48 for(PVecString::const_iterator it(listTemplate.begin()); it != listTemplate.end(); ++it){
49 templateDef += comma;
50 templateDef += *it;
51 comma = ", ";
52 }
53 templateDef += ">\n";
54 return templateDef;
55 }
56
57 ///Saves constructor of the class
58 /** @param[out] fs : header file name
59 * @param classConfig : PClassConfig we vant to save
60 * @param defTemplate : extra template definition for the class name space
61 * @param templateDeclaration : basic template declaration before each method (template< ... >)
62 */
63 5 void class_saveClassConstructorImpl(std::ofstream & fs, const PClassConfig & classConfig, const PString & defTemplate, const PString & templateDeclaration){
64
2/2
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
5 PString name(classConfig.getName());
65
3/3
✓ Branch 0 (4→5) taken 5 times.
✓ Branch 2 (5→6) taken 5 times.
✓ Branch 4 (6→7) taken 5 times.
5 fs << "///Constructor of class " << name << std::endl;
66
1/1
✓ Branch 0 (7→8) taken 5 times.
5 fs << templateDeclaration;
67
5/5
✓ Branch 0 (8→9) taken 5 times.
✓ Branch 2 (9→10) taken 5 times.
✓ Branch 4 (10→11) taken 5 times.
✓ Branch 6 (11→12) taken 5 times.
✓ Branch 8 (12→13) taken 5 times.
5 fs << name << defTemplate << "::" << name << "()";
68
2/3
✓ Branch 0 (13→14) taken 5 times.
✗ Branch 2 (15→16) not taken.
✓ Branch 3 (15→47) taken 5 times.
5 if(classConfig.getListParentClass().size() != 0lu){
69 PVecString::const_iterator it(classConfig.getListParentClass().begin());
70 fs << std::endl << "\t: " << *it << "()";
71 if(classConfig.getListParentClass().size() > 1lu){
72 while(it != classConfig.getListParentClass().end()){
73 fs << ", " << *it << "()";
74 ++it;
75 }
76 }
77 fs << std::endl;
78 }
79
2/2
✓ Branch 0 (47→48) taken 5 times.
✓ Branch 2 (48→49) taken 5 times.
5 fs << "{" << std::endl;
80
4/4
✓ Branch 0 (49→50) taken 5 times.
✓ Branch 2 (50→51) taken 5 times.
✓ Branch 4 (51→52) taken 5 times.
✓ Branch 6 (52→53) taken 5 times.
5 fs << "\tinitialisation" << name << "();" << std::endl;
81
3/3
✓ Branch 0 (53→54) taken 5 times.
✓ Branch 2 (54→55) taken 5 times.
✓ Branch 4 (55→56) taken 5 times.
5 fs << "}" << std::endl << std::endl;
82 5 }
83
84
85 ///Saves destructor of the class
86 /** @param[out] fs : header file name
87 * @param classConfig : PClassConfig we vant to save
88 * @param defTemplate : extra template definition for the class name space
89 * @param templateDeclaration : basic template declaration before each method (template< ... >)
90 */
91 5 void class_saveClassDestructorImpl(std::ofstream & fs, const PClassConfig & classConfig, const PString & defTemplate, const PString & templateDeclaration){
92
2/2
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
5 PString name(classConfig.getName());
93
3/3
✓ Branch 0 (4→5) taken 5 times.
✓ Branch 2 (5→6) taken 5 times.
✓ Branch 4 (6→7) taken 5 times.
5 fs << "///Destructor of class " << name << std::endl;
94
1/1
✓ Branch 0 (7→8) taken 5 times.
5 fs << templateDeclaration;
95
6/6
✓ Branch 0 (8→9) taken 5 times.
✓ Branch 2 (9→10) taken 5 times.
✓ Branch 4 (10→11) taken 5 times.
✓ Branch 6 (11→12) taken 5 times.
✓ Branch 8 (12→13) taken 5 times.
✓ Branch 10 (13→14) taken 5 times.
5 fs << name << defTemplate << "::~" << name << "(){" << std::endl;
96
2/2
✓ Branch 0 (14→15) taken 5 times.
✓ Branch 2 (15→16) taken 5 times.
5 fs << "\t" << std::endl;
97
3/3
✓ Branch 0 (16→17) taken 5 times.
✓ Branch 2 (17→18) taken 5 times.
✓ Branch 4 (18→19) taken 5 times.
5 fs << "}" << std::endl << std::endl;
98 5 }
99
100 ///Saves the copy function of a class
101 /** @param[out] fs : header file name
102 * @param classConfig : PClassConfig we vant to save
103 * @param defTemplate : extra template definition for the class name space
104 * @param templateDeclaration : basic template declaration before each method (template< ... >)
105 */
106 5 void class_saveClassInitialisationFunctionImpl(std::ofstream & fs, const PClassConfig & classConfig, const PString & defTemplate, const PString & templateDeclaration){
107
2/2
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
5 PString name(classConfig.getName());
108
3/3
✓ Branch 0 (4→5) taken 5 times.
✓ Branch 2 (5→6) taken 5 times.
✓ Branch 4 (6→7) taken 5 times.
5 fs << "///Initialisation Function of class " << name << std::endl;
109
1/1
✓ Branch 0 (7→8) taken 5 times.
5 fs << templateDeclaration;
110
7/7
✓ Branch 0 (8→9) taken 5 times.
✓ Branch 2 (9→10) taken 5 times.
✓ Branch 4 (10→11) taken 5 times.
✓ Branch 6 (11→12) taken 5 times.
✓ Branch 8 (12→13) taken 5 times.
✓ Branch 10 (13→14) taken 5 times.
✓ Branch 12 (14→15) taken 5 times.
5 fs << "void " << name << defTemplate << "::initialisation" << name << "(){" << std::endl;
111
1/1
✓ Branch 0 (15→16) taken 5 times.
5 const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
112
2/2
✓ Branch 0 (84→17) taken 11 times.
✓ Branch 1 (84→85) taken 5 times.
32 for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
113
3/4
✓ Branch 0 (19→20) taken 11 times.
✓ Branch 2 (20→21) taken 11 times.
✗ Branch 4 (21→22) not taken.
✓ Branch 5 (21→34) taken 11 times.
11 if(it->getDefaultValue() != ""){
114 fs << "\tp_" << it->getName() << " = "<<it->getDefaultValue()<<";" << std::endl;
115 }else{
116
2/2
✓ Branch 0 (36→37) taken 11 times.
✓ Branch 2 (37→38) taken 11 times.
11 PString varType(it->getType());
117
1/1
✓ Branch 0 (38→39) taken 11 times.
11 bool isSimpleType = getIsSimpleType(varType);
118
1/1
✓ Branch 0 (39→40) taken 11 times.
11 bool isPtr(class_getIsPointer(varType));
119
1/2
✗ Branch 0 (40→41) not taken.
✓ Branch 1 (40→48) taken 11 times.
11 if(isPtr){
120 fs << "\tp_" << it->getName() << " = NULL;" << std::endl;
121
2/2
✓ Branch 0 (48→49) taken 6 times.
✓ Branch 1 (48→63) taken 5 times.
11 }else if(isSimpleType){
122
1/1
✓ Branch 0 (49→50) taken 6 times.
6 PString defaultValue(getDefaultValueTypeInCpp(varType));
123
2/3
✓ Branch 0 (50→51) taken 6 times.
✓ Branch 2 (51→52) taken 6 times.
✗ Branch 3 (51→61) not taken.
6 if(defaultValue != ""){
124
7/7
✓ Branch 0 (52→53) taken 6 times.
✓ Branch 2 (55→56) taken 6 times.
✓ Branch 4 (56→57) taken 6 times.
✓ Branch 6 (57→58) taken 6 times.
✓ Branch 8 (58→59) taken 6 times.
✓ Branch 10 (59→60) taken 6 times.
✓ Branch 12 (60→61) taken 6 times.
12 fs << "\tp_" << it->getName() << " = "<<defaultValue<<";" << std::endl;
125 }
126
2/3
✓ Branch 0 (63→64) taken 5 times.
✗ Branch 2 (64→65) not taken.
✓ Branch 3 (64→72) taken 5 times.
11 }else if(varType == "PString"){
127 fs << "\tp_" << it->getName() << " = \"\";" << std::endl;
128 }
129 11 }
130 }
131
3/3
✓ Branch 0 (85→86) taken 5 times.
✓ Branch 2 (86→87) taken 5 times.
✓ Branch 4 (87→88) taken 5 times.
5 fs << "}" << std::endl << std::endl;
132 5 }
133
134 ///Check if the vector of PClassAttribute has default value
135 /** @param vecAttr : vector of attribute to be checked
136 * @return true if there is at least one default value, false if there is none
137 */
138 1 bool generator_checkDefaultValueExist(const std::vector<PClassAttribute> & vecAttr){
139 1 bool hasDefaultValue = false;
140
5/6
✓ Branch 0 (17→18) taken 2 times.
✓ Branch 1 (17→20) taken 1 times.
✓ Branch 2 (18→19) taken 2 times.
✗ Branch 3 (18→20) not taken.
✓ Branch 4 (21→3) taken 2 times.
✓ Branch 5 (21→22) taken 1 times.
6 for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end() && !hasDefaultValue; ++it){
141
2/2
✓ Branch 0 (5→6) taken 2 times.
✓ Branch 2 (6→7) taken 2 times.
2 hasDefaultValue |= it->getDefaultValue() != "";
142 }
143 1 return hasDefaultValue;
144 }
145
146 ///Create the declaration of the given class
147 /** @param manager : PTraitBackendManager which handles all trait backend
148 * @param[out] fs : file to be completed
149 * @param classConfig : configuration of the class to be used
150 * @param mode : mode of the generator
151 */
152 1 void generator_enum_cpp_header(const PTraitBackendManager & manager, std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){
153
6/7
✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
✓ Branch 4 (4→5) taken 1 times.
✗ Branch 5 (4→8) not taken.
✓ Branch 6 (5→6) taken 1 times.
✓ Branch 8 (6→7) taken 1 times.
✓ Branch 10 (7→8) taken 1 times.
1 if(classConfig.getClassDocumentation() != "") fs << classConfig.getClassDocumentation() << std::endl;
154
2/2
✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (9→10) taken 1 times.
1 PString name(classConfig.getName());
155
3/3
✓ Branch 0 (10→11) taken 1 times.
✓ Branch 2 (11→12) taken 1 times.
✓ Branch 4 (12→13) taken 1 times.
1 fs << "namespace " << name << " {\n";
156
7/8
✓ Branch 0 (13→14) taken 1 times.
✓ Branch 2 (14→15) taken 1 times.
✓ Branch 4 (15→16) taken 1 times.
✗ Branch 5 (15→20) not taken.
✓ Branch 6 (16→17) taken 1 times.
✓ Branch 8 (17→18) taken 1 times.
✓ Branch 10 (18→19) taken 1 times.
✓ Branch 12 (19→20) taken 1 times.
1 if(classConfig.getClassDocumentation() != ""){fs << "\t"<< classConfig.getClassDocumentation() << std::endl;}
157
3/3
✓ Branch 0 (20→21) taken 1 times.
✓ Branch 2 (21→22) taken 1 times.
✓ Branch 4 (22→23) taken 1 times.
1 fs << "\tenum " << name << " {\n\t\t";
158
1/1
✓ Branch 0 (23→24) taken 1 times.
1 const std::vector<PClassAttribute> & vecAttr(classConfig.getListAttribute());
159
1/1
✓ Branch 0 (24→25) taken 1 times.
1 bool isDefaultCounterActivated = !generator_checkDefaultValueExist(vecAttr);
160
1/1
✓ Branch 0 (25→26) taken 1 times.
1 PString comma("");
161 1 size_t i(0lu);
162
2/2
✓ Branch 0 (67→27) taken 2 times.
✓ Branch 1 (67→68) taken 1 times.
6 for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
163
3/8
✓ Branch 0 (29→30) taken 2 times.
✓ Branch 2 (30→31) taken 2 times.
✗ Branch 4 (31→32) not taken.
✓ Branch 5 (31→38) taken 2 times.
✗ Branch 6 (32→33) not taken.
✗ Branch 8 (35→36) not taken.
✗ Branch 10 (36→37) not taken.
✗ Branch 12 (37→38) not taken.
2 if(it->getDocumentation() != "") fs << "\t\t" << it->getDocumentation() << std::endl;
164
3/3
✓ Branch 0 (38→39) taken 2 times.
✓ Branch 2 (41→42) taken 2 times.
✓ Branch 4 (42→43) taken 2 times.
4 fs << comma << it->getName();
165
1/2
✓ Branch 0 (43→44) taken 2 times.
✗ Branch 1 (43→46) not taken.
2 if(isDefaultCounterActivated){
166
2/2
✓ Branch 0 (44→45) taken 2 times.
✓ Branch 2 (45→56) taken 2 times.
2 fs << " = " << i;
167 }else if(it->getDefaultValue() != ""){
168 fs << " = " << it->getDefaultValue();
169 }
170
1/1
✓ Branch 0 (56→57) taken 2 times.
2 comma = ",\n\t\t";
171 2 ++i;
172 }
173
2/2
✓ Branch 0 (68→69) taken 1 times.
✓ Branch 2 (69→70) taken 1 times.
1 fs << "\n\t};" << std::endl;
174
3/3
✓ Branch 0 (70→71) taken 1 times.
✓ Branch 2 (71→72) taken 1 times.
✓ Branch 4 (72→73) taken 1 times.
1 fs << "}" << std::endl << std::endl;
175
1/1
✓ Branch 0 (73→74) taken 1 times.
1 manager.classExtraFunctionDeclaration(fs, classConfig, mode);
176
2/2
✓ Branch 0 (74→75) taken 1 times.
✓ Branch 2 (75→76) taken 1 times.
1 fs << std::endl << std::endl;
177 1 }
178
179
180 ///Create the declaration of the given class
181 /** @param manager : PTraitBackendManager which handles all trait backend
182 * @param[out] fs : file to be completed
183 * @param classConfig : configuration of the class to be used
184 * @param mode : mode of the generator
185 */
186 5 void generator_class_cpp_header(const PTraitBackendManager & manager, std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){
187
6/7
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
✓ Branch 4 (4→5) taken 5 times.
✗ Branch 5 (4→8) not taken.
✓ Branch 6 (5→6) taken 5 times.
✓ Branch 8 (6→7) taken 5 times.
✓ Branch 10 (7→8) taken 5 times.
5 if(classConfig.getClassDocumentation() != "") fs << classConfig.getClassDocumentation() << std::endl;
188
2/2
✓ Branch 0 (8→9) taken 5 times.
✓ Branch 2 (9→10) taken 5 times.
5 PString name(classConfig.getName());
189
1/1
✓ Branch 0 (10→11) taken 5 times.
5 GeneratorMode classMode(mode);
190
1/1
✓ Branch 0 (11→12) taken 5 times.
5 const PVecString & listTemplate = classConfig.getListTemplate();
191
1/1
✓ Branch 0 (12→13) taken 5 times.
5 PString defTemplate(class_getClassDefTemplate(listTemplate));
192
1/1
✓ Branch 0 (13→14) taken 5 times.
5 PString templateDeclaration(class_getClassDeclTempalteDef(listTemplate));
193
1/1
✓ Branch 0 (14→15) taken 5 times.
5 classMode.defTemplate = defTemplate;
194
1/1
✓ Branch 0 (15→16) taken 5 times.
5 classMode.templateDeclaration = templateDeclaration;
195
196
1/1
✓ Branch 0 (16→17) taken 5 times.
5 fs << classMode.templateDeclaration;
197
2/2
✓ Branch 0 (17→18) taken 5 times.
✓ Branch 2 (18→19) taken 5 times.
5 fs << "class " << name;
198
2/3
✓ Branch 0 (19→20) taken 5 times.
✗ Branch 2 (21→22) not taken.
✓ Branch 3 (21→49) taken 5 times.
5 if(classConfig.getListParentClass().size() != 0lu){
199 PVecString::const_iterator it(classConfig.getListParentClass().begin());
200 fs << " : public " << *it;
201 if(classConfig.getListParentClass().size() > 1lu){
202 while(it != classConfig.getListParentClass().end()){
203 fs << ", " << *it;
204 ++it;
205 }
206 }
207 }
208
2/2
✓ Branch 0 (49→50) taken 5 times.
✓ Branch 2 (50→51) taken 5 times.
5 fs << "{" << std::endl;
209
2/2
✓ Branch 0 (51→52) taken 5 times.
✓ Branch 2 (52→53) taken 5 times.
5 fs << "\tpublic:" << std::endl;
210
4/4
✓ Branch 0 (53→54) taken 5 times.
✓ Branch 2 (54→55) taken 5 times.
✓ Branch 4 (55→56) taken 5 times.
✓ Branch 6 (56→57) taken 5 times.
5 fs << "\t\t" << name << "();" << std::endl;
211
4/4
✓ Branch 0 (57→58) taken 5 times.
✓ Branch 2 (58→59) taken 5 times.
✓ Branch 4 (59→60) taken 5 times.
✓ Branch 6 (60→61) taken 5 times.
5 fs << "\t\tvirtual ~" << name << "();" << std::endl;
212
213
1/1
✓ Branch 0 (61→62) taken 5 times.
5 manager.publicMethodDeclaration(fs, classConfig, classMode);
214
2/2
✓ Branch 0 (62→63) taken 5 times.
✓ Branch 2 (63→64) taken 5 times.
5 fs << "\tprotected:" << std::endl;
215
1/1
✓ Branch 0 (64→65) taken 5 times.
5 manager.protectedMethodDeclaration(fs, classConfig, classMode);
216
217
2/2
✓ Branch 0 (65→66) taken 5 times.
✓ Branch 2 (66→67) taken 5 times.
5 fs << "\tprivate:" << std::endl;
218
4/4
✓ Branch 0 (67→68) taken 5 times.
✓ Branch 2 (68→69) taken 5 times.
✓ Branch 4 (69→70) taken 5 times.
✓ Branch 6 (70→71) taken 5 times.
5 fs << "\t\tvoid initialisation" << name << "();" << std::endl;
219
1/1
✓ Branch 0 (71→72) taken 5 times.
5 manager.privateMethodDeclaration(fs, classConfig, classMode);
220
1/1
✓ Branch 0 (72→73) taken 5 times.
5 const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
221
2/2
✓ Branch 0 (107→74) taken 11 times.
✓ Branch 1 (107→108) taken 5 times.
32 for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
222
7/8
✓ Branch 0 (76→77) taken 11 times.
✓ Branch 2 (77→78) taken 11 times.
✓ Branch 4 (78→79) taken 11 times.
✗ Branch 5 (78→85) not taken.
✓ Branch 6 (79→80) taken 11 times.
✓ Branch 8 (82→83) taken 11 times.
✓ Branch 10 (83→84) taken 11 times.
✓ Branch 12 (84→85) taken 11 times.
22 if(it->getDocumentation() != "") fs << "\t\t" << it->getDocumentation() << std::endl;
223
224
8/8
✓ Branch 0 (85→86) taken 11 times.
✓ Branch 2 (88→89) taken 11 times.
✓ Branch 4 (89→90) taken 11 times.
✓ Branch 6 (90→91) taken 11 times.
✓ Branch 8 (93→94) taken 11 times.
✓ Branch 10 (94→95) taken 11 times.
✓ Branch 12 (95→96) taken 11 times.
✓ Branch 14 (96→97) taken 11 times.
33 fs << "\t\t" << it->getType() << " p_" << it->getName() << ";" << std::endl;
225 }
226
3/3
✓ Branch 0 (108→109) taken 5 times.
✓ Branch 2 (109→110) taken 5 times.
✓ Branch 4 (110→111) taken 5 times.
5 fs << "};" << std::endl << std::endl;
227
1/1
✓ Branch 0 (111→112) taken 5 times.
5 manager.classExtraFunctionDeclaration(fs, classConfig, classMode);
228
2/2
✓ Branch 0 (112→113) taken 5 times.
✓ Branch 2 (113→114) taken 5 times.
5 fs << std::endl << std::endl;
229 5 }
230
231 ///Create the declaration of the given class
232 /** @param manager : PTraitBackendManager which handles all trait backend
233 * @param headerFile : file to be saved
234 * @param vecClassConfig : configuration of the class to be used
235 * @param mode : mode of the generator
236 * @param vecInclude : vector of include files to be added into the header
237 * @param includeTemplate : extra include for the template implementation
238 * @return true on success, false otherwise
239 */
240 4 bool generator_class_cpp_headerFile(const PTraitBackendManager & manager, const PPath & headerFile, const std::vector<PClassConfig> & vecClassConfig, const GeneratorMode & mode,
241 const PVecPath & vecInclude, const PString & includeTemplate)
242 {
243
2/3
✓ Branch 0 (2→3) taken 4 times.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→5) taken 4 times.
4 if(headerFile == "") return false;
244
1/1
✓ Branch 0 (5→6) taken 4 times.
4 std::ofstream fs;
245
2/3
✓ Branch 0 (6→7) taken 4 times.
✗ Branch 2 (7→8) not taken.
✓ Branch 3 (7→9) taken 4 times.
4 if(!openFileStream(fs, headerFile)){return false;}
246
1/1
✓ Branch 0 (9→10) taken 4 times.
4 licenceSave(fs);
247
2/2
✓ Branch 0 (10→11) taken 4 times.
✓ Branch 2 (11→12) taken 4 times.
4 PString macroDef(makeMultiIncludeDefineMacro(headerFile.getFileName()));
248
3/3
✓ Branch 0 (13→14) taken 4 times.
✓ Branch 2 (14→15) taken 4 times.
✓ Branch 4 (15→16) taken 4 times.
4 fs << "#ifndef " << macroDef << std::endl;
249
4/4
✓ Branch 0 (16→17) taken 4 times.
✓ Branch 2 (17→18) taken 4 times.
✓ Branch 4 (18→19) taken 4 times.
✓ Branch 6 (19→20) taken 4 times.
4 fs << "#define " << macroDef << std::endl << std::endl;
250
2/2
✓ Branch 0 (20→21) taken 4 times.
✓ Branch 2 (21→22) taken 4 times.
4 fs << "#include <string>" << std::endl;
251
1/2
✗ Branch 0 (23→24) not taken.
✓ Branch 1 (23→42) taken 4 times.
4 if(vecInclude.size() != 0lu){
252 for(PVecPath::const_iterator it(vecInclude.begin()); it != vecInclude.end(); ++it){
253 fs << "#include " << *it << std::endl;
254 }
255 fs << std::endl;
256 }
257
1/1
✓ Branch 0 (42→43) taken 4 times.
4 manager.headerExtraInclude(fs, mode);
258
1/1
✓ Branch 0 (43→44) taken 4 times.
4 fs << std::endl;
259
2/2
✓ Branch 0 (65→45) taken 5 times.
✓ Branch 1 (65→66) taken 4 times.
18 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
260
3/3
✓ Branch 0 (47→48) taken 5 times.
✓ Branch 2 (48→49) taken 1 times.
✓ Branch 3 (48→52) taken 4 times.
5 if(it->getIsEnum()){
261
1/1
✓ Branch 0 (51→55) taken 1 times.
1 generator_enum_cpp_header(manager, fs, *it, mode);
262 // saveEnumDecl(fs, *it, mode);
263 }else{
264
1/1
✓ Branch 0 (54→55) taken 4 times.
4 generator_class_cpp_header(manager, fs, *it, mode);
265 }
266 }
267
268
2/3
✓ Branch 0 (66→67) taken 4 times.
✗ Branch 2 (67→68) not taken.
✓ Branch 3 (67→73) taken 4 times.
4 if(includeTemplate != ""){
269 fs << "#include \""<<includeTemplate<<"\"" << std::endl << std::endl;
270 }
271
272
5/5
✓ Branch 0 (73→74) taken 4 times.
✓ Branch 2 (74→75) taken 4 times.
✓ Branch 4 (75→76) taken 4 times.
✓ Branch 6 (76→77) taken 4 times.
✓ Branch 8 (77→78) taken 4 times.
4 fs << std::endl << std::endl << "#endif" << std::endl << std::endl;
273
1/1
✓ Branch 0 (78→79) taken 4 times.
4 fs.close();
274 4 return true;
275 4 }
276
277 ///Create the implementation of the given class
278 /** @param manager : PTraitBackendManager which handles all trait backend
279 * @param[out] fs : file to be completed
280 * @param classConfig : configuration of the class to be used
281 * @param mode : mode of the generator
282 */
283 6 void generator_class_cpp_source(const PTraitBackendManager & manager, std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){
284
1/1
✓ Branch 0 (2→3) taken 6 times.
6 manager.classExtraFunctionImplementation(fs, classConfig, mode);
285
1/1
✓ Branch 0 (3→4) taken 6 times.
6 GeneratorMode classMode(mode);
286
1/1
✓ Branch 0 (4→5) taken 6 times.
6 const PVecString & listTemplate = classConfig.getListTemplate();
287
1/1
✓ Branch 0 (5→6) taken 6 times.
6 PString defTemplate(class_getClassDefTemplate(listTemplate));
288
1/1
✓ Branch 0 (6→7) taken 6 times.
6 PString templateDeclaration(class_getClassDeclTempalteDef(listTemplate));
289
1/1
✓ Branch 0 (7→8) taken 6 times.
6 classMode.defTemplate = defTemplate;
290
1/1
✓ Branch 0 (8→9) taken 6 times.
6 classMode.templateDeclaration = templateDeclaration;
291
3/3
✓ Branch 0 (9→10) taken 6 times.
✓ Branch 2 (10→11) taken 5 times.
✓ Branch 3 (10→13) taken 1 times.
6 if(!classConfig.getIsEnum()){
292
1/1
✓ Branch 0 (11→12) taken 5 times.
5 class_saveClassConstructorImpl(fs, classConfig, defTemplate, templateDeclaration);
293
1/1
✓ Branch 0 (12→13) taken 5 times.
5 class_saveClassDestructorImpl(fs, classConfig, defTemplate, templateDeclaration);
294 }
295
1/1
✓ Branch 0 (13→14) taken 6 times.
6 manager.publicMethodImplementation(fs, classConfig, classMode);
296
1/1
✓ Branch 0 (14→15) taken 6 times.
6 manager.protectedMethodImplementation(fs, classConfig, classMode);
297
1/1
✓ Branch 0 (15→16) taken 6 times.
6 manager.privateMethodImplementation(fs, classConfig, classMode);
298
3/3
✓ Branch 0 (16→17) taken 6 times.
✓ Branch 2 (17→18) taken 5 times.
✓ Branch 3 (17→19) taken 1 times.
6 if(!classConfig.getIsEnum()){
299
1/1
✓ Branch 0 (18→19) taken 5 times.
5 class_saveClassInitialisationFunctionImpl(fs, classConfig, defTemplate, templateDeclaration);
300 }
301 6 }
302
303 ///Create the implementation of the given file
304 /** @param manager : PTraitBackendManager which handles all trait backend
305 * @param sourceFile : source file to be saved
306 * @param headerFile : header to be used with this source file
307 * @param vecClassConfig : vector of configuration of the classes to be used
308 * @param mode : mode of the generator
309 * @param isTemplateImpl : true to activate
310 * @return true on success, false otherwise
311 */
312 4 bool generator_class_cpp_sourceFile(const PTraitBackendManager & manager, const PPath & sourceFile, const PPath & headerFile,
313 const std::vector<PClassConfig> & vecClassConfig, const GeneratorMode & mode, bool isTemplateImpl)
314 {
315
5/8
✓ Branch 0 (2→3) taken 4 times.
✓ Branch 2 (3→4) taken 4 times.
✗ Branch 3 (3→6) not taken.
✓ Branch 4 (4→5) taken 4 times.
✗ Branch 6 (5→6) not taken.
✓ Branch 7 (5→7) taken 4 times.
✗ Branch 8 (8→9) not taken.
✓ Branch 9 (8→10) taken 4 times.
4 if(sourceFile == "" || headerFile == "") return false;
316
1/1
✓ Branch 0 (10→11) taken 4 times.
4 std::ofstream fs;
317
2/3
✓ Branch 0 (11→12) taken 4 times.
✗ Branch 2 (12→13) not taken.
✓ Branch 3 (12→14) taken 4 times.
4 if(!openFileStream(fs, sourceFile)){return false;}
318
1/1
✓ Branch 0 (14→15) taken 4 times.
4 licenceSave(fs);
319
1/2
✗ Branch 0 (15→16) not taken.
✓ Branch 1 (15→32) taken 4 times.
4 if(isTemplateImpl){
320 PString macroDef(makeMultiIncludeDefineMacro(headerFile.getFileName() + "_IMPL"));
321 fs << "#ifndef " << macroDef << std::endl;
322 fs << "#define " << macroDef << std::endl << std::endl;
323 }
324
7/7
✓ Branch 0 (32→33) taken 4 times.
✓ Branch 2 (33→34) taken 4 times.
✓ Branch 4 (34→35) taken 4 times.
✓ Branch 6 (35→36) taken 4 times.
✓ Branch 8 (36→37) taken 4 times.
✓ Branch 10 (37→38) taken 4 times.
✓ Branch 12 (38→39) taken 4 times.
4 fs << std::endl << "#include \"" << headerFile.getFileName() << "\"" << std::endl << std::endl;
325
2/2
✓ Branch 0 (54→41) taken 5 times.
✓ Branch 1 (54→55) taken 4 times.
18 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
326
1/1
✓ Branch 0 (43→44) taken 5 times.
5 generator_class_cpp_source(manager, fs, *it, mode);
327 }
328
1/2
✗ Branch 0 (55→56) not taken.
✓ Branch 1 (55→59) taken 4 times.
4 if(isTemplateImpl){
329 fs << "#endif" << std::endl << std::endl;
330 }
331
1/1
✓ Branch 0 (59→60) taken 4 times.
4 fs.close();
332
333 4 return true;
334 4 }
335
336
337
338 ///Check if the configuration has source or template to determine if the .cpp or _impl.h files have to be generated
339 /** @param[out] hasSource : true if the configuration needs .cpp file
340 * @param[out] hasTemplate : true if the configuration needs _impl.h file
341 * @param vecClassConfig : class config we want to save
342 */
343 4 void class_checkClassConfig(bool & hasSource, bool & hasTemplate, const std::vector<PClassConfig> & vecClassConfig){
344 4 hasSource = false;
345 4 hasTemplate = false;
346
2/2
✓ Branch 0 (17→3) taken 5 times.
✓ Branch 1 (17→18) taken 4 times.
18 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
347
1/1
✓ Branch 0 (5→6) taken 5 times.
5 bool isTemplate = it->getListTemplate().size() != 0lu;
348 5 hasSource |= !isTemplate;
349 5 hasTemplate |= isTemplate;
350 }
351 4 }
352
353 ///Creates header and source files
354 /** @param manager : PTraitBackendManager which handles all trait backend
355 * @param vecClassConfig : vector of class config we want to save
356 * @param baseFileName : base file name for header or source file
357 * @param outputSourceDir : output directory where to save sources
358 * @param mode : all modes of the generator (data/check/type/config stream)
359 * @return true on success, false otherwise
360 */
361 4 bool generator_class_cpp(const PTraitBackendManager & manager, const std::vector<PClassConfig> & vecClassConfig, const PPath & outputSourceDir, const PPath & baseFileName, const GeneratorMode & mode, const PVecPath & vecInclude){
362
2/3
✓ Branch 0 (2→3) taken 4 times.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→13) taken 4 times.
4 if(baseFileName == ""){
363 std::cerr << termRed() << "generator_class_cpp : baseFileName is empty" << termDefault() << std::endl;
364 return false;
365 }
366 4 bool hasSource(false), hasTemplate(false);
367
1/1
✓ Branch 0 (13→14) taken 4 times.
4 class_checkClassConfig(hasSource, hasTemplate, vecClassConfig);
368
1/1
✓ Branch 0 (14→15) taken 4 times.
4 PString includeTemplate("");
369
1/2
✗ Branch 0 (15→16) not taken.
✓ Branch 1 (15→24) taken 4 times.
4 if(hasTemplate){
370 includeTemplate = PString(baseFileName.getFileName() + "_impl.h");
371 }
372
4/4
✓ Branch 0 (24→25) taken 4 times.
✓ Branch 2 (25→26) taken 4 times.
✓ Branch 4 (26→27) taken 4 times.
✓ Branch 6 (27→28) taken 4 times.
4 PPath headerFile = outputSourceDir / PPath(baseFileName + ".h");
373
2/3
✓ Branch 0 (31→32) taken 4 times.
✗ Branch 2 (32→33) not taken.
✓ Branch 3 (32→44) taken 4 times.
4 if(!generator_class_cpp_headerFile(manager, headerFile, vecClassConfig, mode, vecInclude, includeTemplate)){
374 std::cerr << termRed() << "generator_class_cpp : cannot generate header file '"<<headerFile<<"'" << termDefault() << std::endl;
375 return false;
376 }
377
1/2
✓ Branch 0 (44→45) taken 4 times.
✗ Branch 1 (44→81) not taken.
4 if(hasSource){
378
5/5
✓ Branch 0 (45→46) taken 4 times.
✓ Branch 2 (46→47) taken 4 times.
✓ Branch 4 (47→48) taken 4 times.
✓ Branch 6 (48→49) taken 4 times.
✓ Branch 8 (49→50) taken 4 times.
4 PPath sourceFile = outputSourceDir / PPath(baseFileName + PString(".cpp"));
379
6/7
✓ Branch 0 (54→55) taken 4 times.
✓ Branch 2 (55→56) taken 4 times.
✓ Branch 4 (56→57) taken 4 times.
✓ Branch 6 (57→58) taken 4 times.
✓ Branch 8 (58→59) taken 4 times.
✗ Branch 10 (63→64) not taken.
✓ Branch 11 (63→75) taken 4 times.
4 if(!generator_class_cpp_sourceFile(manager, sourceFile, PPath(baseFileName + PString(".h")), vecClassConfig, mode, false)){
380 std::cerr << termRed() << "generator_class_cpp : cannot generate source file '"<<sourceFile<<"'" << termDefault() << std::endl;
381 return false;
382 }
383 4 }
384
1/2
✗ Branch 0 (81→82) not taken.
✓ Branch 1 (81→118) taken 4 times.
4 if(hasTemplate){
385 PPath implFile = outputSourceDir / PPath(baseFileName + PString("_impl.h"));
386 if(!generator_class_cpp_sourceFile(manager, implFile, PPath(baseFileName + PString(".h")), vecClassConfig, mode, true)){
387 std::cerr << termRed() << "generator_class_cpp : cannot generate impl file '"<<implFile<<"'" << termDefault() << std::endl;
388 return false;
389 }
390 }
391 4 return true;
392 4 }
393
394
395 ///Save the CMakeLists to be used to compile the unit test
396 /** @param manager : PTraitBackendManager which handles all trait backend
397 * @param outputCurrentTestDir : current test directoru in which to create the CMakeLists.txt
398 * @param classConfig : class configuration to be used
399 * @param baseFileName : base of output file name of the generated sources
400 * @param mode : all modes of the generator (data/check/type/config stream)
401 * @return true on success, false oterhwise
402 */
403 4 bool generator_class_testMain(const PTraitBackendManager & manager, const PPath & outputCurrentTestDir, const PClassConfig & classConfig, const PPath & baseFileName, const GeneratorMode & mode){
404
1/1
✓ Branch 0 (2→3) taken 4 times.
4 std::ofstream fs;
405
6/7
✓ Branch 0 (3→4) taken 4 times.
✓ Branch 2 (4→5) taken 4 times.
✓ Branch 4 (5→6) taken 4 times.
✓ Branch 6 (6→7) taken 4 times.
✓ Branch 8 (7→8) taken 4 times.
✗ Branch 10 (12→13) not taken.
✓ Branch 11 (12→14) taken 4 times.
4 if(!openFileStream(fs, PPath(outputCurrentTestDir + PString("/main.cpp")))){return false;}
406
1/1
✓ Branch 0 (14→15) taken 4 times.
4 licenceSave(fs);
407 // body += licenceSaveStr() + "\n";
408
2/3
✓ Branch 0 (15→16) taken 4 times.
✓ Branch 2 (16→17) taken 4 times.
✗ Branch 3 (16→23) not taken.
4 if(mode.assertInclude != ""){
409
3/3
✓ Branch 0 (17→18) taken 4 times.
✓ Branch 2 (18→19) taken 4 times.
✓ Branch 4 (19→20) taken 4 times.
4 fs << "#include \"" + mode.assertInclude + "\"\n\n";
410 }
411
3/3
✓ Branch 0 (23→24) taken 4 times.
✓ Branch 2 (24→25) taken 4 times.
✓ Branch 4 (25→26) taken 4 times.
4 fs << "#include \"" + baseFileName + ".h\"\n\n";
412
1/1
✓ Branch 0 (28→29) taken 4 times.
4 manager.testFunction(fs, classConfig, mode);
413
1/1
✓ Branch 0 (29→30) taken 4 times.
4 fs << "int main(int argc, char ** argv){\n";
414 //Do other test if the enableDataStream is true
415
1/1
✓ Branch 0 (30→31) taken 4 times.
4 manager.testCallFunction(fs, classConfig, mode);
416
1/1
✓ Branch 0 (31→32) taken 4 times.
4 fs << "\treturn 0;\n";
417
1/1
✓ Branch 0 (32→33) taken 4 times.
4 fs << "}\n";
418
1/1
✓ Branch 0 (33→34) taken 4 times.
4 fs.close();
419 4 return true;
420 4 }
421
422 ///Save the CMakeLists to be used to compile the unit test
423 /** @param outputCurrentTestDir : current test directory in which to create the CMakeLists.txt
424 * @param classConfig : class configuration to be used
425 * @param projectName : configuration of the project
426 * @param mode : all modes of the generator (data/check/type/config stream)
427 * @return true on success, false oterhwise
428 */
429 4 bool generator_class_testCMakeLists( const PPath & outputCurrentTestDir, const PClassConfig & classConfig, const PString & projectName, const GeneratorMode & mode){
430
5/5
✓ Branch 0 (2→3) taken 4 times.
✓ Branch 2 (3→4) taken 4 times.
✓ Branch 4 (4→5) taken 4 times.
✓ Branch 6 (5→6) taken 4 times.
✓ Branch 8 (6→7) taken 4 times.
4 PString body(""), testName("test_class_" + classConfig.getName().toLowerUnderscore());
431
2/2
✓ Branch 0 (9→10) taken 4 times.
✓ Branch 2 (10→11) taken 4 times.
4 body += getCMakeListsHeader();
432
3/3
✓ Branch 0 (12→13) taken 4 times.
✓ Branch 2 (13→14) taken 4 times.
✓ Branch 4 (14→15) taken 4 times.
4 body += "add_executable("+testName+" main.cpp)\n";
433
6/6
✓ Branch 0 (17→18) taken 4 times.
✓ Branch 2 (18→19) taken 4 times.
✓ Branch 4 (19→20) taken 4 times.
✓ Branch 6 (20→21) taken 4 times.
✓ Branch 8 (21→22) taken 4 times.
✓ Branch 10 (22→23) taken 4 times.
4 body += "target_link_libraries("+testName+" ${"+projectName.toUpper()+"_TEST_DEPENDENCIES})\n";
434
1/1
✓ Branch 0 (28→29) taken 4 times.
4 body += "\n";
435
4/4
✓ Branch 0 (29→30) taken 4 times.
✓ Branch 2 (30→31) taken 4 times.
✓ Branch 4 (31→32) taken 4 times.
✓ Branch 6 (32→33) taken 4 times.
4 body += "add_test(NAME "+testName.firstToUpper()+"\n";
436
3/3
✓ Branch 0 (36→37) taken 4 times.
✓ Branch 2 (37→38) taken 4 times.
✓ Branch 4 (38→39) taken 4 times.
4 body += "\tCOMMAND ${CMAKE_CURRENT_BINARY_DIR}/"+testName+"\n";
437
1/1
✓ Branch 0 (41→42) taken 4 times.
4 body += "\tWORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}\n";
438
1/1
✓ Branch 0 (42→43) taken 4 times.
4 body += ")\n\n\n";
439
5/5
✓ Branch 0 (43→44) taken 4 times.
✓ Branch 2 (44→45) taken 4 times.
✓ Branch 4 (45→46) taken 4 times.
✓ Branch 6 (46→47) taken 4 times.
✓ Branch 8 (47→48) taken 4 times.
8 return PPath(outputCurrentTestDir + PString("/CMakeLists.txt")).saveFileContent(body);
440 4 }
441
442 ///Save the unit test of the generated PClassConfig
443 /** @param manager : PTraitBackendManager which handles all trait backend
444 * @param outputTestDir : output directory where to put the genreated test (typically ../TESTS if the program is called from ./src)
445 * @param classConfig : class configuration to be used
446 * @param projectName : configuration of the project
447 * @param baseFileName : base of output file name of the generated sources
448 * @param mode : all modes of the generator (data/check/type/config stream)
449 * @return true on success, false oterhwise
450 */
451 4 bool generator_class_test(const PTraitBackendManager & manager, const PPath & outputTestDir, const PClassConfig & classConfig, const PString & projectName, const PPath & baseFileName, const GeneratorMode & mode){
452
2/2
✓ Branch 0 (2→3) taken 4 times.
✓ Branch 2 (3→4) taken 4 times.
4 PString name(classConfig.getName());
453
6/6
✓ Branch 0 (4→5) taken 4 times.
✓ Branch 2 (5→6) taken 4 times.
✓ Branch 4 (6→7) taken 4 times.
✓ Branch 6 (7→8) taken 4 times.
✓ Branch 8 (8→9) taken 4 times.
✓ Branch 10 (9→10) taken 4 times.
4 PPath outputCurrentTestDir(outputTestDir + PString("/TEST_") + name.toUpper());
454
2/7
✓ Branch 0 (15→16) taken 4 times.
✗ Branch 2 (16→17) not taken.
✓ Branch 3 (16→22) taken 4 times.
✗ Branch 4 (17→18) not taken.
✗ Branch 6 (18→19) not taken.
✗ Branch 8 (19→20) not taken.
✗ Branch 10 (20→21) not taken.
4 if(!outputCurrentTestDir.createDirectory()){std::cerr << "generator_class_test : cannot create TEST directory '"<<outputCurrentTestDir<<"'" << std::endl;return false;}
455
456 4 bool b(true);
457
1/1
✓ Branch 0 (22→23) taken 4 times.
4 b &= generator_class_testCMakeLists(outputCurrentTestDir, classConfig, projectName, mode);
458
1/1
✓ Branch 0 (23→24) taken 4 times.
4 b &= generator_class_testMain(manager, outputCurrentTestDir, classConfig, baseFileName, mode);
459 4 return b;
460 4 }
461
462 ///Save the unit test of the generated PClassConfig
463 /** @param manager : PTraitBackendManager which handles all trait backend
464 * @param outputTestDir : output directory where to put the generated test (typically ../TESTS if the program is called from ./src)
465 * @param vecClassConfig : vector of class configuration to be used
466 * @param projectName : configuration of the project
467 * @param baseFileName : base of output file name of the generated sources
468 * @param mode : all modes of the generator (data/check/type/config stream)
469 * @return true on success, false oterhwise
470 */
471 3 bool generator_class_cpp_test(const PTraitBackendManager & manager, const PPath & outputTestDir, const std::vector<PClassConfig> & vecClassConfig, const PString & projectName, const PPath & baseFileName, const GeneratorMode & mode){
472
1/1
✓ Branch 0 (2→3) taken 3 times.
3 PString cmakeListBody;
473
2/2
✓ Branch 0 (3→4) taken 3 times.
✓ Branch 2 (4→5) taken 3 times.
3 cmakeListBody += getCMakeListsHeader();
474 3 bool b(true);
475
4/4
✓ Branch 0 (7→8) taken 3 times.
✓ Branch 2 (8→9) taken 3 times.
✓ Branch 4 (9→10) taken 3 times.
✓ Branch 6 (10→11) taken 3 times.
3 cmakeListBody += "#Generating tests for " + PString::toString(vecClassConfig.size()) + "\n";
476
2/2
✓ Branch 0 (38→15) taken 4 times.
✓ Branch 1 (38→39) taken 3 times.
14 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
477
5/5
✓ Branch 0 (17→18) taken 4 times.
✓ Branch 2 (18→19) taken 4 times.
✓ Branch 4 (19→20) taken 4 times.
✓ Branch 6 (20→21) taken 4 times.
✓ Branch 8 (21→22) taken 4 times.
4 cmakeListBody += "add_subdirectory(TEST_" + it->getName().toUpper() + ")\n";
478
1/1
✓ Branch 0 (27→28) taken 4 times.
4 b &= generator_class_test(manager, outputTestDir, *it, projectName, baseFileName, mode);
479 }
480
1/1
✓ Branch 0 (39→40) taken 3 times.
3 cmakeListBody += "\n\n";
481
3/3
✓ Branch 0 (40→41) taken 3 times.
✓ Branch 2 (41→42) taken 3 times.
✓ Branch 4 (42→43) taken 3 times.
3 PPath cmakelist(outputTestDir / PPath("CMakeLists.txt"));
482
1/1
✓ Branch 0 (45→46) taken 3 times.
3 b &= cmakelist.saveFileContent(cmakeListBody);
483 3 return b;
484 3 }
485
486 ///Generate the full sources and related unit tests from configuration
487 /** @param manager : PTraitBackendManager which handles all trait backend
488 * @param projectParam : description of classes and how and where to generate sources and test
489 * @return true on success, false otherwise
490 */
491 2 bool generator_class_full(const PTraitBackendManager & manager, const ProjectParam & projectParam){
492 2 bool b(true);
493
1/1
✓ Branch 0 (2→3) taken 2 times.
2 b &= projectParam.outputSourceDir.createDirectory();
494
1/1
✓ Branch 0 (3→4) taken 2 times.
2 b &= projectParam.outputTestDir.createDirectory();
495
1/1
✓ Branch 0 (4→5) taken 2 times.
2 PString cmakeListBody;
496
2/2
✓ Branch 0 (5→6) taken 2 times.
✓ Branch 2 (6→7) taken 2 times.
2 cmakeListBody += getCMakeListsHeader();
497 2 const PVecDataConfig & vecDataConfig = projectParam.vecDataConfig;
498
2/2
✓ Branch 0 (77→10) taken 3 times.
✓ Branch 1 (77→78) taken 2 times.
7 for(const PDataConfig & config : vecDataConfig){
499
4/4
✓ Branch 0 (12→13) taken 3 times.
✓ Branch 2 (13→14) taken 3 times.
✓ Branch 4 (14→15) taken 3 times.
✓ Branch 6 (15→16) taken 3 times.
3 PPath baseFileName = config.getFileName().getFileName().eraseExtension();
500
4/5
✓ Branch 0 (17→18) taken 3 times.
✓ Branch 2 (18→19) taken 3 times.
✓ Branch 4 (19→20) taken 3 times.
✗ Branch 6 (20→21) not taken.
✓ Branch 7 (20→32) taken 3 times.
3 if(!generator_class_cpp(manager, config.getVecClassConfig(), projectParam.outputSourceDir, baseFileName, projectParam.mode, config.getVecInclude())){
501 std::cerr << termRed() << "generator_class_full : cannot generate C++ sources at '"<<projectParam.outputSourceDir<<"'" << termDefault() << std::endl;
502 b = false; //best effort strategy
503 }
504
8/8
✓ Branch 0 (32→33) taken 3 times.
✓ Branch 2 (33→34) taken 3 times.
✓ Branch 4 (34→35) taken 3 times.
✓ Branch 6 (35→36) taken 3 times.
✓ Branch 8 (36→37) taken 3 times.
✓ Branch 10 (37→38) taken 3 times.
✓ Branch 12 (38→39) taken 3 times.
✓ Branch 14 (39→40) taken 3 times.
3 PPath outputCurrentTestDir = projectParam.outputTestDir / PPath("TEST_" + config.getFileName().getFileName().eraseExtension().toUpper());
505
4/4
✓ Branch 0 (45→46) taken 3 times.
✓ Branch 2 (46→47) taken 3 times.
✓ Branch 4 (47→48) taken 3 times.
✓ Branch 6 (48→49) taken 3 times.
3 cmakeListBody += "add_subdirectory(" + outputCurrentTestDir.getFileName() + ")\n";
506
3/4
✓ Branch 0 (52→53) taken 3 times.
✓ Branch 2 (53→54) taken 3 times.
✗ Branch 4 (54→55) not taken.
✓ Branch 5 (54→66) taken 3 times.
3 if(!generator_class_cpp_test(manager, outputCurrentTestDir, config.getVecClassConfig(), projectParam.name, baseFileName, projectParam.mode)){
507 std::cerr << termRed() << "generator_class_full : cannot generate C++ tests at '"<<projectParam.outputTestDir<<"'" << termDefault() << std::endl;
508 b = false; //best effort strategy
509 }
510 3 }
511
1/1
✓ Branch 0 (78→79) taken 2 times.
2 cmakeListBody += "\n\n";
512
3/3
✓ Branch 0 (79→80) taken 2 times.
✓ Branch 2 (80→81) taken 2 times.
✓ Branch 4 (81→82) taken 2 times.
2 PPath cmakelist(projectParam.outputTestDir / PPath("CMakeLists.txt"));
513
1/1
✓ Branch 0 (84→85) taken 2 times.
2 b &= cmakelist.saveFileContent(cmakeListBody);
514 2 return b;
515 2 }
516
517
518
519
520