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

Commit f8490f77 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add test with exotic C types

parent 1c3d359d
......@@ -11,4 +11,5 @@ include(callGenerator.cmake)
add_subdirectory(TEST_BASE_CONFIG)
add_subdirectory(TEST_TYPE)
add_subdirectory(TEST_TYPE_T)
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
call_generator(test_type_t_lib configType.ph5)
add_executable(test_type_t main.cpp)
target_link_libraries(test_type_t test_type_t_lib ${HDF5_CXX_LIBRARIES})
add_test(NAME TestTypeT
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_type_t
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
///Table of types
TableType{
///Float value
float valFloat;
///Double value
float valDouble;
///In value
int32_t valInt;
///Short value
int16_t valShort;
///Char value
int8_t valChar;
///unsigned int value
uint32_t 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;
}
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