diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2006-11-20 15:23:29 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2006-11-20 15:23:29 (GMT) |
commit | 98f3bca75e1608438408d6af4655bf98651f89a1 (patch) | |
tree | b8837519ab90fd918c8deaaed5a8d950983cb0d0 /test/links.c | |
parent | 9f55ae114eda54a5ef2d4e524de26dd0fae008dd (diff) | |
download | hdf5-98f3bca75e1608438408d6af4655bf98651f89a1.zip hdf5-98f3bca75e1608438408d6af4655bf98651f89a1.tar.gz hdf5-98f3bca75e1608438408d6af4655bf98651f89a1.tar.bz2 |
[svn-r12949] Description:
Finish implementation of H5Literate() [still needs real tests]
Clean up datatype macro warnings a bit more.
Unify iterator callback macros and put up in public header file, with the
iterator directions.
Tested on:
Mac OS X/32 10.4.8 (amazon)
FreeBSD/32 4.11 (sleipnir)
Linux/32 2.4 (heping)
Linux/64 2.4 (mir)
AIX/32 5.? (copper)
Diffstat (limited to 'test/links.c')
-rw-r--r-- | test/links.c | 356 |
1 files changed, 345 insertions, 11 deletions
diff --git a/test/links.c b/test/links.c index 277146f..85fcb6f 100644 --- a/test/links.c +++ b/test/links.c @@ -5193,7 +5193,6 @@ corder_create_empty(hid_t fapl) TESTING("creating empty group with creation order indexing") /* Create file */ - /* (with creation order tracking for the root group) */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR @@ -5312,7 +5311,6 @@ corder_create_compact(hid_t fapl) TESTING("creating compact group with creation order indexing") /* Create file */ - /* (with creation order tracking for the root group) */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR @@ -5435,7 +5433,6 @@ corder_create_dense(hid_t fapl) TESTING("creating dense group with creation order indexing") /* Create file */ - /* (with creation order tracking for the root group) */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR @@ -5573,7 +5570,6 @@ corder_transition(hid_t fapl) TESTING("transitioning group with creation order indexing between dense & compact forms") /* Create file */ - /* (with creation order tracking for the root group) */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR @@ -5809,7 +5805,6 @@ corder_delete(hid_t fapl) * before deleting group */ for(reopen_file = FALSE; reopen_file <= TRUE; reopen_file++) { /* Create file */ - /* (with creation order tracking for the root group) */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) FAIL_STACK_ERROR @@ -5899,7 +5894,6 @@ error: } H5E_END_TRY; return -1; } /* end corder_delete() */ -#endif /* QAK */ /*------------------------------------------------------------------------- @@ -6060,7 +6054,6 @@ error: return(-1); } /* end link_info_by_idx_check() */ -#ifndef QAK /*------------------------------------------------------------------------- * Function: link_info_by_idx @@ -6112,7 +6105,6 @@ link_info_by_idx(hid_t fapl) } /* end else */ /* Create file */ - /* (with creation order tracking for the root group) */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR @@ -6489,7 +6481,6 @@ delete_by_idx(hid_t fapl) } /* end else */ /* Create file */ - /* (with creation order tracking for the root group) */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR @@ -6742,7 +6733,6 @@ error: } H5E_END_TRY; return -1; } /* end delete_by_idx() */ -#endif /* QAK */ /*------------------------------------------------------------------------- @@ -6976,6 +6966,350 @@ error: return -1; } /* end delete_by_idx_old() */ +#endif /* QAK */ + + +/*------------------------------------------------------------------------- + * Function: link_iterate_cb + * + * Purpose: Callback routine for iterating over links in group + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Quincey Koziol + * Monday, November 20, 2006 + * + *------------------------------------------------------------------------- + */ +static int +link_iterate_cb(hid_t group_id, const char *link_name, const H5L_info_t * info, + void *op_data) +{ + return(H5_ITER_CONT); +} /* end link_iterate_cb() */ + + +/*------------------------------------------------------------------------- + * Function: link_iterate + * + * Purpose: Create a group with creation order indices and test deleting + * links by index. + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Quincey Koziol + * Tuesday, November 14, 2006 + * + *------------------------------------------------------------------------- + */ +static int +link_iterate(hid_t fapl) +{ + hid_t file_id = (-1); /* File ID */ + hid_t group_id = (-1); /* Group ID */ + hid_t gcpl_id = (-1); /* Group creation property list ID */ + H5L_index_t idx_type; /* Type of index to operate on */ + H5_iter_order_t order; /* Order within in the index */ + hbool_t use_index; /* Use index on creation order values */ + unsigned max_compact; /* Maximum # of links to store in group compactly */ + unsigned min_dense; /* Minimum # of links to store in group "densely" */ + H5L_info_t linfo; /* Link info struct */ + char objname[NAME_BUF_SIZE]; /* Object name */ + char filename[NAME_BUF_SIZE];/* File name */ + char tmpname[NAME_BUF_SIZE]; /* Temporary link name */ + unsigned u; /* Local index variable */ + herr_t ret; /* Generic return value */ + + /* Loop over operating on different indices on link fields */ + for(idx_type = H5L_INDEX_NAME; idx_type <=H5L_INDEX_CRT_ORDER; idx_type++) { + /* Loop over operating in different orders */ + for(order = H5_ITER_INC; order <=H5_ITER_DEC; order++) { + /* Loop over using index for creation order value */ + for(use_index = FALSE; use_index <= TRUE; use_index++) { + /* Print appropriate test message */ + if(idx_type == H5L_INDEX_CRT_ORDER) { + if(order == H5_ITER_INC) { + if(use_index) + TESTING("iterating over links by creation order index in increasing order w/creation order index") + else + TESTING("iterating over links by creation order index in increasing order w/o creation order index") + } /* end if */ + else { + if(use_index) + TESTING("iterating over links by creation order index in decreasing order w/creation order index") + else + TESTING("iterating over links by creation order index in decreasing order w/o creation order index") + } /* end else */ + } /* end if */ + else { + if(order == H5_ITER_INC) { + if(use_index) + TESTING("iterating over links by name index in increasing order w/creation order index") + else + TESTING("iterating over links by name index in increasing order w/o creation order index") + } /* end if */ + else { + if(use_index) + TESTING("iterating over links by name index in decreasing order w/creation order index") + else + TESTING("iterating over links by name index in decreasing order w/o creation order index") + } /* end else */ + } /* end else */ + + /* Create file */ + h5_fixname(FILENAME[0], fapl, filename, sizeof filename); + if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create group creation property list */ + if((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0) TEST_ERROR + + /* Set creation order tracking & indexing on group */ + if(use_index) + if(H5Pset_creation_order_index(gcpl_id, TRUE) < 0) TEST_ERROR + if(H5Pset_creation_order_tracking(gcpl_id, TRUE) < 0) TEST_ERROR + + /* Create group with creation order tracking on */ + if((group_id = H5Gcreate_expand(file_id, gcpl_id, H5P_DEFAULT)) < 0) TEST_ERROR + if(H5Llink(file_id, CORDER_GROUP_NAME, group_id, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Query the group creation properties */ + if(H5Pget_link_phase_change(gcpl_id, &max_compact, &min_dense) < 0) TEST_ERROR + + + /* Check for iteration on empty group */ + H5E_BEGIN_TRY { + ret = H5Literate(group_id, ".", idx_type, order, NULL, link_iterate_cb, NULL, H5P_DEFAULT); + } H5E_END_TRY; + if(ret >= 0) TEST_ERROR + +#ifdef QAK + /* Create several links, up to limit of compact form */ + for(u = 0; u < max_compact; u++) { + hid_t group_id2; /* Group ID */ + + /* Make name for link */ + sprintf(objname, "filler %02u", u); + + /* Create hard link, with group object */ + if((group_id2 = H5Gcreate(group_id, objname, (size_t)0)) < 0) TEST_ERROR + if(H5Gclose(group_id2) < 0) TEST_ERROR + + /* Verify link information for new link */ + if(link_info_by_idx_check(group_id, objname, (hsize_t)u, TRUE, use_index) < 0) TEST_ERROR + } /* end for */ + + /* Verify state of group (compact) */ + if(H5G_has_links_test(group_id, NULL) != TRUE) TEST_ERROR + + /* Check for out of bound deletion */ + H5E_BEGIN_TRY { + ret = H5Ldelete_by_idx(group_id, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT); + } H5E_END_TRY; + if(ret >= 0) TEST_ERROR + + /* Delete links from compact group */ + for(u = 0; u < (max_compact - 1); u++) { + /* Delete first link in appropriate order */ + if(H5Ldelete_by_idx(group_id, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT) < 0) TEST_ERROR + + /* Verify the link information for first link in appropriate order */ + HDmemset(&linfo, 0, sizeof(linfo)); + if(H5Lget_info_by_idx(group_id, ".", idx_type, order, (hsize_t)0, &linfo, H5P_DEFAULT) < 0) TEST_ERROR + if(order == H5_ITER_INC) { + if(linfo.corder != (u + 1)) TEST_ERROR + } /* end if */ + else { + if(linfo.corder != (max_compact - (u + 2))) TEST_ERROR + } /* end else */ + + /* Verify the name for first link in appropriate order */ + HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE); + if(H5Lget_name_by_idx(group_id, ".", idx_type, order, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT) < 0) TEST_ERROR + if(order == H5_ITER_INC) + sprintf(objname, "filler %02u", (u + 1)); + else + sprintf(objname, "filler %02u", (max_compact - (u + 2))); + if(HDstrcmp(objname, tmpname)) TEST_ERROR + } /* end for */ + + /* Delete last link */ + if(H5Ldelete_by_idx(group_id, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT) < 0) TEST_ERROR + + /* Verify state of group (empty) */ + if(H5G_has_links_test(group_id, NULL) == TRUE) TEST_ERROR + + /* Create more links, to push group into dense form */ + for(u = 0; u < (max_compact * 2); u++) { + hid_t group_id2; /* Group ID */ + + /* Make name for link */ + sprintf(objname, "filler %02u", u); + + /* Create hard link, with group object */ + if((group_id2 = H5Gcreate(group_id, objname, (size_t)0)) < 0) TEST_ERROR + if(H5Gclose(group_id2) < 0) TEST_ERROR + + /* Verify state of group (dense) */ + if(u >= max_compact) + if(H5G_is_new_dense_test(group_id) != TRUE) TEST_ERROR + + /* Verify link information for new link */ + if(link_info_by_idx_check(group_id, objname, (hsize_t)u, TRUE, use_index) < 0) TEST_ERROR + } /* end for */ + + /* Check for out of bound deletion again */ + H5E_BEGIN_TRY { + ret = H5Ldelete_by_idx(group_id, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT); + } H5E_END_TRY; + if(ret >= 0) TEST_ERROR + + /* Delete links from dense group, in appropriate order */ + for(u = 0; u < ((max_compact * 2) - 1); u++) { + /* Delete first link in appropriate order */ + if(H5Ldelete_by_idx(group_id, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT) < 0) TEST_ERROR + + /* Verify the link information for first link in appropriate order */ + HDmemset(&linfo, 0, sizeof(linfo)); + if(H5Lget_info_by_idx(group_id, ".", idx_type, order, (hsize_t)0, &linfo, H5P_DEFAULT) < 0) TEST_ERROR + if(order == H5_ITER_INC) { + if(linfo.corder != (u + 1)) TEST_ERROR + } /* end if */ + else { + if(linfo.corder != ((max_compact * 2) - (u + 2))) TEST_ERROR + } /* end else */ + + /* Verify the name for first link in appropriate order */ + HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE); + if(H5Lget_name_by_idx(group_id, ".", idx_type, order, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT) < 0) TEST_ERROR + if(order == H5_ITER_INC) + sprintf(objname, "filler %02u", (u + 1)); + else + sprintf(objname, "filler %02u", ((max_compact * 2) - (u + 2))); + if(HDstrcmp(objname, tmpname)) TEST_ERROR + } /* end for */ + + /* Delete last link */ + if(H5Ldelete_by_idx(group_id, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT) < 0) TEST_ERROR + + /* Verify state of group (empty) */ + if(H5G_has_links_test(group_id, NULL) == TRUE) TEST_ERROR + if(H5G_is_new_dense_test(group_id) == TRUE) TEST_ERROR + + /* Check for deletion on empty group again */ + H5E_BEGIN_TRY { + ret = H5Ldelete_by_idx(group_id, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT); + } H5E_END_TRY; + if(ret >= 0) TEST_ERROR + + + /* Delete links in middle */ + + + /* Create more links, to push group into dense form */ + for(u = 0; u < (max_compact * 2); u++) { + hid_t group_id2; /* Group ID */ + + /* Make name for link */ + sprintf(objname, "filler %02u", u); + + /* Create hard link, with group object */ + if((group_id2 = H5Gcreate(group_id, objname, (size_t)0)) < 0) TEST_ERROR + if(H5Gclose(group_id2) < 0) TEST_ERROR + + /* Verify state of group (dense) */ + if(u >= max_compact) + if(H5G_is_new_dense_test(group_id) != TRUE) TEST_ERROR + + /* Verify link information for new link */ + if(link_info_by_idx_check(group_id, objname, (hsize_t)u, TRUE, use_index) < 0) TEST_ERROR + } /* end for */ + + /* Delete every other link from dense group, in appropriate order */ + for(u = 0; u < max_compact; u++) { + /* Delete link */ + if(H5Ldelete_by_idx(group_id, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT) < 0) TEST_ERROR + + /* Verify the link information for current link in appropriate order */ + HDmemset(&linfo, 0, sizeof(linfo)); + if(H5Lget_info_by_idx(group_id, ".", idx_type, order, (hsize_t)u, &linfo, H5P_DEFAULT) < 0) TEST_ERROR + if(order == H5_ITER_INC) { + if(linfo.corder != ((u * 2) + 1)) TEST_ERROR + } /* end if */ + else { + if(linfo.corder != ((max_compact * 2) - ((u * 2) + 2))) TEST_ERROR + } /* end else */ + + /* Verify the name for current link in appropriate order */ + HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE); + if(H5Lget_name_by_idx(group_id, ".", idx_type, order, (hsize_t)u, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT) < 0) TEST_ERROR + if(order == H5_ITER_INC) + sprintf(objname, "filler %02u", ((u * 2) + 1)); + else + sprintf(objname, "filler %02u", ((max_compact * 2) - ((u * 2) + 2))); + if(HDstrcmp(objname, tmpname)) TEST_ERROR + } /* end for */ + + /* Delete remaining links from dense group, in appropriate order */ + for(u = 0; u < (max_compact - 1); u++) { + /* Delete link */ + if(H5Ldelete_by_idx(group_id, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT) < 0) TEST_ERROR + + /* Verify the link information for first link in appropriate order */ + HDmemset(&linfo, 0, sizeof(linfo)); + if(H5Lget_info_by_idx(group_id, ".", idx_type, order, (hsize_t)0, &linfo, H5P_DEFAULT) < 0) TEST_ERROR + if(order == H5_ITER_INC) { + if(linfo.corder != ((u * 2) + 3)) TEST_ERROR + } /* end if */ + else { + if(linfo.corder != ((max_compact * 2) - ((u * 2) + 4))) TEST_ERROR + } /* end else */ + + /* Verify the name for first link in appropriate order */ + HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE); + if(H5Lget_name_by_idx(group_id, ".", idx_type, order, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT) < 0) TEST_ERROR + if(order == H5_ITER_INC) + sprintf(objname, "filler %02u", ((u * 2) + 3)); + else + sprintf(objname, "filler %02u", ((max_compact * 2) - ((u * 2) + 4))); + if(HDstrcmp(objname, tmpname)) TEST_ERROR + } /* end for */ + + /* Delete last link */ + if(H5Ldelete_by_idx(group_id, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT) < 0) TEST_ERROR + + /* Verify state of group (empty) */ + if(H5G_has_links_test(group_id, NULL) == TRUE) TEST_ERROR + if(H5G_is_new_dense_test(group_id) == TRUE) TEST_ERROR +#endif /* QAK */ + + + + /* Close the group */ + if(H5Gclose(group_id) < 0) TEST_ERROR + + /* Close the group creation property list */ + if(H5Pclose(gcpl_id) < 0) TEST_ERROR + + /* Close the file */ + if(H5Fclose(file_id) < 0) TEST_ERROR + + PASSED(); + } /* end for */ + } /* end for */ + } /* end for */ + + return 0; + +error: + H5E_BEGIN_TRY { + H5Pclose(gcpl_id); + H5Gclose(group_id); + H5Fclose(file_id); + } H5E_END_TRY; + return -1; +} /* end link_iterate() */ /*------------------------------------------------------------------------- @@ -7092,7 +7426,7 @@ main(void) } /* end for */ #else /* QAK */ HDfprintf(stderr, "Uncomment tests!\n"); - nerrors += delete_by_idx_old(fapl) < 0 ? 1 : 0; + nerrors += link_iterate(fapl2) < 0 ? 1 : 0; #endif /* QAK */ /* Close 2nd FAPL */ |