summaryrefslogtreecommitdiffstats
path: root/test/objcopy.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/objcopy.c')
-rw-r--r--test/objcopy.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/test/objcopy.c b/test/objcopy.c
index ce0f3d3..6b56b66 100644
--- a/test/objcopy.c
+++ b/test/objcopy.c
@@ -11452,6 +11452,104 @@ error:
/*-------------------------------------------------------------------------
+ * Function: test_copy_iterate
+ *
+ * Purpose: Tests iterating over objects in the root group, copying
+ * all of them.
+ *
+ * Return: Success: 0
+ * Failure: number of errors
+ *
+ * Programmer: Neil Fortner
+ * Thursday, July 12, 2012
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_copy_iterate_cb(hid_t loc_id, const char *name,
+ const H5L_info_t UNUSED *link_info, void *op_data)
+{
+ hid_t dst_loc_id = *((hid_t *)op_data);
+
+ if(H5Ocopy(loc_id, name, dst_loc_id, name, H5P_DEFAULT, H5P_DEFAULT) < 0)
+ TEST_ERROR
+
+ return(H5_ITER_CONT);
+
+error:
+ return(H5_ITER_ERROR);
+} /* end test_copy_iterate_cb */
+
+static int
+test_copy_iterate(hid_t fcpl_src, hid_t fcpl_dst, hid_t src_fapl, hid_t dst_fapl)
+{
+ hid_t fid1 = -1, fid2 = -1; /* File IDs */
+ hid_t gid = -1; /* Group ID */
+ int i;
+ char grp_name[8];
+ char src_filename[NAME_BUF_SIZE];
+ char dst_filename[NAME_BUF_SIZE];
+
+ TESTING("H5Ocopy(): inside H5Literate() callback");
+
+ /* Initialize the filenames */
+ h5_fixname(FILENAME[0], src_fapl, src_filename, sizeof src_filename);
+ h5_fixname(FILENAME[1], src_fapl, dst_filename, sizeof dst_filename);
+
+ /* Reset file address checking info */
+ addr_reset();
+
+ /* Create source file */
+ if((fid1 = H5Fcreate(src_filename, H5F_ACC_TRUNC, fcpl_src, src_fapl)) < 0)
+ TEST_ERROR
+
+ /* Create groups */
+ for(i=0; i<9; i++) {
+ HDsnprintf(grp_name, sizeof(grp_name), "grp%d", i);
+ if((gid = H5Gcreate2(fid1, grp_name, H5P_DEFAULT, H5P_DEFAULT,
+ H5P_DEFAULT)) < 0)
+ TEST_ERROR
+ if(H5Gclose(gid) < 0)
+ TEST_ERROR
+ } /* end for */
+
+ /* Create destination file */
+ if((fid2 = H5Fcreate(dst_filename, H5F_ACC_TRUNC, fcpl_dst, dst_fapl)) < 0)
+ TEST_ERROR
+
+ /* Close files */
+ if(H5Fclose(fid1) < 0) TEST_ERROR
+ if(H5Fclose(fid2) < 0) TEST_ERROR
+
+ /* Reopen files */
+ if((fid1 = H5Fopen(src_filename, H5F_ACC_RDWR, src_fapl)) < 0) TEST_ERROR
+ if((fid2 = H5Fopen(dst_filename, H5F_ACC_RDWR, dst_fapl)) < 0) TEST_ERROR
+
+ /* Iterate over links in the root group, copying each object */
+ if((gid = H5Gopen2(fid1, "/", H5P_DEFAULT)) < 0) TEST_ERROR
+ if(H5Literate(gid, H5_INDEX_NAME, H5_ITER_INC, NULL, test_copy_iterate_cb,
+ &fid2) < 0)
+ TEST_ERROR
+
+ /* Close */
+ if(H5Gclose(gid) < 0) TEST_ERROR
+ if(H5Fclose(fid1) < 0) TEST_ERROR
+ if(H5Fclose(fid2) < 0) TEST_ERROR
+
+ PASSED();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Gclose(gid);
+ H5Fclose(fid1);
+ H5Fclose(fid2);
+ } H5E_END_TRY;
+ return 1;
+} /* end test_copy_iterate */
+
+
+/*-------------------------------------------------------------------------
* Function: test_copy_option
*
* Purpose: Create a group in SRC file and copy it to DST file
@@ -12289,6 +12387,7 @@ main(void)
nerrors += test_copy_same_file_named_datatype(fcpl_src, src_fapl);
nerrors += test_copy_old_layout(fcpl_dst, dst_fapl);
nerrors += test_copy_null_ref(fcpl_src, fcpl_dst, src_fapl, dst_fapl);
+ nerrors += test_copy_iterate(fcpl_src, fcpl_dst, src_fapl, dst_fapl);
}
/* TODO: not implemented