2016-09-22 03:53:17 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:36 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2016-09-22 03:53:17 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2017-09-13 03:46:06 +08:00
|
|
|
FILE
|
|
|
|
titerate.cpp - HDF5 C++ testing iterate related functionality
|
2016-09-22 03:53:17 +08:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
#include <iostream>
|
2016-10-20 04:50:17 +08:00
|
|
|
using std::cerr;
|
|
|
|
using std::endl;
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2016-10-20 04:50:17 +08:00
|
|
|
#include <string>
|
2020-09-30 22:27:10 +08:00
|
|
|
#include "H5Cpp.h" // C++ API header file
|
2016-10-20 04:50:17 +08:00
|
|
|
using namespace H5;
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2016-10-20 04:50:17 +08:00
|
|
|
#include "h5test.h"
|
2020-09-30 22:27:10 +08:00
|
|
|
#include "h5cpputil.h" // C++ utilility header file
|
2016-09-22 03:53:17 +08:00
|
|
|
|
|
|
|
/* Number of datasets for group iteration test */
|
|
|
|
#define NDATASETS 50
|
|
|
|
|
|
|
|
/* Number of attributes for attribute iteration test */
|
|
|
|
//#define NATTR 50
|
|
|
|
|
|
|
|
/* Number of groups for second group iteration test */
|
|
|
|
//#define ITER_NGROUPS 150
|
|
|
|
|
|
|
|
/* General maximum length of names used */
|
2020-09-30 22:27:10 +08:00
|
|
|
#define NAMELEN 80
|
2016-09-22 03:53:17 +08:00
|
|
|
|
|
|
|
/* 1-D dataset with fixed dimensions */
|
|
|
|
//#define SPACE1_RANK 1
|
|
|
|
//#define SPACE1_DIM1 4
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
const H5std_string FILE_ITERATE("titerate.h5");
|
|
|
|
const H5std_string GROUP1("Top Group");
|
|
|
|
const H5std_string GROUP1_PATH("/Top Group");
|
|
|
|
const H5std_string GROUP1_1("Sub-Group 1.1");
|
|
|
|
const H5std_string GROUP1_1_PATH("/Top Group/Sub-Group 1.1");
|
|
|
|
const H5std_string GROUP1_2("Sub-Group 1.2");
|
|
|
|
const H5std_string GROUP1_2_PATH("/Top Group/Sub-Group 1.2");
|
|
|
|
const H5std_string DSET_DEFAULT_NAME("default");
|
|
|
|
const H5std_string DSET_IN_FILE("Dataset in File");
|
|
|
|
const H5std_string DSET_IN_FILE_PATH("/Dataset in File");
|
|
|
|
const H5std_string DSET_IN_GRP1("Dataset in Group 1");
|
|
|
|
const H5std_string DSET_IN_GRP1_PATH("/Top Group/Dataset in Group 1");
|
|
|
|
const H5std_string DSET_IN_GRP1_2("Dataset in Group 1.2");
|
|
|
|
const H5std_string DSET_IN_GRP1_2_PATH("/Top Group/Sub-Group 1.2/Dataset in Group 1.2");
|
|
|
|
|
|
|
|
typedef enum { RET_ZERO, RET_TWO, RET_CHANGE, RET_CHANGE2 } iter_enum;
|
2016-09-22 03:53:17 +08:00
|
|
|
|
|
|
|
/* Custom group iteration callback data */
|
|
|
|
typedef struct {
|
2020-09-30 22:27:10 +08:00
|
|
|
char name[NAMELEN]; /* The name of the object */
|
|
|
|
H5O_type_t type; /* The type of the object */
|
|
|
|
iter_enum command; /* The type of return value */
|
2016-09-22 03:53:17 +08:00
|
|
|
} iter_info;
|
|
|
|
|
2021-06-01 21:49:39 +08:00
|
|
|
static int iter_strcmp(const void *s1, const void *s2);
|
|
|
|
static void printelems(const Group &group, const H5std_string &dsname, const H5std_string &atname);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: iter_strcmp
|
|
|
|
*
|
|
|
|
* Purpose String comparison routine for qsort
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2021-06-01 21:49:39 +08:00
|
|
|
static int
|
2020-09-30 22:27:10 +08:00
|
|
|
iter_strcmp(const void *s1, const void *s2)
|
2016-09-22 03:53:17 +08:00
|
|
|
{
|
2021-06-01 21:49:39 +08:00
|
|
|
return (HDstrcmp(*reinterpret_cast<const char *const *>(s1), *reinterpret_cast<const char *const *>(s2)));
|
2016-09-22 03:53:17 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: liter_cb
|
|
|
|
*
|
|
|
|
* Purpose Custom link iteration callback routine
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static herr_t
|
|
|
|
liter_cb(hid_t H5_ATTR_UNUSED group, const char *name, const H5L_info2_t H5_ATTR_UNUSED *link_info,
|
|
|
|
void *op_data)
|
2016-09-22 03:53:17 +08:00
|
|
|
{
|
2021-06-01 21:49:39 +08:00
|
|
|
iter_info *info = static_cast<iter_info *>(op_data);
|
2020-09-30 22:27:10 +08:00
|
|
|
static int count = 0;
|
2016-09-22 03:53:17 +08:00
|
|
|
static int count2 = 0;
|
|
|
|
|
|
|
|
HDstrcpy(info->name, name);
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
switch (info->command) {
|
2016-09-22 03:53:17 +08:00
|
|
|
case RET_ZERO:
|
2020-09-30 22:27:10 +08:00
|
|
|
return (0);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
|
|
|
case RET_TWO:
|
2020-09-30 22:27:10 +08:00
|
|
|
return (2);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
|
|
|
case RET_CHANGE:
|
|
|
|
count++;
|
2020-09-30 22:27:10 +08:00
|
|
|
return (count > 10 ? 1 : 0);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
|
|
|
case RET_CHANGE2:
|
|
|
|
count2++;
|
2020-09-30 22:27:10 +08:00
|
|
|
return (count2 > 10 ? 1 : 0);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
printf("invalid iteration command");
|
2020-09-30 22:27:10 +08:00
|
|
|
return (-1);
|
2016-09-22 03:53:17 +08:00
|
|
|
} /* end switch */
|
|
|
|
} /* end liter_cb() */
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2017-03-03 22:45:57 +08:00
|
|
|
* Function: test_iter_group
|
2016-09-22 03:53:17 +08:00
|
|
|
*
|
2017-03-03 22:45:57 +08:00
|
|
|
* Purpose Tests group iteration
|
2016-09-22 03:53:17 +08:00
|
|
|
*
|
2017-03-03 22:45:57 +08:00
|
|
|
* Return Success: 0
|
|
|
|
* Failure: -1
|
2016-09-22 03:53:17 +08:00
|
|
|
*
|
2017-03-03 22:45:57 +08:00
|
|
|
* Programmer Binh-Minh Ribler
|
|
|
|
* Friday, September 9, 2016
|
2016-09-22 03:53:17 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_iter_group(FileAccPropList &fapl)
|
2016-09-22 03:53:17 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t idx; /* Index in the group */
|
|
|
|
char name[NAMELEN]; /* temporary name buffer */
|
2022-07-27 05:45:46 +08:00
|
|
|
char *lnames[NDATASETS + 2]; /* Names of the links created */
|
2020-09-30 22:27:10 +08:00
|
|
|
iter_info info; /* Custom iteration information */
|
|
|
|
herr_t ret; /* Generic return value */
|
2016-09-22 03:53:17 +08:00
|
|
|
|
|
|
|
/* Output message about test being performed */
|
|
|
|
SUBTEST("Group Iteration");
|
|
|
|
|
|
|
|
/* Create the test file with the datasets */
|
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create file
|
|
|
|
H5File file(FILE_ITERATE, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Test iterating over empty group */
|
|
|
|
info.command = RET_ZERO;
|
2020-09-30 22:27:10 +08:00
|
|
|
idx = 0;
|
|
|
|
ret = H5Literate2(file.getId(), H5_INDEX_NAME, H5_ITER_INC, &idx, liter_cb, &info);
|
2017-03-03 22:45:57 +08:00
|
|
|
verify_val(ret, SUCCEED, "H5Literate", __LINE__, __FILE__);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
DataType datatype(PredType::NATIVE_INT);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a scalar file space
|
|
|
|
DataSpace filespace;
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2021-06-01 21:49:39 +08:00
|
|
|
for (int i = 0; i < NDATASETS; i++) {
|
2022-01-29 00:34:57 +08:00
|
|
|
snprintf(name, sizeof(name), "Dataset %d", i);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Create a dataset in the file
|
|
|
|
DataSet dataset = file.createDataSet(name, datatype, filespace);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
/* Keep a copy of the dataset names */
|
|
|
|
lnames[i] = HDstrdup(name);
|
|
|
|
check_values(lnames[i], "HDstrdup returns NULL", __LINE__, __FILE__);
|
2021-06-01 21:49:39 +08:00
|
|
|
}
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Create a group and named datatype under root group for testing */
|
|
|
|
Group grp(file.createGroup(GROUP1, 0));
|
|
|
|
lnames[NDATASETS] = HDstrdup("grp");
|
|
|
|
check_values(lnames[NDATASETS], "HDstrdup returns NULL", __LINE__, __FILE__);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
datatype.commit(file, "dtype");
|
|
|
|
lnames[NDATASETS + 1] = HDstrdup("dtype");
|
|
|
|
check_values(lnames[NDATASETS], "HDstrdup returns NULL", __LINE__, __FILE__);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Sort the dataset names */
|
2023-06-28 23:31:32 +08:00
|
|
|
qsort(lnames, NDATASETS + 2, sizeof(char *), iter_strcmp);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Iterate through the datasets in the root group in various ways */
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open data file to read
|
|
|
|
file.openFile(FILE_ITERATE, H5F_ACC_RDONLY, fapl);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the root group
|
|
|
|
Group root_group(file.openGroup("/"));
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the number of object in the root group
|
|
|
|
hsize_t nobjs = root_group.getNumObjs();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(nobjs), NDATASETS + 2, "H5Gget_info", __LINE__, __FILE__);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
H5std_string obj_name;
|
2021-06-01 21:49:39 +08:00
|
|
|
for (hsize_t i = 0; i < nobjs; i++) {
|
2020-09-30 22:27:10 +08:00
|
|
|
// H5O_info2_t oinfo; /* Object info */
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
obj_name = root_group.getObjnameByIdx(i);
|
2020-09-30 22:27:10 +08:00
|
|
|
// ret = (herr_t)H5Lget_name_by_idx(root_group, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)i,
|
|
|
|
// dataset_name, (size_t)NAMELEN, H5P_DEFAULT);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// oinfo = root_group.childObjType((hsize_t)i, H5_INDEX_NAME, H5_ITER_INC, ".");
|
|
|
|
// ret = H5Oget_info_by_idx(root_group, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)i, &oinfo,
|
|
|
|
// H5P_DEFAULT);
|
2021-06-01 21:49:39 +08:00
|
|
|
}
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Attempted to iterate with invalid index, should fail
|
|
|
|
try {
|
|
|
|
obj_name = root_group.getObjnameByIdx(NDATASETS + 3);
|
|
|
|
|
|
|
|
// Should FAIL but didn't, so throw an invalid action exception
|
|
|
|
throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with invalid index");
|
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (GroupIException &invalid_action) // invalid index
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Attempted to iterate with negative index, should fail
|
|
|
|
try {
|
|
|
|
info.command = RET_ZERO;
|
2021-06-01 21:49:39 +08:00
|
|
|
idx = HSIZE_UNDEF;
|
2020-09-30 22:27:10 +08:00
|
|
|
obj_name = root_group.getObjnameByIdx(idx);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Should FAIL but didn't, so throw an invalid action exception
|
|
|
|
throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with negative index");
|
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (FileIException &invalid_action) // invalid index
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
|
|
|
catch (GroupIException &invalid_action) // invalid index
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
/* Test skipping exactly as many entries as in the group */
|
|
|
|
try {
|
|
|
|
info.command = RET_ZERO;
|
2020-09-30 22:27:10 +08:00
|
|
|
idx = NDATASETS + 2;
|
|
|
|
obj_name = root_group.getObjnameByIdx(idx);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Should FAIL but didn't, so throw an invalid action exception
|
|
|
|
throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with negative index");
|
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (FileIException &invalid_action) // invalid index
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
|
|
|
catch (GroupIException &invalid_action) // invalid index
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
/* Test skipping more entries than are in the group */
|
|
|
|
try {
|
|
|
|
info.command = RET_ZERO;
|
2020-09-30 22:27:10 +08:00
|
|
|
idx = NDATASETS + 3;
|
|
|
|
obj_name = root_group.getObjnameByIdx(idx);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Should FAIL but didn't, so throw an invalid action exception
|
|
|
|
throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with negative index");
|
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (FileIException &invalid_action) // invalid index
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
|
|
|
catch (GroupIException &invalid_action) // invalid index
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
/* Free the dataset names */
|
2021-06-01 21:49:39 +08:00
|
|
|
for (int i = 0; i < NDATASETS + 2; i++)
|
2023-06-29 06:48:12 +08:00
|
|
|
free(lnames[i]);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Everything will be closed as they go out of scope
|
|
|
|
|
|
|
|
PASSED();
|
2020-09-30 22:27:10 +08:00
|
|
|
} // try block
|
2016-09-22 03:53:17 +08:00
|
|
|
|
|
|
|
// catch all other exceptions
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_iter_group", __LINE__, __FILE__);
|
2016-09-22 03:53:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Test all objects in group, when callback always returns 0 */
|
|
|
|
info.command = RET_ZERO;
|
|
|
|
idx = 0;
|
2020-01-17 05:29:34 +08:00
|
|
|
if((ret = H5Literate2(file, H5_INDEX_NAME, H5_ITER_INC, &idx, liter_cb, &info)) > 0)
|
2016-09-22 03:53:17 +08:00
|
|
|
TestErrPrintf("Group iteration function didn't return zero correctly!\n");
|
|
|
|
|
|
|
|
/* Test all objects in group, when callback always returns 1 */
|
|
|
|
/* This also tests the "restarting" ability, because the index changes */
|
|
|
|
info.command = RET_TWO;
|
|
|
|
i = 0;
|
|
|
|
idx = 0;
|
2020-01-17 05:29:34 +08:00
|
|
|
while((ret = H5Literate2(file, H5_INDEX_NAME, H5_ITER_INC, &idx, liter_cb, &info)) > 0) {
|
2016-09-22 03:53:17 +08:00
|
|
|
/* Verify return value from iterator gets propagated correctly */
|
|
|
|
verify_val(ret, 2, "H5Literate", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
/* Increment the number of times "2" is returned */
|
|
|
|
i++;
|
|
|
|
|
|
|
|
/* Verify that the index is the correct value */
|
|
|
|
verify_val(idx, (hsize_t)i, "H5Literate", __LINE__, __FILE__);
|
|
|
|
if(idx > (NDATASETS + 2))
|
|
|
|
TestErrPrintf("Group iteration function walked too far!\n");
|
|
|
|
|
|
|
|
/* Verify that the correct name is retrieved */
|
|
|
|
if(HDstrcmp(info.name, lnames[(size_t)(idx - 1)]) != 0)
|
|
|
|
TestErrPrintf("Group iteration function didn't return name correctly for link - lnames[%u] = '%s'!\n", (unsigned)(idx - 1), lnames[(size_t)(idx - 1)]);
|
|
|
|
} /* end while */
|
|
|
|
verify_val(ret, -1, "H5Literate", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
if(i != (NDATASETS + 2))
|
|
|
|
TestErrPrintf("%u: Group iteration function didn't perform multiple iterations correctly!\n", __LINE__);
|
|
|
|
|
|
|
|
/* Test all objects in group, when callback changes return value */
|
|
|
|
/* This also tests the "restarting" ability, because the index changes */
|
|
|
|
info.command = new_format ? RET_CHANGE2 : RET_CHANGE;
|
|
|
|
i = 0;
|
|
|
|
idx = 0;
|
2020-01-17 05:29:34 +08:00
|
|
|
while((ret = H5Literate2(file, H5_INDEX_NAME, H5_ITER_INC, &idx, liter_cb, &info)) >= 0) {
|
2016-09-22 03:53:17 +08:00
|
|
|
/* Verify return value from iterator gets propagated correctly */
|
|
|
|
verify_val(ret, 1, "H5Literate", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
/* Increment the number of times "1" is returned */
|
|
|
|
i++;
|
|
|
|
|
|
|
|
/* Verify that the index is the correct value */
|
|
|
|
verify_val(idx, (hsize_t)(i + 10), "H5Literate", __LINE__, __FILE__);
|
|
|
|
if(idx > (NDATASETS + 2))
|
|
|
|
TestErrPrintf("Group iteration function walked too far!\n");
|
|
|
|
|
|
|
|
/* Verify that the correct name is retrieved */
|
|
|
|
if(HDstrcmp(info.name, lnames[(size_t)(idx - 1)]) != 0)
|
|
|
|
TestErrPrintf("Group iteration function didn't return name correctly for link - lnames[%u] = '%s'!\n", (unsigned)(idx - 1), lnames[(size_t)(idx - 1)]);
|
|
|
|
} /* end while */
|
|
|
|
verify_val(ret, -1, "H5Literate", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
if(i != 42 || idx != 52)
|
|
|
|
TestErrPrintf("%u: Group iteration function didn't perform multiple iterations correctly!\n", __LINE__);
|
|
|
|
|
|
|
|
ret = H5Fclose(file);
|
|
|
|
CHECK(ret, FAIL, "H5Fclose");
|
|
|
|
|
|
|
|
#endif
|
|
|
|
} /* test_iter_group() */
|
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: printelems
|
|
|
|
*
|
|
|
|
* Purpose Open an attribute and verify that it has a the correct name
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2022-02-05 06:50:45 +08:00
|
|
|
const H5std_string FILE_NAME("test_member_access.h5");
|
2017-03-03 22:45:57 +08:00
|
|
|
const H5std_string GRP_NAME("/Group_A");
|
|
|
|
const H5std_string FDATASET_NAME("file dset");
|
|
|
|
const H5std_string GDATASET_NAME("group dset");
|
|
|
|
const H5std_string ATTR_NAME("Units");
|
|
|
|
const H5std_string FATTR_NAME("F attr");
|
|
|
|
const H5std_string GATTR_NAME("G attr");
|
2020-09-30 22:27:10 +08:00
|
|
|
const int DIM1 = 2;
|
2021-06-01 21:49:39 +08:00
|
|
|
static void
|
2020-09-30 22:27:10 +08:00
|
|
|
printelems(const Group &group, const H5std_string &dsname, const H5std_string &atname)
|
2016-09-22 03:53:17 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
try {
|
|
|
|
DataSet d1(group.openDataSet(dsname));
|
2017-03-03 22:45:57 +08:00
|
|
|
DataSpace s1 = d1.getSpace();
|
|
|
|
s1.close();
|
|
|
|
d1.close();
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
unsigned idx = 0;
|
|
|
|
Attribute a1(group.openAttribute(idx));
|
2017-03-03 22:45:57 +08:00
|
|
|
H5std_string aname = a1.getName();
|
2016-09-22 03:53:17 +08:00
|
|
|
verify_val(aname, atname, "printelems", __LINE__, __FILE__);
|
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
a1.close();
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
2017-09-13 03:46:06 +08:00
|
|
|
// Catch all exceptions and rethrow so caller can handle
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-09-13 03:46:06 +08:00
|
|
|
throw;
|
|
|
|
}
|
2016-09-22 03:53:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2017-03-03 22:45:57 +08:00
|
|
|
* Function: test_HDFFV_9920
|
2016-09-22 03:53:17 +08:00
|
|
|
*
|
2017-03-03 22:45:57 +08:00
|
|
|
* Purpose Tests the fix for HDFFV-9920
|
2016-09-22 03:53:17 +08:00
|
|
|
*
|
2017-03-03 22:45:57 +08:00
|
|
|
* Programmer Binh-Minh Ribler
|
|
|
|
* Friday, September 9, 2016
|
2016-09-22 03:53:17 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_HDFFV_9920()
|
2016-09-22 03:53:17 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
int attr_data[2] = {100, 200};
|
|
|
|
hsize_t dims[1] = {DIM1};
|
2020-04-21 07:12:00 +08:00
|
|
|
|
2022-02-05 06:50:45 +08:00
|
|
|
/* Output message about test being performed */
|
|
|
|
SUBTEST("Member access");
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a new file and a group in it
|
2020-09-30 22:27:10 +08:00
|
|
|
H5File file(FILE_NAME, H5F_ACC_TRUNC);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
Group gr1(file.createGroup(GRP_NAME));
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create the data space for the attribute.
|
2020-09-30 22:27:10 +08:00
|
|
|
DataSpace dspace = DataSpace(1, dims);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
DataSet fds = file.createDataSet(FDATASET_NAME, PredType::STD_I32BE, dspace);
|
|
|
|
DataSet gds = gr1.createDataSet(GDATASET_NAME, PredType::STD_I32BE, dspace);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2020-04-21 07:12:00 +08:00
|
|
|
// Create a file attribute and a group attribute.
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute fa1 = file.createAttribute(FATTR_NAME, PredType::STD_I32BE, dspace);
|
|
|
|
Attribute ga1 = gr1.createAttribute(GATTR_NAME, PredType::STD_I32BE, dspace);
|
2020-04-21 07:12:00 +08:00
|
|
|
|
|
|
|
// Write the attribute data.
|
2020-09-30 22:27:10 +08:00
|
|
|
fa1.write(PredType::NATIVE_INT, attr_data);
|
|
|
|
ga1.write(PredType::NATIVE_INT, attr_data);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
fa1.close();
|
|
|
|
ga1.close();
|
|
|
|
fds.close();
|
|
|
|
gds.close();
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify the attributes have correct names.
|
|
|
|
printelems(file, FDATASET_NAME, FATTR_NAME);
|
|
|
|
printelems(gr1, GDATASET_NAME, GATTR_NAME);
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2022-02-05 06:50:45 +08:00
|
|
|
PASSED();
|
2020-09-30 22:27:10 +08:00
|
|
|
} // end of try block
|
2017-09-13 03:46:06 +08:00
|
|
|
|
|
|
|
// Catch all failures for handling in the same way
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-09-13 03:46:06 +08:00
|
|
|
issue_fail_msg("test_HDFFV_9920()", __LINE__, __FILE__, E.getCDetailMsg());
|
|
|
|
}
|
2016-09-22 03:53:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2017-03-03 22:45:57 +08:00
|
|
|
* Function: test_iterate
|
2016-09-22 03:53:17 +08:00
|
|
|
*
|
2017-03-03 22:45:57 +08:00
|
|
|
* Purpose Tests iterate functionality
|
2016-09-22 03:53:17 +08:00
|
|
|
*
|
2017-03-03 22:45:57 +08:00
|
|
|
* Return Success: 0
|
|
|
|
* Failure: -1
|
2016-09-22 03:53:17 +08:00
|
|
|
*
|
2017-03-03 22:45:57 +08:00
|
|
|
* Programmer Binh-Minh Ribler
|
|
|
|
* Tuesday, September 6, 2016
|
2016-09-22 03:53:17 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
extern "C" void
|
|
|
|
test_iterate()
|
2016-09-22 03:53:17 +08:00
|
|
|
{
|
|
|
|
// Output message about test being performed
|
|
|
|
MESSAGE(5, ("Testing Iterate Feature\n"));
|
|
|
|
|
|
|
|
// Create access property with latest library version.
|
|
|
|
FileAccPropList fapl;
|
|
|
|
fapl.setLibverBounds(H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
test_iter_group(fapl); // Test iterating groups
|
|
|
|
test_HDFFV_9920(); // Test the fix of HDFFV-9920
|
|
|
|
// test_iter_attr(fapl); // Test iterating attributes
|
2016-09-22 03:53:17 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_iterate
|
2016-09-22 03:53:17 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: cleanup_iterate
|
|
|
|
*
|
2017-03-03 22:45:57 +08:00
|
|
|
* Purpose Cleanup temporary test files
|
2016-09-22 03:53:17 +08:00
|
|
|
*
|
2017-03-03 22:45:57 +08:00
|
|
|
* Return none
|
2016-09-22 03:53:17 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
extern "C" void
|
|
|
|
cleanup_iterate()
|
2016-09-22 03:53:17 +08:00
|
|
|
{
|
|
|
|
HDremove(FILE_ITERATE.c_str());
|
2022-02-05 06:50:45 +08:00
|
|
|
HDremove(FILE_NAME.c_str());
|
2016-09-22 03:53:17 +08:00
|
|
|
} // cleanup_iterate
|