summaryrefslogtreecommitdiffstats
path: root/c++/test/tobject.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2017-03-14 03:53:43 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2017-03-14 03:53:43 (GMT)
commita48c9c4024e7ede0021e1a9d8c1d4c197333e0d0 (patch)
tree4f69e727c624eafc5c1a812e24cc27b71175d69f /c++/test/tobject.cpp
parent56e5b4ed05fb3bad51c226ec5b567871a45e0bce (diff)
downloadhdf5-a48c9c4024e7ede0021e1a9d8c1d4c197333e0d0.zip
hdf5-a48c9c4024e7ede0021e1a9d8c1d4c197333e0d0.tar.gz
hdf5-a48c9c4024e7ede0021e1a9d8c1d4c197333e0d0.tar.bz2
Purpose: Add new C++ wrappers
Description: Added wrappers for H5Iis_valid, H5Ps/get_nlinks, H5Tget_create_plist, H5Oopen, H5Oclose and H5Pset_virtual // Checks if the given ID is valid. static bool isValid(hid_t an_id); // Sets the number of soft or user-defined links that can be // traversed before a failure occurs. void setNumLinks(size_t nlinks) const; // Gets the number of soft or user-defined link traversals allowed size_t getNumLinks() const; // Returns a copy of the creation property list of a datatype. PropList getCreatePlist() const; // Opens an object within a group or a file, i.e., root group. hid_t getObjId(const char* name,...); hid_t getObjId(const H5std_string& name,...); // Closes an object opened by getObjId(). void closeObjId(hid_t obj_id) const; // Maps elements of a virtual dataset to elements of the source dataset. void setVirtual(const DataSpace& vspace, const char *src_fname,...); void setVirtual(const DataSpace& vspace, const H5std_string src_fname,...); Platforms tested: Linux/32 2.6 (jam) Linux/64 (platypus) Darwin (osx1010test)
Diffstat (limited to 'c++/test/tobject.cpp')
-rw-r--r--c++/test/tobject.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/c++/test/tobject.cpp b/c++/test/tobject.cpp
index 6003dd6..3c9c1b0 100644
--- a/c++/test/tobject.cpp
+++ b/c++/test/tobject.cpp
@@ -32,6 +32,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");
@@ -395,7 +396,126 @@ static void test_get_objtype()
issue_fail_msg("test_get_objtype", __LINE__, __FILE__);
}
} // test_get_objtype
+
+/*-------------------------------------------------------------------------
+ * Function: test_open_object_header
+ *
+ * Purpose Test Group::getObjId function.
+ *
+ * Return None
+ *
+ * Programmer Binh-Minh Ribler (use C version)
+ * March, 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("Group::getObjId");
+
+ 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 getObjId can open all three types of objects
+ hid_t obj_grp = file1.getObjId(GROUPNAME);
+ hid_t obj_dtype = file1.getObjId(DTYPENAME);
+ hid_t obj_dset = file1.getObjId(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.getObjId(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_objects
*
@@ -421,6 +541,7 @@ void test_object()
test_existance(); // Test check for object existance
test_get_objname_ontypes(); // Test get object name from types
test_get_objtype(); // Test get object type
+ test_open_object_header(); // Test object header functions (H5O)
} // test_objects