2006-10-22 16:24:24 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2006-10-22 16:24:24 +08:00
|
|
|
* 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. *
|
2007-03-06 06:56:44 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2007-01-26 13:40:17 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
FILE
|
|
|
|
trefer.cpp - HDF5 C++ testing the functionalities associated with the C
|
2017-03-18 00:03:18 +08:00
|
|
|
Reference interface (H5R)
|
2007-01-26 13:40:17 +08:00
|
|
|
|
|
|
|
***************************************************************************/
|
2006-10-22 16:24:24 +08:00
|
|
|
#include <iostream>
|
2016-10-20 04:50:17 +08:00
|
|
|
using std::cerr;
|
|
|
|
using std::endl;
|
2006-10-22 16:24:24 +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;
|
2006-10-22 16:24:24 +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
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
const H5std_string FILE1("trefer1.h5");
|
|
|
|
const H5std_string FILE2("trefer2.h5");
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2010-05-02 22:25:42 +08:00
|
|
|
// Dataset 1
|
2020-09-30 22:27:10 +08:00
|
|
|
const H5std_string DSET1_NAME("Dataset1");
|
|
|
|
const H5std_string DSET2_NAME("Dataset2");
|
2010-05-02 22:25:42 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
const H5std_string MEMBER1("a_name");
|
|
|
|
const H5std_string MEMBER2("b_name");
|
|
|
|
const H5std_string MEMBER3("c_name");
|
2006-10-22 16:24:24 +08:00
|
|
|
|
|
|
|
// 1-D dataset with fixed dimensions
|
|
|
|
const int SPACE1_RANK = 1;
|
|
|
|
const int SPACE1_DIM1 = 4;
|
|
|
|
|
2013-09-23 08:39:44 +08:00
|
|
|
/* Larger 1-D dataset with fixed dimensions */
|
|
|
|
const int SPACE3_RANK = 1;
|
|
|
|
const int SPACE3_DIM1 = 100;
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2013-09-23 08:39:44 +08:00
|
|
|
/* Element selection information */
|
|
|
|
const int POINT1_NPOINTS = 10;
|
2006-10-22 16:24:24 +08:00
|
|
|
|
|
|
|
// Compound datatype
|
|
|
|
typedef struct s1_t {
|
|
|
|
unsigned int a;
|
|
|
|
unsigned int b;
|
2020-09-30 22:27:10 +08:00
|
|
|
float c;
|
2006-10-22 16:24:24 +08:00
|
|
|
} s1_t;
|
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_reference_params
|
|
|
|
*
|
|
|
|
* Purpose Test basic H5R (reference) parameters for correct processing
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_reference_params()
|
2013-09-23 08:39:44 +08:00
|
|
|
{
|
|
|
|
const char *write_comment = "Foo!"; /* Comments for group */
|
|
|
|
|
|
|
|
// Output message about test being performed
|
|
|
|
SUBTEST("Object Reference Parameters");
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
H5File *file1 = NULL;
|
2013-09-23 08:39:44 +08:00
|
|
|
try {
|
2020-09-30 22:27:10 +08:00
|
|
|
hobj_ref_t *wbuf, // buffer to write to disk
|
|
|
|
*rbuf, // buffer read from disk
|
|
|
|
*tbuf; // temp. buffer read from disk
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Allocate write & read buffers
|
2022-07-11 23:59:51 +08:00
|
|
|
size_t temp_size = MAX(sizeof(unsigned), sizeof(hobj_ref_t));
|
2023-06-29 06:48:12 +08:00
|
|
|
wbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));
|
|
|
|
rbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));
|
|
|
|
tbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));
|
2013-09-23 08:39:44 +08:00
|
|
|
|
|
|
|
// Create file FILE1
|
2020-09-30 22:27:10 +08:00
|
|
|
file1 = new H5File(FILE1, H5F_ACC_TRUNC);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for datasets
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims1[] = {SPACE1_DIM1};
|
2017-03-03 22:45:57 +08:00
|
|
|
DataSpace sid1(SPACE1_RANK, dims1);
|
|
|
|
|
|
|
|
// Create a group
|
|
|
|
Group group = file1->createGroup("Group1");
|
|
|
|
|
|
|
|
// Set group's comment
|
|
|
|
group.setComment(".", write_comment);
|
|
|
|
|
|
|
|
// Create a dataset (inside /Group1)
|
|
|
|
DataSet dataset = group.createDataSet(DSET1_NAME, PredType::NATIVE_UINT, sid1);
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
unsigned *tu32; // Temporary pointer to uint32 data
|
2022-07-11 23:59:51 +08:00
|
|
|
unsigned i;
|
2021-06-01 21:49:39 +08:00
|
|
|
for (tu32 = reinterpret_cast<unsigned *>(wbuf), i = 0; i < SPACE1_DIM1; i++)
|
2020-09-30 22:27:10 +08:00
|
|
|
*tu32++ = i * 3; // from C test
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Write selection to disk
|
|
|
|
dataset.write(wbuf, PredType::NATIVE_UINT);
|
|
|
|
|
|
|
|
// Close Dataset
|
|
|
|
dataset.close();
|
|
|
|
|
|
|
|
// Create another dataset (inside /Group1)
|
|
|
|
dataset = group.createDataSet("Dataset2", PredType::NATIVE_UCHAR, sid1);
|
|
|
|
|
|
|
|
// Close Dataset
|
|
|
|
dataset.close();
|
|
|
|
|
|
|
|
// Create a datatype to refer to
|
|
|
|
CompType dtype1(sizeof(s1_t));
|
|
|
|
|
|
|
|
// Insert fields
|
|
|
|
dtype1.insertMember(MEMBER1, HOFFSET(s1_t, a), PredType::NATIVE_INT);
|
|
|
|
dtype1.insertMember(MEMBER2, HOFFSET(s1_t, b), PredType::NATIVE_INT);
|
|
|
|
dtype1.insertMember(MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_FLOAT);
|
|
|
|
|
|
|
|
// Save datatype for later
|
|
|
|
dtype1.commit(group, "Datatype1");
|
|
|
|
|
|
|
|
// Close datatype and group
|
|
|
|
dtype1.close();
|
|
|
|
group.close();
|
|
|
|
|
|
|
|
// Create a dataset
|
|
|
|
dataset = file1->createDataSet("Dataset3", PredType::STD_REF_OBJ, sid1);
|
|
|
|
|
|
|
|
/* Test parameters to H5Location::reference */
|
|
|
|
try {
|
|
|
|
file1->reference(NULL, "/Group1/Dataset1");
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
catch (ReferenceException &E) {
|
|
|
|
} // We expect this to fail
|
2017-03-03 22:45:57 +08:00
|
|
|
try {
|
|
|
|
file1->reference(&wbuf[0], NULL);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
catch (ReferenceException &E) {
|
|
|
|
} // We expect this to fail
|
2017-03-03 22:45:57 +08:00
|
|
|
try {
|
|
|
|
file1->reference(&wbuf[0], "");
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
catch (ReferenceException &E) {
|
|
|
|
} // We expect this to fail
|
2017-03-03 22:45:57 +08:00
|
|
|
try {
|
|
|
|
file1->reference(&wbuf[0], "/Group1/Dataset1", H5R_MAXTYPE);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
catch (ReferenceException &E) {
|
|
|
|
} // We expect this to fail
|
2017-03-03 22:45:57 +08:00
|
|
|
try {
|
|
|
|
file1->reference(&wbuf[0], "/Group1/Dataset1", H5R_DATASET_REGION);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
catch (ReferenceException &E) {
|
|
|
|
} // We expect this to fail
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Close resources
|
|
|
|
dataset.close();
|
|
|
|
file1->close();
|
|
|
|
// Let sid1 go out of scope
|
|
|
|
|
|
|
|
// Free memory buffers
|
2023-06-29 06:48:12 +08:00
|
|
|
free(wbuf);
|
|
|
|
free(rbuf);
|
|
|
|
free(tbuf);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
PASSED();
|
2013-09-23 08:39:44 +08:00
|
|
|
} // end try
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
|
|
|
issue_fail_msg("test_reference_param()", __LINE__, __FILE__, E.getCFuncName(), E.getCDetailMsg());
|
2013-09-23 08:39:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-23 01:51:18 +08:00
|
|
|
delete file1;
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* test_reference_param() */
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_reference_obj
|
|
|
|
*
|
|
|
|
* Purpose Test basic object reference functions to various kinds
|
|
|
|
* of objects
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_reference_obj()
|
2006-10-22 16:24:24 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
const H5std_string write_comment = "Foo!"; // Comments for group
|
2006-10-22 16:24:24 +08:00
|
|
|
|
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("Object Reference Functions");
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
H5File *file1 = NULL;
|
2006-10-22 16:24:24 +08:00
|
|
|
try {
|
2020-09-30 22:27:10 +08:00
|
|
|
hobj_ref_t *wbuf, // buffer to write to disk
|
|
|
|
*rbuf, // buffer read from disk
|
|
|
|
*tbuf; // temp. buffer read from disk
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Allocate write & read buffers
|
2022-07-11 23:59:51 +08:00
|
|
|
size_t temp_size = MAX(sizeof(unsigned), sizeof(hobj_ref_t));
|
2023-06-29 06:48:12 +08:00
|
|
|
wbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));
|
|
|
|
rbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));
|
|
|
|
tbuf = static_cast<hobj_ref_t *>(malloc(temp_size * SPACE1_DIM1));
|
2006-10-22 16:24:24 +08:00
|
|
|
|
|
|
|
// Create file FILE1
|
2020-09-30 22:27:10 +08:00
|
|
|
file1 = new H5File(FILE1, H5F_ACC_TRUNC);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for datasets
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims1[] = {SPACE1_DIM1};
|
2017-03-03 22:45:57 +08:00
|
|
|
DataSpace sid1(SPACE1_RANK, dims1);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataset access property list
|
|
|
|
PropList dapl(H5P_DATASET_ACCESS);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a group
|
|
|
|
Group group = file1->createGroup("Group1");
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Set group's comment
|
|
|
|
group.setComment(".", write_comment);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a dataset (inside /Group1)
|
|
|
|
DataSet dataset = group.createDataSet(DSET1_NAME, PredType::NATIVE_UINT, sid1);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
unsigned *tu32; // Temporary pointer to uint32 data
|
2022-07-11 23:59:51 +08:00
|
|
|
unsigned i;
|
2021-06-01 21:49:39 +08:00
|
|
|
for (tu32 = reinterpret_cast<unsigned *>(wbuf), i = 0; i < SPACE1_DIM1; i++)
|
2020-09-30 22:27:10 +08:00
|
|
|
*tu32++ = i * 3; // from C test
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write selection to disk
|
|
|
|
dataset.write(wbuf, PredType::NATIVE_UINT);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close Dataset
|
|
|
|
dataset.close();
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create another dataset (inside /Group1)
|
|
|
|
dataset = group.createDataSet("Dataset2", PredType::NATIVE_UCHAR, sid1);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close Dataset
|
|
|
|
dataset.close();
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a datatype to refer to
|
|
|
|
CompType dtype1(sizeof(s1_t));
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Insert fields
|
|
|
|
dtype1.insertMember(MEMBER1, HOFFSET(s1_t, a), PredType::NATIVE_INT);
|
|
|
|
dtype1.insertMember(MEMBER2, HOFFSET(s1_t, b), PredType::NATIVE_INT);
|
|
|
|
dtype1.insertMember(MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_FLOAT);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Save datatype for later
|
|
|
|
dtype1.commit(group, "Datatype1");
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close datatype and group
|
|
|
|
dtype1.close();
|
|
|
|
group.close();
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a dataset
|
|
|
|
dataset = file1->createDataSet("Dataset3", PredType::STD_REF_OBJ, sid1);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create reference to dataset and test getRefObjType
|
|
|
|
file1->reference(&wbuf[0], "/Group1/Dataset1");
|
|
|
|
H5O_type_t refobj_type = dataset.getRefObjType(&wbuf[0], H5R_OBJECT);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(refobj_type), static_cast<long>(H5O_TYPE_DATASET),
|
|
|
|
"DataSet::getRefObjType", __LINE__, __FILE__);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create reference to dataset and test getRefObjType
|
|
|
|
file1->reference(&wbuf[1], "/Group1/Dataset2");
|
|
|
|
refobj_type = dataset.getRefObjType(&wbuf[1], H5R_OBJECT);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(refobj_type), static_cast<long>(H5O_TYPE_DATASET),
|
|
|
|
"DataSet::getRefObjType", __LINE__, __FILE__);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create reference to group
|
|
|
|
file1->reference(&wbuf[2], "/Group1");
|
|
|
|
refobj_type = dataset.getRefObjType(&wbuf[2], H5R_OBJECT);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(refobj_type), static_cast<long>(H5O_TYPE_GROUP),
|
|
|
|
"DataSet::getRefObjType", __LINE__, __FILE__);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create reference to named datatype
|
|
|
|
file1->reference(&wbuf[3], "/Group1/Datatype1");
|
|
|
|
refobj_type = dataset.getRefObjType(&wbuf[3], H5R_OBJECT);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(refobj_type), static_cast<long>(H5O_TYPE_NAMED_DATATYPE),
|
|
|
|
"DataSet::getRefObjType", __LINE__, __FILE__);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write selection to disk
|
|
|
|
dataset.write(wbuf, PredType::STD_REF_OBJ);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close disk dataspace, dataset, and file
|
|
|
|
sid1.close();
|
|
|
|
dataset.close();
|
|
|
|
delete file1;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Re-open the file
|
|
|
|
file1 = new H5File(FILE1, H5F_ACC_RDWR);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the dataset
|
|
|
|
dataset = file1->openDataSet("/Dataset3");
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read selection from disk
|
|
|
|
dataset.read(rbuf, PredType::STD_REF_OBJ);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Dereference dataset object by ctor, from the location where
|
|
|
|
// 'dataset' is located
|
|
|
|
DataSet dset2(dataset, &rbuf[0], H5R_OBJECT, dapl);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check information in the referenced dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
sid1 = dset2.getSpace();
|
2017-03-03 22:45:57 +08:00
|
|
|
hssize_t n_elements = sid1.getSimpleExtentNpoints();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(n_elements), 4, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read from disk
|
|
|
|
dset2.read(tbuf, PredType::NATIVE_UINT);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2021-06-01 21:49:39 +08:00
|
|
|
for (tu32 = reinterpret_cast<unsigned *>(tbuf), i = 0; i < SPACE1_DIM1; i++, tu32++)
|
|
|
|
verify_val(*tu32, static_cast<uint32_t>(i * 3), "DataSpace::getSimpleExtentNpoints", __LINE__,
|
|
|
|
__FILE__);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close dereferenced dataset
|
|
|
|
dset2.close();
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Dereference group object from the location where 'dataset' is located
|
|
|
|
group.dereference(dataset, &rbuf[2]);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get group's comment using
|
|
|
|
// H5std_string getComment(const char* name, <buf_size=0 by default>)
|
|
|
|
H5std_string read_comment1 = group.getComment(".", 10);
|
2020-09-30 22:27:10 +08:00
|
|
|
verify_val(read_comment1.c_str(), write_comment, "Group::getComment", __LINE__, __FILE__);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Test with the old default value
|
|
|
|
read_comment1 = group.getComment(".", 256);
|
2020-09-30 22:27:10 +08:00
|
|
|
verify_val(read_comment1.c_str(), write_comment, "Group::getComment", __LINE__, __FILE__);
|
2014-04-26 03:47:57 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Test that getComment handles failures gracefully, using
|
|
|
|
// H5std_string getComment(const char* name, <buf_size=0 by default>)
|
|
|
|
try {
|
|
|
|
H5std_string read_comment_tmp = group.getComment(NULL);
|
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
|
|
|
} // We expect this to fail
|
2010-04-28 04:19:20 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close group
|
|
|
|
group.close();
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/*
|
|
|
|
* Verify correct referenced datatype
|
|
|
|
*/
|
|
|
|
// Open datatype object
|
|
|
|
dtype1.dereference(dataset, &rbuf[3]);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify correct datatype
|
2013-09-23 08:39:44 +08:00
|
|
|
H5T_class_t tclass;
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2013-09-23 08:39:44 +08:00
|
|
|
tclass = dtype1.getClass();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(tclass), static_cast<long>(H5T_COMPOUND), "DataType::getClass", __LINE__,
|
|
|
|
__FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
int n_members = dtype1.getNmembers();
|
2020-09-30 22:27:10 +08:00
|
|
|
verify_val(n_members, 3, "CompType::getNmembers", __LINE__, __FILE__);
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close all objects and file
|
|
|
|
dtype1.close();
|
|
|
|
dataset.close();
|
|
|
|
file1->close();
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Free allocated buffers
|
2023-06-29 06:48:12 +08:00
|
|
|
free(wbuf);
|
|
|
|
free(rbuf);
|
|
|
|
free(tbuf);
|
2007-03-18 00:26:53 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2006-10-22 16:24:24 +08:00
|
|
|
} // end try
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
|
|
|
issue_fail_msg("test_reference_obj()", __LINE__, __FILE__, E.getCFuncName(), E.getCDetailMsg());
|
2006-10-22 16:24:24 +08:00
|
|
|
}
|
2011-02-06 11:24:42 +08:00
|
|
|
|
2021-03-23 01:51:18 +08:00
|
|
|
delete file1;
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_reference_obj()
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_reference_group
|
|
|
|
*
|
|
|
|
* Purpose Test object reference functionality on group.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
#define GROUPNAME "/group"
|
|
|
|
#define GROUPNAME2 "group2"
|
|
|
|
#define GROUPNAME3 "group3"
|
|
|
|
#define DSETNAME "/dset"
|
|
|
|
#define DSETNAME2 "dset2"
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_reference_group()
|
2013-09-23 08:39:44 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hobj_ref_t wref; /* Reference to write */
|
|
|
|
hobj_ref_t rref; /* Reference to read */
|
|
|
|
const H5std_string write_comment = "Foo!"; // Comments for group
|
2013-09-23 08:39:44 +08:00
|
|
|
|
|
|
|
// Output message about test being performed
|
|
|
|
SUBTEST("Object Reference to Group");
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
H5File *file1 = NULL;
|
2013-09-23 08:39:44 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
/*
|
|
|
|
* Create file with a group and a dataset containing an object
|
|
|
|
* reference to the group
|
|
|
|
*/
|
2013-09-23 08:39:44 +08:00
|
|
|
|
|
|
|
// Create file FILE1
|
2020-09-30 22:27:10 +08:00
|
|
|
file1 = new H5File(FILE1, H5F_ACC_TRUNC);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create scalar dataspace
|
|
|
|
DataSpace sid1;
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a group
|
|
|
|
Group group = file1->createGroup(GROUPNAME);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Create nested groups */
|
|
|
|
Group group2 = group.createGroup(GROUPNAME2);
|
|
|
|
group2.close();
|
|
|
|
group2 = group.createGroup(GROUPNAME3);
|
|
|
|
group2.close();
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create bottom dataset
|
|
|
|
DataSet dset1 = group.createDataSet(DSETNAME2, PredType::NATIVE_INT, sid1);
|
|
|
|
dset1.close();
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close group 1
|
|
|
|
group.close();
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataset
|
|
|
|
DataSet dset2 = file1->createDataSet(DSETNAME, PredType::STD_REF_OBJ, sid1);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
file1->reference(&wref, GROUPNAME);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write selection to disk
|
|
|
|
dset2.write(&wref, PredType::STD_REF_OBJ);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close resources
|
|
|
|
dset2.close();
|
|
|
|
sid1.close();
|
|
|
|
file1->close();
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/*
|
2022-08-11 04:57:26 +08:00
|
|
|
* Re-open the file and test dereferencing group
|
2017-03-03 22:45:57 +08:00
|
|
|
*/
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Re-open file
|
2013-09-23 08:39:44 +08:00
|
|
|
file1->openFile(FILE1, H5F_ACC_RDWR);
|
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Re-open dataset
|
|
|
|
dset1 = file1->openDataSet(DSETNAME);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read in the reference
|
|
|
|
dset1.read(&rref, PredType::STD_REF_OBJ);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Dereference to get the group
|
|
|
|
Group refgroup(dset1, &rref);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Dereference group object the other way
|
|
|
|
group.dereference(dset1, &rref);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/*
|
|
|
|
* Various queries on the group opened
|
|
|
|
*/
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check number of objects in the group dereferenced by constructor
|
|
|
|
hsize_t nobjs = refgroup.getNumObjs();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(nobjs), 3, "H5Group::getNumObjs", __LINE__, __FILE__);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check number of objects in the group dereferenced by ::reference
|
|
|
|
nobjs = group.getNumObjs();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(nobjs), 3, "H5Group::getNumObjs", __LINE__, __FILE__);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check getting file name given the group dereferenced via constructor
|
|
|
|
H5std_string fname = refgroup.getFileName();
|
2020-09-30 22:27:10 +08:00
|
|
|
verify_val(fname, FILE1, "H5Group::getFileName", __LINE__, __FILE__);
|
2020-04-21 07:12:00 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check getting file name given the group dereferenced by ::reference
|
|
|
|
fname = group.getFileName();
|
2020-09-30 22:27:10 +08:00
|
|
|
verify_val(fname, FILE1, "H5Group::getFileName", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
2018-07-21 13:40:57 +08:00
|
|
|
// Check object type using Group::getObjinfo()
|
2020-01-17 05:29:34 +08:00
|
|
|
H5O_info2_t oinfo;
|
2023-06-30 03:33:46 +08:00
|
|
|
memset(&oinfo, 0, sizeof(oinfo));
|
2021-06-01 21:49:39 +08:00
|
|
|
group.getObjinfo(".", H5_INDEX_NAME, H5_ITER_INC, 0, oinfo);
|
|
|
|
verify_val(static_cast<long>(oinfo.type), static_cast<long>(H5O_TYPE_DATASET), "Group::getObjinfo",
|
|
|
|
__LINE__, __FILE__);
|
Fixed HDFFV-10458 partially
Description:
Added wrappers for H5Oget_info_by_idx2.
// Returns information about an HDF5 object, given its index.
void getInfo(const char* grp_name, H5_index_t idx_type,
H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo,
unsigned fields = H5O_INFO_BASIC,
const LinkAccPropList& lapl = LinkAccPropList::DEFAULT)
void getInfo(const H5std_string& grp_name, H5_index_t idx_type,
H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo,
unsigned fields = H5O_INFO_BASIC,
const LinkAccPropList& lapl = LinkAccPropList::DEFAULT)
Platforms tested:
Linux/64 (jelly)
Linux/32 (jam)
Darwin (osx1010test)
2018-07-17 22:12:10 +08:00
|
|
|
|
|
|
|
// Check for out of bound query by index
|
|
|
|
try {
|
2023-06-30 03:33:46 +08:00
|
|
|
memset(&oinfo, 0, sizeof(oinfo));
|
2021-06-01 21:49:39 +08:00
|
|
|
group.getObjinfo(".", H5_INDEX_NAME, H5_ITER_INC, 9, oinfo);
|
Fixed HDFFV-10458 partially
Description:
Added wrappers for H5Oget_info_by_idx2.
// Returns information about an HDF5 object, given its index.
void getInfo(const char* grp_name, H5_index_t idx_type,
H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo,
unsigned fields = H5O_INFO_BASIC,
const LinkAccPropList& lapl = LinkAccPropList::DEFAULT)
void getInfo(const H5std_string& grp_name, H5_index_t idx_type,
H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo,
unsigned fields = H5O_INFO_BASIC,
const LinkAccPropList& lapl = LinkAccPropList::DEFAULT)
Platforms tested:
Linux/64 (jelly)
Linux/32 (jam)
Darwin (osx1010test)
2018-07-17 22:12:10 +08:00
|
|
|
|
|
|
|
// Should FAIL but didn't, so throw an invalid action exception
|
2018-07-21 13:40:57 +08:00
|
|
|
throw InvalidActionException("Group::getObjinfo", "Out of bound index.");
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
catch (Exception &err) {
|
|
|
|
} // do nothing, failure expected
|
Fixed HDFFV-10458 partially
Description:
Added wrappers for H5Oget_info_by_idx2.
// Returns information about an HDF5 object, given its index.
void getInfo(const char* grp_name, H5_index_t idx_type,
H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo,
unsigned fields = H5O_INFO_BASIC,
const LinkAccPropList& lapl = LinkAccPropList::DEFAULT)
void getInfo(const H5std_string& grp_name, H5_index_t idx_type,
H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo,
unsigned fields = H5O_INFO_BASIC,
const LinkAccPropList& lapl = LinkAccPropList::DEFAULT)
Platforms tested:
Linux/64 (jelly)
Linux/32 (jam)
Darwin (osx1010test)
2018-07-17 22:12:10 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Unlink one of the objects in the dereferenced group, and re-check
|
|
|
|
refgroup.unlink(GROUPNAME2);
|
|
|
|
nobjs = refgroup.getNumObjs();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(nobjs), 2, "H5Group::getNumObjs", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Close resources
|
|
|
|
group.close();
|
|
|
|
refgroup.close();
|
|
|
|
dset1.close();
|
|
|
|
file1->close();
|
|
|
|
|
|
|
|
PASSED();
|
2013-09-23 08:39:44 +08:00
|
|
|
} // end try
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
|
|
|
issue_fail_msg("test_reference_group()", __LINE__, __FILE__, E.getCFuncName(), E.getCDetailMsg());
|
2013-09-23 08:39:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-23 01:51:18 +08:00
|
|
|
delete file1;
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* test_reference_group() */
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_reference_region_1D
|
|
|
|
*
|
|
|
|
* Purpose Test 1-D reference functionality on various kinds of objects.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_reference_region_1D()
|
2013-09-23 08:39:44 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t start[SPACE3_RANK]; /* Starting location of hyperslab */
|
|
|
|
hsize_t stride[SPACE3_RANK]; /* Stride of hyperslab */
|
|
|
|
hsize_t count[SPACE3_RANK]; /* Element count of hyperslab */
|
|
|
|
hsize_t block[SPACE3_RANK]; /* Block size of hyperslab */
|
|
|
|
hsize_t coord1[POINT1_NPOINTS][SPACE3_RANK]; /* Coordinates for point selection */
|
|
|
|
hsize_t *coords; /* Coordinate buffer */
|
|
|
|
hsize_t low[SPACE3_RANK]; /* Selection bounds */
|
|
|
|
hsize_t high[SPACE3_RANK]; /* Selection bounds */
|
|
|
|
int i; /* counting variables */
|
2013-09-23 08:39:44 +08:00
|
|
|
|
|
|
|
// Output message about test being performed
|
|
|
|
SUBTEST("1-D Dataset Region Reference Functions");
|
|
|
|
|
|
|
|
try {
|
2020-09-30 22:27:10 +08:00
|
|
|
hdset_reg_ref_t *wbuf, // buffer to write to disk
|
|
|
|
*rbuf; // buffer read from disk
|
|
|
|
uint8_t *dwbuf, // Buffer for writing numeric data to disk
|
|
|
|
*drbuf; // Buffer for reading numeric data from disk
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Allocate write & read buffers
|
2023-06-29 06:48:12 +08:00
|
|
|
wbuf = static_cast<hdset_reg_ref_t *>(calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1));
|
|
|
|
rbuf = static_cast<hdset_reg_ref_t *>(malloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1));
|
|
|
|
dwbuf = static_cast<uint8_t *>(malloc(sizeof(uint8_t) * SPACE3_DIM1));
|
|
|
|
drbuf = static_cast<uint8_t *>(calloc(sizeof(uint8_t), SPACE3_DIM1));
|
2013-09-23 08:39:44 +08:00
|
|
|
|
|
|
|
// Create file FILE1
|
|
|
|
H5File file1(FILE2, H5F_ACC_TRUNC);
|
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for datasets
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims3[] = {SPACE3_DIM1};
|
2017-03-03 22:45:57 +08:00
|
|
|
DataSpace sid3(SPACE3_RANK, dims3);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataset access property list
|
|
|
|
PropList dapl(H5P_DATASET_ACCESS);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a dataset
|
|
|
|
DataSet dset3 = file1.createDataSet(DSET2_NAME, PredType::STD_U8LE, sid3);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
uint8_t *tu8; // Temporary pointer to uint8 data
|
2017-03-03 22:45:57 +08:00
|
|
|
for (tu8 = dwbuf, i = 0; i < SPACE3_DIM1; i++)
|
2021-06-01 21:49:39 +08:00
|
|
|
*tu8++ = static_cast<uint8_t>(i); // from C test
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write selection to disk
|
|
|
|
dset3.write(dwbuf, PredType::STD_U8LE);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close Dataset
|
|
|
|
dset3.close();
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for datasets
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims1[] = {SPACE1_DIM1};
|
2017-03-03 22:45:57 +08:00
|
|
|
DataSpace sid1(SPACE1_RANK, dims1);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a dataset
|
|
|
|
DataSet dset1 = file1.createDataSet(DSET1_NAME, PredType::STD_REF_DSETREG, sid1);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/*
|
|
|
|
* Create references and prepare for testing
|
|
|
|
*/
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Select 15 2x1 hyperslabs for first reference */
|
2020-09-30 22:27:10 +08:00
|
|
|
start[0] = 2;
|
2017-03-03 22:45:57 +08:00
|
|
|
stride[0] = 5;
|
2020-09-30 22:27:10 +08:00
|
|
|
count[0] = 15;
|
|
|
|
block[0] = 2;
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Select a hyperslab region to add to the current selected region
|
|
|
|
sid3.selectHyperslab(H5S_SELECT_SET, count, start, stride, block);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get and verify the number of elements in a dataspace selection
|
|
|
|
hssize_t nelms = sid3.getSelectNpoints();
|
2020-09-30 22:27:10 +08:00
|
|
|
verify_val(nelms, 30, "DataSet::getRefObjType", __LINE__, __FILE__);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Store first dataset region
|
|
|
|
file1.reference(&wbuf[0], "/Dataset2", sid3);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get and verify object type
|
|
|
|
H5O_type_t obj_type = dset1.getRefObjType(&wbuf[0], H5R_DATASET_REGION);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(obj_type), static_cast<long>(H5O_TYPE_DATASET), "DataSet::getRefObjType",
|
|
|
|
__LINE__, __FILE__);
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Select sequence of ten points for second reference */
|
|
|
|
coord1[0][0] = 16;
|
|
|
|
coord1[1][0] = 22;
|
|
|
|
coord1[2][0] = 38;
|
|
|
|
coord1[3][0] = 41;
|
|
|
|
coord1[4][0] = 52;
|
|
|
|
coord1[5][0] = 63;
|
|
|
|
coord1[6][0] = 70;
|
|
|
|
coord1[7][0] = 89;
|
|
|
|
coord1[8][0] = 97;
|
|
|
|
coord1[9][0] = 3;
|
|
|
|
|
|
|
|
// Selects array elements to be included in the selection for sid3
|
2021-06-01 21:49:39 +08:00
|
|
|
sid3.selectElements(H5S_SELECT_SET, POINT1_NPOINTS, reinterpret_cast<const hsize_t *>(coord1));
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Get and verify the number of elements in a dataspace selection
|
|
|
|
nelms = sid3.getSelectNpoints();
|
2020-09-30 22:27:10 +08:00
|
|
|
verify_val(nelms, 10, "DataSet::getRefObjType", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Store first dataset region
|
|
|
|
file1.reference(&wbuf[1], "/Dataset2", sid3);
|
|
|
|
|
|
|
|
// Write selection to disk
|
|
|
|
dset1.write(wbuf, PredType::STD_REF_DSETREG);
|
|
|
|
|
|
|
|
// Close disk dataspace, dataset, and file
|
|
|
|
sid1.close();
|
|
|
|
dset1.close();
|
|
|
|
sid3.close();
|
|
|
|
file1.close();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing various dereference functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Re-open the file
|
|
|
|
file1.openFile(FILE2, H5F_ACC_RDWR);
|
|
|
|
|
|
|
|
// Open the dataset
|
|
|
|
dset1 = file1.openDataSet("/Dataset1");
|
|
|
|
|
|
|
|
// Read selection from disk
|
|
|
|
dset1.read(rbuf, PredType::STD_REF_DSETREG);
|
|
|
|
|
|
|
|
{ // Test DataSet::dereference
|
|
|
|
dset3.dereference(dset1, &rbuf[0], H5R_DATASET_REGION, dapl);
|
|
|
|
|
|
|
|
// Get and verify object type
|
|
|
|
obj_type = dset1.getRefObjType(&rbuf[0], H5R_DATASET_REGION);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(obj_type), static_cast<long>(H5O_TYPE_DATASET),
|
|
|
|
"DataSet::getRefObjType", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Get dataspace of dset3 the verify number of elements
|
2020-09-30 22:27:10 +08:00
|
|
|
sid1 = dset3.getSpace();
|
2017-03-03 22:45:57 +08:00
|
|
|
nelms = sid1.getSimpleExtentNpoints();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(nelms), 100, "DataSpace::getSimpleExtentNpoints", __LINE__,
|
|
|
|
__FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
} // End of test DataSet::dereference
|
|
|
|
|
|
|
|
{ // Test DataSet constructor -by dereference
|
|
|
|
// Dereference dataset object by ctor, from the location where
|
|
|
|
// 'dset1' is located
|
|
|
|
DataSet newds(dset1, &rbuf[0], H5R_DATASET_REGION, dapl);
|
|
|
|
|
|
|
|
// Get dataspace of newds then verify number of elements
|
2020-09-30 22:27:10 +08:00
|
|
|
sid1 = newds.getSpace();
|
2017-03-03 22:45:57 +08:00
|
|
|
nelms = sid1.getSimpleExtentNpoints();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(nelms), 100, "DataSpace::getSimpleExtentNpoints", __LINE__,
|
|
|
|
__FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Close objects for this mini test
|
|
|
|
newds.close();
|
|
|
|
sid1.close();
|
|
|
|
} // End of test DataSet constructor -by dereference
|
|
|
|
|
|
|
|
// Read from disk
|
|
|
|
dset3.read(drbuf, PredType::STD_U8LE);
|
|
|
|
|
2021-06-01 21:49:39 +08:00
|
|
|
for (tu8 = static_cast<uint8_t *>(drbuf), i = 0; i < SPACE3_DIM1; i++, tu8++)
|
|
|
|
verify_val(*tu8, static_cast<uint8_t>(i), "DataSpace::getSimpleExtentNpoints", __LINE__,
|
|
|
|
__FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test getting the referenced region
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Get region
|
|
|
|
DataSpace reg_sp = dset1.getRegion(&rbuf[0]);
|
|
|
|
|
|
|
|
// Get and verify number of elements in a dataspace selection
|
|
|
|
nelms = reg_sp.getSelectNpoints();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(nelms), 30, "DataSpace::getSelectNpoints", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Get and verify number of hyperslab blocks
|
|
|
|
nelms = reg_sp.getSelectHyperNblocks();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(nelms), 15, "DataSpace::getSelectNpoints", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
/* Allocate space for the hyperslab blocks */
|
2022-07-11 23:59:51 +08:00
|
|
|
coords =
|
2023-06-29 06:48:12 +08:00
|
|
|
static_cast<hsize_t *>(malloc(static_cast<size_t>(nelms) * SPACE3_RANK * sizeof(hsize_t) * 2));
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Get the list of hyperslab blocks currently selected
|
2021-06-01 21:49:39 +08:00
|
|
|
reg_sp.getSelectHyperBlocklist(0, static_cast<hsize_t>(nelms), coords);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Verify values in the list
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(coords[0]), 2, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[1]), 3, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[2]), 7, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[3]), 8, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[4]), 12, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[5]), 13, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[6]), 17, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[7]), 18, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[8]), 22, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[9]), 23, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[10]), 27, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[11]), 28, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[12]), 32, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[13]), 33, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[14]), 37, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[15]), 38, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[16]), 42, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[17]), 43, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[18]), 47, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[19]), 48, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[20]), 52, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[21]), 53, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[22]), 57, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[23]), 58, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[24]), 62, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[25]), 63, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[26]), 67, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[27]), 68, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[28]), 72, "Hyperslab Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(coords[29]), 73, "Hyperslab Coordinates", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
2023-06-29 06:48:12 +08:00
|
|
|
free(coords);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Check boundaries
|
|
|
|
reg_sp.getSelectBounds(low, high);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(low[0]), 2, "DataSpace::getSelectBounds", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(high[0]), 73, "DataSpace::getSelectBounds", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
/* Close region space */
|
|
|
|
reg_sp.close();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Another test on getting the referenced region
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Get region
|
|
|
|
DataSpace elm_sp = dset1.getRegion(&rbuf[1]);
|
|
|
|
|
|
|
|
// Get and verify number of element points in the current selection
|
|
|
|
hssize_t nelmspts = elm_sp.getSelectElemNpoints();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(nelmspts), 10, "DataSpace::getSelectNpoints", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
/* Allocate space for the hyperslab blocks */
|
2022-07-11 23:59:51 +08:00
|
|
|
coords =
|
2023-06-29 06:48:12 +08:00
|
|
|
static_cast<hsize_t *>(malloc(static_cast<size_t>(nelmspts) * SPACE3_RANK * sizeof(hsize_t)));
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Get the list of element points currently selected
|
2021-06-01 21:49:39 +08:00
|
|
|
elm_sp.getSelectElemPointlist(0, static_cast<hsize_t>(nelmspts), coords);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Verify points
|
2020-09-30 22:27:10 +08:00
|
|
|
verify_val(coords[0], coord1[0][0], "Element Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(coords[1], coord1[1][0], "Element Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(coords[2], coord1[2][0], "Element Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(coords[3], coord1[3][0], "Element Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(coords[4], coord1[4][0], "Element Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(coords[5], coord1[5][0], "Element Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(coords[6], coord1[6][0], "Element Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(coords[7], coord1[7][0], "Element Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(coords[8], coord1[8][0], "Element Coordinates", __LINE__, __FILE__);
|
|
|
|
verify_val(coords[9], coord1[9][0], "Element Coordinates", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
2023-06-29 06:48:12 +08:00
|
|
|
free(coords);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Check boundaries
|
|
|
|
elm_sp.getSelectBounds(low, high);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(low[0]), 3, "DataSpace::getSelectBounds", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(high[0]), 97, "DataSpace::getSelectBounds", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Close element space
|
|
|
|
elm_sp.close();
|
|
|
|
|
|
|
|
// Close resources
|
|
|
|
sid1.close();
|
|
|
|
dset3.close();
|
|
|
|
dset1.close();
|
|
|
|
file1.close();
|
|
|
|
|
|
|
|
// Free memory buffers
|
2023-06-29 06:48:12 +08:00
|
|
|
free(wbuf);
|
|
|
|
free(rbuf);
|
|
|
|
free(dwbuf);
|
|
|
|
free(drbuf);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
PASSED();
|
2013-09-23 08:39:44 +08:00
|
|
|
} // end try
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
|
|
|
issue_fail_msg("test_reference_region_1D()", __LINE__, __FILE__, E.getCFuncName(), E.getCDetailMsg());
|
2013-09-23 08:39:44 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* test_reference_region_1D() */
|
2013-09-23 08:39:44 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* test_reference(): Main reference testing routine.
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
extern "C" void
|
|
|
|
test_reference()
|
2006-10-22 16:24:24 +08:00
|
|
|
{
|
|
|
|
// Output message about test being performed
|
|
|
|
MESSAGE(5, ("Testing References\n"));
|
|
|
|
|
2013-09-23 08:39:44 +08:00
|
|
|
test_reference_params(); // Test basic parameters of reference functionality
|
2006-10-22 16:24:24 +08:00
|
|
|
test_reference_obj(); // Test basic object reference functionality
|
2013-09-23 08:39:44 +08:00
|
|
|
test_reference_group(); // Test group reference functionality
|
|
|
|
test_reference_region_1D(); // Test 1-D reference functionality
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_reference()
|
2006-10-22 16:24:24 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: cleanup_reference
|
|
|
|
*
|
|
|
|
* Purpose Cleanup temporary test files
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
extern "C" void
|
|
|
|
cleanup_reference()
|
2006-10-22 16:24:24 +08:00
|
|
|
{
|
2007-03-18 00:26:53 +08:00
|
|
|
HDremove(FILE1.c_str());
|
2013-09-23 08:39:44 +08:00
|
|
|
HDremove(FILE2.c_str());
|
2006-10-22 16:24:24 +08:00
|
|
|
}
|