diff options
Diffstat (limited to 'c++')
-rw-r--r-- | c++/src/H5Object.cpp | 54 | ||||
-rw-r--r-- | c++/src/H5Object.h | 5 | ||||
-rw-r--r-- | c++/test/tattr.cpp | 19 | ||||
-rw-r--r-- | c++/test/tfile.cpp | 14 | ||||
-rw-r--r-- | c++/test/tlinks.cpp | 7 | ||||
-rw-r--r-- | c++/test/tobject.cpp | 98 |
6 files changed, 187 insertions, 10 deletions
diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index b95e222..940a7c6 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -227,6 +227,60 @@ int H5Object::iterateAttrs(attr_operator_t user_op, unsigned *_idx, void *op_dat } //-------------------------------------------------------------------------- +// Function: H5Object::getInfo +///\brief Returns information about an HDF5 object. +///\return Struct containing the object info +///\exception +// July, 2018 +//-------------------------------------------------------------------------- +void H5Object::getInfo(H5O_info_t& objinfo, unsigned fields) const +{ + + // Use C API to get information of the object + herr_t ret_value = H5Oget_info2(getId(), &objinfo, fields); + + // Throw exception if C API returns failure + if (ret_value < 0) + throwException(inMemFunc("getObjinfo"), "H5Oget_info2 failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::getInfo +///\brief Returns information about an HDF5 object given its name. +///\return Struct containing the object info +///\exception +// July, 2018 +//-------------------------------------------------------------------------- +void H5Object::getInfo(const char* name, H5O_info_t& objinfo, unsigned fields, const LinkAccPropList& lapl) const +{ + // Use C API to get information of the object + herr_t ret_value = H5Oget_info_by_name2(getId(), name, &objinfo, fields, lapl.getId()); + + // Throw exception if C API returns failure + if (ret_value < 0) + throwException(inMemFunc("getObjinfo"), "H5Oget_info_by_name2 failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::getInfo +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes +/// a reference to an \c H5std_string for \a name. +///\return Struct containing the object info +///\exception +// July, 2018 +//-------------------------------------------------------------------------- +void H5Object::getInfo(const H5std_string& name, H5O_info_t& objinfo, unsigned fields, const LinkAccPropList& lapl) const +{ + // Use C API to get information of the object + herr_t ret_value = H5Oget_info_by_name2(getId(), name.c_str(), &objinfo, fields, lapl.getId()); + + // Throw exception if C API returns failure + if (ret_value < 0) + throwException(inMemFunc("getObjinfo"), "H5Oget_info_by_name2 failed"); +} + +//-------------------------------------------------------------------------- // Function: H5Object::objVersion ///\brief Returns the header version of this HDF5 object. ///\return Object version, which can have the following values: diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h index 10b3865..606b0ce 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -92,6 +92,11 @@ class H5_DLLCPP H5Object : public H5Location { // Returns an identifier. virtual hid_t getId() const = 0; + // Returns information about an HDF5 object. + void getInfo(H5O_info_t& objinfo, unsigned fields = H5O_INFO_BASIC) const; + void getInfo(const char* name, H5O_info_t& objinfo, unsigned fields = H5O_INFO_BASIC, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; + void getInfo(const H5std_string& name, H5O_info_t& objinfo, unsigned fields = H5O_INFO_BASIC, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; + // Gets the name of this HDF5 object, i.e., Group, DataSet, or // DataType. ssize_t getObjName(char *obj_name, size_t buf_size = 0) const; diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index 5aa4bf5..94c811a 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -518,6 +518,12 @@ static void test_attr_basic_read() int num_attrs = dataset.getNumAttrs(); verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); + // Verify the correct number of attributes another way + H5O_info_t oinfo; + HDmemset(&oinfo, 0, sizeof(oinfo)); + dataset.getInfo(oinfo, H5O_INFO_NUM_ATTRS); + verify_val(oinfo.num_attrs, 3, "DataSet::getInfo", __LINE__, __FILE__); + // Open an attribute for the dataset Attribute ds_attr=dataset.openAttribute(ATTR1_NAME); @@ -538,7 +544,12 @@ static void test_attr_basic_read() // Verify the correct number of attributes num_attrs = group.getNumAttrs(); - verify_val(num_attrs, 1, "H5Group::getNumAttrs", __LINE__, __FILE__); + verify_val(num_attrs, 1, "Group::getNumAttrs", __LINE__, __FILE__); + + // Verify the correct number of attributes another way + HDmemset(&oinfo, 0, sizeof(oinfo)); + group.getInfo(oinfo, H5O_INFO_NUM_ATTRS); + verify_val(oinfo.num_attrs, 1, "Group::getInfo", __LINE__, __FILE__); // Open an attribute for the group Attribute gr_attr = group.openAttribute(ATTR2_NAME); @@ -658,6 +669,12 @@ static void test_attr_compound_read() int num_attrs = dataset.getNumAttrs(); verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__); + // Verify the correct number of attributes another way + H5O_info_t oinfo; + HDmemset(&oinfo, 0, sizeof(oinfo)); + dataset.getInfo(oinfo, H5O_INFO_NUM_ATTRS); + verify_val(oinfo.num_attrs, 1, "DataSet::getInfo", __LINE__, __FILE__); + // Open 1st attribute for the dataset Attribute attr = dataset.openAttribute((unsigned)0); diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp index c82ab42..dd32364 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -657,8 +657,15 @@ static void test_libver_bounds_real( unsigned obj_version = file.childObjVersion(ROOTGROUP); verify_val(obj_version, oh_vers_create, "H5File::childObjVersion", __LINE__, __FILE__); + // Verify object header version another way + H5O_info_t oinfo; + HDmemset(&oinfo, 0, sizeof(oinfo)); + file.getInfo(oinfo, H5O_INFO_HDR); + verify_val(oinfo.hdr.version, oh_vers_create, "H5File::getInfo", __LINE__, __FILE__); + /* - * Reopen the file and make sure the root group still has the correct version + * Reopen the file and make sure the root group still has the correct + * version */ file.close(); @@ -678,6 +685,11 @@ static void test_libver_bounds_real( obj_version = group.objVersion(); verify_val(obj_version, oh_vers_mod, "Group::objVersion", __LINE__, __FILE__); + // Verify object header version another way + HDmemset(&oinfo, 0, sizeof(oinfo)); + group.getInfo(oinfo, H5O_INFO_HDR); + verify_val(oinfo.hdr.version, oh_vers_mod, "Group::getInfo", __LINE__, __FILE__); + group.close(); // close "/G1" /* diff --git a/c++/test/tlinks.cpp b/c++/test/tlinks.cpp index b8560aa..f8d7089 100644 --- a/c++/test/tlinks.cpp +++ b/c++/test/tlinks.cpp @@ -515,7 +515,7 @@ test_lcpl(hid_t fapl_id, hbool_t new_format) } // end of try block catch (Exception& E) { - issue_fail_msg("test_num_links()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_lcpl()", __LINE__, __FILE__, E.getCDetailMsg()); } } // end test_lcpl() @@ -657,7 +657,7 @@ test_move(hid_t fapl_id, hbool_t new_format) } // end of try block catch (Exception& E) { - issue_fail_msg("test_num_links()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_move()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_move @@ -792,7 +792,7 @@ static void test_copy(hid_t fapl_id, hbool_t new_format) } // end of try block catch (Exception& E) { - issue_fail_msg("test_num_links()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_copy()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_copy @@ -892,6 +892,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); test_move(my_fapl_id, new_format); test_copy(my_fapl_id, new_format); test_lcpl(my_fapl_id, new_format); diff --git a/c++/test/tobject.cpp b/c++/test/tobject.cpp index 9980ce0..bfc13a0 100644 --- a/c++/test/tobject.cpp +++ b/c++/test/tobject.cpp @@ -523,19 +523,106 @@ static void test_open_object_header() cerr << " in Exception" << endl; issue_fail_msg("test_file_name()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_open_object_header() */ +} // test_open_object_header /*------------------------------------------------------------------------- - * Function: test_objects + * Function: test_getobjectinfo_same_file + * + * Purpose Test that querying the object info for objects in the same + * file will return the same file "number". + * + * Return None + * + * July, 2018 + *------------------------------------------------------------------------- + */ +const H5std_string FILE_OBJINFO("tobject_getinfo.h5"); +const H5std_string GROUP1NAME("group1"); +const H5std_string GROUP2NAME("group2"); +static void test_getobjectinfo_same_file() +{ + H5O_info_t oinfo1, oinfo2; /* Object info structs */ + + // Output message about test being performed + SUBTEST("Group::getInfo"); + + try { + // Create a new HDF5 file + H5File file1(FILE_OBJINFO, H5F_ACC_TRUNC); + + // Create two groups in the file + Group grp1(file1.createGroup(GROUP1NAME)); + Group grp2(file1.createGroup(GROUP2NAME)); + + // Reset object info + HDmemset(&oinfo1, 0, sizeof(oinfo1)); + HDmemset(&oinfo2, 0, sizeof(oinfo2)); + + // Query the info of two groups and verify that they have the same + // file number + grp1.getInfo(oinfo1); + grp2.getInfo(oinfo2); + verify_val(oinfo1.fileno, oinfo2.fileno, "file number from getInfo", __LINE__, __FILE__); + + // Close groups and file + grp1.close(); + grp2.close(); + file1.close(); + + // Open the file twice + file1.openFile(FILE_OBJINFO, H5F_ACC_RDWR); + H5File file2(FILE_OBJINFO, H5F_ACC_RDWR); + + // Create two groups in the file + grp1 = file1.openGroup(GROUP1NAME); + grp2 = file2.openGroup(GROUP2NAME); + + // Reset object info + HDmemset(&oinfo1, 0, sizeof(oinfo1)); + HDmemset(&oinfo2, 0, sizeof(oinfo2)); + + // Query the info of two groups and verify that they have the same + // file number + grp1.getInfo(oinfo1); + grp2.getInfo(oinfo2); + verify_val(oinfo1.fileno, oinfo2.fileno, "file number from getInfo", __LINE__, __FILE__); + + + // Reset object info + HDmemset(&oinfo1, 0, sizeof(oinfo1)); + HDmemset(&oinfo2, 0, sizeof(oinfo2)); + + file1.getInfo(GROUP1NAME, oinfo1); + file1.getInfo(GROUP2NAME, oinfo2); + verify_val(oinfo1.fileno, oinfo2.fileno, "file number from getObjectInfo", __LINE__, __FILE__); + + // Close groups and files + grp1.close(); + grp2.close(); + file1.close(); + file2.close(); + + PASSED(); + } // end of try block + // catch all other exceptions + catch (Exception& E) + { + cerr << " in Exception " << E.getCFuncName() << "detail: " << E.getCDetailMsg() << endl; + issue_fail_msg("test_file_name()", __LINE__, __FILE__, E.getCDetailMsg()); + } + +} // test_h5o_getinfo_same_file + +/*------------------------------------------------------------------------- + * Function: test_object * * Purpose Tests HDF5 object related functionality * * Return Success: 0 * Failure: -1 * - * Programmer Binh-Minh Ribler - * Friday, Mar 4, 2014 + * March 4, 2014 *------------------------------------------------------------------------- */ extern "C" @@ -549,8 +636,9 @@ void test_object() 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_getobjectinfo_same_file(); // Test object info in same file -} // test_objects +} // test_object /*------------------------------------------------------------------------- |