diff options
Diffstat (limited to 'test/dtypes.c')
-rw-r--r-- | test/dtypes.c | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/test/dtypes.c b/test/dtypes.c index 54aebcc..184cbf7 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -71,6 +71,7 @@ } const char *FILENAME[] = { + "dtypes0", "dtypes1", "dtypes2", "dtypes3", @@ -79,6 +80,7 @@ const char *FILENAME[] = { "dtypes6", "dtypes7", "dtypes8", + "dtypes9", NULL }; @@ -102,6 +104,11 @@ typedef enum dtype_t { #define COMPOUND13_ARRAY_SIZE 256 #define COMPOUND13_ATTR_NAME "attr" +/* Constants for delete_obj_named test */ +#define DEL_OBJ_NAMED_DATASET "/Dataset" +#define DEL_OBJ_NAMED_NAMED_DTYPE "/Dtype" +#define DEL_OBJ_NAMED_ATTRIBUTE "Attr" + /* Count opaque conversions */ static int num_opaque_conversions_g = 0; @@ -6612,6 +6619,197 @@ error: return 1; } /* end test_named_indirect_reopen() */ +static void create_del_obj_named_test_file(const char *filename, hid_t fapl, + hbool_t new_format) +{ + hid_t file; /* File ID */ + hid_t type; /* Datatype ID */ + hid_t space; /* Dataspace ID */ + hid_t attr; /* Attribute ID */ + hid_t dset; /* Dataset ID */ + hid_t fcpl; /* File creation property list ID */ + hid_t my_fapl; /* Copy of file access property list ID */ + hid_t dcpl; /* Dataset creation property list ID */ + herr_t status; /* Generic return value */ + + /* Make copy of FAPL */ + my_fapl = H5Pcopy(fapl); + assert(my_fapl > 0); + + if(new_format) { + /* Use latest version of file format */ + status = H5Pset_libver_bounds(my_fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST); + assert(status >= 0); + } /* end if */ + + /* Create a file creation property list (used for the root group's creation property list) */ + fcpl = H5Pcreate(H5P_FILE_CREATE); + assert(fcpl > 0); + + if(new_format) { + /* Use dense link storage for all links in root group */ + status = H5Pset_link_phase_change(fcpl, 0, 0); + assert(status >= 0); + } /* end if */ + + /* Create file with attribute that uses committed datatype */ + file = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, my_fapl); + assert(file > 0); + + /* Close FCPL */ + status = H5Pclose(fcpl); + assert(status >= 0); + + /* Close FAPL */ + status = H5Pclose(my_fapl); + assert(status >= 0); + + /* Create datatype to commit */ + type = H5Tvlen_create(H5T_NATIVE_INT); + assert(type > 0); + + /* Commit datatype */ + status = H5Tcommit2(file, DEL_OBJ_NAMED_NAMED_DTYPE, type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + assert(status >= 0); + + /* Create scalar dataspace */ + space = H5Screate(H5S_SCALAR); + assert(space > 0); + + /* Create a dataset creation property list */ + dcpl = H5Pcreate(H5P_DATASET_CREATE); + assert(dcpl > 0); + + if(new_format) { + /* Use dense attribute storage for all attributes on dataset */ + status = H5Pset_attr_phase_change(dcpl, 0, 0); + assert(status >= 0); + } /* end if */ + + /* Create dataset */ + dset = H5Dcreate2(file, DEL_OBJ_NAMED_DATASET, type, space, H5P_DEFAULT, dcpl, H5P_DEFAULT); + assert(dset > 0); + + /* Close DCPL */ + status = H5Pclose(dcpl); + assert(status >= 0); + + /* Close dataset */ + status = H5Dclose(dset); + assert(status >= 0); + + /* Create attribute */ + attr = H5Acreate_by_name(file, DEL_OBJ_NAMED_DATASET, DEL_OBJ_NAMED_ATTRIBUTE, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + assert(attr > 0); + + /* Close dataspace */ + status = H5Sclose(space); + assert(status >= 0); + + /* Close datatype */ + status = H5Tclose(type); + assert(status >= 0); + + /* Close attribute */ + status = H5Aclose(attr); + assert(status >= 0); + + /* Close file */ + status = H5Fclose(file); + assert(status >= 0); +} /* end create_del_obj_named_test_file() */ + + +/*------------------------------------------------------------------------- + * Function: test_delete_obj_named + * + * Purpose: Tests that delete objects that use named datatypes through + * different file IDs + * + * Return: Success: 0 + * Failure: number of errors + * + * Programmer: Quincey Koziol + * Monday, July 18, 2011 + * + *------------------------------------------------------------------------- + */ +static int +test_delete_obj_named(hid_t fapl) +{ + hid_t filea1 = -1, filea2 = -1, fileb = -1; /* File IDs */ + hid_t attr = -1; /* Attribute ID */ + hid_t dset = -1; /* Dataset ID */ + hid_t fapl2 = -1; /* File access property list ID */ + hbool_t new_format; /* Whether to use old or new format */ + char filename[1024], filename2[1024]; + + TESTING("deleting objects that use named datatypes"); + + /* Set up filenames & FAPLs */ + if((fapl2 = H5Pcopy(fapl)) < 0) FAIL_STACK_ERROR + h5_fixname(FILENAME[8], fapl, filename, sizeof filename); + h5_fixname(FILENAME[9], fapl2, filename2, sizeof filename2); + + /* Loop over old & new format files */ + for(new_format = FALSE; new_format <= TRUE; new_format++) { + /* Create test file, with attribute that uses committed datatype */ + create_del_obj_named_test_file(filename, fapl, new_format); + +/* Test deleting dataset opened through different file ID */ + if((filea1 = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR + if((filea2 = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR + + if((dset = H5Dopen2(filea1, DEL_OBJ_NAMED_DATASET, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR + if(H5Dclose(dset) < 0) FAIL_STACK_ERROR + + if(H5Fclose(filea1) < 0) FAIL_STACK_ERROR + + if((fileb = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fapl2)) < 0) FAIL_STACK_ERROR + + if(H5Ldelete(filea2, DEL_OBJ_NAMED_DATASET, H5P_DEFAULT) < 0) FAIL_STACK_ERROR + + if(H5Fclose(filea2) < 0) FAIL_STACK_ERROR + if(H5Fclose(fileb) < 0) FAIL_STACK_ERROR + + + /* Create test file, with attribute that uses committed datatype */ + create_del_obj_named_test_file(filename, fapl, new_format); + +/* Test deleting attribute opened through different file ID */ + if((filea1 = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR + if((filea2 = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR + + if((attr = H5Aopen_by_name(filea1, DEL_OBJ_NAMED_DATASET, DEL_OBJ_NAMED_ATTRIBUTE, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR + if(H5Aclose(attr) < 0) FAIL_STACK_ERROR + + if(H5Fclose(filea1) < 0) FAIL_STACK_ERROR + + if((fileb = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fapl2)) < 0) FAIL_STACK_ERROR + + if(H5Adelete_by_name(filea2, DEL_OBJ_NAMED_DATASET, DEL_OBJ_NAMED_ATTRIBUTE, H5P_DEFAULT) < 0) FAIL_STACK_ERROR + + if(H5Fclose(filea2) < 0) FAIL_STACK_ERROR + if(H5Fclose(fileb) < 0) FAIL_STACK_ERROR + } /* end for */ + + if(H5Pclose(fapl2) < 0) FAIL_STACK_ERROR + + PASSED(); + return 0; + +error: + H5E_BEGIN_TRY { + H5Tclose(attr); + H5Dclose(dset); + H5Pclose(fapl2); + H5Fclose(filea1); + H5Fclose(filea2); + H5Fclose(fileb); + } H5E_END_TRY; + return 1; +} /* end test_delete_obj_named() */ + /*------------------------------------------------------------------------- * Function: test_deprec @@ -6806,6 +7004,7 @@ main(void) nerrors += test_latest(); nerrors += test_int_float_except(); nerrors += test_named_indirect_reopen(fapl); + nerrors += test_delete_obj_named(fapl); nerrors += test_set_order_compound(fapl); nerrors += test_str_create(); #ifndef H5_NO_DEPRECATED_SYMBOLS |