Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit 1c3d359d authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add test with type

parent 6020c644
......@@ -10,4 +10,5 @@ message(STATUS "HDF5_CXX_LIBRARIES = ${HDF5_CXX_LIBRARIES}")
include(callGenerator.cmake)
add_subdirectory(TEST_BASE_CONFIG)
add_subdirectory(TEST_TYPE)
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
call_generator(test_type_lib configType.ph5)
add_executable(test_type main.cpp)
target_link_libraries(test_type test_type_lib ${HDF5_CXX_LIBRARIES})
add_test(NAME TestType
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_type
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
///Table of types
TableType{
///Float value
float valFloat;
///Double value
float valDouble;
///In value
int valInt;
///Short value
short valShort;
///Char value
char valChar;
///unsigned int value
unsigned int valUInt;
}
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include "configType.h"
///Test to write data
/** @param fileName : name of the file to be written
* @return true on success, false otherwise
*/
bool testWriteData(const std::string & fileName){
TableType table;
size_t nbRow(10lu);
table.resize(nbRow);
//Let's set some values in the Table
for(size_t i(0lu); i < nbRow; ++i){
table.setValFloat(i, i);
table.setValDouble(i, 2lu*i);
table.setValInt(i, 3lu*i);
table.setValShort(i, 4lu*i);
table.setValUInt(i, 5lu*i);
table.setValChar(i, i);
}
//Now let's open a file
H5::H5File file(fileName, H5F_ACC_TRUNC);
//And write our table directly in it
table.write(file);
//We can also explicitly cloase the file, otherwise it will do it automatically
file.close();
return true;
}
///Test to read data
/** @param fileName : name of the file to be read
* @return true on success, false otherwise
*/
bool testReadData(const std::string & fileName){
//First let's open a file in read only mode (better for concurencial access)
H5::H5File file(fileName, H5F_ACC_RDONLY);
//Let's create our table
TableType table;
//Add read the file
table.read(file);
//Now we can close the file and use the Table directly
file.close();
//Get the number of rows and number of columns
size_t nbRow = table.getNbRow();
bool b(true);
for(size_t i(0lu); i < nbRow; ++i){
b &= table.getValFloat(i) == i;
b &= table.getValDouble(i) == 2lu*i;
b &= table.getValInt(i) == (int)(3lu*i);
b &= table.getValShort(i) == (short)(4lu*i);
b &= table.getValUInt(i) == 5lu*i;
b &= table.getValChar(i) == (char)i;
}
return b;
}
int main(int argc, char** argv){
std::string fileName("configType.h5");
if(!testWriteData(fileName)){
std::cerr << "Cannot write file '"<<fileName<<"'" << std::endl;
return -1;
}
if(!testReadData(fileName)){
std::cerr << "Cannot read file '"<<fileName<<"'" << std::endl;
return -1;
}
return 0;
}
......@@ -164,20 +164,22 @@ std::string ph5_backendTableHeader(const PTable & table){
body += ph5_backendTableHeaderCompType(table);
body += ph5_backendTableHeaderDataType(table);
body += "\n\t\tvoid setAllDim(";
bool addComma(false);
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
if(addComma){body += ", ";}
body += "size_t " + (*it);
addComma = true;
}
body += ");\n";
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
body += "\t\tvoid set"+firstToUpper(*it)+"(size_t val);\n";
body += "\t\tsize_t get"+firstToUpper(*it)+"() const;\n";
if(vecDimVar.size() != 0lu){
body += "\n\t\tvoid setAllDim(";
bool addComma(false);
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
if(addComma){body += ", ";}
body += "size_t " + (*it);
addComma = true;
}
body += ");\n";
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
body += "\t\tvoid set"+firstToUpper(*it)+"(size_t val);\n";
body += "\t\tsize_t get"+firstToUpper(*it)+"() const;\n";
}
body += "\n";
}
body += "\tprivate:\n";
body += "\t\tvoid readDataSet(const H5::DataSet & dataset);\n";
body += "\t\tvoid writeDataSet(H5::DataSet & dataset) const;\n";
......@@ -188,11 +190,13 @@ std::string ph5_backendTableHeader(const PTable & table){
body += "\t\t///Number of rows in the table "+name+"\n";
body += "\t\tsize_t p__nbRow;\n\n";
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
body += "\t\t///Tensor dimension "+(*it)+"\n";
body += "\t\tsize_t p_"+(*it)+";\n";
if(vecDimVar.size() != 0lu){
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
body += "\t\t///Tensor dimension "+(*it)+"\n";
body += "\t\tsize_t p_"+(*it)+";\n";
}
body += "\n";
}
body += "\n";
body += ph5_backendTableHeaderAttribute(table);
body += "};\n\n";
......@@ -388,7 +392,7 @@ std::string ph5_backendTableSourceGetter(const PTable & table){
std::string ph5_backendTableSourceDimGetterSetter(const PTable & table){
std::string body(""), name(table.getName());
PVecStr vecDimVar = ph5_getDimName(table);
if(vecDimVar.size() == 0lu){return "";}
body += "///Set all the dimentions of the Tensor in the table\n";
std::string docPrefix("/**");
for(PVecStr::iterator it(vecDimVar.begin()); it != vecDimVar.end(); ++it){
......@@ -504,12 +508,12 @@ std::string ph5_backendTableSourceCompType(const PTable & table){
* @return HDF5 type
*/
std::string ph5_cTypeToHDF5(const std::string & type){
if(type == "char"){return "H5::PredType::NATIVE_INT8";}
else if(type == "unsinged char"){return "H5::PredType::NATIVE_UINT8";}
else if(type == "short"){return "H5::PredType::NATIVE_INT16";}
else if(type == "unsigned short"){return "H5::PredType::NATIVE_UINT16";}
else if(type == "int"){return "H5::PredType::NATIVE_INT";}
else if(type == "unsigned int"){return "H5::PredType::NATIVE_UINT";}
if(type == "char" || type == "int8_t"){return "H5::PredType::NATIVE_INT8";}
else if(type == "unsinged char" || type == "int8_t"){return "H5::PredType::NATIVE_UINT8";}
else if(type == "short" || type == "int16_t"){return "H5::PredType::NATIVE_INT16";}
else if(type == "unsigned short" || type == "uint16_t"){return "H5::PredType::NATIVE_UINT16";}
else if(type == "int" || type == "int32_t"){return "H5::PredType::NATIVE_INT32";}
else if(type == "unsigned int" || type == "uint32_t"){return "H5::PredType::NATIVE_UINT32";}
else if(type == "float"){return "H5::PredType::NATIVE_FLOAT";}
else if(type == "double"){return "H5::PredType::NATIVE_DOUBLE";}
return "";
......
......@@ -153,7 +153,8 @@ bool ConfigParser::parseAttribute(PAttribute & attr){
std::cerr << "ConfigParser::parseAttribute : expect '(' after token 'Tensor'" << std::endl;
return true;
}
type = p_parser->getNextToken();
parseType(type);
if(!p_parser->isMatch(",")){
errorAt();
std::cerr << "ConfigParser::parseAttribute : expect ',' after type '"<<type<<"'" << std::endl;
......@@ -175,7 +176,7 @@ bool ConfigParser::parseAttribute(PAttribute & attr){
}
}
}else{
type = p_parser->getNextToken();
parseType(type);
}
std::string varName(p_parser->getNextToken());
std::string colName(varName);
......@@ -210,5 +211,15 @@ bool ConfigParser::parseDimention(PDimention & dim){
return true;
}
///Parse a data type
/** @param[out] type : type to be parsed
*/
void ConfigParser::parseType(std::string & type){
type = p_parser->getNextToken();
if(type == "unsigned"){
type += " " + p_parser->getNextToken();
}
}
......@@ -34,6 +34,7 @@ class ConfigParser : public PMultiFileParser{
bool parseTable(PTable & table);
bool parseAttribute(PAttribute & attr);
bool parseDimention(PDimention & dim);
void parseType(std::string & type);
///Last documentation string
std::string p_lastDocString;
......
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