Files
hdf5/c++/test/trefer.cpp
Dana Robinson 9a4b225cb0 VFD SWMR: sync with develop (#725)
* Brings CMake updates from develop

* Brings reduction in pedantic casts from develop

* Purges UFAIL from the library (#637)

* Committing clang-format changes

* Purges UFAIL from the library

* H5HL_insert change requested in PR

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Removes gratuitous (double)x.yF casts (#632)

* Committing clang-format changes

* Removes gratuitous (double)x.yF casts

* Committing clang-format changes

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Committing clang-format changes

* Cleans up a const warning left over from previous constification (#633)

* Committing clang-format changes

* Adds consts to a few global variables

* Cleans up a const warning left over from previous constification

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Formatted source

* Bring over some VOL registration changes

* VOL cleanup

* H5VL_request_status_t substitutions

* H5F.c cleanup

* Minor API tweaks from develop

* Moves H5G package init/teardown to H5Gint.c

* H5G cleanup

* H5M cleanup

* H5SM cleanup

* H5T cleanup

* H5R cleanup

* H5Lpublic.h cleanup

* H5L cleanup

* H5O cleanup

* H5A, H5CS, and H5AC cleanup

* Moved H5A init/teardown code to H5Aint.c

* Moves H5D I/O functions to H5D.c

* H5D cleanup

* Misc minor cleanup

* H5P close cleanup

* H5Tpublic.h cleanup

* Fixes err_compat test

* H5PLpublic.h cleanup

* Updates H5Ppublic.h

* H5Fpublic.h updates

* H5A.c cleanup

* Brings over H5Aexists and related changes

* Brings CMake shell testing changes from develop

* Close callback changes

* H5R and H5Tcommit normalization

* err_compat test works now

* H5O tweaks

* Updates VOL registration code

* Brings over H5VL_create_object

* H5Tconv.c reformatting

* H5T.c tweaks

* Brings datatype and reference updates from develop

* Brings VOL plugin loading changes from develop

* Brings event sets from develop

* Brings async functions over

* Tools changes

* Brings over many tools changes from develop

* Brings VOL flags from develop

* Fixes h5dump double/float tests

* Updates h5repack tests

* Brings h5diff test changes from develop

* Last h5dump changes

* Brings test changes from develop

* Committing clang-format changes

* Tidied h5_testing()

* Brings chunk iteration code + misc from develop

* Updates vds test

* Enables external link parallel test

* Brings updated property lists from develop

* H5G changes from develop

* H5MF cleanup

* Brings vfd_swmr test back into CMake

* Updates threadsafe test

* Updates plist test

* Brings recent changes from develop

* Require a C++11 compiler to build the C++ wrappers (#693)

* Committing clang-format changes

* Requires a C++11 compiler to build the C++ wrappers

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Fix H5FD_mpio_Debug="rw" can report MPI_count instead of bytes (#699)

* Removes pre-C99 build and header cruft (#700)

* Assumes ANSI C headers exist
* Assumes stdbool.h, stdint.h, and inttypes.h are present
* Assumes the C++ compiler can handle stdint.h
* Removes all work-arounds for missing functionality, especially stdbool.h

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Updates release documents

* Brings parallel changes from develop

* Adds a VFD/parallel check program for the VFD SWMR shell test

* Updates MANIFEST

* Disable building VFD SWMR acceptance tests on CMake

* Removes err.h from genall5.c

* Partial cleanup of H5Cpkg.h

* Fixes printf specifiers in H5Cdbg.c

* Java and fortran cmake changes (#694)

* OESS-98 convert plugin option to FetchContent, add tests

* Fixes for pkcfg files because of plugin option

* OESS-98 fix tools test for plugins

* Keep doxygen comments under 100 chars long - format hint

* Whitespace

* HDFFV-11144 - Reclassify CMake messages

* HDFFV-11099/11100 added help text

* Reworked switch statement to compare string instead

* Fix typo

* Update CDash mode

* Correct name of threadsafe

* Correct option name

* Undo accidental commit

* Note LLVM 10 to 11 format default changes

* Update format plugin

* Undo clang-format version 11 changes

* One more correction

* Update supported platforms

* Revert whitespace changes

* Correct whitespace

* Changes from PR#3

* HDFFV-11213 added option to control gcc10 warnings diagnostics

* HDFFV-11212 Use the new references correctly in JNI utility and tests

* format source

* Fix typo

* Add new test file

* HDFFV-11212 - update test and remove unused arg

* Minor non-space formatting changes

* Use H5I_INVALID_ID instead of "-1"

* source formatting

* add missing testfile, update jni function

* Undo commit of debug code

* remove mislocated file

* Fix h5repack test for handling of fapls and id close

* Update h5diff test files usage text

* HDFFV-11212 add new ref tests for JNI export dataset

* src format update

* Remove blank line typo

* src format typo

* long double requires %Lg

* Another long double foramt specifer S.B. %Lg

* issue with t128bit test

* Windows issue with h5dump and type.

* Fix review issues

* refactor function nesting and fix error checks

* format fixes

* Remove untested functions and javadoc quiet comments

* Restore TRY block.

* Change string append errors to memory exception

* revert to H5_JNI_FATAL_ERROR - support functions need work

* Add assertion error for h5util functions

* remove duplicate function

* format fix

* Revert HD function error handling

* Update copyright comments

* GH #386 java folder copyright corrections

* Whitespace

* GH #359 implement and fix tools 1.6 API usage

* remove excessive comments

* Flip inits to correct ifdef section

* rework ifdef to be simpler

* format issue

* Reformat ifdef inits

* remove static attribute

* format compliance

* Update names

* Revert because logic relies on float not being int

* Changes noticed from creating merge of #412

* Double underscore change

* Correct compiler version variable used

* Remove header guard underscores

* Whitespace cleanup

* Split format source and commit changes on repo push

* remove pre-split setting

* Change windows TS to use older VS.

* correct window os name

* HDFFV-11212 JNI export util and Javadoc

* Suggested review changes

* Another change found

* Committing clang-format changes

* HDFFV-11113 long double in tools

* HDFFV-11113 add note

* Disable long double tests for now

* HDFFV-11228 remove arbitrary CMake warning groups.

* Make each flag a string

* Some Javadoc warning fixes

* Updated javadoc fixes

* # WARNING: head commit changed in the meantime

HDFFV-11229 Fix long double usage in tools and java

Changed h5dump and h5ls to just print 128-bit for long double type.
Added test and file for dataset and attributes with all three float
types.

* Committing clang-format changes

* HDFFV-11229 Add release note

* HDFFV-11229 windows testfile needed

* fix typo

* Remove non supported message text

* HDFFV-11229 - change ldouble test to check both native and general

* HDFFV-11229 add second file compare

* HDFFV-11229 fix reference file

* HDFFV-11229 autotools check two refs

* HDFFV-11229 revert back to removal of NATIVE_LDOUBLE in tools output

* Committing clang-format changes

* Update release note

* Update attribute type of ref file

* Change source of ninja for macs

* try port instead of brew

* Recommended is to use brew.

* Undo non long double changes

* remove unneeded file

* Fix perl and doxygen CMake code

* Add "option" command for clang options

* Rework CMake add_custom to use the BYPRODUCTS argument

* Add stamp files to BYPRODUCTS

* Only one copy of file exists

* Fix custom cmmand depends targets

* Fix fortran custom command DEPENDS

* Add LD_LIBRARY_PATH to tests

* Add custom target for DEPENDS

* Add h5detect conditionaly to generated target DEPENDS

* Correct DEPENDS targets

* Parallel builds need the mpi compiler for pkgconfig scripts.

* install only if MPI build

* Fortran target depends

* Remove incorrect source attribute

* doxygen adjustments

* doxygen build updates

* Correct version

* Correct function version - function has been merged to 1.12

* Correct version string for map functions

* Cleanup warnings for tools debug builds

* TRILAB-227 - fix indexing for h5diff selections

* Correct location of pos to index function call

* TRILAB-227 Enable test

* Quote subset args

* Use MATCHES because of AppleClang

* if blocks needed for build modes

* Update list of DT platforms

* VS2019 correctly displays float values

* revert VS2019 change

* Issue #669 remove version from pkgcfg filename

* remove version from h5cc script

* Java reference functions updated

enabled fortran in cmake gcc action yaml file
java reference test changed to correctly test refs
jni reference functions that create ids changed to use jni id logging

* Correct BYPRODUCTS argument

* Correct more genereated files BYPRODUCTS

* BYPRODUCTS must have unique locations

* Fix typo

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Removes alternative function enter/leave macro scheme (#678)

* Committing clang-format changes

* Converted BEGIN_FUNC, etc. macros to FUNC_ENTER

* Rips out the BEGIN_FUNC, etc. macros

* Removes 'end if', etc. comments from H5HL package

* Committing clang-format changes

* Fixes an H5EA iterate issue

* Fixes an issue in the H5FA iterator code

* Further cleanup in bin/trace after macro removal

* Iterator changes in H5EA and H5FA

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Split H5L.c internal code to H5Lint.c (#691)

* Committing clang-format changes

* Splits internal parts of H5L.c to H5Lint.c

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Clean up type size checks in configure.ac (#702)

* Committing clang-format changes

* C++ warning and build fixes (#707)

* Committing clang-format changes

* C++ build and warning updates

* Fixes all warnings on C++ (with gcc 9.3)
* Updates CMake and Autotools C++ builds

* Undo warning clobber

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Removes some DEC Alpha cruft from H5detect and H5private.h (#708)

* Cleans up hsize_t and haddr_t size guessing (#709)

* Cleans up definitions of haddr_t and hsize_t + cruft removal

* Formatted source

* Updates PGI C/C++ configurations (#715)

* Updates PGI C/C++ configurations

Tweaks some settings and configures pgc++ to use C++11

* Updated copyright information

* Adds an Intel C++ configuration file (#716)

* Adds an Intel C++ configuration file

* Committing clang-format changes

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Updates bin/trace script to correctly wrap H5TRACE macros near clang-format column limit (#719)

* Removes clang-format comments from H5O.c call

* Fixes bin/trace to correctly wrap lines near the clang-format limit

* Removed unused variable from bin/trace

* Fixes issue with ccmake that prevents building Fortran (#723)

ccmake runs iteratively, and the check_fortran_source_runs
macros were clobbering a single output file that did not
get updated on further configure iterations

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2021-06-04 07:29:02 -07:00

856 lines
32 KiB
C++

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*****************************************************************************
FILE
trefer.cpp - HDF5 C++ testing the functionalities associated with the C
Reference interface (H5R)
***************************************************************************/
#include <iostream>
using std::cerr;
using std::endl;
#include <string>
#include "H5Cpp.h" // C++ API header file
using namespace H5;
#include "h5test.h"
#include "h5cpputil.h" // C++ utilility header file
const H5std_string FILE1("trefer1.h5");
const H5std_string FILE2("trefer2.h5");
// Dataset 1
const H5std_string DSET1_NAME("Dataset1");
const H5std_string DSET2_NAME("Dataset2");
const H5std_string MEMBER1("a_name");
const H5std_string MEMBER2("b_name");
const H5std_string MEMBER3("c_name");
// 1-D dataset with fixed dimensions
const int SPACE1_RANK = 1;
const int SPACE1_DIM1 = 4;
/* Larger 1-D dataset with fixed dimensions */
const int SPACE3_RANK = 1;
const int SPACE3_DIM1 = 100;
/* Element selection information */
const int POINT1_NPOINTS = 10;
// Compound datatype
typedef struct s1_t {
unsigned int a;
unsigned int b;
float c;
} s1_t;
/*-------------------------------------------------------------------------
* Function: test_reference_params
*
* Purpose Test basic H5R (reference) parameters for correct processing
*
* Return None
*-------------------------------------------------------------------------
*/
static void
test_reference_params()
{
const char *write_comment = "Foo!"; /* Comments for group */
// Output message about test being performed
SUBTEST("Object Reference Parameters");
H5File *file1 = NULL;
try {
hobj_ref_t *wbuf, // buffer to write to disk
*rbuf, // buffer read from disk
*tbuf; // temp. buffer read from disk
// Allocate write & read buffers
int temp_size = MAX(sizeof(unsigned), sizeof(hobj_ref_t));
wbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
rbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
tbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
// Create file FILE1
file1 = new H5File(FILE1, H5F_ACC_TRUNC);
// Create dataspace for datasets
hsize_t dims1[] = {SPACE1_DIM1};
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);
unsigned *tu32; // Temporary pointer to uint32 data
int i;
for (tu32 = reinterpret_cast<unsigned *>(wbuf), i = 0; i < SPACE1_DIM1; i++)
*tu32++ = i * 3; // from C test
// 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");
}
catch (ReferenceException &E) {
} // We expect this to fail
try {
file1->reference(&wbuf[0], NULL);
}
catch (ReferenceException &E) {
} // We expect this to fail
try {
file1->reference(&wbuf[0], "");
}
catch (ReferenceException &E) {
} // We expect this to fail
try {
file1->reference(&wbuf[0], "/Group1/Dataset1", H5R_MAXTYPE);
}
catch (ReferenceException &E) {
} // We expect this to fail
try {
file1->reference(&wbuf[0], "/Group1/Dataset1", H5R_DATASET_REGION);
}
catch (ReferenceException &E) {
} // We expect this to fail
// Close resources
dataset.close();
file1->close();
// Let sid1 go out of scope
// Free memory buffers
HDfree(wbuf);
HDfree(rbuf);
HDfree(tbuf);
PASSED();
} // end try
catch (Exception &E) {
issue_fail_msg("test_reference_param()", __LINE__, __FILE__, E.getCFuncName(), E.getCDetailMsg());
}
delete file1;
} /* test_reference_param() */
/*-------------------------------------------------------------------------
* Function: test_reference_obj
*
* Purpose Test basic object reference functions to various kinds
* of objects
*
* Return None
*-------------------------------------------------------------------------
*/
static void
test_reference_obj()
{
int i; // counting variables
const H5std_string write_comment = "Foo!"; // Comments for group
// Output message about test being performed
SUBTEST("Object Reference Functions");
H5File *file1 = NULL;
try {
hobj_ref_t *wbuf, // buffer to write to disk
*rbuf, // buffer read from disk
*tbuf; // temp. buffer read from disk
// Allocate write & read buffers
int temp_size = MAX(sizeof(unsigned), sizeof(hobj_ref_t));
wbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
rbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
tbuf = static_cast<hobj_ref_t *>(HDmalloc(temp_size * SPACE1_DIM1));
// Create file FILE1
file1 = new H5File(FILE1, H5F_ACC_TRUNC);
// Create dataspace for datasets
hsize_t dims1[] = {SPACE1_DIM1};
DataSpace sid1(SPACE1_RANK, dims1);
// Create dataset access property list
PropList dapl(H5P_DATASET_ACCESS);
// 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);
unsigned *tu32; // Temporary pointer to uint32 data
for (tu32 = reinterpret_cast<unsigned *>(wbuf), i = 0; i < SPACE1_DIM1; i++)
*tu32++ = i * 3; // from C test
// 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);
// Create reference to dataset and test getRefObjType
file1->reference(&wbuf[0], "/Group1/Dataset1");
H5O_type_t refobj_type = dataset.getRefObjType(&wbuf[0], H5R_OBJECT);
verify_val(static_cast<long>(refobj_type), static_cast<long>(H5O_TYPE_DATASET),
"DataSet::getRefObjType", __LINE__, __FILE__);
// Create reference to dataset and test getRefObjType
file1->reference(&wbuf[1], "/Group1/Dataset2");
refobj_type = dataset.getRefObjType(&wbuf[1], H5R_OBJECT);
verify_val(static_cast<long>(refobj_type), static_cast<long>(H5O_TYPE_DATASET),
"DataSet::getRefObjType", __LINE__, __FILE__);
// Create reference to group
file1->reference(&wbuf[2], "/Group1");
refobj_type = dataset.getRefObjType(&wbuf[2], H5R_OBJECT);
verify_val(static_cast<long>(refobj_type), static_cast<long>(H5O_TYPE_GROUP),
"DataSet::getRefObjType", __LINE__, __FILE__);
// Create reference to named datatype
file1->reference(&wbuf[3], "/Group1/Datatype1");
refobj_type = dataset.getRefObjType(&wbuf[3], H5R_OBJECT);
verify_val(static_cast<long>(refobj_type), static_cast<long>(H5O_TYPE_NAMED_DATATYPE),
"DataSet::getRefObjType", __LINE__, __FILE__);
// Write selection to disk
dataset.write(wbuf, PredType::STD_REF_OBJ);
// Close disk dataspace, dataset, and file
sid1.close();
dataset.close();
delete file1;
// Re-open the file
file1 = new H5File(FILE1, H5F_ACC_RDWR);
// Open the dataset
dataset = file1->openDataSet("/Dataset3");
// Read selection from disk
dataset.read(rbuf, PredType::STD_REF_OBJ);
// Dereference dataset object by ctor, from the location where
// 'dataset' is located
DataSet dset2(dataset, &rbuf[0], H5R_OBJECT, dapl);
// Check information in the referenced dataset
sid1 = dset2.getSpace();
hssize_t n_elements = sid1.getSimpleExtentNpoints();
verify_val(static_cast<long>(n_elements), 4, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Read from disk
dset2.read(tbuf, PredType::NATIVE_UINT);
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__);
// Close dereferenced dataset
dset2.close();
// Dereference group object from the location where 'dataset' is located
group.dereference(dataset, &rbuf[2]);
// Get group's comment using
// H5std_string getComment(const char* name, <buf_size=0 by default>)
H5std_string read_comment1 = group.getComment(".", 10);
verify_val(read_comment1.c_str(), write_comment, "Group::getComment", __LINE__, __FILE__);
// Test with the old default value
read_comment1 = group.getComment(".", 256);
verify_val(read_comment1.c_str(), write_comment, "Group::getComment", __LINE__, __FILE__);
// 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);
}
catch (Exception &E) {
} // We expect this to fail
// Close group
group.close();
/*
* Verify correct referenced datatype
*/
// Open datatype object
dtype1.dereference(dataset, &rbuf[3]);
// Verify correct datatype
H5T_class_t tclass;
tclass = dtype1.getClass();
verify_val(static_cast<long>(tclass), static_cast<long>(H5T_COMPOUND), "DataType::getClass", __LINE__,
__FILE__);
int n_members = dtype1.getNmembers();
verify_val(n_members, 3, "CompType::getNmembers", __LINE__, __FILE__);
// Close all objects and file
dtype1.close();
dataset.close();
file1->close();
// Free allocated buffers
HDfree(wbuf);
HDfree(rbuf);
HDfree(tbuf);
PASSED();
} // end try
catch (Exception &E) {
issue_fail_msg("test_reference_obj()", __LINE__, __FILE__, E.getCFuncName(), E.getCDetailMsg());
}
delete file1;
} // test_reference_obj()
/*-------------------------------------------------------------------------
* Function: test_reference_group
*
* Purpose Test object reference functionality on group.
*
* Return None
*-------------------------------------------------------------------------
*/
#define GROUPNAME "/group"
#define GROUPNAME2 "group2"
#define GROUPNAME3 "group3"
#define DSETNAME "/dset"
#define DSETNAME2 "dset2"
#define NAME_SIZE 16
static void
test_reference_group()
{
hobj_ref_t wref; /* Reference to write */
hobj_ref_t rref; /* Reference to read */
const H5std_string write_comment = "Foo!"; // Comments for group
// Output message about test being performed
SUBTEST("Object Reference to Group");
H5File *file1 = NULL;
try {
/*
* Create file with a group and a dataset containing an object
* reference to the group
*/
// Create file FILE1
file1 = new H5File(FILE1, H5F_ACC_TRUNC);
// Create scalar dataspace
DataSpace sid1;
// Create a group
Group group = file1->createGroup(GROUPNAME);
/* Create nested groups */
Group group2 = group.createGroup(GROUPNAME2);
group2.close();
group2 = group.createGroup(GROUPNAME3);
group2.close();
// Create bottom dataset
DataSet dset1 = group.createDataSet(DSETNAME2, PredType::NATIVE_INT, sid1);
dset1.close();
// Close group 1
group.close();
// Create dataset
DataSet dset2 = file1->createDataSet(DSETNAME, PredType::STD_REF_OBJ, sid1);
file1->reference(&wref, GROUPNAME);
// Write selection to disk
dset2.write(&wref, PredType::STD_REF_OBJ);
// Close resources
dset2.close();
sid1.close();
file1->close();
/*
* Re-open the file and test deferencing group
*/
// Re-open file
file1->openFile(FILE1, H5F_ACC_RDWR);
// Re-open dataset
dset1 = file1->openDataSet(DSETNAME);
// Read in the reference
dset1.read(&rref, PredType::STD_REF_OBJ);
// Dereference to get the group
Group refgroup(dset1, &rref);
// Dereference group object the other way
group.dereference(dset1, &rref);
/*
* Various queries on the group opened
*/
// Check number of objects in the group dereferenced by constructor
hsize_t nobjs = refgroup.getNumObjs();
verify_val(static_cast<long>(nobjs), 3, "H5Group::getNumObjs", __LINE__, __FILE__);
// Check number of objects in the group dereferenced by ::reference
nobjs = group.getNumObjs();
verify_val(static_cast<long>(nobjs), 3, "H5Group::getNumObjs", __LINE__, __FILE__);
// Check getting file name given the group dereferenced via constructor
H5std_string fname = refgroup.getFileName();
verify_val(fname, FILE1, "H5Group::getFileName", __LINE__, __FILE__);
// Check getting file name given the group dereferenced by ::reference
fname = group.getFileName();
verify_val(fname, FILE1, "H5Group::getFileName", __LINE__, __FILE__);
// Check object type using Group::getObjinfo()
H5O_info2_t oinfo;
HDmemset(&oinfo, 0, sizeof(oinfo));
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__);
// Check for out of bound query by index
try {
HDmemset(&oinfo, 0, sizeof(oinfo));
group.getObjinfo(".", H5_INDEX_NAME, H5_ITER_INC, 9, oinfo);
// Should FAIL but didn't, so throw an invalid action exception
throw InvalidActionException("Group::getObjinfo", "Out of bound index.");
}
catch (Exception &err) {
} // do nothing, failure expected
// Unlink one of the objects in the dereferenced group, and re-check
refgroup.unlink(GROUPNAME2);
nobjs = refgroup.getNumObjs();
verify_val(static_cast<long>(nobjs), 2, "H5Group::getNumObjs", __LINE__, __FILE__);
// Close resources
group.close();
refgroup.close();
dset1.close();
file1->close();
PASSED();
} // end try
catch (Exception &E) {
issue_fail_msg("test_reference_group()", __LINE__, __FILE__, E.getCFuncName(), E.getCDetailMsg());
}
delete file1;
} /* test_reference_group() */
/*-------------------------------------------------------------------------
* Function: test_reference_region_1D
*
* Purpose Test 1-D reference functionality on various kinds of objects.
*
* Return None
*-------------------------------------------------------------------------
*/
static void
test_reference_region_1D()
{
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 */
// Output message about test being performed
SUBTEST("1-D Dataset Region Reference Functions");
try {
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
// Allocate write & read buffers
wbuf = static_cast<hdset_reg_ref_t *>(HDcalloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1));
rbuf = static_cast<hdset_reg_ref_t *>(HDmalloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1));
dwbuf = static_cast<uint8_t *>(HDmalloc(sizeof(uint8_t) * SPACE3_DIM1));
drbuf = static_cast<uint8_t *>(HDcalloc(sizeof(uint8_t), SPACE3_DIM1));
// Create file FILE1
H5File file1(FILE2, H5F_ACC_TRUNC);
// Create dataspace for datasets
hsize_t dims3[] = {SPACE3_DIM1};
DataSpace sid3(SPACE3_RANK, dims3);
// Create dataset access property list
PropList dapl(H5P_DATASET_ACCESS);
// Create a dataset
DataSet dset3 = file1.createDataSet(DSET2_NAME, PredType::STD_U8LE, sid3);
uint8_t *tu8; // Temporary pointer to uint8 data
for (tu8 = dwbuf, i = 0; i < SPACE3_DIM1; i++)
*tu8++ = static_cast<uint8_t>(i); // from C test
// Write selection to disk
dset3.write(dwbuf, PredType::STD_U8LE);
// Close Dataset
dset3.close();
// Create dataspace for datasets
hsize_t dims1[] = {SPACE1_DIM1};
DataSpace sid1(SPACE1_RANK, dims1);
// Create a dataset
DataSet dset1 = file1.createDataSet(DSET1_NAME, PredType::STD_REF_DSETREG, sid1);
/*
* Create references and prepare for testing
*/
/* Select 15 2x1 hyperslabs for first reference */
start[0] = 2;
stride[0] = 5;
count[0] = 15;
block[0] = 2;
// Select a hyperslab region to add to the current selected region
sid3.selectHyperslab(H5S_SELECT_SET, count, start, stride, block);
// Get and verify the number of elements in a dataspace selection
hssize_t nelms = sid3.getSelectNpoints();
verify_val(nelms, 30, "DataSet::getRefObjType", __LINE__, __FILE__);
// Store first dataset region
file1.reference(&wbuf[0], "/Dataset2", sid3);
// Get and verify object type
H5O_type_t obj_type = dset1.getRefObjType(&wbuf[0], H5R_DATASET_REGION);
verify_val(static_cast<long>(obj_type), static_cast<long>(H5O_TYPE_DATASET), "DataSet::getRefObjType",
__LINE__, __FILE__);
/* 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
sid3.selectElements(H5S_SELECT_SET, POINT1_NPOINTS, reinterpret_cast<const hsize_t *>(coord1));
// Get and verify the number of elements in a dataspace selection
nelms = sid3.getSelectNpoints();
verify_val(nelms, 10, "DataSet::getRefObjType", __LINE__, __FILE__);
// 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);
verify_val(static_cast<long>(obj_type), static_cast<long>(H5O_TYPE_DATASET),
"DataSet::getRefObjType", __LINE__, __FILE__);
// Get dataspace of dset3 the verify number of elements
sid1 = dset3.getSpace();
nelms = sid1.getSimpleExtentNpoints();
verify_val(static_cast<long>(nelms), 100, "DataSpace::getSimpleExtentNpoints", __LINE__,
__FILE__);
} // 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
sid1 = newds.getSpace();
nelms = sid1.getSimpleExtentNpoints();
verify_val(static_cast<long>(nelms), 100, "DataSpace::getSimpleExtentNpoints", __LINE__,
__FILE__);
// 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);
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__);
/*
* 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();
verify_val(static_cast<long>(nelms), 30, "DataSpace::getSelectNpoints", __LINE__, __FILE__);
// Get and verify number of hyperslab blocks
nelms = reg_sp.getSelectHyperNblocks();
verify_val(static_cast<long>(nelms), 15, "DataSpace::getSelectNpoints", __LINE__, __FILE__);
/* Allocate space for the hyperslab blocks */
coords = static_cast<hsize_t *>(HDmalloc(nelms * SPACE3_RANK * sizeof(hsize_t) * 2));
// Get the list of hyperslab blocks currently selected
reg_sp.getSelectHyperBlocklist(0, static_cast<hsize_t>(nelms), coords);
// Verify values in the list
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__);
HDfree(coords);
// Check boundaries
reg_sp.getSelectBounds(low, high);
verify_val(static_cast<long>(low[0]), 2, "DataSpace::getSelectBounds", __LINE__, __FILE__);
verify_val(static_cast<long>(high[0]), 73, "DataSpace::getSelectBounds", __LINE__, __FILE__);
/* 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();
verify_val(static_cast<long>(nelmspts), 10, "DataSpace::getSelectNpoints", __LINE__, __FILE__);
/* Allocate space for the hyperslab blocks */
coords = static_cast<hsize_t *>(HDmalloc(nelmspts * SPACE3_RANK * sizeof(hsize_t)));
// Get the list of element points currently selected
elm_sp.getSelectElemPointlist(0, static_cast<hsize_t>(nelmspts), coords);
// Verify points
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__);
HDfree(coords);
// Check boundaries
elm_sp.getSelectBounds(low, high);
verify_val(static_cast<long>(low[0]), 3, "DataSpace::getSelectBounds", __LINE__, __FILE__);
verify_val(static_cast<long>(high[0]), 97, "DataSpace::getSelectBounds", __LINE__, __FILE__);
// Close element space
elm_sp.close();
// Close resources
sid1.close();
dset3.close();
dset1.close();
file1.close();
// Free memory buffers
HDfree(wbuf);
HDfree(rbuf);
HDfree(dwbuf);
HDfree(drbuf);
PASSED();
} // end try
catch (Exception &E) {
issue_fail_msg("test_reference_region_1D()", __LINE__, __FILE__, E.getCFuncName(), E.getCDetailMsg());
}
} /* test_reference_region_1D() */
/*-------------------------------------------------------------------------
*
* test_reference(): Main reference testing routine.
*
*-------------------------------------------------------------------------
*/
extern "C" void
test_reference()
{
// Output message about test being performed
MESSAGE(5, ("Testing References\n"));
test_reference_params(); // Test basic parameters of reference functionality
test_reference_obj(); // Test basic object reference functionality
test_reference_group(); // Test group reference functionality
test_reference_region_1D(); // Test 1-D reference functionality
} // test_reference()
/*-------------------------------------------------------------------------
* Function: cleanup_reference
*
* Purpose Cleanup temporary test files
*
* Return None
*-------------------------------------------------------------------------
*/
extern "C" void
cleanup_reference()
{
HDremove(FILE1.c_str());
HDremove(FILE2.c_str());
}