17#include "gtest/gtest.h"
30 class NoFile_Test :
public ::testing::Test
36 mNoFileName =
"no_file.h5";
37 mWrongFileName =
"just_txt.h5";
38 std::fstream
fs(mWrongFileName, std::ios::out);
39 fs <<
"This file is not a hdf5 file" << std::endl;
47 class Group_Test :
public ::testing::Test
54 mFs = {
"field1",
"second",
"real"};
69 for(
i = 0;
i.lex() !=
rs->size(); ++
i){
96 File f(mNoFileName,
true);
102 File f1(mWrongFileName,
true);
103 File f2(mWrongFileName,
false);
110 std::remove(mFileName.c_str());
114 h5f.addAttribute(
"fprop",
static_cast<Double>(3.141));
116 h5f.getGroup(
"gr1")->addAttribute(
"att1",
String(
"text"));
120 h5f.addGroup(
"moregroups");
125 evenmore->addAttribute(
"moreatt",
static_cast<Int>(12));
127 evenmore->getGroup(
"we")->addAttribute(
"wex",
static_cast<Int>(9));
130 evenmore->getGroup(
"need")->addAttribute(
"wex",
static_cast<Int>(7));
132 evenmore->getGroup(
"more")->addAttribute(
"wex",
static_cast<Int>(4));
134 evenmore->getGroup(
"groups")->addAttribute(
"wex",
static_cast<Int>(2));
143 h5f.getGroup(
"gr1")->open().addTable(
"tab1", mTabA, mFs);
144 h5f.getGroup(
"moregroups")->open().getGroup(
"evenmore")->open().getGroup(
"need")->open().addTable(
"tab1", mTabA, mFs);
152 h5f.getGroup(
"gr2")->open().addDataset(
"dat1", mData);
164 auto gr1 =
h5f.getGroup(
"gr1");
166 auto tab =
gr1->getTable(
"tab1");
173 EXPECT_THROW(
h5f.getTable(
"moregroups/evenmore/need/tab1/a"), std::runtime_error);
174 auto tab2 =
h5f.getTable(
"moregroups/evenmore/need/tab1/");
178 h5f.iter( [](
const auto& c) {
VCHECK(c->path()); } )();
179 h5f.iterRecursive( [](
const auto& c) {
VCHECK(c->path()); } )();
180 h5f.iterRecursive( [](
const auto& c) { c->open();
VCHECK(
toString(c->getRecursiveAttributes())); } )();
181 h5f.iterRecursive( [](
const auto& c) {
182 if(c->type() == ContentType::TABLE) { c->open();
VCHECK(
toString(c->getRecursiveAttributes())); }
193 auto tab =
h5f.getGroup(
"gr1")->open().getTable(
"tab1",
RecType());
200 for(;
i.lex() !=
i.lmax().val(); ++
i){
203 auto dtab =
h5f.getGroup(
"gr1")->open().getTable(
"tab1");
218 auto dset =
h5f.getGroup(
"gr2")->open().getDataset(
"dat1",
Double{});
219 auto data =
dset->read();
222 EXPECT_EQ( data.range()->sub(
i)->size(), mData.range()->sub(
i)->size() );
224 auto i = std::make_shared<CIndex>(data.range());
233 auto dset =
h5f.getGroup(
"gr2")->open().getDataset(
"dat1",
Double{});
238 auto data =
dset->read(
beg,end);
240 EXPECT_EQ( data.range()->sub(0)->size(), 1u );
242 EXPECT_EQ( data.range()->sub(
i)->size(), mData.range()->sub(
i)->size() );
244 auto i = std::make_shared<CIndex>(data.range());
245 auto j = std::make_shared<DIndex>(
beg.pack().get(0) );
257 auto checkatt = [](
const std::map<String,DType>&
m,
258 const std::map<String,DType>&
cs) {
259 for(
const auto& c:
cs){
260 if(
m.count(c.first)){
261 if(
m.at(c.first).str() != c.second.str()){
271 std::map<String,DType>
constr;
274 h5f.iterRecursive( [&](
const auto& c) {
275 if(c->type() == ContentType::TABLE) {
277 auto av = c->getRecursiveAttributes();
278 auto cx = std::dynamic_pointer_cast<Table>(c);
280 cx->iterRecords( [&](const MArray<DType>& r) {
282 auto fi = UIndex<std::pair<SizeT,String>>(r.range()->sub(0));
283 for(; fi.lex() != fi.lmax().val(); ++fi) { ax[fi.meta().second] = r[fi]; }
284 attrs.push_back(toString(ax));
285 if(checkatt(ax,constr)){
286 paths.push_back(c->path()+
"/@"+toString(cnt));
292 for(
const auto& x:
attrs){
295 for(
const auto&
p:
paths){
311 ::testing::InitGoogleTest(&
argc,
argv);
YIndex & setSub(SizeT ind, SizeT lex)
int main(int argc, char **argv)
RangePtr yrange(const Vector< RangePtr > &rs)
Sptr< RangeBase > RangePtr
std::vector< T, Allocator< T > > Vector
Sptr< Range > rangeCast(const RangePtr r)
String toString(const T &a)
constexpr decltype(auto) operation(F &&f, const Ops &... ops)