further hdf5 test

This commit is contained in:
Christian Zimmermann 2023-01-15 03:18:21 +01:00
parent e331f6c4e2
commit d72bf23049
6 changed files with 72 additions and 11 deletions

View file

@ -13,6 +13,8 @@ namespace CNORXZ
class File : public ContentBase class File : public ContentBase
{ {
public: public:
typedef URange<String> RangeT;
DEFAULT_MEMBERS(File); DEFAULT_MEMBERS(File);
File(const String& fname, bool _ro = true); File(const String& fname, bool _ro = true);
~File(); ~File();
@ -28,7 +30,8 @@ namespace CNORXZ
virtual String filename() const override final; virtual String filename() const override final;
Int exists() const; Int exists() const;
File& append(const ContentPtr& c); File& set(const RangePtr& range);
File& append(const String& cname);
private: private:
bool mRo = true; bool mRo = true;

View file

@ -18,6 +18,7 @@ namespace CNORXZ
virtual ContentType type() const override final; virtual ContentType type() const override final;
virtual bool ro() const override final; virtual bool ro() const override final;
virtual Group& load() override final; virtual Group& load() override final;
virtual Group& write() override final;
virtual Group& close() override final; virtual Group& close() override final;
virtual MArray<Sptr<ContentBase>>* get() override final; virtual MArray<Sptr<ContentBase>>* get() override final;
virtual const MArray<Sptr<ContentBase>>* get() const override final; virtual const MArray<Sptr<ContentBase>>* get() const override final;

View file

@ -62,9 +62,13 @@ namespace CNORXZ
File& File::close() File& File::close()
{ {
if(mCont.range() != nullptr){
for(auto& x: mCont){ for(auto& x: mCont){
if(x != nullptr){
x->close(); x->close();
} }
}
}
if(mId != 0){ if(mId != 0){
H5Fclose(mId); H5Fclose(mId);
} }
@ -107,5 +111,41 @@ namespace CNORXZ
return ex; return ex;
} }
File& File::set(const RangePtr& range)
{
if(mCont.range() != nullptr){
CXZ_ERROR("IMPLEMENT");
// operator+ for RangePtr!!!
}
else {
mCont = MArray<ContentPtr>(range);
}
return *this;
}
File& File::append(const String& cname)
{
if(mCont.range() != nullptr){
auto oldrange = std::dynamic_pointer_cast<URange<String>>(mCont.range());
Vector<String> names(oldrange->size());
for(auto i = oldrange->begin(); i != oldrange->end(); ++i){
names[i.lex()] = *i;
}
names[names.size()-1] = cname;
auto range = URangeFactory<String>( names ).create();
MArray<ContentPtr> ncont( range );
auto j = ncont.begin();
for(auto i = mCont.begin(); i != mCont.end(); ++i){
j.at( i.meta() );
ncont[j] = mCont[i];
}
mCont = ncont;
}
else {
auto range = URangeFactory<String>( Vector<String>({cname}) ).create();
mCont = MArray<ContentPtr>( range );
}
return *this;
}
} }
} }

View file

@ -43,6 +43,12 @@ namespace CNORXZ
return *this; return *this;
} }
Group& Group::write()
{
// ...!!!
return *this;
}
Group& Group::close() Group& Group::close()
{ {
return *this; return *this;

View file

@ -1,10 +1,4 @@
set(TEST_FILE_BASE "${CMAKE_CURRENT_BINARY_DIR}/test-file-")
message(STATUS "TEST_FILE_BASE = ${TEST_FILE_BASE}")
add_definitions(-DTEST_FILE_BASE=${TEST_FILE_BASE})
#add_test(NAME clean COMMAND rm -f ${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)

View file

@ -2,6 +2,7 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <filesystem>
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -11,6 +12,7 @@ namespace
{ {
using namespace CNORXZ; using namespace CNORXZ;
using namespace CNORXZ::hdf5; using namespace CNORXZ::hdf5;
namespace sfs = std::filesystem;
class NoFile_Test : public ::testing::Test class NoFile_Test : public ::testing::Test
{ {
@ -35,8 +37,11 @@ namespace
Group_Test() Group_Test()
{ {
mFileName = "test_file.h5";
sfs::remove(mFileName);
} }
String mFileName;
}; };
TEST_F(NoFile_Test, NoFile) TEST_F(NoFile_Test, NoFile)
@ -52,6 +57,18 @@ namespace
EXPECT_THROW(l1(), std::runtime_error); EXPECT_THROW(l1(), std::runtime_error);
EXPECT_THROW(l2(), std::runtime_error); EXPECT_THROW(l2(), std::runtime_error);
} }
TEST_F(Group_Test, Create)
{
File h5f(mFileName, false);
EXPECT_FALSE(h5f.ro());
//h5f.append("gr1");
auto grange = URangeFactory<String>( Vector<String>( { "gr1", "gr2" } ) ).create();
h5f.set( grange );
for(auto i = grange->begin(); i != grange->end(); ++i){
(*h5f.get())[i] = std::make_shared<Group>( i.meta().str(), &h5f );
}
}
} }
// check write to new file // check write to new file