Commit 271ad962 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add class config test

parent 5739316b
Pipeline #98115 passed with stages
in 25 minutes
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
add_subdirectory(TEST_CLASS_CONFIG)
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
add_executable(test_pclass_config main.cpp)
target_link_libraries(test_pclass_config phoenix_generator file_parser string_utils)
add_test(NAME TestPClassConfig
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_pclass_config
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include <iostream>
#include "class_attribute_utils.h"
#include "saveClassConfig.h"
///Print PClassAttribute
/** @param[out] attr : PClassAttribute to be printed
*/
void printPClassAttribute(PClassAttribute & attr){
std::cout << "PClassAttribute(type = '" << attr.getType() << "', name = '"<<attr.getName()<<"', isPointer = " << attr.getIsPointer() << ", isReference = " << attr.getIsReference() << ", doc = '"<<attr.getDocumentation()<<"'" << std::endl;
}
///Print PClassAttribute
/** @param[out] attr : PClassAttribute to be printed
*/
void printPClassAttributeConst(const PClassAttribute & attr){
std::cout << "const PClassAttribute(type = '" << attr.getType() << "', name = '"<<attr.getName()<<"', isPointer = " << attr.getIsPointer() << ", isReference = " << attr.getIsReference() << ", doc = '"<<attr.getDocumentation()<<"'" << std::endl;
}
///Test the PClassConfig
/** @return true on success, false otherwise
*/
bool testClassConfig(){
bool b(true);
PClassConfig conf;
PClassAttribute attrA(createClassAttribute("int", "attr1", "some attribute doc")), attrB, attrC, attrD;
attrB = createClassAttribute("int", "attr2", false, true, "some attribute doc");
attrC = createClassAttribute("double", "attr3", true, false, "some attribute doc");
attrD = createClassAttribute("float", "attr4", true, true, "some attribute doc");
printPClassAttribute(attrA);
printPClassAttributeConst(attrA);
conf.setClassDocumentation("Some documentation of the class");
conf.setName("Shadok");
std::list<PClassAttribute> listAttribute1, listAttribute2;
listAttribute1.push_back(attrA);
listAttribute1.push_back(attrB);
listAttribute2.push_back(attrD);
conf.setListAttribute(listAttribute1);
conf.addAttribute(attrC);
conf.addListAttribute(listAttribute2);
std::list<PClassConfig> listClassConfig;
listClassConfig.push_back(conf);
b &= saveClassImplDecl(listClassConfig, "Shadok");
return b;
}
///Test the PClassConfig
/** @return true on success, false otherwise
*/
bool testClassConfigInheritance(){
bool b(true);
PClassConfig conf;
PClassAttribute attrA(createClassAttribute("int", "attr1", false, false, "some attribute doc")), attrB, attrC, attrD;
attrB = createClassAttribute("int", "attr2", false, true, "some attribute doc");
attrC = createClassAttribute("double", "attr3", true, false, "some attribute doc");
attrD = createClassAttribute("float", "attr4", true, true, "some attribute doc");
printPClassAttribute(attrA);
printPClassAttributeConst(attrA);
conf.setClassDocumentation("Some documentation of the class");
conf.setName("Shadok");
conf.addParentClass("SomeParent");
std::list<std::string> listParentClass;
listParentClass.push_back("OtherParent");
listParentClass.push_back("OtherParent2");
conf.addListParentClass(listParentClass);
std::list<PClassAttribute> listAttribute1, listAttribute2;
listAttribute1.push_back(attrA);
listAttribute1.push_back(attrB);
listAttribute2.push_back(attrD);
conf.setListAttribute(listAttribute1);
conf.addAttribute(attrC);
conf.addListAttribute(listAttribute2);
std::list<PClassConfig> listClassConfig;
listClassConfig.push_back(conf);
std::list<std::string> listInclude;
listInclude.push_back("SomeParent");
listInclude.push_back("OtherParent");
listInclude.push_back("OtherParent2");
b &= saveClassImplDecl(listClassConfig, "ShadokParent", listInclude);
return b;
}
int main(int argc, char ** argv){
bool b(testClassConfig());
b &= testClassConfigInheritance();
return b - 1;
}
......@@ -20,4 +20,23 @@ PClassAttribute createClassAttribute(const std::string & type, const std::string
return attr;
}
///Create an attribute
/** @param typeName : type of the attribute
* @param name : name of the attribute
* @param isPointer : true if the attribute is a pointer
* @param isReference : true if the attribute is a reference
* @param documentation : documentation of the attribute
* @return PClassAttribute
*/
PClassAttribute createClassAttribute(const std::string & typeName, const std::string & name, bool isPointer, bool isReference, const std::string & documentation){
PClassAttribute attr;
attr.setType(typeName);
attr.setName(name);
attr.setIsPointer(isPointer);
attr.setIsReference(isReference);
attr.setDocumentation(documentation);
return attr;
}
......@@ -10,6 +10,6 @@
#include "PClassAttribute.h"
PClassAttribute createClassAttribute(const std::string & type, const std::string & name, const std::string & documentation = "");
PClassAttribute createClassAttribute(const std::string & typeName, const std::string & name, bool isPointer, bool isReference, const std::string & documentation);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment