further hdf5 test
This commit is contained in:
parent
e331f6c4e2
commit
d72bf23049
6 changed files with 72 additions and 11 deletions
|
@ -13,6 +13,8 @@ namespace CNORXZ
|
|||
class File : public ContentBase
|
||||
{
|
||||
public:
|
||||
typedef URange<String> RangeT;
|
||||
|
||||
DEFAULT_MEMBERS(File);
|
||||
File(const String& fname, bool _ro = true);
|
||||
~File();
|
||||
|
@ -28,7 +30,8 @@ namespace CNORXZ
|
|||
virtual String filename() const override final;
|
||||
|
||||
Int exists() const;
|
||||
File& append(const ContentPtr& c);
|
||||
File& set(const RangePtr& range);
|
||||
File& append(const String& cname);
|
||||
|
||||
private:
|
||||
bool mRo = true;
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace CNORXZ
|
|||
virtual ContentType type() const override final;
|
||||
virtual bool ro() const override final;
|
||||
virtual Group& load() override final;
|
||||
virtual Group& write() override final;
|
||||
virtual Group& close() override final;
|
||||
virtual MArray<Sptr<ContentBase>>* get() override final;
|
||||
virtual const MArray<Sptr<ContentBase>>* get() const override final;
|
||||
|
|
|
@ -62,8 +62,12 @@ namespace CNORXZ
|
|||
|
||||
File& File::close()
|
||||
{
|
||||
for(auto& x: mCont){
|
||||
x->close();
|
||||
if(mCont.range() != nullptr){
|
||||
for(auto& x: mCont){
|
||||
if(x != nullptr){
|
||||
x->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(mId != 0){
|
||||
H5Fclose(mId);
|
||||
|
@ -107,5 +111,41 @@ namespace CNORXZ
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,12 @@ namespace CNORXZ
|
|||
return *this;
|
||||
}
|
||||
|
||||
Group& Group::write()
|
||||
{
|
||||
// ...!!!
|
||||
return *this;
|
||||
}
|
||||
|
||||
Group& Group::close()
|
||||
{
|
||||
return *this;
|
||||
|
|
|
@ -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_dependencies(h5basic cnorxz cnorxzhdf5)
|
||||
target_link_libraries(h5basic ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${HDF5_LIBS} cnorxz cnorxzhdf5)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
@ -11,7 +12,8 @@ namespace
|
|||
{
|
||||
using namespace CNORXZ;
|
||||
using namespace CNORXZ::hdf5;
|
||||
|
||||
namespace sfs = std::filesystem;
|
||||
|
||||
class NoFile_Test : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -35,8 +37,11 @@ namespace
|
|||
|
||||
Group_Test()
|
||||
{
|
||||
|
||||
mFileName = "test_file.h5";
|
||||
sfs::remove(mFileName);
|
||||
}
|
||||
|
||||
String mFileName;
|
||||
};
|
||||
|
||||
TEST_F(NoFile_Test, NoFile)
|
||||
|
@ -52,6 +57,18 @@ namespace
|
|||
EXPECT_THROW(l1(), 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
|
||||
|
|
Loading…
Reference in a new issue