summaryrefslogtreecommitdiffstats
path: root/c++/test
diff options
context:
space:
mode:
Diffstat (limited to 'c++/test')
-rw-r--r--c++/test/dsets.cpp2
-rw-r--r--c++/test/h5cpputil.cpp25
-rw-r--r--c++/test/h5cpputil.h2
-rw-r--r--c++/test/tattr.cpp135
-rw-r--r--c++/test/tfile.cpp113
-rw-r--r--c++/test/trefer.cpp718
6 files changed, 828 insertions, 167 deletions
diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp
index 58436f1..811d8c7 100644
--- a/c++/test/dsets.cpp
+++ b/c++/test/dsets.cpp
@@ -1058,7 +1058,7 @@ void test_dset()
// Cause the library to emit initial messages
Group grp = file.createGroup( "emit diagnostics", 0);
- grp.setComment( ".", "Causes diagnostic messages to be emitted");
+ grp.setComment("Causes diagnostic messages to be emitted");
nerrors += test_create(file)<0 ?1:0;
nerrors += test_simple_io(file)<0 ?1:0;
diff --git a/c++/test/h5cpputil.cpp b/c++/test/h5cpputil.cpp
index 4485808..cd85b6e 100644
--- a/c++/test/h5cpputil.cpp
+++ b/c++/test/h5cpputil.cpp
@@ -100,12 +100,37 @@ void issue_fail_msg(const char* where, int line, const char* file_name,
{
//if (GetTestVerbosity()>=VERBO_HI)
{
+ cerr << endl;
cerr << ">>> FAILED in " << where << " at line " << line
<< " in " << file_name << " - " << message << endl << endl;
}
}
/*-------------------------------------------------------------------------
+ * Function: issue_fail_msg
+ *
+ * Purpose: Displays that a function has failed with its location.
+ *
+ * Return: None
+ *
+ * Programmer: Binh-Minh Ribler (copied and modified macro CHECK from C)
+ * Monday, December 20, 2004
+ *
+ *-------------------------------------------------------------------------
+ */
+void issue_fail_msg(const char* where, int line, const char* file_name,
+ const char* func_name, const char* message)
+{
+ //if (GetTestVerbosity()>=VERBO_HI)
+ {
+ cerr << endl;
+ cerr << ">>> FAILED in " << where << ": " << func_name << endl <<
+ " at line " << line << " in " << file_name << endl <<
+ " C library detail: " << message << endl << endl;
+ }
+}
+
+/*-------------------------------------------------------------------------
* Function: check_values
*
* Purpose: Checks a read value against the written value. If they are
diff --git a/c++/test/h5cpputil.h b/c++/test/h5cpputil.h
index 02f3d0d..e6aba79 100644
--- a/c++/test/h5cpputil.h
+++ b/c++/test/h5cpputil.h
@@ -42,6 +42,8 @@ int check_values (hsize_t i, hsize_t j, int apoint, int acheck);
int test_report (int, const H5std_string&);
void issue_fail_msg(const char* where, int line, const char* file_name,
const char* message="");
+void issue_fail_msg(const char* where, int line, const char* file_name,
+ const char* func_name, const char* message);
class InvalidActionException : public Exception {
public:
diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp
index 6bb9ca0..6f7674d 100644
--- a/c++/test/tattr.cpp
+++ b/c++/test/tattr.cpp
@@ -42,8 +42,13 @@
#include "h5cpputil.h" // C++ utilility header file
-const H5std_string FILENAME("tattr.h5");
-const H5std_string ATTR_TMP_NAME("temp_name");
+const H5std_string FILE_BASIC("tattr_basic.h5");
+const H5std_string FILE_COMPOUND("tattr_compound.h5");
+const H5std_string FILE_SCALAR("tattr_scalar.h5");
+const H5std_string FILE_MULTI("tattr_multi.h5");
+const H5std_string FILE_DTYPE("tattr_dtype.h5");
+const H5std_string ATTR_TMP_NAME("temp_attr_name");
+const H5std_string FATTR_TMP_NAME("temp_fattr_name");
const size_t ATTR_MAX_DIMS = 7;
/* 3-D dataset with fixed dimensions */
@@ -63,6 +68,10 @@ const int ATTR1_RANK = 1;
const int ATTR1_DIM1 = 3;
int attr_data1[ATTR1_DIM1]={512,-234,98123}; /* Test data for 1st attribute */
+// File attribute, using the same rank and dimensions as ATTR1_NAME's
+const H5std_string FATTR1_NAME("File Attr1");
+const H5std_string FATTR2_NAME("File Attr2");
+
const H5std_string ATTR2_NAME("Attr2");
const int ATTR2_RANK = 2;
const int ATTR2_DIM1 = 2;
@@ -121,7 +130,7 @@ static void test_attr_basic_write()
try {
// Create file
- H5File fid1 (FILENAME, H5F_ACC_TRUNC);
+ H5File fid1 (FILE_BASIC, H5F_ACC_TRUNC);
// Create dataspace for dataset
DataSpace ds_space (SPACE1_RANK, dims1);
@@ -136,6 +145,12 @@ static void test_attr_basic_write()
// Create dataspace for attribute
DataSpace att_space (ATTR1_RANK, dims2);
+ // Create a file attribute
+ Attribute file_attr2 = fid1.createAttribute (FATTR1_NAME, PredType::NATIVE_INT, att_space);
+
+ // Create a file attribute
+ Attribute file_attr1 = fid1.createAttribute (FATTR2_NAME, PredType::NATIVE_INT, att_space);
+
// Create an attribute for the dataset
Attribute ds_attr1 = dataset.createAttribute (ATTR1_NAME, PredType::NATIVE_INT, att_space);
@@ -163,8 +178,9 @@ static void test_attr_basic_write()
if(attr_data1[i]!=read_data1[i])
TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]);
- // Create another attribute for this dataset
- Attribute ds_attr2 = dataset.createAttribute (ATTR1A_NAME, PredType::NATIVE_INT, att_space);
+ // Create two more attributes for this dataset, but only write to one.
+ Attribute ds_attr2 = dataset.createAttribute (ATTR2_NAME, PredType::NATIVE_INT, att_space);
+ Attribute ds_attr3 = dataset.createAttribute (ATTR3_NAME, PredType::NATIVE_INT, att_space);
// Write attribute information
ds_attr2.write (PredType::NATIVE_INT, attr_data1a);
@@ -180,6 +196,7 @@ static void test_attr_basic_write()
// Close both attributes
ds_attr1.close();
ds_attr2.close();
+ ds_attr3.close();
/*
* Test attribute with group
@@ -240,14 +257,32 @@ static void test_attr_rename()
try {
// Open file
- H5File fid1(FILENAME, H5F_ACC_RDWR);
+ H5File fid1(FILE_BASIC, H5F_ACC_RDWR);
+
+ // Check rename of attribute belonging to a file
+
+ // Change attribute name
+ fid1.renameAttr(FATTR1_NAME, FATTR_TMP_NAME);
+
+ // Open attribute again
+ Attribute fattr1(fid1.openAttribute(FATTR_TMP_NAME));
+
+ // Verify new attribute name
+ H5std_string fattr_name = fattr1.getName();
+ verify_val(fattr_name, FATTR_TMP_NAME, "Attribute::getName", __LINE__, __FILE__);
+
+ int num_attrs = fid1.getNumAttrs();
+ verify_val(num_attrs, 2, "Attribute::getNumAttrs", __LINE__, __FILE__);
+
+ // Change first file attribute back to the original name
+ fid1.renameAttr(FATTR_TMP_NAME, FATTR1_NAME);
// Open the dataset
DataSet dataset = fid1.openDataSet(DSET1_NAME);
- // Check rename
+ // Check rename of attribute belonging to a dataset
- // change attribute name
+ // Change attribute name
dataset.renameAttr(ATTR1_NAME, ATTR_TMP_NAME);
// Open attribute again
@@ -269,11 +304,11 @@ static void test_attr_rename()
attr1.close();
// Open the second attribute
- Attribute attr2(dataset.openAttribute(ATTR1A_NAME));
+ Attribute attr2(dataset.openAttribute(ATTR2_NAME));
// Verify second attribute name
H5std_string attr2_name = attr2.getName();
- verify_val(attr2_name, ATTR1A_NAME, "Attribute::getName", __LINE__, __FILE__);
+ verify_val(attr2_name, ATTR2_NAME, "Attribute::getName", __LINE__, __FILE__);
// Read attribute information immediately, without closing attribute
attr2.read (PredType::NATIVE_INT, read_data1);
@@ -311,14 +346,14 @@ static void test_attr_basic_read()
try {
// Open file
- H5File fid1(FILENAME, H5F_ACC_RDWR);
+ H5File fid1(FILE_BASIC, H5F_ACC_RDWR);
// Open the dataset
DataSet dataset = fid1.openDataSet(DSET1_NAME);
// Verify the correct number of attributes
int num_attrs = dataset.getNumAttrs();
- verify_val(num_attrs, 2, "H5Object::getNumAttrs", __LINE__, __FILE__);
+ verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__);
// Open an attribute for the dataset
Attribute ds_attr=dataset.openAttribute(ATTR1_NAME);
@@ -378,7 +413,7 @@ static void test_attr_compound_write()
try {
// Create file
- H5File fid1(FILENAME.c_str(), H5F_ACC_TRUNC);
+ H5File fid1(FILE_COMPOUND.c_str(), H5F_ACC_TRUNC);
// Create dataspace for dataset
hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
@@ -442,14 +477,14 @@ static void test_attr_compound_read()
try {
// Open file
- H5File fid1(FILENAME, H5F_ACC_RDWR);
+ H5File fid1(FILE_COMPOUND, H5F_ACC_RDWR);
// Open the dataset
DataSet dataset = fid1.openDataSet(DSET1_NAME);
// Verify the correct number of attributes
int num_attrs = dataset.getNumAttrs();
- verify_val(num_attrs, 1, "H5Object::getNumAttrs", __LINE__, __FILE__);
+ verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__);
// Open 1st attribute for the dataset
Attribute attr = dataset.openAttribute((unsigned)0);
@@ -571,7 +606,7 @@ static void test_attr_scalar_write()
try {
// Create file
- H5File fid1(FILENAME, H5F_ACC_TRUNC);
+ H5File fid1(FILE_SCALAR, H5F_ACC_TRUNC);
// Create dataspace for dataset
hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
@@ -625,14 +660,14 @@ static void test_attr_scalar_read()
try {
// Open file
- H5File fid1(FILENAME, H5F_ACC_RDWR);
+ H5File fid1(FILE_SCALAR, H5F_ACC_RDWR);
// Open the dataset
DataSet dataset = fid1.openDataSet(DSET1_NAME);
// Verify the correct number of attributes
int num_attrs = dataset.getNumAttrs();
- verify_val(num_attrs, 1, "H5Object::getNumAttrs", __LINE__, __FILE__);
+ verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__);
// Open an attribute for the dataset
Attribute ds_attr=dataset.openAttribute(ATTR5_NAME);
@@ -669,7 +704,7 @@ static void test_attr_mult_write()
try {
// Create file
- H5File fid1 (FILENAME, H5F_ACC_TRUNC);
+ H5File fid1 (FILE_MULTI, H5F_ACC_TRUNC);
// Create dataspace for dataset
hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
@@ -746,14 +781,14 @@ static void test_attr_mult_read()
try {
// Open file
- H5File fid1(FILENAME, H5F_ACC_RDWR);
+ H5File fid1(FILE_MULTI, H5F_ACC_RDWR);
// Open the dataset
DataSet dataset = fid1.openDataSet(DSET1_NAME);
// Verify the correct number of attributes
int num_attrs = dataset.getNumAttrs();
- verify_val(num_attrs, 3, "H5Object::getNumAttrs", __LINE__, __FILE__);
+ verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__);
// Open 1st attribute for the dataset
Attribute attr = dataset.openAttribute((unsigned)0);
@@ -929,22 +964,42 @@ static void test_attr_mult_read()
static void test_attr_delete()
{
H5std_string attr_name; // Buffer for attribute names
+ int ii;
- // Output message about test being performed
+ // Output message about test being performed
SUBTEST("Removing Attribute Function");
try {
- // Open file
- H5File fid1(FILENAME, H5F_ACC_RDWR);
+ // Open file.
+ H5File fid1(FILE_BASIC, H5F_ACC_RDWR);
+
+ // Get the number of file attributes
+ int num_attrs = fid1.getNumAttrs();
+ verify_val(num_attrs, 2, "H5File::getNumAttrs", __LINE__, __FILE__);
+
+ // Delete the second file attribute
+ fid1.removeAttr(FATTR2_NAME);
+
+ // Get the number of file attributes
+ num_attrs = fid1.getNumAttrs();
+ verify_val(num_attrs, 1, "H5File::getNumAttrs", __LINE__, __FILE__);
+
+ // Verify the name of the only file attribute left
+ Attribute fattr = fid1.openAttribute((uint)0);
+ H5std_string attr_name = fattr.getName();
+ verify_val(attr_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__);
+ fattr.close();
+
+ // Test deleting non-existing attribute
// Open the dataset
DataSet dataset = fid1.openDataSet(DSET1_NAME);
// Verify the correct number of attributes
- int num_attrs = dataset.getNumAttrs();
- verify_val(num_attrs, 3, "H5Object::getNumAttrs", __LINE__, __FILE__);
+ num_attrs = dataset.getNumAttrs();
+ verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__);
- // Try to delete bogus attribute, should fail.
+ // Try to delete bogus attribute, should fail
try {
dataset.removeAttr("Bogus");
@@ -954,16 +1009,18 @@ static void test_attr_delete()
catch (AttributeIException E) // catching invalid removing attribute
{} // do nothing, exception expected
+ // Test deleting dataset's attributes
+
// Verify the correct number of attributes
num_attrs = dataset.getNumAttrs();
- verify_val(num_attrs, 3, "H5Object::getNumAttrs", __LINE__, __FILE__);
+ verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__);
// Delete middle (2nd) attribute
dataset.removeAttr(ATTR2_NAME);
// Verify the correct number of attributes
num_attrs = dataset.getNumAttrs();
- verify_val(num_attrs, 2, "H5Object::getNumAttrs", __LINE__, __FILE__);
+ verify_val(num_attrs, 2, "DataSet::getNumAttrs", __LINE__, __FILE__);
// Open 1st attribute for the dataset
Attribute attr = dataset.openAttribute((unsigned)0);
@@ -989,9 +1046,9 @@ static void test_attr_delete()
// Verify the correct number of attributes
num_attrs = dataset.getNumAttrs();
- verify_val(num_attrs, 1, "H5Object::getNumAttrs", __LINE__, __FILE__);
+ verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__);
- // Open last (formally 3rd) attribute for the dataset
+ // Open the only attribute for the dataset (formally 3rd)
attr = dataset.openAttribute((unsigned)0);
// Verify Name
@@ -1005,7 +1062,7 @@ static void test_attr_delete()
// Verify the correct number of attributes
num_attrs = dataset.getNumAttrs();
- verify_val(num_attrs, 0, "H5Object::getNumAttrs", __LINE__, __FILE__);
+ verify_val(num_attrs, 0, "DataSet::getNumAttrs", __LINE__, __FILE__);
PASSED();
} // end try block
@@ -1035,19 +1092,19 @@ static void test_attr_dtype_shared()
try {
// Create a file
- H5File fid1(FILENAME, H5F_ACC_TRUNC);
+ H5File fid1(FILE_DTYPE, H5F_ACC_TRUNC);
// Close file
fid1.close();
// Get size of file
h5_stat_size_t empty_filesize; // Size of empty file
- empty_filesize = h5_get_file_size(FILENAME.c_str(), H5P_DEFAULT);
+ empty_filesize = h5_get_file_size(FILE_DTYPE.c_str(), H5P_DEFAULT);
if (empty_filesize < 0)
TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
// Open the file again
- fid1.openFile(FILENAME, H5F_ACC_RDWR);
+ fid1.openFile(FILE_DTYPE, H5F_ACC_RDWR);
// Enclosing to work around the issue of unused variables and/or
// objects created by copy constructors stay around until end of
@@ -1120,7 +1177,7 @@ static void test_attr_dtype_shared()
fid1.close();
// Open the file again
- fid1.openFile(FILENAME, H5F_ACC_RDWR);
+ fid1.openFile(FILE_DTYPE, H5F_ACC_RDWR);
{ // Second enclosed block...
@@ -1161,7 +1218,7 @@ static void test_attr_dtype_shared()
fid1.close();
// Check size of file
- filesize = h5_get_file_size(FILENAME.c_str(), H5P_DEFAULT);
+ filesize = h5_get_file_size(FILE_DTYPE.c_str(), H5P_DEFAULT);
verify_val((long)filesize, (long)empty_filesize, "Checking file size", __LINE__, __FILE__);
PASSED();
@@ -1192,7 +1249,7 @@ static void test_string_attr()
try {
// Create file
- H5File fid1(FILENAME, H5F_ACC_RDWR);
+ H5File fid1(FILE_BASIC, H5F_ACC_RDWR);
//
// Fixed-lenth string attributes
@@ -1349,6 +1406,6 @@ extern "C"
#endif
void cleanup_attr()
{
- HDremove(FILENAME.c_str());
+ //HDremove(FILENAME.c_str());
}
diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp
index 765168c..65b7f11 100644
--- a/c++/test/tfile.cpp
+++ b/c++/test/tfile.cpp
@@ -140,7 +140,7 @@ static void test_file_create()
// Test create with H5F_ACC_TRUNC. This will truncate the existing file.
file1 = new H5File (FILE1, H5F_ACC_TRUNC);
- // Try to truncate first file again. This should fail because file1
+ // Try to create first file again. This should fail because file1
// is the same file and is currently open. Skip it on OpenVMS because
// it creates another version of the file.
#ifndef H5_HAVE_FILE_VERSIONS
@@ -492,6 +492,116 @@ static void test_file_name()
} // test_file_name()
+#define NUM_OBJS 4
+#define NUM_ATTRS 3
+const int RANK1 = 1;
+const int ATTR1_DIM1 = 3;
+const H5std_string FILE5("tfattrs.h5");
+const H5std_string FATTR1_NAME ("file attribute 1");
+const H5std_string FATTR2_NAME ("file attribute 2");
+int fattr_data[ATTR1_DIM1]={512,-234,98123}; /* Test data for file attribute */
+int dattr_data[ATTR1_DIM1]={256,-123,1000}; /* Test data for dataset attribute */
+static void test_file_attribute()
+{
+ int rdata[ATTR1_DIM1];
+ int i;
+
+ // Output message about test being performed
+ SUBTEST("File Attribute");
+
+ H5std_string file_name;
+ try {
+ // Create a file using default properties.
+ H5File file5(FILE5, H5F_ACC_TRUNC);
+
+ // Create the data space
+ hsize_t dims[RANK1] = {ATTR1_DIM1};
+ DataSpace space(RANK1, dims);
+
+ // Create two attributes for the file
+ Attribute fattr1(file5.createAttribute(FATTR1_NAME, PredType::NATIVE_FLOAT, space));
+ Attribute fattr2(file5.createAttribute(FATTR2_NAME, PredType::NATIVE_INT, space));
+
+ fattr2.write(PredType::NATIVE_INT, fattr_data);
+
+ try {
+ // Try to create the same attribute again (should fail)
+ Attribute fattr_dup(file5.createAttribute(FATTR2_NAME, PredType::NATIVE_INT, space));
+ // Should FAIL but didn't, so throw an invalid action exception
+ throw InvalidActionException("H5File createAttribute", "Attempted to create an existing attribute.");
+ }
+ catch( AttributeIException E ) // catch creating existing attribute
+ {} // do nothing, FAIL expected
+
+ // Create a new dataset
+ DataSet dataset(file5.createDataSet (DSETNAME, PredType::NATIVE_INT, space));
+
+ // Create an attribute for the dataset
+ Attribute dattr(dataset.createAttribute(DATTRNAME, PredType::NATIVE_INT, space));
+
+ // Write data to the second file attribute
+ dattr.write(PredType::NATIVE_INT, dattr_data);
+
+ // Test flushing out the data from the attribute object
+ dattr.flush(H5F_SCOPE_GLOBAL);
+
+ // Get and verify the number of all objects in the file
+ // Current: 1 file, 2 file attr, 1 ds, and 1 ds attr.
+ ssize_t num_objs = file5.getObjCount(H5F_OBJ_ALL);
+ verify_val(num_objs, 5, "H5File::getObjCount", __LINE__, __FILE__);
+
+ num_objs = file5.getObjCount(H5F_OBJ_GROUP);
+ verify_val(num_objs, 0, "H5File::getObjCount(H5F_OBJ_GROUP)", __LINE__, __FILE__);
+ num_objs = file5.getObjCount(H5F_OBJ_DATASET);
+ verify_val(num_objs, 1, "H5File::getObjCount(H5F_OBJ_DATASET)", __LINE__, __FILE__);
+ num_objs = file5.getObjCount(H5F_OBJ_ATTR);
+ verify_val(num_objs, 3, "H5File::getObjCount(H5F_OBJ_ATTR)", __LINE__, __FILE__);
+ num_objs = file5.getObjCount(H5F_OBJ_DATATYPE);
+ verify_val(num_objs, 0, "H5File::getObjCount(H5F_OBJ_DATATYPE)", __LINE__, __FILE__);
+ num_objs = file5.getObjCount(H5F_OBJ_FILE);
+ verify_val(num_objs, 1, "H5File::getObjCount(H5F_OBJ_FILE)", __LINE__, __FILE__);
+
+ // Get the file name using the attributes
+ H5std_string fname = fattr1.getFileName();
+ verify_val(fname, FILE5, "H5File::getFileName()", __LINE__, __FILE__);
+
+ fname.clear();
+ fname = dattr.getFileName();
+ verify_val(fname, FILE5, "H5File::getFileName()", __LINE__, __FILE__);
+
+ // Get the class of a file attribute's datatype
+ H5T_class_t atclass = fattr1.getTypeClass();
+ verify_val(atclass, H5T_FLOAT, "Attribute::getTypeClass()", __LINE__, __FILE__);
+
+ // Get and verify the number of attributes attached to a file
+ int n_attrs = file5.getNumAttrs();
+ verify_val(n_attrs, 2, "H5File::getNumAttrs()", __LINE__, __FILE__);
+
+ // Get and verify the number of attributes attached to a dataset
+ n_attrs = 0;
+ n_attrs = dataset.getNumAttrs();
+ verify_val(n_attrs, 1, "DataSet::getNumAttrs()", __LINE__, __FILE__);
+
+ // Read back attribute's data
+ HDmemset(rdata, 0, sizeof(rdata));
+ dattr.read(PredType::NATIVE_INT, rdata);
+ /* Check results */
+ for (i = 0; i < ATTR1_DIM1; i++) {
+ if (rdata[i] != dattr_data[i]) {
+ H5_FAILED();
+ cerr << endl;
+ cerr << "element [" << i << "] is " << rdata[i] <<
+ "but should have been " << dattr_data[i] << endl;
+ }
+ }
+ PASSED();
+ } // end of try block
+
+ catch (Exception E) {
+ issue_fail_msg("test_file_name()", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+} // test_file_attribute()
+
/*-------------------------------------------------------------------------
* Function: test_file
*
@@ -518,6 +628,7 @@ void test_file()
test_file_open(); // Test file opening
test_file_size(); // Test file size
test_file_name(); // Test getting file's name
+ test_file_attribute(); // Test file attribute feature
} // test_file()
diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp
index dcb32dc..ae1ab02 100644
--- a/c++/test/trefer.cpp
+++ b/c++/test/trefer.cpp
@@ -27,13 +27,6 @@
#endif
#include <string>
-#ifndef H5_NO_NAMESPACE
-#ifndef H5_NO_STD
- using std::cerr;
- using std::endl;
-#endif // H5_NO_STD
-#endif
-
#include "H5Cpp.h" // C++ API header file
#ifndef H5_NO_NAMESPACE
@@ -42,29 +35,31 @@
#include "h5cpputil.h" // C++ utilility header file
+// File names
const H5std_string FILE1("trefer1.h5");
const H5std_string FILE2("trefer2.h5");
-const H5std_string FILE3("trefer3.h5");
-const H5std_string DSET_DEFAULT_NAME("default");
-// Dataset 1
+// Dataset and datatype names
const H5std_string DSET1_NAME("Dataset1");
-const int DSET1_LEN = 8;
+const H5std_string DSET2_NAME("Dataset2");
+const H5std_string DSET3_NAME("Dataset3");
+const H5std_string DTYPE_NAME("Datatype1");
+// Compound type member names
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 H5std_string SPACE1_NAME("Space1");
const int SPACE1_RANK = 1;
const int SPACE1_DIM1 = 4;
-// 2-D dataset with fixed dimensions
-const H5std_string SPACE2_NAME("Space2");
+/* Larger 1-D dataset with fixed dimensions */
+const int SPACE3_RANK = 1;
+const int SPACE3_DIM1 = 100;
-// Larger 1-D dataset with fixed dimensions
-const H5std_string SPACE3_NAME("Space3");
+/* Element selection information */
+const int POINT1_NPOINTS = 10;
// Compound datatype
typedef struct s1_t {
@@ -75,8 +70,123 @@ typedef struct s1_t {
/****************************************************************
**
-** test_reference_obj(): Test basic object reference functionality.
-** Tests references to various kinds of objects
+** test_reference_params(): Test basic H5R (reference) parameters
+** for correct processing
+**
+****************************************************************/
+static void
+test_reference_params(void)
+{
+ 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=(hobj_ref_t*)HDmalloc(temp_size*SPACE1_DIM1);
+ rbuf=(hobj_ref_t*)HDmalloc(temp_size*SPACE1_DIM1);
+ tbuf=(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=(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(DSET2_NAME, 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, DTYPE_NAME);
+
+ // Close datatype and group
+ dtype1.close();
+ group.close();
+
+ // Create a dataset
+ dataset = file1->createDataSet(DSET3_NAME, 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());
+ }
+
+ if(file1)
+ delete file1;
+} /* test_reference_param() */
+
+/****************************************************************
+**
+** test_reference_obj(): Test basic object reference functions
+** to various kinds of objects
**
****************************************************************/
static void test_reference_obj(void)
@@ -107,7 +217,7 @@ static void test_reference_obj(void)
DataSpace sid1(SPACE1_RANK, dims1);
// Create a group
- Group group = file1->createGroup("Group1", (size_t)-1);
+ Group group = file1->createGroup("Group1");
// Set group's comment
group.setComment(".", write_comment);
@@ -116,7 +226,7 @@ static void test_reference_obj(void)
DataSet dataset = group.createDataSet(DSET1_NAME, PredType::NATIVE_UINT, sid1);
unsigned *tu32; // Temporary pointer to uint32 data
- for (tu32=(unsigned *)wbuf, i=0; i<SPACE1_DIM1; i++)
+ for (tu32 = (unsigned *)wbuf, i = 0; i < SPACE1_DIM1; i++)
*tu32++=i*3; // from C test
// Write selection to disk
@@ -126,7 +236,7 @@ static void test_reference_obj(void)
dataset.close();
// Create another dataset (inside /Group1)
- dataset = group.createDataSet("Dataset2", PredType::NATIVE_UCHAR, sid1);
+ dataset = group.createDataSet(DSET2_NAME, PredType::NATIVE_UCHAR, sid1);
// Close Dataset
dataset.close();
@@ -140,43 +250,34 @@ static void test_reference_obj(void)
dtype1.insertMember(MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_FLOAT);
// Save datatype for later
- dtype1.commit(group, "Datatype1");
+ dtype1.commit(group, DTYPE_NAME);
// Close datatype and group
dtype1.close();
group.close();
// Create a dataset
- dataset = file1->createDataSet("Dataset3", PredType::STD_REF_OBJ, sid1);
+ dataset = file1->createDataSet(DSET3_NAME, PredType::STD_REF_OBJ, sid1);
- // Create reference to dataset
+ // 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(refobj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__);
-#ifndef H5_NO_DEPRECATED_SYMBOLS
- H5G_obj_t obj_type = dataset.getObjType(&wbuf[0], H5R_OBJECT);
- verify_val(obj_type, H5G_DATASET, "DataSet::getObjType", __LINE__, __FILE__);
-#endif /* H5_NO_DEPRECATED_SYMBOLS */
-
- // Create reference to dataset
+ // Create reference to dataset and test getRefObjType
file1->reference(&wbuf[1], "/Group1/Dataset2");
-#ifndef H5_NO_DEPRECATED_SYMBOLS
- obj_type = dataset.getObjType(&wbuf[1], H5R_OBJECT);
- verify_val(obj_type, H5G_DATASET, "DataSet::getObjType", __LINE__, __FILE__);
-#endif /* H5_NO_DEPRECATED_SYMBOLS */
+ refobj_type = dataset.getRefObjType(&wbuf[1], H5R_OBJECT);
+ verify_val(refobj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__);
// Create reference to group
file1->reference(&wbuf[2], "/Group1");
-#ifndef H5_NO_DEPRECATED_SYMBOLS
- obj_type = dataset.getObjType(&wbuf[2], H5R_OBJECT);
- verify_val(obj_type, H5G_GROUP, "DataSet::getObjType", __LINE__, __FILE__);
-#endif /* H5_NO_DEPRECATED_SYMBOLS */
+ refobj_type = dataset.getRefObjType(&wbuf[2], H5R_OBJECT);
+ verify_val(refobj_type, H5O_TYPE_GROUP, "DataSet::getRefObjType",__LINE__,__FILE__);
// Create reference to named datatype
file1->reference(&wbuf[3], "/Group1/Datatype1");
-#ifndef H5_NO_DEPRECATED_SYMBOLS
- obj_type = dataset.getObjType(&wbuf[3], H5R_OBJECT);
- verify_val(obj_type, H5G_TYPE, "DataSet::getObjType", __LINE__, __FILE__);
-#endif /* H5_NO_DEPRECATED_SYMBOLS */
+ refobj_type = dataset.getRefObjType(&wbuf[3], H5R_OBJECT);
+ verify_val(refobj_type, H5O_TYPE_NAMED_DATATYPE, "DataSet::getRefObjType",__LINE__,__FILE__);
// Write selection to disk
dataset.write(wbuf, PredType::STD_REF_OBJ);
@@ -190,25 +291,25 @@ static void test_reference_obj(void)
file1 = new H5File(FILE1, H5F_ACC_RDWR);
// Open the dataset
- dataset = file1->openDataSet("/Dataset3");
+ dataset = file1->openDataSet(DSET3_NAME);
// 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]);
+ DataSet dset2(dataset, &rbuf[0], H5R_OBJECT);
// Check information in the referenced dataset
sid1 = dset2.getSpace();
hssize_t n_elements = sid1.getSimpleExtentNpoints();
- verify_val((long)n_elements, 4, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
+ verify_val((long)n_elements, 4, "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__);
// Read from disk
dset2.read(tbuf, PredType::NATIVE_UINT);
- for(tu32=(unsigned *)tbuf,i=0; i<SPACE1_DIM1; i++,tu32++)
- verify_val(*tu32, (uint32_t)(i*3), "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
+ for(tu32 = (unsigned *)tbuf, i = 0; i < SPACE1_DIM1; i++, tu32++)
+ verify_val(*tu32, (uint32_t)(i*3), "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__);
// Close dereferenced dataset
dset2.close();
@@ -218,7 +319,7 @@ static void test_reference_obj(void)
// Get group's comment
H5std_string read_comment1 = group.getComment(".", 10);
- verify_val(read_comment1, write_comment, "Group::getComment", __LINE__, __FILE__);
+ verify_val(read_comment1.c_str(), write_comment, "Group::getComment",__LINE__,__FILE__);
// Test that getComment handles failures gracefully
try {
@@ -226,96 +327,29 @@ static void test_reference_obj(void)
}
catch (Exception E) {} // We expect this to fail
- // Test reading the name of an item in the group
-
- // Test getObjnameByIdx(idx)
- H5std_string name;
- name = group.getObjnameByIdx(0);
- verify_val(name, DSET1_NAME, "Group::getObjnameByIdx", __LINE__, __FILE__);
- // Test getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size)
- name.clear();
- ssize_t name_size = group.getObjnameByIdx(0, name, 5);
- verify_val(name, "Data", "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__);
- verify_val(name_size, DSET1_LEN, "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__);
-
- name.clear();
- name_size = group.getObjnameByIdx(0, name, name_size+1);
- verify_val(name, DSET1_NAME, "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__);
- verify_val(name_size, DSET1_LEN, "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__);
-
- // Test getObjnameByIdx(hsize_t idx, char* name, size_t size)
- group.getObjnameByIdx(0, name, name_size+1);
- verify_val(name, DSET1_NAME, "Group::getObjnameByIdx(index,(char*)buf,buf_len)", __LINE__, __FILE__);
- verify_val(name_size, DSET1_LEN, "Group::getObjnameByIdx(index,(char*)buf,buf_len)", __LINE__, __FILE__);
-
-#ifndef H5_NO_DEPRECATED_SYMBOLS
- // Test getting the type of objects
-
- // Test getObjTypeByIdx(hsize_t idx)
- obj_type = group.getObjTypeByIdx(0);
- verify_val(obj_type, H5G_DATASET, "Group::getObjTypeByIdx(index)", __LINE__, __FILE__);
-
- // Test getObjTypeByIdx(hsize_t idx, char* type_name)
- obj_type = H5G_UNKNOWN;
- char type_name_C[256];
- obj_type = group.getObjTypeByIdx(0, type_name_C);
- verify_val(obj_type, H5G_DATASET, "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__);
- verify_val((const char*)type_name_C, (const char*)"dataset", "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__);
-
- // Test getObjTypeByIdx(hsize_t idx, H5std_string& type_name)
- obj_type = H5G_UNKNOWN;
- H5std_string type_name;
- obj_type = group.getObjTypeByIdx(0, type_name);
- verify_val(obj_type, H5G_DATASET, "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__);
- verify_val(type_name, "dataset", "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__);
-
-#endif // ifndef H5_NO_DEPRECATED_SYMBOLS
-
// Close group
group.close();
- // Dereference group object using file to specify location
- group.dereference(*file1, &rbuf[2]);
- H5std_string read_comment2 = group.getComment(".", 10);
- verify_val(read_comment2, write_comment, "Group::getComment", __LINE__, __FILE__);
- group.close();
-
- // Dereference group object by ctor and using dataset to specify
- // location
- Group new_group(dataset, &rbuf[2]);
- H5std_string read_comment3 = new_group.getComment(".", 10);
- verify_val(read_comment3, write_comment, "Group::getComment", __LINE__, __FILE__);
- new_group.close();
-
- // Dereference datatype object from the location where 'dataset'
- // is located
+ /*
+ * Verify correct referenced datatype
+ */
+ // Open datatype object
dtype1.dereference(dataset, &rbuf[3]);
// Verify correct datatype
- H5T_class_t tclass = dtype1.getClass();
- verify_val(tclass, H5T_COMPOUND, "DataType::getClass", __LINE__, __FILE__);
+ H5T_class_t tclass;
+ tclass = dtype1.getClass();
+ verify_val(tclass, H5T_COMPOUND, "DataType::getClass",__LINE__,__FILE__);
int n_members = dtype1.getNmembers();
- verify_val(n_members, 3, "DataType::getNmembers", __LINE__, __FILE__);
+ verify_val(n_members, 3, "CompType::getNmembers",__LINE__,__FILE__);
- // Close datatype
+ // Close all objects and file
dtype1.close();
-
- // Dereference datatype object by ctor, using file to specify location
- DataType dtype2(*file1, &rbuf[3]);
-
- // Verify correct datatype
- H5T_class_t tclass2 = dtype2.getClass();
- verify_val(tclass2, H5T_COMPOUND, "DataType::getClass", __LINE__, __FILE__);
-
- // Close datatype
- dtype2.close();
-
- // Close dataset and file
dataset.close();
file1->close();
- // Free memory buffers
+ // Free allocated buffers
HDfree(wbuf);
HDfree(rbuf);
HDfree(tbuf);
@@ -323,13 +357,440 @@ static void test_reference_obj(void)
PASSED();
} // end try
catch (Exception E) {
- issue_fail_msg("test_reference_obj()", __LINE__, __FILE__, E.getCDetailMsg());
+ issue_fail_msg("test_reference_obj()",__LINE__,__FILE__,
+ E.getCFuncName(), E.getCDetailMsg());
}
if(file1)
delete file1;
} // test_reference_obj()
+
+/****************************************************************
+**
+** test_reference_group(): Test object reference functionality
+** Tests for correct behavior of various routines on
+** dereferenced group
+**
+****************************************************************/
+#define GROUPNAME "/group"
+#define GROUPNAME2 "group2"
+#define GROUPNAME3 "group3"
+#define DSETNAME "/dset"
+#define DSETNAME2 "dset2"
+#define NAME_SIZE 16
+
+static void
+test_reference_group(void)
+{
+ 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(nobjs, 3, "H5Group::getNumObjs",__LINE__,__FILE__);
+
+ // Check number of objects in the group dereferenced by ::reference
+ nobjs = group.getNumObjs();
+ verify_val(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__);
+
+ // Unlink one of the objects in the dereferenced group, and re-check
+ refgroup.unlink(GROUPNAME2);
+ nobjs = refgroup.getNumObjs();
+ verify_val(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());
+ }
+
+ if(file1)
+ delete file1;
+} /* test_reference_group() */
+
+/****************************************************************
+**
+** test_reference_region_1D(): Test 1-D reference functionality
+** Tests 1-D references to various kinds of objects
+**
+****************************************************************/
+static void
+test_reference_region_1D(void)
+{
+ 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 = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)SPACE1_DIM1);
+ rbuf = (hdset_reg_ref_t *)HDmalloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1);
+ dwbuf = (uint8_t *)HDmalloc(sizeof(uint8_t) * SPACE3_DIM1);
+ drbuf = (uint8_t *)HDcalloc(sizeof(uint8_t), (size_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 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++ = i * 3; // 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(obj_type, 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, (size_t)POINT1_NPOINTS, (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);
+
+ // Get and verify object type
+ obj_type = dset1.getRefObjType(&rbuf[0], H5R_DATASET_REGION);
+ verify_val(obj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__);
+
+ // Get dataspace of dset3 the verify number of elements
+ sid1 = dset3.getSpace();
+ nelms = sid1.getSimpleExtentNpoints();
+ verify_val((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);
+
+ // Get dataspace of newds then verify number of elements
+ sid1 = newds.getSpace();
+ nelms = sid1.getSimpleExtentNpoints();
+ verify_val((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 = (uint8_t *)drbuf, i = 0; i < SPACE3_DIM1; i++, tu8++)
+ verify_val(*tu8, (uint8_t)(i * 3), "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((long)nelms, 30, "DataSpace::getSelectNpoints",__LINE__,__FILE__);
+
+ // Get and verify number of hyperslab blocks
+ nelms = reg_sp.getSelectHyperNblocks();
+ verify_val((long)nelms, 15, "DataSpace::getSelectNpoints",__LINE__,__FILE__);
+
+ /* Allocate space for the hyperslab blocks */
+ coords = (hsize_t *)HDmalloc(nelms * SPACE3_RANK * sizeof(hsize_t) * 2);
+
+ // Get the list of hyperslab blocks currently selected
+ reg_sp.getSelectHyperBlocklist((hsize_t)0, (hsize_t)nelms, coords);
+
+ // Verify values in the list
+ verify_val(coords[0], 2, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[1], 3, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[2], 7, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[3], 8, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[4], 12, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[5], 13, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[6], 17, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[7], 18, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[8], 22, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[9], 23, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[10], 27, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[11], 28, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[12], 32, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[13], 33, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[14], 37, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[15], 38, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[16], 42, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[17], 43, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[18], 47, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[19], 48, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[20], 52, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[21], 53, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[22], 57, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[23], 58, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[24], 62, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[25], 63, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[26], 67, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[27], 68, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[28], 72, "Hyperslab Coordinates",__LINE__,__FILE__);
+ verify_val(coords[29], 73, "Hyperslab Coordinates",__LINE__,__FILE__);
+
+ HDfree(coords);
+
+ // Check boundaries
+ reg_sp.getSelectBounds(low, high);
+ verify_val(low[0], 2, "DataSpace::getSelectBounds",__LINE__,__FILE__);
+ verify_val(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((long)nelmspts, 10, "DataSpace::getSelectNpoints",__LINE__,__FILE__);
+
+ /* Allocate space for the hyperslab blocks */
+ coords = (hsize_t *)HDmalloc(nelmspts * SPACE3_RANK * sizeof(hsize_t));
+
+ // Get the list of element points currently selected
+ elm_sp.getSelectElemPointlist((hsize_t)0, (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(low[0], 3, "DataSpace::getSelectBounds",__LINE__,__FILE__);
+ verify_val(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_compat(): Test basic object reference functionality.
+** Tests references to various kinds of objects using deprecated API.
+**
+****************************************************************/
+static void test_reference_compat(void)
+{
+ // Not yet
+} // test_reference_compat()
+
+
/****************************************************************
**
** test_reference(): Main reference testing routine.
@@ -344,7 +805,11 @@ void test_reference(void)
//MESSAGE("Testing References\n");
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_compat(); // Tests deprecated reference routines (not yet)
} // test_reference()
@@ -360,5 +825,6 @@ extern "C"
void cleanup_reference(void)
{
HDremove(FILE1.c_str());
+ HDremove(FILE2.c_str());
}