17 if(type ==
"PString"){
18 return "\"Some string\"";
19 }
else if(type ==
"char"){
21 }
else if(type ==
"unsigned char"){
23 }
else if(type ==
"int" || type ==
"short" || type ==
"unsigned short"){
25 }
else if(type ==
"unsigned int"){
27 }
else if(type ==
"long int" || type ==
"long" || type ==
"ssize_t"){
29 }
else if(type ==
"size_t" || type ==
"long unsigned int"){
31 }
else if(type ==
"bool"){
48 body +=
"///Check the equality between two "+name+
" classes\n";
49 body +=
"/**\t@param var : variable to be checked\n";
50 body +=
" * \t@param reference : reference\n";
51 body +=
" * \t@return true on success, false otherwise\n";
53 body +=
"bool check"+name+
"Equality";
57 body +=
"(" + strConst + name +
" & var, " + strConst + name +
" & reference){\n";
58 body +=
"\tbool b(true);\n";
60 const std::vector<PClassAttribute> & listAttr = classConfig.
getListAttribute();
61 for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
62 PString attrName(it->getName().firstToUpper());
64 std::cout <<
"createCheckClassEquality : attrName = '"<<attrName<<
"', isSimpleType = " << isSimpleType <<
", it->getIsPointer() = " << it->getIsPointer() <<
", it->getIsReference() = " << it->getIsReference() << std::endl;
65 if(isSimpleType || it->getIsPointer() || it->getType() ==
"PString"){
66 body +=
"\tb &= var.get"+attrName+
"() == reference.get"+attrName+
"();\n";
70 body +=
"\treturn b;\n";
83 body +=
"///Check copy of class "+name+
"\n";
84 body +=
"bool check"+name+
"Copy(){\n";
86 body +=
"\t"+name+
" reference;\n";
87 body +=
"\t//Let's use the setters\n";
88 const std::vector<PClassAttribute> & listAttr = classConfig.
getListAttribute();
89 for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
91 if(defaultValue !=
""){
92 body +=
"\treference.set"+attrName+
"("+defaultValue+
");\n";
96 body +=
"\t"+name+
" varCopy(reference);\n";
97 body +=
"\t"+name+
" varEqual;\n";
98 body +=
"\tvarEqual = reference;\n";
99 body +=
"\tbool b(true);\n";
100 body +=
"\tb &= check"+name+
"Equality(varCopy, reference);\n";
101 body +=
"\tb &= check"+name+
"EqualityConst(varCopy, reference);\n";
103 body +=
"\tb &= check"+name+
"Equality(varEqual, reference);\n";
104 body +=
"\tb &= check"+name+
"EqualityConst(varEqual, reference);\n";
105 body +=
"\tb &= phoenix_getTypeToStr<"+name+
">() == \""+name+
"\";\n";
107 body +=
"\treturn b;\n";
126 body +=
"#include \"" + (baseFileName +
".h\"\n\n");
133 body +=
"int main(int argc, char ** argv){\n";
134 body +=
"\tbool b(check"+name+
"Copy());\n";
138 body +=
"\treturn b - 1;\n";
155 body +=
"add_executable("+testName+
" main.cpp)\n";
157 extraLib +=
" " + libName;
158 if(enableTypeStream){
159 extraLib +=
" phoenix_type_stream";
161 if(enableDataStream){
162 extraLib +=
" phoenix_data_stream";
164 if(extraLib.size() != 0lu){
165 body +=
"target_link_libraries("+testName+extraLib+
")\n";
169 body +=
"\tCOMMAND ${CMAKE_CURRENT_BINARY_DIR}/"+testName+
"\n";
170 body +=
"\tWORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}\n";
188 if(!outputCurrentTestDir.
createDirectory()){std::cerr <<
"saveClassTest : cannot create TEST directory '"<<outputCurrentTestDir<<
"'" << std::endl;
return false;}
192 b &=
saveClassTestMain(outputCurrentTestDir, classConfig, baseFileName, enableDataStream, enableTypeStream);
207 bool saveClassTest(
const PPath & outputTestDir,
const PString & libName,
const std::vector<PClassConfig> & classConfig,
const PPath & baseFileName,
bool enableDataStream,
bool enableTypeStream){
209 for(std::vector<PClassConfig>::const_iterator it(classConfig.begin()); it != classConfig.end(); ++it){
210 b &=
saveClassTest(outputTestDir, libName, *it, baseFileName, enableDataStream, enableTypeStream);
Class to describe a basic class.
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.
const PString & getName() const
Returns the class name.
Path of a directory or a file.
bool saveFileContent(const PString &content) const
Save a PString in a file.
bool createDirectory(mode_t mode=0755) const
Create the current directory.
PString toLowerUnderscore() const
Convert std::string in lower case and space in '_'.
PString toUpper() const
Convert std::string in upper case.
PString firstToUpper() const
Convert first letter of the PString in upper case.
PString getCMakeListsHeader()
Get the CMakeLists.txt header.
PString getTestDefaultValueTypeInCpp(const PString &type)
Get the default value of a type in C++.
PString createTestClassCopy(const PClassConfig &classConfig, bool enableTypeStream)
Create the class check.
PString createCheckClassEquality(const PClassConfig &classConfig, bool isConst)
Create the class check.
bool saveClassTestCMakeLists(const PPath &outputCurrentTestDir, const PString &libName, const PClassConfig &classConfig, bool enableDataStream, bool enableTypeStream)
Save the CMakeLists to be used to compile the unit test.
bool saveClassTestMain(const PPath &outputCurrentTestDir, const PClassConfig &classConfig, const PPath &baseFileName, bool enableDataStream, bool enableTypeStream)
Save the CMakeLists to be used to compile the unit test.
bool saveClassTest(const PPath &outputTestDir, const PString &libName, const PClassConfig &classConfig, const PPath &baseFileName, bool enableDataStream, bool enableTypeStream)
Save the unit test of the generated PClassConfig.
bool getIsSimpleType(const PString &varType)
Check if the given type is a simple type.