16 if(type ==
"int" || type ==
"long" || type ==
"long int" || type ==
"size_t" || type ==
"unsigned int" || type ==
"unsigned short" || type ==
"char" || type ==
"unsigned char" || type ==
"long unsigned int"){
18 }
else if(type ==
"float" || type ==
"double"){
20 }
else if(type ==
"std::string"){
22 }
else if(type ==
"DataStreamMsg"){
23 return "bytearray(b\"Shadoko\")";
27 if(nestedDefaultValue !=
""){
28 return "["+nestedDefaultValue+
"]";
46 const std::map<std::string, PClassConfig> & mapClass)
53 body += varName +
"." + attr.
getName() +
" = "+initValue+
"\n";
55 std::map<std::string, PClassConfig>::const_iterator it(mapClass.find(type));
56 if(it != mapClass.end()){
58 body += varName +
"." + attr.
getName() +
" = "+moduleName+
"."+type+
"."+it->second.getListAttribute().back().getName()+
"\n";
75 const std::map<std::string, PClassConfig> & mapClass)
82 body +=
"assert " + varName +
"." + attr.
getName() +
" == "+initValue+
"\n";
84 std::map<std::string, PClassConfig>::const_iterator it(mapClass.find(type));
85 if(it != mapClass.end()){
86 body +=
"assert " + varName +
"." + attr.
getName() +
".value == "+moduleName+
"."+type+
"."+it->second.getListAttribute().back().getName()+
".value\n";
102 const std::map<std::string, PClassConfig> & mapClass)
109 body +=
"import "+moduleName+
"\n";
111 body +=
"from "+moduleName+
" import "+className+
"\n";
113 body +=
"#Unit Test of the " + className +
"\n";
114 body +=
"def test_"+className+
"():\n";
115 body +=
"\tassert "+className+
".getTypeName() == \"" + className +
"\"\n";
117 body +=
"\t#Let's test the stream now\n";
118 body +=
"\tshadok = "+moduleName+
"."+className+
"()\n";
119 const std::vector<PClassAttribute> & vecAttr = classConfig.
getListAttribute();
120 for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
123 body +=
"\tstream = shadok.toBytes()\n";
124 body +=
"\tassert len(stream) != 0\n";
126 body +=
"\tother = "+moduleName+
"."+className+
"()\n";
127 body +=
"\tother.fromBytes(stream)\n";
128 for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
138 PPath fileName(testDirectory /
PPath(
"test_" + className +
".py"));
151 std::map<std::string, PClassConfig> mapClass;
152 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end() && b; ++it){
153 mapClass[it->getName()] = *it;
155 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end() && b; ++it){
170 PPath testDirectory(projectPath /
PPath(
"tests"));
172 std::cerr <<
"project_wrapper_generator : cannot create unit tests directory of project '"<<testDirectory<<
"'" << std::endl;
std::vector< PPath > PVecPath
Describes a class attribute.
const PString & getType() const
Gets the type of the PClassAttribute.
bool getIsEnum() const
Gets the isEnum of the PClassAttribute.
const PString & getName() const
Gets the name of the PClassAttribute.
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.
bool getIsEnum() const
Say if the current PClassConfig is an enum.
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 getCMakeListsHeader()
Get the CMakeLists.txt header.
Configuration of the project.
PString generator_getListNestedType(const PString &type)
Get the nested type inside a std::list.
bool generator_typeIsList(const PString &type)
Say if a given type is a std::list.
bool project_wrapper_moduleGeneratorTest(const PPath &projectPath, const ProjectConfig &projectConfig, const PString &moduleName, const std::vector< PClassConfig > &vecClassConfig, const PVecPath &vecInclude)
Generate the unit tests of the project.
PString pythonAssertTestValue(const PString &varName, const PClassAttribute &attr, const PString &moduleName, const PString &indentation, const std::map< std::string, PClassConfig > &mapClass)
Get the default set of given attribute for a test.
bool project_wrapper_allClassTest(const PPath &testDirectory, const PString &moduleName, const std::vector< PClassConfig > &vecClassConfig)
Generate the test for all class inside the module.
bool project_wrapper_classTest(const PPath &testDirectory, const PString &moduleName, const PClassConfig &classConfig, const std::map< std::string, PClassConfig > &mapClass)
Generate the test for all class inside the module.
PString pythonDefaultTestValue(const PString &varName, const PClassAttribute &attr, const PString &moduleName, const PString &indentation, const std::map< std::string, PClassConfig > &mapClass)
Get the default set of given attribute for a test.
PString pythonGetDefaultTestValue(PString &type)
Get the default of a given type for a test.