diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2020-10-01 14:04:36 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2020-10-01 14:04:36 (GMT) |
commit | f1ba03cea5b82699a984c80bd2deac14fdc8df18 (patch) | |
tree | ebe777c3e0b83f4c4cec9212731da9ebe0a0cfd3 /test/unregister.c | |
parent | 10343c197906415388f2a4c8d292e21d25cf7381 (diff) | |
download | hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.zip hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.tar.gz hdf5-f1ba03cea5b82699a984c80bd2deac14fdc8df18.tar.bz2 |
Source formatted
Diffstat (limited to 'test/unregister.c')
-rw-r--r-- | test/unregister.c | 182 |
1 files changed, 88 insertions, 94 deletions
diff --git a/test/unregister.c b/test/unregister.c index a2a507d..775da82 100644 --- a/test/unregister.c +++ b/test/unregister.c @@ -17,40 +17,35 @@ */ #include "h5test.h" -#include "H5CXprivate.h" /* API Contexts */ +#include "H5CXprivate.h" /* API Contexts */ -const char *FILENAME[] = { - "unregister_filter_1", - "unregister_filter_2", - NULL -}; +const char *FILENAME[] = {"unregister_filter_1", "unregister_filter_2", NULL}; -#define GROUP_NAME "test_group" -#define DSET_NAME "test_dataset" -#define FILENAME_BUF_SIZE 1024 -#define DSET_DIM1 100 -#define DSET_DIM2 200 -#define FILTER_CHUNK_DIM1 2 -#define FILTER_CHUNK_DIM2 25 -#define GROUP_ITERATION 1000 +#define GROUP_NAME "test_group" +#define DSET_NAME "test_dataset" +#define FILENAME_BUF_SIZE 1024 +#define DSET_DIM1 100 +#define DSET_DIM2 200 +#define FILTER_CHUNK_DIM1 2 +#define FILTER_CHUNK_DIM2 25 +#define GROUP_ITERATION 1000 -#define H5Z_FILTER_DUMMY 312 +#define H5Z_FILTER_DUMMY 312 -static size_t do_nothing(unsigned int flags, size_t cd_nelmts, - const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf); +static size_t do_nothing(unsigned int flags, size_t cd_nelmts, const unsigned int *cd_values, size_t nbytes, + size_t *buf_size, void **buf); /* Dummy filter for test_unregister_filters only */ const H5Z_class2_t H5Z_DUMMY[1] = {{ - H5Z_CLASS_T_VERS, /* H5Z_class_t version */ - H5Z_FILTER_DUMMY, /* Filter ID number */ - 1, 1, /* Encoding and decoding enabled */ - "dummy", /* Filter name for debugging */ - NULL, /* The "can apply" callback */ - NULL, /* The "set local" callback */ - do_nothing, /* The actual filter function */ + H5Z_CLASS_T_VERS, /* H5Z_class_t version */ + H5Z_FILTER_DUMMY, /* Filter ID number */ + 1, 1, /* Encoding and decoding enabled */ + "dummy", /* Filter name for debugging */ + NULL, /* The "can apply" callback */ + NULL, /* The "set local" callback */ + do_nothing, /* The actual filter function */ }}; - /*------------------------------------------------------------------------- * Function: do_nothing * @@ -64,8 +59,8 @@ const H5Z_class2_t H5Z_DUMMY[1] = {{ */ static size_t do_nothing(unsigned int H5_ATTR_UNUSED flags, size_t H5_ATTR_UNUSED cd_nelmts, - const unsigned int H5_ATTR_UNUSED *cd_values, size_t nbytes, - size_t H5_ATTR_UNUSED *buf_size, void H5_ATTR_UNUSED **buf) + const unsigned int H5_ATTR_UNUSED *cd_values, size_t nbytes, size_t H5_ATTR_UNUSED *buf_size, + void H5_ATTR_UNUSED **buf) { return nbytes; } @@ -82,41 +77,41 @@ do_nothing(unsigned int H5_ATTR_UNUSED flags, size_t H5_ATTR_UNUSED cd_nelmts, static herr_t test_unregister_filters(hid_t fapl_id) { - hid_t fid1 = H5I_INVALID_HID; - hid_t fid2 = H5I_INVALID_HID; - hid_t dcpl_id = H5I_INVALID_HID; - hid_t gcpl_id = H5I_INVALID_HID; - hid_t gid = H5I_INVALID_HID; - hid_t gid_loop = H5I_INVALID_HID; - hid_t did = H5I_INVALID_HID; - hid_t sid = H5I_INVALID_HID; - int i, j, n; - char group_name[32]; - char filename[FILENAME_BUF_SIZE]; - const hsize_t chunk_dims[2] = {FILTER_CHUNK_DIM1, FILTER_CHUNK_DIM2}; /* Chunk dimensions */ - hsize_t dims[2]; - int **buf = NULL; - int *buf_data = NULL; - herr_t ret; + hid_t fid1 = H5I_INVALID_HID; + hid_t fid2 = H5I_INVALID_HID; + hid_t dcpl_id = H5I_INVALID_HID; + hid_t gcpl_id = H5I_INVALID_HID; + hid_t gid = H5I_INVALID_HID; + hid_t gid_loop = H5I_INVALID_HID; + hid_t did = H5I_INVALID_HID; + hid_t sid = H5I_INVALID_HID; + int i, j, n; + char group_name[32]; + char filename[FILENAME_BUF_SIZE]; + const hsize_t chunk_dims[2] = {FILTER_CHUNK_DIM1, FILTER_CHUNK_DIM2}; /* Chunk dimensions */ + hsize_t dims[2]; + int ** buf = NULL; + int * buf_data = NULL; + herr_t ret; TESTING("Unregistering filter"); /* Set up data array */ - if(NULL == (buf_data = (int *)HDcalloc(DSET_DIM1 * DSET_DIM2, sizeof(int)))) + if (NULL == (buf_data = (int *)HDcalloc(DSET_DIM1 * DSET_DIM2, sizeof(int)))) TEST_ERROR; - if(NULL == (buf = (int **)HDcalloc(DSET_DIM1, sizeof(buf_data)))) + if (NULL == (buf = (int **)HDcalloc(DSET_DIM1, sizeof(buf_data)))) TEST_ERROR; for (i = 0; i < DSET_DIM1; i++) buf[i] = buf_data + (i * DSET_DIM2); /* Create first file */ h5_fixname(FILENAME[0], fapl_id, filename, sizeof(filename)); - if((fid1 = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) + if ((fid1 = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) goto error; /* Create second file */ h5_fixname(FILENAME[1], fapl_id, filename, sizeof(filename)); - if((fid2 = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) + if ((fid2 = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) goto error; /* Register DUMMY filter */ @@ -130,44 +125,43 @@ test_unregister_filters(hid_t fapl_id) *******************/ /* Use DUMMY filter for creating groups */ - if((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0) + if ((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0) goto error; - if(H5Pset_filter(gcpl_id, H5Z_FILTER_DUMMY, H5Z_FLAG_MANDATORY, (size_t)0, NULL) < 0) + if (H5Pset_filter(gcpl_id, H5Z_FILTER_DUMMY, H5Z_FLAG_MANDATORY, (size_t)0, NULL) < 0) goto error; /* Create a group using this filter */ - if((gid = H5Gcreate2(fid1, GROUP_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) + if ((gid = H5Gcreate2(fid1, GROUP_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) goto error; /* Create multiple groups under the main group */ - for(i = 0; i < GROUP_ITERATION; i++) { + for (i = 0; i < GROUP_ITERATION; i++) { HDsprintf(group_name, "group_%d", i); - if((gid_loop = H5Gcreate2(gid, group_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + if ((gid_loop = H5Gcreate2(gid, group_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; - if(H5Gclose(gid_loop) < 0) + if (H5Gclose(gid_loop) < 0) goto error; } /* Flush the file containing the groups */ - if(H5Fflush(fid1, H5F_SCOPE_GLOBAL) < 0) + if (H5Fflush(fid1, H5F_SCOPE_GLOBAL) < 0) goto error; /* Unregister the filter before closing the group. It should fail */ - H5E_BEGIN_TRY { - ret = H5Zunregister(H5Z_FILTER_DUMMY); - } H5E_END_TRY; - if(ret >= 0) { + H5E_BEGIN_TRY { ret = H5Zunregister(H5Z_FILTER_DUMMY); } + H5E_END_TRY; + if (ret >= 0) { H5_FAILED(); HDprintf(" Line %d: Should not be able to unregister filter\n", __LINE__); goto error; } /* Close the group */ - if(H5Gclose(gid) < 0) + if (H5Gclose(gid) < 0) goto error; /* Clean up objects used for this test */ - if(H5Pclose (gcpl_id) < 0) + if (H5Pclose(gcpl_id) < 0) goto error; /********************* @@ -175,70 +169,69 @@ test_unregister_filters(hid_t fapl_id) *********************/ /* Use DUMMY filter for creating datasets */ - if((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) + if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; - if(H5Pset_chunk(dcpl_id, 2, chunk_dims) < 0) + if (H5Pset_chunk(dcpl_id, 2, chunk_dims) < 0) goto error; - if(H5Pset_filter(dcpl_id, H5Z_FILTER_DUMMY, 0, (size_t)0, NULL) < 0) + if (H5Pset_filter(dcpl_id, H5Z_FILTER_DUMMY, 0, (size_t)0, NULL) < 0) goto error; /* Initialize the data for writing */ - for(i = n = 0; i < DSET_DIM1; i++) - for(j = 0; j < DSET_DIM2; j++) + for (i = n = 0; i < DSET_DIM1; i++) + for (j = 0; j < DSET_DIM2; j++) buf[i][j] = n++; /* Create the dataspace */ dims[0] = DSET_DIM1; dims[1] = DSET_DIM2; - if((sid = H5Screate_simple(2, dims, NULL)) < 0) + if ((sid = H5Screate_simple(2, dims, NULL)) < 0) goto error; /* Create a dataset in the first file */ - if((did = H5Dcreate2(fid1, DSET_NAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) + if ((did = H5Dcreate2(fid1, DSET_NAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) goto error; /* Write the data to the dataset */ - if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_data) < 0) + if (H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_data) < 0) goto error; /* Unregister the filter before closing the dataset. It should fail */ - H5E_BEGIN_TRY { - ret = H5Zunregister(H5Z_FILTER_DUMMY); - } H5E_END_TRY; - if(ret >= 0) { + H5E_BEGIN_TRY { ret = H5Zunregister(H5Z_FILTER_DUMMY); } + H5E_END_TRY; + if (ret >= 0) { H5_FAILED(); HDprintf(" Line %d: Should not be able to unregister filter\n", __LINE__); goto error; } /* Close the dataset */ - if(H5Dclose(did) < 0) + if (H5Dclose(did) < 0) goto error; /* Create a dataset in the second file */ - if((did = H5Dcreate2(fid2, DSET_NAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) + if ((did = H5Dcreate2(fid2, DSET_NAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) goto error; /* Write the data to the dataset */ - if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_data) < 0) + if (H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_data) < 0) goto error; /* Close the dataset in the second file */ - if(H5Dclose(did) < 0) + if (H5Dclose(did) < 0) goto error; /* Unregister the filter after closing all objects but before closing files. * It should flush all files. */ - if(H5Zunregister(H5Z_FILTER_DUMMY) < 0) + if (H5Zunregister(H5Z_FILTER_DUMMY) < 0) goto error; /* Clean up objects used for this test */ - if(H5Pclose(dcpl_id) < 0) + if (H5Pclose(dcpl_id) < 0) goto error; - if(H5Fclose(fid1) < 0) + if (H5Fclose(fid1) < 0) goto error; - if(H5Fclose(fid2) < 0) + if (H5Fclose(fid2) < 0) goto error; HDfree(buf); @@ -248,7 +241,8 @@ test_unregister_filters(hid_t fapl_id) return SUCCEED; error: - H5E_BEGIN_TRY { + H5E_BEGIN_TRY + { H5Fclose(fid1); H5Fclose(fid2); H5Pclose(dcpl_id); @@ -257,7 +251,8 @@ error: H5Gclose(gid_loop); H5Dclose(did); H5Sclose(sid); - } H5E_END_TRY; + } + H5E_END_TRY; HDfree(buf); HDfree(buf_data); @@ -265,7 +260,6 @@ error: return FAIL; } - /*------------------------------------------------------------------------- * Function: main * @@ -278,20 +272,21 @@ error: int main(void) { - hid_t fapl_id = H5I_INVALID_HID; - int nerrors = 0; - hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */ + hid_t fapl_id = H5I_INVALID_HID; + int nerrors = 0; + hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */ /* Testing setup */ h5_reset(); fapl_id = h5_fileaccess(); /* Push API context */ - if(H5CX_push() < 0) FAIL_STACK_ERROR + if (H5CX_push() < 0) + FAIL_STACK_ERROR api_ctx_pushed = TRUE; /* Test unregistering filter in its own file */ - nerrors += (test_unregister_filters(fapl_id) < 0 ? 1 : 0); + nerrors += (test_unregister_filters(fapl_id) < 0 ? 1 : 0); h5_cleanup(FILENAME, fapl_id); @@ -300,19 +295,18 @@ main(void) HDprintf("All filter unregistration tests passed.\n"); /* Pop API context */ - if(api_ctx_pushed && H5CX_pop() < 0) FAIL_STACK_ERROR + if (api_ctx_pushed && H5CX_pop() < 0) + FAIL_STACK_ERROR api_ctx_pushed = FALSE; - HDexit(EXIT_SUCCESS); error: nerrors = MAX(1, nerrors); - HDprintf("***** %d FILTER UNREGISTRATION TEST%s FAILED! *****\n", - nerrors, 1 == nerrors ? "" : "S"); + HDprintf("***** %d FILTER UNREGISTRATION TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S"); - if(api_ctx_pushed) H5CX_pop(); + if (api_ctx_pushed) + H5CX_pop(); HDexit(EXIT_FAILURE); } /* end main() */ - |