diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/null_vol_connector.c | 7 | ||||
-rw-r--r-- | test/tattr.c | 109 | ||||
-rw-r--r-- | test/tfile.c | 107 |
3 files changed, 174 insertions, 49 deletions
diff --git a/test/null_vol_connector.c b/test/null_vol_connector.c index b78e859..5ed8545 100644 --- a/test/null_vol_connector.c +++ b/test/null_vol_connector.c @@ -15,8 +15,15 @@ * (registration, etc.). */ + +/* Public HDF5 header */ +#include "hdf5.h" + +/* For HDF5 plugin functionality */ #include "H5PLextern.h" + +/* This connector's header */ #include "null_vol_connector.h" /* The VOL class struct */ diff --git a/test/tattr.c b/test/tattr.c index 37763da..b83ed9f 100644 --- a/test/tattr.c +++ b/test/tattr.c @@ -581,107 +581,118 @@ test_attr_flush(hid_t fapl) static void test_attr_plist(hid_t fapl) { - hid_t fid1; /* HDF5 File IDs */ - hid_t dataset; /* Dataset ID */ - hid_t sid1,sid2; /* Dataspace ID */ - hid_t attr; /* Attribute ID */ - hid_t plist; /* Property list ID */ - hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; - hsize_t dims2[] = {ATTR1_DIM1}; - H5T_cset_t cset; /* Character set for attributes */ - herr_t ret; /* Generic return value */ + hid_t fid = H5I_INVALID_HID; /* File ID */ + hid_t did = H5I_INVALID_HID; /* Dataset ID */ + hid_t dsid = H5I_INVALID_HID; /* Dataspace ID (for dataset) */ + hid_t asid = H5I_INVALID_HID; /* Dataspace ID (for attribute) */ + hid_t aid = H5I_INVALID_HID; /* Attribute ID */ + hid_t acpl_id = H5I_INVALID_HID; /* Attribute creation property list ID */ + hid_t aapl_id = H5I_INVALID_HID; /* Attribute access property list ID */ + hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; + hsize_t dims2[] = {ATTR1_DIM1}; + H5T_cset_t cset; /* Character set for attributes */ + herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Attribute Property Lists\n")); /* Create file */ - fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); - CHECK(fid1, FAIL, "H5Fcreate"); + fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); + CHECK(fid, H5I_INVALID_HID, "H5Fcreate"); /* Create dataspace for dataset */ - sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL); - CHECK(sid1, FAIL, "H5Screate_simple"); + dsid = H5Screate_simple(SPACE1_RANK, dims1, NULL); + CHECK(dsid, H5I_INVALID_HID, "H5Screate_simple"); /* Create a dataset */ - dataset = H5Dcreate2(fid1, DSET1_NAME, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, dcpl_g, H5P_DEFAULT); - CHECK(dataset, FAIL, "H5Dcreate2"); + did = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, dsid, H5P_DEFAULT, dcpl_g, H5P_DEFAULT); + CHECK(did, H5I_INVALID_HID, "H5Dcreate2"); /* Create dataspace for attribute */ - sid2 = H5Screate_simple(ATTR1_RANK, dims2, NULL); - CHECK(sid2, FAIL, "H5Screate_simple"); + asid = H5Screate_simple(ATTR1_RANK, dims2, NULL); + CHECK(asid, H5I_INVALID_HID, "H5Screate_simple"); + + /* Create default creation property list for attribute */ + acpl_id = H5Pcreate(H5P_ATTRIBUTE_CREATE); + CHECK(acpl_id, H5I_INVALID_HID, "H5Pcreate"); - /* Create default property list for attribute */ - plist = H5Pcreate(H5P_ATTRIBUTE_CREATE); - CHECK(plist, FAIL, "H5Pcreate"); + /* Create default access property list for attribute + * This currently has no properties, but we need to test its creation + * and use. + */ + aapl_id = H5Pcreate(H5P_ATTRIBUTE_ACCESS); + CHECK(aapl_id, H5I_INVALID_HID, "H5Pcreate"); /* Get the character encoding and ensure that it is the default (ASCII) */ - ret = H5Pget_char_encoding(plist, &cset); + ret = H5Pget_char_encoding(acpl_id, &cset); CHECK(ret, FAIL, "H5Pget_char_encoding"); VERIFY(cset, H5T_CSET_ASCII, "H5Pget_char_encoding"); /* Create an attribute for the dataset using the property list */ - attr = H5Acreate2(dataset, ATTR1_NAME, H5T_NATIVE_INT, sid2, plist, H5P_DEFAULT); - CHECK(attr, FAIL, "H5Acreate2"); + aid = H5Acreate2(did, ATTR1_NAME, H5T_NATIVE_INT, asid, acpl_id, aapl_id); + CHECK(aid, H5I_INVALID_HID, "H5Acreate2"); - /* Close the property list, and get the attribute's property list */ - ret = H5Pclose(plist); + /* Close the property list, and get the attribute's creation property list */ + ret = H5Pclose(acpl_id); CHECK(ret, FAIL, "H5Pclose"); - plist = H5Aget_create_plist(attr); - CHECK(plist, FAIL, "H5Aget_create_plist"); + acpl_id = H5Aget_create_plist(aid); + CHECK(acpl_id, H5I_INVALID_HID, "H5Aget_create_plist"); /* Get the character encoding and ensure that it is the default (ASCII) */ - ret = H5Pget_char_encoding(plist, &cset); + ret = H5Pget_char_encoding(acpl_id, &cset); CHECK(ret, FAIL, "H5Pget_char_encoding"); VERIFY(cset, H5T_CSET_ASCII, "H5Pget_char_encoding"); /* Close the property list and attribute */ - ret = H5Pclose(plist); + ret = H5Pclose(acpl_id); CHECK(ret, FAIL, "H5Pclose"); - ret = H5Aclose(attr); + ret = H5Aclose(aid); CHECK(ret, FAIL, "H5Aclose"); /* Create a new property list and modify it to use a different encoding */ - plist = H5Pcreate(H5P_ATTRIBUTE_CREATE); - CHECK(plist, FAIL, "H5Pcreate"); - ret = H5Pset_char_encoding(plist, H5T_CSET_UTF8); + acpl_id = H5Pcreate(H5P_ATTRIBUTE_CREATE); + CHECK(acpl_id, H5I_INVALID_HID, "H5Pcreate"); + ret = H5Pset_char_encoding(acpl_id, H5T_CSET_UTF8); CHECK(ret, FAIL, "H5Pset_char_encoding"); /* Get the character encoding and ensure that it has been changed */ - ret = H5Pget_char_encoding(plist, &cset); + ret = H5Pget_char_encoding(acpl_id, &cset); CHECK(ret, FAIL, "H5Pget_char_encoding"); VERIFY(cset, H5T_CSET_UTF8, "H5Pget_char_encoding"); /* Create an attribute for the dataset using the modified property list */ - attr = H5Acreate2(dataset, ATTR2_NAME, H5T_NATIVE_INT, sid2, plist, H5P_DEFAULT); - CHECK(attr, FAIL, "H5Acreate2"); + aid = H5Acreate2(did, ATTR2_NAME, H5T_NATIVE_INT, asid, acpl_id, aapl_id); + CHECK(aid, H5I_INVALID_HID, "H5Acreate2"); /* Close the property list and attribute */ - ret = H5Pclose(plist); + ret = H5Pclose(acpl_id); CHECK(ret, FAIL, "H5Pclose"); - ret = H5Aclose(attr); + ret = H5Aclose(aid); CHECK(ret, FAIL, "H5Aclose"); /* Re-open the second attribute and ensure that its character encoding is correct */ - attr = H5Aopen(dataset, ATTR2_NAME, H5P_DEFAULT); - CHECK(attr, FAIL, "H5Aopen"); - plist = H5Aget_create_plist(attr); - CHECK(plist, FAIL, "H5Aget_create_plist"); - ret = H5Pget_char_encoding(plist, &cset); + aid = H5Aopen(did, ATTR2_NAME, H5P_DEFAULT); + CHECK(aid, H5I_INVALID_HID, "H5Aopen"); + acpl_id = H5Aget_create_plist(aid); + CHECK(acpl_id, H5I_INVALID_HID, "H5Aget_create_plist"); + ret = H5Pget_char_encoding(acpl_id, &cset); CHECK(ret, FAIL, "H5Pget_char_encoding"); VERIFY(cset, H5T_CSET_UTF8, "H5Pget_char_encoding"); /* Close everything */ - ret=H5Sclose(sid1); + ret = H5Sclose(dsid); CHECK(ret, FAIL, "H5Sclose"); - ret=H5Sclose(sid2); + ret = H5Sclose(asid); CHECK(ret, FAIL, "H5Sclose"); - ret = H5Pclose(plist); + ret = H5Pclose(aapl_id); + CHECK(ret, FAIL, "H5Pclose"); + ret = H5Pclose(acpl_id); CHECK(ret, FAIL, "H5Pclose"); - ret=H5Aclose(attr); + ret = H5Aclose(aid); CHECK(ret, FAIL, "H5Aclose"); - ret=H5Dclose(dataset); + ret = H5Dclose(did); CHECK(ret, FAIL, "H5Dclose"); - ret=H5Fclose(fid1); + ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_plist() */ diff --git a/test/tfile.c b/test/tfile.c index e903ea7..140bd14 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -1859,6 +1859,102 @@ test_file_ishdf5(const char *env_h5_drvr) } /* end test_file_ishdf5() */ #endif /* H5_NO_DEPRECATED_SYMBOLS */ + +/**************************************************************** +** +** test_file_delete(): tests H5Fdelete for all VFDs +** +*****************************************************************/ +#define FILE_DELETE "test_file_delete" +#define FILE_DELETE_NOT_HDF5 "test_file_delete_not_hdf5" +static void +test_file_delete(hid_t fapl_id) +{ + hid_t fid = H5I_INVALID_HID; /* File to be deleted */ + char filename[FILENAME_LEN]; /* Filename to use */ + htri_t is_hdf5; /* Whether a file is an HDF5 file */ + int fd; /* POSIX file descriptor */ + int iret; + herr_t ret; + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Deletion of HDF5 Files\n")); + + /*************/ + /* HDF5 FILE */ + /*************/ + + /* This is just a placeholder until the native VOL connector supports + * H5Fdelete(). + */ + + /* Get fapl-dependent filename */ + h5_fixname(FILE_DELETE, fapl_id, filename, sizeof(filename)); + + /* Create a file */ + fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); + CHECK(fid, H5I_INVALID_HID, "H5Fcreate"); + + /* Close file */ + ret = H5Fclose(fid); + VERIFY(ret, SUCCEED, "H5Fclose"); + + /* Verify that the file is an HDF5 file */ + is_hdf5 = H5Fis_accessible(filename, fapl_id); + VERIFY(is_hdf5, TRUE, "H5Fis_accessible"); + + /* Attempt to delete the file - should fail */ + H5E_BEGIN_TRY { + ret = H5Fdelete(filename, fapl_id); + } H5E_END_TRY; + VERIFY(ret, FAIL, "H5Fdelete"); + + /* Verify that the file still exists */ + is_hdf5 = H5Fis_accessible(filename, fapl_id); + VERIFY(is_hdf5, TRUE, "H5Fis_accessible"); + + /* Actually delete the test file */ + h5_delete_test_file(FILE_DELETE, fapl_id); + + /*****************/ + /* NON-HDF5 FILE */ + /*****************/ + + /* Get fapl-dependent filename */ + h5_fixname(FILE_DELETE_NOT_HDF5, fapl_id, filename, sizeof(filename)); + + /* Create a non-HDF5 file */ + fd = HDopen(filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW); + CHECK_I(fd, "HDopen"); + + /* Close the file */ + ret = HDclose(fd); + VERIFY(ret, 0, "HDclose"); + + /* Verify that the file is not an HDF5 file */ + /* Note that you can get a FAIL result when h5_fixname() + * perturbs the filename as a file with that exact name + * may not have been created since we created it with + * open(2) and not the library. + */ + H5E_BEGIN_TRY { + is_hdf5 = H5Fis_accessible(filename, fapl_id); + } H5E_END_TRY; + CHECK(is_hdf5, TRUE, "H5Fis_accessible"); + + /* Try to delete it (should fail) */ + H5E_BEGIN_TRY { + ret = H5Fdelete(filename, fapl_id); + } H5E_END_TRY; + VERIFY(ret, FAIL, "H5Fdelete"); + + /* Delete the file */ + iret = HDremove(filename); + VERIFY(iret, 0, "HDremove"); + +} /* end test_file_delete() */ + + /**************************************************************** ** ** test_file_open_dot(): low-level file test routine. @@ -7689,6 +7785,8 @@ void test_file(void) { const char *env_h5_drvr; /* File Driver value from environment */ + hid_t fapl_id = H5I_INVALID_HID; /* VFD-dependent fapl ID */ + herr_t ret; /* Output message about test being performed */ MESSAGE(5, ("Testing Low-Level File I/O\n")); @@ -7698,6 +7796,10 @@ test_file(void) if(env_h5_drvr == NULL) env_h5_drvr = "nomatch"; + /* Improved version of VFD-dependent checks */ + fapl_id = h5_fileaccess(); + CHECK(fapl_id, H5I_INVALID_HID, "h5_fileaccess"); + test_file_create(); /* Test file creation(also creation templates)*/ test_file_open(); /* Test file opening */ test_file_reopen(); /* Test file reopening */ @@ -7707,6 +7809,7 @@ test_file(void) test_file_perm(); /* Test file access permissions */ test_file_perm2(); /* Test file access permission again */ test_file_is_accessible(env_h5_drvr); /* Test detecting HDF5 files correctly */ + test_file_delete(fapl_id); /* Test H5Fdelete */ test_file_open_dot(); /* Test opening objects with "." for a name */ test_file_open_overlap(); /* Test opening files in an overlapping manner */ test_file_getname(); /* Test basic H5Fget_name() functionality */ @@ -7745,6 +7848,10 @@ test_file(void) test_file_ishdf5(env_h5_drvr); /* Test detecting HDF5 files correctly */ test_deprec(); /* Test deprecated routines */ #endif /* H5_NO_DEPRECATED_SYMBOLS */ + + ret = H5Pclose(fapl_id); + CHECK(ret, FAIL, "H5Pclose"); + } /* test_file() */ |