From 539f4691fa1cd9e86965106ce69b08d3e18a80a9 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Fri, 9 Mar 2018 21:29:28 -0600 Subject: Added C++ wrappers - HDFFV-10149 Description: Added the following wrappers to class H5::Group: + H5Lcreate_soft: // Creates a soft link from link_name to target_name. void newLink(const char *target_name, const char *link_name,...) void newLink(const H5std_string& target_name,...) + H5Lcreate_hard: // Creates a hard link from new_name to curr_name. void newLink(const char *curr_name, const Group& new_loc,...) void newLink(const H5std_string& curr_name, const Group& new_loc,...) // Creates a hard link from new_name to curr_name in same location. void newLink(const char *curr_name, const hid_t same_loc,...) void newLink(const H5std_string& curr_name, const hid_t same_loc,...) + H5Lcopy: // Copy an object from a group of file to another. void copyLink(const char *src_name, const Group& dst,...) void copyLink(const H5std_string& src_name, const Group& dst,...) // Copy an object from a group of file to the same location. void copyLink(const char *src_name, const char *dst_name,...) void copyLink(const H5std_string& src_name,...) + H5Lmove: // Rename an object in a group or file to a new location. void moveLink(const char* src_name, const Group& dst,...) void moveLink(const H5std_string& src_name, const Group& dst,...) // Rename an object in a group or file to the same location. void moveLink(const char* src_name, const char* dst_name,...) void moveLink(const H5std_string& src_name,...) Platforms tested: Linux/64 (jelly) Linux/ppc64 (ostrich) Darwin (osx1010test) --- c++/src/H5Group.cpp | 311 ++++++++++++++++++++++++++++++++++++--- c++/src/H5Group.h | 69 +++++++++ c++/src/H5Location.cpp | 3 + c++/test/tlinks.cpp | 391 +++++++++++++++++++++++++++++++++---------------- 4 files changed, 628 insertions(+), 146 deletions(-) diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index c0e0dd1..aa27a18 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -76,6 +76,297 @@ void Group::closeObjId(hid_t obj_id) const } } +/*** For H5L API ***/ + +//-------------------------------------------------------------------------- +// Function: Group::newLink +///\brief Creates a soft link from \a link_name to \a target_name. +///\param target_name - IN: Name of object, can be a non-existing object +///\param link_name - IN: Link name for the target name +///\param lcpl - IN: Link creation plist - default to PropList::DEFAULT +///\param lapl - IN: Link access plist - default to PropList::DEFAULT +///\exception H5::FileIException or H5::GroupIException +///\par Description +/// Note that both names are interpreted relative to the current +/// location. +/// For information on creating a soft link, please refer to the +/// H5Lcreate_soft APIs in the HDF5 C Reference Manual. +// March 2018 +//-------------------------------------------------------------------------- +void Group::newLink(const char *target_name, const char *link_name, + const PropList& lcpl, const PropList& lapl) const +{ + herr_t ret_value = -1; + hid_t lcpl_id = lcpl.getId(); + hid_t lapl_id = lapl.getId(); + + ret_value = H5Lcreate_soft(target_name, id, link_name, lcpl_id, lapl_id); + if (ret_value < 0) + throwException("newLink", "creating soft link failed"); +} + +//-------------------------------------------------------------------------- +// Function: Group::newLink +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a target_name and \a link_name. +///\exception H5::FileIException or H5::GroupIException +// March, 2018 +//-------------------------------------------------------------------------- +void Group::newLink(const H5std_string& target_name, const H5std_string& + link_name, const PropList& lcpl, const PropList& lapl) const +{ + newLink(target_name.c_str(), link_name.c_str(), lcpl, lapl); +} + +//-------------------------------------------------------------------------- +// Function: Group::newLink +///\brief Creates a hard link from \a new_name to \a curr_name. +///\param curr_name - IN: Name of the existing object +///\param new_name - IN: New name for the object +///\param lcpl - IN: Link creation plist - default to PropList::DEFAULT +///\param lapl - IN: Link access plist - default to PropList::DEFAULT +///\exception H5::FileIException or H5::GroupIException +///\par Description +/// Note that both names are interpreted relative to the +/// specified location. +/// For information on creating a hard link, please refer to the +/// H5Lcreate_hard APIs in the HDF5 C Reference Manual. +// March 2018 +//-------------------------------------------------------------------------- +void Group::newLink(const char *curr_name, const Group& new_loc, + const char *new_name, const PropList& lcpl, const PropList& lapl) const +{ + herr_t ret_value = -1; + hid_t new_loc_id = new_loc.getId(); + hid_t lcpl_id = lcpl.getId(); + hid_t lapl_id = lapl.getId(); + + ret_value = H5Lcreate_hard(getId(), curr_name, new_loc.getId(), new_name, H5P_DEFAULT, H5P_DEFAULT); + if (ret_value < 0) + throwException("newLink", "creating link failed"); +} + +//-------------------------------------------------------------------------- +// Function: Group::newLink +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a curr_name and \a new_name. +///\exception H5::FileIException or H5::GroupIException +// March, 2018 +//-------------------------------------------------------------------------- +void Group::newLink(const H5std_string& curr_name, const Group& new_loc, + const H5std_string& new_name, const PropList& lcpl, const PropList& lapl) const +{ + newLink(curr_name.c_str(), new_loc, new_name.c_str(), lcpl, lapl); +} + +//-------------------------------------------------------------------------- +// Function: Group::newLink +///\brief Creates a hard link from \a new_name to \a curr_name - can be +/// used to pass in H5L_SAME_LOC. +///\param curr_name - IN: Name of the existing object +///\param new_name - IN: New name for the object +///\param lcpl - IN: Link creation plist - default to PropList::DEFAULT +///\param lapl - IN: Link access plist - default to PropList::DEFAULT +///\exception H5::FileIException or H5::GroupIException +///\par Description +/// Note that both names are interpreted relative to the +/// specified location. +/// For information on creating a hard link, please refer to the +/// H5Lcreate_hard APIs in the HDF5 C Reference Manual. +// March 2018 +//-------------------------------------------------------------------------- +void Group::newLink(const char *curr_name, const hid_t same_loc, + const char *new_name, const PropList& lcpl, const PropList& lapl) const +{ + herr_t ret_value = -1; + hid_t lcpl_id = lcpl.getId(); + hid_t lapl_id = lapl.getId(); + + ret_value = H5Lcreate_hard(getId(), curr_name, same_loc, new_name, H5P_DEFAULT, H5P_DEFAULT); + + if (ret_value < 0) + throwException("newLink", "creating link failed"); +} + +//-------------------------------------------------------------------------- +// Function: Group::newLink +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a curr_name and \a new_name. +///\exception H5::FileIException or H5::GroupIException +// March, 2018 +//-------------------------------------------------------------------------- +void Group::newLink(const H5std_string& curr_name, const hid_t same_loc, + const H5std_string& new_name, const PropList& lcpl, const PropList& lapl) const +{ + newLink(curr_name.c_str(), same_loc, new_name.c_str(), lcpl, lapl); +} + + +//-------------------------------------------------------------------------- +// Function: Group::copyLink +///\brief Copies a link from one location to another. +///\param src - IN: Source location +///\param src_name - IN: Original name +///\param dst - IN: Destination location +///\param dst_name - IN: New name +///\param lcpl - IN: Link creation plist - default PropList::DEFAULT +///\param lapl - IN: Link access plist - default PropList::DEFAULT +///\exception H5::FileIException or H5::GroupIException +// March, 2018 +//-------------------------------------------------------------------------- +void Group::copyLink(const char *src_name, + const Group& dst, const char *dst_name, const PropList& lcpl, + const PropList& lapl) const +{ + herr_t ret_value; + hid_t dst_id = dst.getId(); + hid_t lcpl_id = lcpl.getId(); + hid_t lapl_id = lapl.getId(); + + ret_value = H5Lcopy(getId(), src_name, dst_id, dst_name, lcpl_id, lapl_id); + if(ret_value < 0) + throwException("copyLink", "H5Lcopy failed"); +} + +//-------------------------------------------------------------------------- +// Function: Group::copyLink +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a src_name and \a dst_name. +///\exception H5::FileIException or H5::GroupIException +// March, 2018 +//-------------------------------------------------------------------------- +void Group::copyLink(const H5std_string& src_name, + const Group& dst, const H5std_string& dst_name, const PropList& lcpl, + const PropList& lapl) const +{ + copyLink(src_name.c_str(), dst, dst_name.c_str(), lcpl, lapl); +} + +//-------------------------------------------------------------------------- +// Function: Group::copyLink +///\brief Copies a link to the same location. +///\param src - IN: Source location +///\param src_name - IN: Original name +///\param dst_name - IN: New name +///\param lcpl - IN: Link creation plist - default PropList::DEFAULT +///\param lapl - IN: Link access plist - default PropList::DEFAULT +///\exception H5::FileIException or H5::GroupIException +// March, 2018 +//-------------------------------------------------------------------------- +void Group::copyLink(const char *src_name, + const char *dst_name, const PropList& lcpl, + const PropList& lapl) const +{ + herr_t ret_value; + hid_t lcpl_id = lcpl.getId(); + hid_t lapl_id = lapl.getId(); + + ret_value = H5Lcopy(getId(), src_name, H5L_SAME_LOC, dst_name, lcpl_id, lapl_id); + if(ret_value < 0) + throwException("copyLink", "H5Lcopy H5L_SAME_LOC failed"); +} + +//-------------------------------------------------------------------------- +// Function: Group::copyLink +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a src_name and \a dst_name. +///\exception H5::FileIException or H5::GroupIException +// March, 2018 +//-------------------------------------------------------------------------- +void Group::copyLink(const H5std_string& src_name, + const H5std_string& dst_name, const PropList& lcpl, + const PropList& lapl) const +{ + copyLink(src_name.c_str(), dst_name.c_str(), lcpl, lapl); +} + +//-------------------------------------------------------------------------- +// Function: Group::moveLink +///\brief Renames an object in a group/file and moves it to a new location. +///\param src - IN: Source location +///\param src_name - IN: Original name +///\param dst - IN: Destination location +///\param dst_name - IN: New name +///\param lcpl - IN: Link creation plist - default PropList::DEFAULT +///\param lapl - IN: Link access plist - default PropList::DEFAULT +///\exception H5::FileIException or H5::GroupIException +///\note +/// Exercise care in moving groups as it is possible to render +/// data in a file inaccessible with Group::moveLink. Please refer +/// to the Group Interface in the HDF5 User's Guide for details. +// March, 2018 +//-------------------------------------------------------------------------- +void Group::moveLink(const char* src_name, const Group& dst, const char* dst_name, const PropList& lcpl, const PropList& lapl) const +{ + herr_t ret_value; + hid_t dst_id = dst.getId(); + hid_t lcpl_id = lcpl.getId(); + hid_t lapl_id = lapl.getId(); + + ret_value = H5Lmove(getId(), src_name, dst_id, dst_name, lcpl_id, lapl_id); + if (ret_value < 0) + throwException("moveLink", "H5Lmove failed"); +} + +//-------------------------------------------------------------------------- +// Function: Group::moveLink +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a src_name and \a dst_name. +///\exception H5::FileIException or H5::GroupIException +// March, 2018 +//-------------------------------------------------------------------------- +void Group::moveLink(const H5std_string& src_name, const Group& dst, const H5std_string& dst_name, const PropList& lcpl, const PropList& lapl) const +{ + moveLink(src_name.c_str(), dst, dst_name.c_str(), lcpl, lapl); +} + +//-------------------------------------------------------------------------- +// Function: Group::moveLink +///\brief Renames an object in a group or file to the same location. +///\param src - IN: Source location +///\param src_name - IN: Original name +///\param dst_name - IN: New name +///\param lcpl - IN: Link creation plist - default PropList::DEFAULT +///\param lapl - IN: Link access plist - default PropList::DEFAULT +///\exception H5::FileIException or H5::GroupIException +///\note +/// Exercise care in moving groups as it is possible to render +/// data in a file inaccessible with Group::moveLink. Please refer +/// to the Group Interface in the HDF5 User's Guide for details. +// March, 2018 +//-------------------------------------------------------------------------- +void Group::moveLink(const char* src_name, const char* dst_name, const PropList& lcpl, const PropList& lapl) const +{ + herr_t ret_value; + hid_t lcpl_id = lcpl.getId(); + hid_t lapl_id = lapl.getId(); + + ret_value = H5Lmove(getId(), src_name, H5L_SAME_LOC, dst_name, lcpl_id, lapl_id); + if (ret_value < 0) + throwException("moveLink", "H5Lmove H5L_SAME_LOC failed"); +} + +//-------------------------------------------------------------------------- +// Function: Group::moveLink +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a src_name and \a dst_name. +///\exception H5::FileIException or H5::GroupIException +// March, 2018 +//-------------------------------------------------------------------------- +void Group::moveLink(const H5std_string& src_name, const H5std_string& dst_name, const PropList& lcpl, const PropList& lapl) const +{ + moveLink(src_name.c_str(), H5L_SAME_LOC, dst_name.c_str(), lcpl, lapl); +} + +/*** End of H5L API section ***/ + //-------------------------------------------------------------------------- // Function: Group::getLocId // Purpose: Get the id of this group @@ -123,26 +414,6 @@ Group::Group(const H5Location& loc, const void* ref, H5R_type_t ref_type, const } //-------------------------------------------------------------------------- -// Function: Group overload constructor - dereference -// brief Given a reference, ref, to an hdf5 group, creates a Group objec -// param attr - IN: Specifying location where the referenced object is i -// param ref - IN: Reference pointer -// param ref_type - IN: Reference type - default to H5R_OBJECT -// param plist - IN: Property list - default to PropList::DEFAULT -// exception H5::ReferenceException -// Programmer Binh-Minh Ribler - Oct, 2006 -// Modification -// Mar, 2017 -// Removed in 1.10.1 because H5Location is Attribute's baseclass -// now. -BMR -//-------------------------------------------------------------------------- -/* Group::Group(const Attribute& attr, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object(), id(H5I_INVALID_HID) -{ - id = H5Location::p_dereference(attr.getId(), ref, ref_type, plist, "constructor - by dereference"); -} - */ - -//-------------------------------------------------------------------------- // Function: Group::getNumObjs ///\brief Returns the number of objects in this group. ///\return Number of objects diff --git a/c++/src/H5Group.h b/c++/src/H5Group.h index b3a9007..d95d996 100644 --- a/c++/src/H5Group.h +++ b/c++/src/H5Group.h @@ -50,6 +50,75 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { // Closes an object opened by getObjId(). void closeObjId(hid_t obj_id) const; + /*** For H5L API ***/ + + // Creates a soft link from link_name to target_name. + void newLink(const char *target_name, const char *link_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + void newLink(const H5std_string& target_name, + const H5std_string& link_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + + // Creates a hard link from new_name to curr_name. + void newLink(const char *curr_name, + const Group& new_loc, const char *new_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + void newLink(const H5std_string& curr_name, + const Group& new_loc, const H5std_string& new_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + + // Creates a hard link from new_name to curr_name in same location. + void newLink(const char *curr_name, + const hid_t same_loc, const char *new_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + void newLink(const H5std_string& curr_name, + const hid_t same_loc, const H5std_string& new_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + + // Copy an object from a group of file to another. + void copyLink(const char *src_name, + const Group& dst, const char *dst_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + void copyLink(const H5std_string& src_name, + const Group& dst, const H5std_string& dst_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + + // Copy an object from a group of file to the same location. + void copyLink(const char *src_name, const char *dst_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + void copyLink(const H5std_string& src_name, + const H5std_string& dst_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + + // Rename an object in a group or file to a new location. + void moveLink(const char* src_name, + const Group& dst, const char* dst_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + void moveLink(const H5std_string& src_name, + const Group& dst, const H5std_string& dst_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + + // Rename an object in a group or file to the same location. + void moveLink(const char* src_name, const char* dst_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + void moveLink(const H5std_string& src_name, + const H5std_string& dst_name, + const PropList& lcpl = PropList::DEFAULT, + const PropList& lapl = PropList::DEFAULT) const; + // default constructor Group(); diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp index 95c96ad..3ca080e 100644 --- a/c++/src/H5Location.cpp +++ b/c++/src/H5Location.cpp @@ -951,6 +951,9 @@ DataSet H5Location::openDataSet(const H5std_string& name) const // Programmer Binh-Minh Ribler - 2000 // Modification // 2007: QAK modified to use H5L APIs - BMR +// Mar 2018: Inadequate functionality, new hard link is only in +// H5L_SAME_LOC. This function will be retired in favor of +// its replacement, Group::newLink(). - BMR //-------------------------------------------------------------------------- void H5Location::link(H5L_type_t link_type, const char* curr_name, const char* new_name) const { diff --git a/c++/test/tlinks.cpp b/c++/test/tlinks.cpp index e348d64..93bd0266 100644 --- a/c++/test/tlinks.cpp +++ b/c++/test/tlinks.cpp @@ -323,11 +323,9 @@ static const char *FILENAME[] = { * Purpose Test building a file with assorted links. * * Return Success: 0 - * * Failure: -1 * - * Programmer Binh-Minh Ribler - * October 16, 2009 + * October 16, 2009 *------------------------------------------------------------------------- */ static void test_basic_links(hid_t fapl_id, hbool_t new_format) @@ -438,16 +436,267 @@ static void test_basic_links(hid_t fapl_id, hbool_t new_format) /*------------------------------------------------------------------------- + * Function: test_move + * + * Purpose: Tests wrappers of H5Lmove() + * + * Return: Success: 0 + * Failure: number of errors + * March, 2018 + *------------------------------------------------------------------------- + */ +const H5std_string GROUP1NAME("First_group"); +const H5std_string GROUP2NAME("Second_group"); +static void +test_move(hid_t fapl_id, hbool_t new_format) +{ + char filename[1024]; + + if(new_format) + SUBTEST("Group::moveLink (w/new group format)") + else + SUBTEST("Group::moveLink") + + try + { + // Create two new files + h5_fixname(FILENAME[0], fapl_id, filename, sizeof filename); + H5File file_a(filename, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl_id); + h5_fixname(FILENAME[1], fapl_id, filename, sizeof filename); + H5File file_b(filename, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl_id); + + // Create groups in first file + Group grp_1(file_a.createGroup(GROUP1NAME)); + Group grp_2(file_a.createGroup(GROUP2NAME)); + Group grp_move(grp_1.createGroup("group_move")); + + // Create hard and soft links + grp_1.link(H5L_TYPE_HARD, "group_move", "hard"); + grp_2.link(H5L_TYPE_SOFT, "/First_group/group_copy", "soft"); + + // Move a group across files, should fail + try { + grp_1.moveLink("group_move", file_b, "group_new_name"); + + // Should throw an exception but didn't + H5_FAILED(); + cerr << " Group group_move should not be moved across files" << endl; + } catch (Exception& E) { + // expected + } + + // Move a soft link across files, should succeed + grp_2.moveLink("soft", file_b, "soft_new_name"); + if(file_b.exists("soft_new_name") != TRUE) + throw InvalidActionException("H5File::exists", "grp1/soft doesn't exist"); + + // Move a group across groups in the same file while renaming it + grp_1.moveLink("group_move", grp_2, "group_new_name"); + + // Open the group just moved to the new location. */ + Group moved_grp = grp_2.openGroup("group_new_name"); + moved_grp.close(); + + // Verify that the group is no longer in the original location + try { + moved_grp = grp_1.openGroup("group_move"); + + // Should throw an exception but didn't + H5_FAILED(); + cerr << " Group group_move should not be in original location" << endl; + } catch (Exception& E) { + // expected + } + + // Use H5Lmove to rename a group without moving it + H5std_string new_name("group_new_name"); + H5std_string newer_name("group_newer_name"); + grp_2.moveLink(new_name, newer_name); + + // Open the group + moved_grp = grp_2.openGroup("group_newer_name"); + moved_grp.close(); + + // Use H5Lmove to move a group without renaming it + grp_2.moveLink(newer_name, grp_1, newer_name); + + // Open the group + moved_grp = grp_1.openGroup("group_newer_name"); + moved_grp.close(); + + // Move the group while giving long paths + file_a.moveLink("/First_group/group_newer_name", grp_2, "/Second_group/group_newest_name"); + + // Open the group just moved to the new location + moved_grp = grp_2.openGroup("group_newest_name"); + moved_grp.close(); + + // Verify that the groups are not in previous locations + try { + moved_grp = grp_1.openGroup("group_newer_name"); + moved_grp.close(); + + H5_FAILED(); // Should throw an exception but didn't + cerr << " Group group_newer_name should not be in GROUP1NAME" << endl; + } catch (Exception& E) { + // expected + } + try { + moved_grp = grp_2.openGroup("group_newer_name"); + moved_grp.close(); + + H5_FAILED(); // Should throw an exception but didn't + cerr << " Group group_newer_name should not be in GROUP2NAME" << endl; + } catch (Exception& E) { + // expected + } + try { + moved_grp = grp_2.openGroup("group_new_name"); + moved_grp.close(); + + H5_FAILED(); // Should throw an exception but didn't + cerr << " Group group_new_name should not be in GROUP2NAME" << endl; + } catch (Exception& E) { + // expected + } + try { + moved_grp = grp_1.openGroup("group_copy"); + moved_grp.close(); + + H5_FAILED(); // Should throw an exception but didn't + cerr << " Group group_copy should not be in GROUP1NAME" << endl; + } catch (Exception& E) { + // expected + } + PASSED(); + } // end of try block + catch (Exception& E) + { + issue_fail_msg("test_num_links()", __LINE__, __FILE__, E.getCDetailMsg()); + } +} + +/*------------------------------------------------------------------------- + * Function: test_copy + * + * Purpose: Tests wrappers of H5Lcopy() + * + * Return: Success: 0 + * Failure: number of errors + * March, 2018 + *------------------------------------------------------------------------- + */ +static void test_copy(hid_t fapl_id, hbool_t new_format) +{ + char filename[1024]; + + if(new_format) + SUBTEST("Group::copyLink (w/new group format)") + else + SUBTEST("Group::copyLink") + + try + { + // Create two new files + h5_fixname(FILENAME[0], fapl_id, filename, sizeof filename); + H5File file_a(filename, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl_id); + h5_fixname(FILENAME[1], fapl_id, filename, sizeof filename); + H5File file_b(filename, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl_id); + + // Create groups in first file + Group grp_1(file_a.createGroup(GROUP1NAME)); + Group grp_2(file_a.createGroup(GROUP2NAME)); + Group grp_move(grp_1.createGroup("group_copy")); + + // Create hard and soft links + grp_1.newLink("group_copy", H5L_SAME_LOC, "hard"); + grp_2.newLink("/First_group/group_copy", "soft"); + + // Copy a group across files, should fail + try { + grp_1.copyLink("group_copy", file_b, "group_new_name"); + } catch (Exception& E) { + // expected + } + + // Copy a soft link across files, should succeed + grp_2.copyLink("soft", file_b, "soft_new_name"); + if (file_b.exists("soft_new_name") != TRUE) + throw InvalidActionException("H5File::exists", "soft_new_name doesn't exist"); + + // Move a group across groups in the same file while renaming it + H5std_string copy_name("group_copy"); + H5std_string new_name("group_new_name"); + grp_1.copyLink(copy_name, grp_2, new_name); + + // Open the group just moved to the new location. + Group moved_grp(grp_2.openGroup("group_new_name")); + moved_grp.close(); + + // Verify that the group is also in the original location + moved_grp = grp_1.openGroup("group_copy"); + moved_grp.close(); + + // Create a group in the same location with a different name + grp_2.copyLink("group_new_name", "group_newer_name"); + + // Open the group + moved_grp = grp_2.openGroup("group_newer_name"); + moved_grp.close(); + + // Verify that the group is also in the original location + moved_grp = grp_2.openGroup("group_new_name"); + moved_grp.close(); + + // Use H5Lcopy to copy to a different location with the same name + grp_2.copyLink("group_newer_name", grp_1, "group_newer_name"); + + // Open the group + moved_grp = grp_1.openGroup("group_newer_name"); + moved_grp.close(); + + // Verify that the group is still in the previous location + moved_grp = grp_2.openGroup("group_new_name"); + moved_grp.close(); + + // Copy the group while giving long paths + file_a.copyLink("/First_group/group_newer_name", grp_2, "/Second_group/group_newest_name"); + + // Open the newest group just moved to the new location + moved_grp = grp_2.openGroup("group_newest_name"); + moved_grp.close(); + + // Verify that the group is still in all previous original locations + moved_grp = grp_1.openGroup("group_newer_name"); + moved_grp.close(); + + moved_grp = grp_2.openGroup("group_newer_name"); + moved_grp.close(); + + moved_grp = grp_2.openGroup("group_new_name"); + moved_grp.close(); + + moved_grp = grp_1.openGroup("group_copy"); + moved_grp.close(); + + PASSED(); + } // end of try block + catch (Exception& E) + { + issue_fail_msg("test_num_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 - * October 16, 2009 + * October 16, 2009 *------------------------------------------------------------------------- */ static void test_num_links(hid_t fapl_id, hbool_t new_format) @@ -491,8 +740,7 @@ static void test_num_links(hid_t fapl_id, hbool_t new_format) * * Return None * - * Programmer Binh-Minh Ribler - * October 16, 2009 + * October 16, 2009 *------------------------------------------------------------------------- */ extern "C" @@ -516,9 +764,10 @@ void test_links() if((fapl2_id = H5Pcopy(fapl_id)) < 0) throw Exception("test_links", "H5Pcopy failed"); - /* Set the "use the latest version of the format" bounds for creating objects in the file */ + /* Set the "use the latest version of the format" bounds for creating + objects in the file */ if(H5Pset_libver_bounds(fapl2_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) - throw Exception("test_links", "H5Pset_libver_bounds failed"); + throw Exception("test_links", "H5Pset_libver_bounds failed"); /* Loop over using new group format */ for(new_format = FALSE; new_format <= TRUE; new_format++) @@ -534,124 +783,10 @@ 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); -#if 0 -// these tests are from the C test links.c and left here for future -// implementation of H5L API - nerrors += test_basic_links(fapl_id, new_format) < 0 ? 1 : 0; - nerrors += cklinks(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += new_links(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += ck_new_links(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += long_links(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += toomany(my_fapl, new_format) < 0 ? 1 : 0; - - /* Test new H5L link creation routine */ - nerrors += test_lcpl(my_fapl, new_format); - nerrors += test_move(my_fapl, new_format); - nerrors += test_copy(my_fapl, new_format); - nerrors += test_move_preserves(my_fapl, new_format); -#ifndef H5_NO_DEPRECATED_SYMBOLS - nerrors += test_deprec(my_fapl, new_format); -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - nerrors += external_link_root(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_path(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_mult(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_self(envval, my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_pingpong(envval, my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_toomany(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_dangling(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_recursive(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_query(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_unlink_compact(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_unlink_dense(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_move(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_ride(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_closing(envval, my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_endian(new_format) < 0 ? 1 : 0; - nerrors += external_link_strong(my_fapl, new_format) < 0 ? 1 : 0; - - /* tests for external link */ - nerrors += external_link_env(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_prefix(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_abs_mainpath(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_rel_mainpath(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_cwd(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_abstar(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_abstar_cur(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_reltar(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_chdir(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_set_elink_fapl1(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_set_elink_fapl2(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_set_elink_fapl3(new_format) < 0 ? 1 : 0; - nerrors += external_set_elink_acc_flags(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_set_elink_cb(my_fapl, new_format) < 0 ? 1 : 0; - -#ifdef H5_HAVE_WINDOW_PATH - nerrors += external_link_win1(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_win2(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_win3(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_win4(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_win5(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_win6(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_win7(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_win8(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += external_link_win9(my_fapl, new_format) < 0 ? 1 : 0; -#endif - /* These tests assume that external links are a form of UD links, - * so assume that everything that passed for external links - * above has already been tested for UD links. - */ - if(new_format == TRUE) { - nerrors += ud_hard_links(fapl2) < 0 ? 1 : 0; /* requires new format groups */ - nerrors += ud_link_reregister(fapl2) < 0 ? 1 : 0; /* requires new format groups */ - } /* end if */ - - nerrors += ud_callbacks(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += ud_link_errors(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += lapl_udata(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += lapl_nlinks(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += linkinfo(my_fapl, new_format) < 0 ? 1 : 0; - - /* Misc. extra tests, useful for both new & old format files */ - nerrors += link_visit(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += link_visit_by_name(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += obj_visit(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += obj_visit_by_name(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += obj_visit_stop(my_fapl, new_format) < 0 ? 1 : 0; - - /* Keep this test last, it's testing files that are used above */ - /* do not do this for files used by external link tests */ - nerrors += check_all_closed(my_fapl, new_format, EXTSTOP) < 0 ? 1 : 0; -#endif // 0 + test_move(my_fapl_id, new_format); + test_copy(my_fapl_id, new_format); } /* end for */ -#if 0 - /* New group revision feature tests */ - nerrors += corder_create_empty(fapl2) < 0 ? 1 : 0; -/* XXX: when creation order indexing is fully working, go back and add checks -* to these tests to make certain that the creation order values are -* correct. -*/ - nerrors += corder_create_compact(fapl2) < 0 ? 1 : 0; - nerrors += corder_create_dense(fapl2) < 0 ? 1 : 0; - nerrors += corder_transition(fapl2) < 0 ? 1 : 0; - nerrors += corder_delete(fapl2) < 0 ? 1 : 0; - nerrors += link_info_by_idx(fapl2) < 0 ? 1 : 0; - nerrors += delete_by_idx(fapl2) < 0 ? 1 : 0; - nerrors += link_iterate(fapl2) < 0 ? 1 : 0; - nerrors += open_by_idx(fapl2) < 0 ? 1 : 0; - nerrors += object_info(fapl2) < 0 ? 1 : 0; - nerrors += group_info(fapl2) < 0 ? 1 : 0; - nerrors += timestamps(fapl2) < 0 ? 1 : 0; - - /* Test new API calls on old-style groups */ - nerrors += link_info_by_idx_old(fapl) < 0 ? 1 : 0; - nerrors += delete_by_idx_old(fapl) < 0 ? 1 : 0; - nerrors += link_iterate_old(fapl) < 0 ? 1 : 0; - nerrors += open_by_idx_old(fapl) < 0 ? 1 : 0; - nerrors += object_info_old(fapl) < 0 ? 1 : 0; - nerrors += group_info_old(fapl) < 0 ? 1 : 0; - -#endif /* Close 2nd FAPL */ H5Pclose(fapl2_id); @@ -683,5 +818,9 @@ extern "C" void cleanup_links() { HDremove(FILENAME[0]); + HDremove(FILENAME[1]); } + + + -- cgit v0.12