first hdf5 test
This commit is contained in:
parent
b6455049c4
commit
e331f6c4e2
4 changed files with 66 additions and 4 deletions
4
src/opt/hdf5/include/cnorxz_hdf5.h
Normal file
4
src/opt/hdf5/include/cnorxz_hdf5.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
#include "h5_content_base.h"
|
||||||
|
#include "h5_file.h"
|
||||||
|
#include "h5_group.h"
|
|
@ -13,7 +13,7 @@ namespace CNORXZ
|
||||||
Int ex = this->exists();
|
Int ex = this->exists();
|
||||||
const String fn = this->filename();
|
const String fn = this->filename();
|
||||||
CXZ_ASSERT( ex != 2, "tried to open non-h5 file '" << fn << "'" );
|
CXZ_ASSERT( ex != 2, "tried to open non-h5 file '" << fn << "'" );
|
||||||
if(this->ro()){
|
if(mRo){
|
||||||
CXZ_ASSERT( ex == 1, "could not open file as read-only: '"
|
CXZ_ASSERT( ex == 1, "could not open file as read-only: '"
|
||||||
<< fn << "' does not exist'");
|
<< fn << "' does not exist'");
|
||||||
mId = H5Fopen( fn.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT );
|
mId = H5Fopen( fn.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT );
|
||||||
|
|
|
@ -8,4 +8,4 @@ add_definitions(-DTEST_FILE_BASE=${TEST_FILE_BASE})
|
||||||
add_executable(h5basic h5_basic_unit_test.cc)
|
add_executable(h5basic h5_basic_unit_test.cc)
|
||||||
add_dependencies(h5basic cnorxz cnorxzhdf5)
|
add_dependencies(h5basic cnorxz cnorxzhdf5)
|
||||||
target_link_libraries(h5basic ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${HDF5_LIBS} cnorxz cnorxzhdf5)
|
target_link_libraries(h5basic ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${HDF5_LIBS} cnorxz cnorxzhdf5)
|
||||||
add_test(NAME h5basic COMMAND rm -f ${TEST_FILE_BASE}* ; h5basic)
|
add_test(NAME h5basic COMMAND h5basic)
|
||||||
|
|
|
@ -1,8 +1,66 @@
|
||||||
|
|
||||||
// check no file
|
#include <cstdlib>
|
||||||
// check no hdf5 file
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include "cnorxz_hdf5.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
using namespace CNORXZ;
|
||||||
|
using namespace CNORXZ::hdf5;
|
||||||
|
|
||||||
|
class NoFile_Test : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
NoFile_Test()
|
||||||
|
{
|
||||||
|
mNoFileName = "no_file.h5";
|
||||||
|
mWrongFileName = "just_txt.h5";
|
||||||
|
std::fstream fs(mWrongFileName, std::ios::out);
|
||||||
|
fs << "This file is not a hdf5 file" << std::endl;
|
||||||
|
fs.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
String mNoFileName;
|
||||||
|
String mWrongFileName;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Group_Test : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
Group_Test()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(NoFile_Test, NoFile)
|
||||||
|
{
|
||||||
|
auto l = [&](){ return std::make_shared<File>(mNoFileName, true); };
|
||||||
|
EXPECT_THROW(l(), std::runtime_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(NoFile_Test, NoH5Format)
|
||||||
|
{
|
||||||
|
auto l1 = [&](){ return std::make_shared<File>(mWrongFileName, true); };
|
||||||
|
auto l2 = [&](){ return std::make_shared<File>(mWrongFileName, false); };
|
||||||
|
EXPECT_THROW(l1(), std::runtime_error);
|
||||||
|
EXPECT_THROW(l2(), std::runtime_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check write to new file
|
// check write to new file
|
||||||
// check read from that file
|
// check read from that file
|
||||||
// check write to existing file
|
// check write to existing file
|
||||||
// check again read from that file
|
// check again read from that file
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue