summaryrefslogtreecommitdiffstats
path: root/c++/test
diff options
context:
space:
mode:
Diffstat (limited to 'c++/test')
-rw-r--r--c++/test/tfile.cpp213
-rw-r--r--c++/test/tlinks.cpp49
-rw-r--r--c++/test/tobject.cpp185
-rw-r--r--c++/test/ttypes.cpp20
4 files changed, 435 insertions, 32 deletions
diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp
index 6e12dfd..de62cf5 100644
--- a/c++/test/tfile.cpp
+++ b/c++/test/tfile.cpp
@@ -28,13 +28,10 @@
#else
#include <iostream>
#endif
-#include <string>
-
-#ifndef H5_NO_STD
- using std::cerr;
- using std::endl;
-#endif // H5_NO_STD
+using std::cerr;
+using std::endl;
+#include <string>
#include "H5Cpp.h" // C++ API header file
using namespace H5;
@@ -52,6 +49,7 @@ const size_t F2_OFFSET_SIZE = 8;
const size_t F2_LENGTH_SIZE = 8;
const unsigned F2_SYM_LEAF_K = 8;
const unsigned F2_SYM_INTERN_K = 32;
+const unsigned F2_ISTORE = 64;
const H5std_string FILE2("tfile2.h5");
const hsize_t F3_USERBLOCK_SIZE = (hsize_t)0;
@@ -510,15 +508,13 @@ 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 */
+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()
{
@@ -691,8 +687,8 @@ static void test_libver_bounds_real(
*/
Group group = file.createGroup(GROUP1);
- obj_version = file.childObjVersion(GROUP1);
- verify_val(obj_version, oh_vers_mod, "H5File::childObjVersion", __LINE__, __FILE__);
+ obj_version = group.objVersion();
+ verify_val(obj_version, oh_vers_mod, "Group::objVersion", __LINE__, __FILE__);
group.close(); // close "/G1"
@@ -702,8 +698,8 @@ static void test_libver_bounds_real(
*/
group = file.createGroup(SUBGROUP3);
- obj_version = group.childObjVersion(SUBGROUP3);
- verify_val(obj_version, oh_vers_mod, "H5File::childObjVersion", __LINE__, __FILE__);
+ obj_version = group.objVersion();
+ verify_val(obj_version, oh_vers_mod, "Group::objVersion", __LINE__, __FILE__);
group.close(); // close "/G1/G3"
@@ -747,15 +743,175 @@ static void test_libver_bounds()
test_libver_bounds_real(H5F_LIBVER_LATEST, H5O_VERSION_2, H5F_LIBVER_EARLIEST, H5O_VERSION_1);
PASSED();
} /* end test_libver_bounds() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_commonfg
+ *
+ * Purpose Verify that H5File works as a root group.
+ *
+ * Return None
+ *
+ * Programmer Binh-Minh Ribler (use C version)
+ * March, 2015
+ *
+ *-------------------------------------------------------------------------
+ */
+static void test_commonfg()
+{
+ // Output message about test being performed
+ SUBTEST("Root group");
+
+ try {
+ // Create a file using default properties.
+ H5File file4(FILE4, H5F_ACC_TRUNC);
+
+ // Try opening the root group.
+ Group rootgroup(file4.openGroup(ROOTGROUP));
+
+ // Create a group in the root group.
+ Group group(rootgroup.createGroup(GROUPNAME, 0));
+
+ // Create the data space.
+ hsize_t dims[RANK] = {NX, NY};
+ DataSpace space(RANK, dims);
+
+ // Create a new dataset.
+ DataSet dataset(group.createDataSet (DSETNAME, PredType::NATIVE_INT, space));
+
+ // Get and verify file name via a dataset.
+ H5std_string file_name = dataset.getFileName();
+ verify_val(file_name, FILE4, "DataSet::getFileName", __LINE__, __FILE__);
+
+ // Create an attribute for the dataset.
+ Attribute attr(dataset.createAttribute(DATTRNAME, PredType::NATIVE_INT, space));
+
+ // Get and verify file name via an attribute.
+ file_name = attr.getFileName();
+ verify_val(file_name, FILE4, "Attribute::getFileName", __LINE__, __FILE__);
+
+ // Create an attribute for the file via root group.
+ Attribute rootg_attr(rootgroup.createAttribute(FATTRNAME, PredType::NATIVE_INT, space));
+
+ // Get and verify file name via an attribute.
+ file_name = attr.getFileName();
+ verify_val(file_name, FILE4, "Attribute::getFileName", __LINE__, __FILE__);
+
+ PASSED();
+ } // end of try block
+
+ catch (Exception& E)
+ {
+ issue_fail_msg("test_commonfg()", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+
+} /* end test_commonfg() */
+
+
+const H5std_string FILE7("tfile7.h5");
+
+/*-------------------------------------------------------------------------
+ * Function: test_file_info
+ *
+ * Purpose Verify that various properties in a file creation property
+ * lists are stored correctly in the file and can be retrieved
+ * when the file is re-opened.
+ *
+ * Return None
+ *
+ * Programmer Binh-Minh Ribler
+ * February, 2017
+ *
+ *-------------------------------------------------------------------------
+ */
+const hsize_t FSP_SIZE_DEF = 4096;
+const hsize_t FSP_SIZE512 = 512;
+static void test_file_info()
+{
+ // Output message about test being performed
+ SUBTEST("File general information");
+
+ hsize_t out_threshold = 0; // Free space section threshold to get
+ hbool_t out_persist = FALSE;// Persist free-space read
+
+ try {
+ // Create a file using default properties.
+ H5File tempfile(FILE7, H5F_ACC_TRUNC);
+
+ // Get the file's version information.
+ H5F_info_t finfo;
+ tempfile.getFileInfo(finfo); // there's no C test for H5Fget_info
+
+ // Close the file.
+ tempfile.close();
+
+ // Create file creation property list.
+ FileCreatPropList fcpl;
+
+ // Set various file information.
+ fcpl.setUserblock(F2_USERBLOCK_SIZE);
+ fcpl.setSizes(F2_OFFSET_SIZE, F2_LENGTH_SIZE);
+ fcpl.setSymk(F2_SYM_INTERN_K, F2_SYM_LEAF_K);
+ fcpl.setIstorek(F2_ISTORE);
+
+ // Creating a file with the non-default file creation property list
+ // should create a version 1 superblock
+
+ // Create file with custom file creation property list.
+ H5File file7(FILE7, H5F_ACC_TRUNC, fcpl);
+
+ // Close the file creation property list.
+ fcpl.close();
+
+ // Get the file's version information.
+ file7.getFileInfo(finfo); // there's no C test for H5Fget_info
+
+ // Close the file.
+ file7.close();
+
+ // Re-open the file.
+ file7.openFile(FILE7, H5F_ACC_RDONLY);
+
+ // Get the file's creation property list.
+ FileCreatPropList fcpl2 = file7.getCreatePlist();
+
+ // Get the file's version information.
+ file7.getFileInfo(finfo); // there's no C test for H5Fget_info
+
+ // Retrieve the property values & check them.
+ hsize_t userblock = fcpl2.getUserblock();
+ verify_val(userblock, F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__);
+
+ size_t off_size = 0, len_size = 0;
+ fcpl2.getSizes(off_size, len_size);
+ verify_val(off_size, F2_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__);
+ verify_val(len_size, F2_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__);
+
+ unsigned sym_ik = 0, sym_lk = 0;
+ fcpl2.getSymk(sym_ik, sym_lk);
+ verify_val(sym_ik, F2_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__);
+ verify_val(sym_lk, F2_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__);
+
+ unsigned istore_ik = fcpl2.getIstorek();
+ verify_val(istore_ik, F2_ISTORE, "FileCreatPropList::getIstorek", __LINE__, __FILE__);
+
+ PASSED();
+ } // end of try block
+ catch (Exception& E)
+ {
+ issue_fail_msg("test_filespace_info()", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+} /* test_file_info() */
+
/*-------------------------------------------------------------------------
* Function: test_file
*
- * Purpose: Main file testing routine
+ * Purpose Main file testing routine
*
- * Return: None
+ * Return None
*
- * Programmer: Binh-Minh Ribler (use C version)
+ * Programmer Binh-Minh Ribler (use C version)
* January 2001
*
* Modifications:
@@ -768,29 +924,33 @@ void test_file()
// Output message about test being performed
MESSAGE(5, ("Testing File I/O Operations\n"));
- test_file_create(); // Test file creation (also creation templates)
- 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_libver_bounds(); // Test format version
+ test_file_create(); // Test file creation (also creation templates)
+ 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_libver_bounds(); // Test format version
+ test_commonfg(); // Test H5File as a root group
+ test_file_info(); // Test various file info
} // test_file()
/*-------------------------------------------------------------------------
* Function: cleanup_file
*
- * Purpose: Cleanup temporary test files
+ * Purpose Cleanup temporary test files
*
- * Return: none
+ * Return none
*
- * Programmer: (use C version)
+ * Programmer (use C version)
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
+#ifdef __cplusplus
extern "C"
+#endif
void cleanup_file()
{
HDremove(FILE1.c_str());
@@ -799,4 +959,5 @@ void cleanup_file()
HDremove(FILE4.c_str());
HDremove(FILE5.c_str());
HDremove(FILE6.c_str());
+ HDremove(FILE7.c_str());
} // cleanup_file
diff --git a/c++/test/tlinks.cpp b/c++/test/tlinks.cpp
index 0786bb5..58dd63a 100644
--- a/c++/test/tlinks.cpp
+++ b/c++/test/tlinks.cpp
@@ -441,7 +441,55 @@ static void test_basic_links(hid_t fapl_id, hbool_t new_format)
issue_fail_msg("test_basic_links()", __LINE__, __FILE__, E.getCDetailMsg());
}
}
+
+/*-------------------------------------------------------------------------
+ * Function: test_num_links
+ *
+ * Purpose Test setting and getting limit of number of links
+ *
+ * Return Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer Binh-Minh Ribler
+ * Mar, 2017
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void test_num_links(hid_t fapl_id, hbool_t new_format)
+{
+ char filename[NAME_BUF_SIZE];
+
+ if(new_format)
+ SUBTEST("Setting number of links (w/new group format)")
+ else
+ SUBTEST("Setting number of links")
+ try
+ {
+ // Use the file access template id to create a file access prop. list.
+ FileAccPropList fapl(fapl_id);
+
+ h5_fixname(FILENAME[0], fapl_id, filename, sizeof filename);
+ H5File file(filename, H5F_ACC_RDWR, FileCreatPropList::DEFAULT, fapl);
+
+ LinkAccPropList lapl;
+ size_t nlinks = 5;
+ lapl.setNumLinks(nlinks);
+
+ // Read it back and verify
+ size_t read_nlinks = lapl.getNumLinks();
+ verify_val(read_nlinks, nlinks, "LinkAccPropList::setNumLinks", __LINE__, __FILE__);
+
+ PASSED();
+ } // end of try block
+ catch (Exception& E)
+ {
+ issue_fail_msg("test_num_links()", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+} // test_num_links
/*-------------------------------------------------------------------------
* Function: test_links
@@ -494,6 +542,7 @@ void test_links()
/* General tests... (on both old & new format groups */
// FileAccPropList may be passed in instead of fapl id
test_basic_links(my_fapl_id, new_format);
+ test_num_links(my_fapl_id, new_format);
#if 0
// these tests are from the C test links.c and left here for future
// implementation of H5L API
diff --git a/c++/test/tobject.cpp b/c++/test/tobject.cpp
index 2639092..10012fc 100644
--- a/c++/test/tobject.cpp
+++ b/c++/test/tobject.cpp
@@ -37,6 +37,7 @@ using namespace H5;
#include "h5cpputil.h" // C++ utilility header file
const H5std_string FILE_OBJECTS("tobjects.h5");
+const H5std_string FILE_OBJHDR("tobject_header.h5");
const H5std_string GROUP1("Top Group");
const H5std_string GROUP1_PATH("/Top Group");
const H5std_string GROUP1_1("Sub-Group 1.1");
@@ -267,25 +268,25 @@ static void test_get_objtype()
// Get and verify object type with
// H5O_type_t childObjType(const H5std_string& objname)
H5O_type_t objtype = file.childObjType(DSET_IN_FILE);
- verify_val(objtype, H5O_TYPE_DATASET, "DataSet::childObjType", __LINE__, __FILE__);
+ verify_val(objtype, H5O_TYPE_DATASET, "H5File::childObjType", __LINE__, __FILE__);
// Get and verify object type with
// H5O_type_t childObjType(const char* objname)
objtype = grp1.childObjType(GROUP1_1.c_str());
- verify_val(objtype, H5O_TYPE_GROUP, "DataSet::childObjType", __LINE__, __FILE__);
+ verify_val(objtype, H5O_TYPE_GROUP, "Group::childObjType", __LINE__, __FILE__);
// Get and verify object type with
// H5O_type_t childObjType(hsize_t index, H5_index_t index_type,
// H5_iter_order_t order, const char* objname=".")
objtype = grp1.childObjType((hsize_t)1, H5_INDEX_NAME, H5_ITER_INC);
- verify_val(objtype, H5O_TYPE_NAMED_DATATYPE, "DataSet::childObjType", __LINE__, __FILE__);
+ verify_val(objtype, H5O_TYPE_NAMED_DATATYPE, "Group::childObjType", __LINE__, __FILE__);
// Get and verify object type with
// H5O_type_t childObjType(hsize_t index,
// H5_index_t index_type=H5_INDEX_NAME,
// H5_iter_order_t order=H5_ITER_INC, const char* objname=".")
objtype = grp1.childObjType((hsize_t)2);
- verify_val(objtype, H5O_TYPE_GROUP, "DataSet::childObjType", __LINE__, __FILE__);
+ verify_val(objtype, H5O_TYPE_GROUP, "Group::childObjType", __LINE__, __FILE__);
// Everything will be closed as they go out of scope
@@ -298,6 +299,180 @@ static void test_get_objtype()
issue_fail_msg("test_get_objtype", __LINE__, __FILE__);
}
} // test_get_objtype
+
+/*-------------------------------------------------------------------------
+ * Function: test_open_object_header
+ *
+ * Purpose Test H5Location::openObjId function.
+ *
+ * Return None
+ *
+ * Programmer Binh-Minh Ribler (use C version)
+ * May 15, 2017
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+const H5std_string GROUPNAME("group");
+const H5std_string DTYPENAME("group/datatype");
+const H5std_string DTYPENAME_INGRP("datatype");
+const H5std_string DSETNAME("dataset");
+#define RANK 2
+#define DIM0 5
+#define DIM1 10
+static void test_open_object_header()
+{
+ hsize_t dims[2];
+ H5G_info_t ginfo; /* Group info struct */
+
+ // Output message about test being performed
+ SUBTEST("H5Location::openObjId and H5Location::closeObjId");
+
+ try {
+ // Create file FILE1
+ H5File file1(FILE_OBJHDR, H5F_ACC_TRUNC);
+ /* Create a group, dataset, and committed datatype within the file */
+
+ // Create a group in the root group
+ Group grp(file1.createGroup(GROUPNAME));
+ grp.close();
+
+ // Commit the type inside the file
+ IntType dtype(PredType::NATIVE_INT);
+ dtype.commit(file1, DTYPENAME);
+ dtype.close();
+
+ // Create a new dataset
+ dims[0] = DIM0;
+ dims[1] = DIM1;
+ DataSpace dspace(RANK, dims);
+ DataSet dset(file1.createDataSet(DSETNAME, PredType::NATIVE_INT, dspace));
+
+ // Close dataset and dataspace
+ dset.close();
+ dspace.close();
+
+ // Now make sure that openObjId can open all three types of objects
+ hid_t obj_grp = file1.openObjId(GROUPNAME);
+ hid_t obj_dtype = file1.openObjId(DTYPENAME);
+ hid_t obj_dset = file1.openObjId(DSETNAME);
+
+ // Make sure that each is the right kind of ID
+ H5I_type_t id_type = IdComponent::getHDFObjType(obj_grp);
+ verify_val(id_type, H5I_GROUP, "H5Iget_type for group ID", __LINE__, __FILE__);
+ id_type = IdComponent::getHDFObjType(obj_dtype);
+ verify_val(id_type, H5I_DATATYPE, "H5Iget_type for datatype ID", __LINE__, __FILE__);
+ id_type = IdComponent::getHDFObjType(obj_dset);
+ verify_val(id_type, H5I_DATASET, "H5Iget_type for dataset ID", __LINE__, __FILE__);
+
+ /* Do something more complex with each of the IDs to make sure */
+
+ Group grp2(obj_grp);
+ hsize_t num_objs = grp2.getNumObjs();
+ verify_val(num_objs, 1, "H5Gget_info", __LINE__, __FILE__);
+ // There should be one object, the datatype
+
+ // Close datatype object opened from the file
+ file1.closeObjId(obj_dtype);
+
+ dset.setId(obj_dset);
+ dspace = dset.getSpace();
+ bool is_simple = dspace.isSimple();
+ dspace.close();
+
+ // Open datatype object from the group
+ obj_dtype = grp2.openObjId(DTYPENAME_INGRP);
+
+ dtype.setId(obj_dtype);
+ H5T_class_t type_class = dtype.getClass();
+ verify_val(type_class, H5T_INTEGER, "H5Tget_class", __LINE__, __FILE__);
+ dtype.close();
+
+ // Close datatype object
+ grp2.closeObjId(obj_dtype);
+
+ // Close the group object
+ file1.closeObjId(obj_grp);
+
+ // Try doing something with group, the ID should still work
+ num_objs = grp2.getNumObjs();
+ verify_val(num_objs, 1, "H5Gget_info", __LINE__, __FILE__);
+
+ // Close the cloned group
+ grp2.close();
+
+ PASSED();
+ } // end of try block
+ // catch invalid action exception
+ catch (InvalidActionException& E)
+ {
+ cerr << " in InvalidActionException" << endl;
+ cerr << " *FAILED*" << endl;
+ cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl;
+ }
+ // catch all other exceptions
+ catch (Exception& E)
+ {
+ cerr << " in Exception" << endl;
+ issue_fail_msg("test_file_name()", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+} /* test_open_object_header() */
+
+/*-------------------------------------------------------------------------
+ * Function: test_is_valid
+ *
+ * Purpose: Tests validating IDs.
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ * Programmer: Binh-Minh Ribler
+ * May 15, 2017
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void test_is_valid()
+{
+ SUBTEST("IdComponent::isValid");
+
+ try {
+ // Create a datatype
+ IntType int1(PredType::NATIVE_INT);
+
+ // Check that the ID is valid
+ hid_t int1_id = int1.getId();
+ bool is_valid = IdComponent::isValid(int1_id);
+ verify_val(is_valid, true, "IdComponent::isValid", __LINE__, __FILE__);
+
+ // Create another datatype
+ FloatType float1(PredType::NATIVE_FLOAT);
+
+ // Check that the ID is valid
+ is_valid = IdComponent::isValid(float1.getId());
+ verify_val(is_valid, true, "IdComponent::isValid", __LINE__, __FILE__);
+
+ // Close the integer type, then check the id, it should no longer be valid
+ int1.close();
+ is_valid = IdComponent::isValid(int1_id);
+ verify_val(is_valid, false, "IdComponent::isValid", __LINE__, __FILE__);
+
+ // Check that an id of -1 is invalid
+ is_valid = IdComponent::isValid((hid_t)-1);
+ verify_val(is_valid, false, "IdComponent::isValid", __LINE__, __FILE__);
+
+ PASSED();
+ } // try block
+
+ // catch all other exceptions
+ catch (Exception& E)
+ {
+ cerr << " in catch " << endl;
+ issue_fail_msg("test_get_objtype", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+} // test_is_valid
/*-------------------------------------------------------------------------
* Function: test_objects
@@ -323,6 +498,8 @@ void test_object()
test_get_objname(); // Test get object name from groups/datasets
test_get_objname_ontypes(); // Test get object name from types
test_get_objtype(); // Test get object type
+ test_is_valid(); // Test validating IDs
+ test_open_object_header(); // Test object header functions (H5O)
} // test_objects
diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp
index 9da05e6..384e913 100644
--- a/c++/test/ttypes.cpp
+++ b/c++/test/ttypes.cpp
@@ -248,12 +248,28 @@ static void test_query()
index = tid2.getMemberIndex("ORANGE");
verify_val(index, 3, "EnumType::getMemberIndex()", __LINE__, __FILE__);
- // Commit compound datatype and close it
+ // Commit compound datatype, and test getting the datatype creation
+ // prop list, then close it
tid1.commit(file, CompT_NAME);
+ PropList tcpl = tid1.getCreatePlist();
+ if (!IdComponent::isValid(tcpl.getId()))
+ {
+ // Throw an invalid action exception
+ throw InvalidActionException("IdComponent::isValid", "Datatype creation property list is not valid");
+ }
+ tcpl.close();
tid1.close();
- // Commit enumeration datatype and close it
+ // Commit enumeration datatype, and test getting the datatype creation
+ // prop list, then close it
tid2.commit(file, EnumT_NAME);
+ tcpl = tid2.getCreatePlist();
+ if (!IdComponent::isValid(tcpl.getId()))
+ {
+ // Throw an invalid action exception
+ throw InvalidActionException("IdComponent::isValid", "Datatype creation property list is not valid");
+ }
+ tcpl.close();
tid2.close();
// Open the datatypes for query