diff options
Diffstat (limited to 'test/extend.c')
-rw-r--r-- | test/extend.c | 114 |
1 files changed, 47 insertions, 67 deletions
diff --git a/test/extend.c b/test/extend.c index a13d606..42348bc 100644 --- a/test/extend.c +++ b/test/extend.c @@ -8,44 +8,18 @@ * Purpose: Tests extendible datasets. */ -/* See H5private.h for how to include headers */ -#undef NDEBUG -#include <hdf5.h> +#include <h5test.h> -#ifdef STDC_HEADERS -# include <assert.h> -# include <stdlib.h> -#endif +const char *FILENAME[] = { + "extend", + NULL +}; -#define TEST_FILE_NAME "extend.h5" #define NX 100 /* USE AN EVEN NUMBER!*/ #define NY 100 /* USE AN EVEN NUMBER!*/ /*------------------------------------------------------------------------- - * Function: cleanup - * - * Purpose: Cleanup temporary test files - * - * Return: none - * - * Programmer: Albert Cheng - * May 28, 1998 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -static void -cleanup(void) -{ - if (!getenv ("HDF5_NOCLEANUP")) { - remove(TEST_FILE_NAME); - } -} - - -/*------------------------------------------------------------------------- * Function: main * * Purpose: Tests extendible datasets @@ -65,6 +39,7 @@ int main (void) { hid_t file, dataset, mem_space, file_space, cparms; + hid_t fapl; herr_t status; int i, j, k, m; static int buf1[NY][NX], buf2[NX/2][NY/2]; @@ -74,6 +49,11 @@ main (void) static hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; static hsize_t size[2]; hssize_t offset[2]; + char filename[1024]; + + TESTING("dataset extend"); + h5_reset(); + fapl = h5_fileaccess(); /* Initialize buffer and space */ for (i=0; i<NX; i++) { @@ -81,22 +61,19 @@ main (void) buf1[i][j] = i*NY+j; } } - mem_space = H5Screate_simple (2, dims, maxdims); - assert (mem_space>=0); + if ((mem_space = H5Screate_simple (2, dims, maxdims))<0) goto error; /* Create the file */ - file = H5Fcreate (TEST_FILE_NAME, H5F_ACC_TRUNC|H5F_ACC_DEBUG, - H5P_DEFAULT, H5P_DEFAULT); - assert (file>=0); + h5_fixname(FILENAME[0], fapl, filename, sizeof filename); + if ((file = H5Fcreate (filename, H5F_ACC_TRUNC|H5F_ACC_DEBUG, + H5P_DEFAULT, fapl))<0) goto error; /* Create the dataset which is originally NX by NY */ - cparms = H5Pcreate (H5P_DATASET_CREATE); - assert (cparms>=0); - status = H5Pset_chunk (cparms, 2, chunk_dims); - assert (status>=0); - dataset = H5Dcreate (file, "dataset", H5T_NATIVE_INT, mem_space, cparms); - assert (dataset>=0); - H5Pclose (cparms); + if ((cparms = H5Pcreate (H5P_DATASET_CREATE))<0) goto error; + if (H5Pset_chunk (cparms, 2, chunk_dims)<0) goto error; + if ((dataset = H5Dcreate (file, "dataset", H5T_NATIVE_INT, mem_space, + cparms))<0) goto error; + if (H5Pclose (cparms)<0) goto error; /* Write the data */ for (i=0; i<5; i++) { @@ -107,57 +84,60 @@ main (void) offset[1] = j * NY; size[0] = offset[0] + NX; size[1] = offset[1] + NY; - status = H5Dextend (dataset, size); - assert (status>=0); + if (H5Dextend (dataset, size)<0) goto error; /* Select a hyperslab */ - file_space = H5Dget_space (dataset); - assert (file_space>=0); - status = H5Sselect_hyperslab (file_space, H5S_SELECT_SET, offset, NULL, dims, NULL); - assert (status>=0); + if ((file_space = H5Dget_space (dataset))<0) goto error; + if (H5Sselect_hyperslab (file_space, H5S_SELECT_SET, offset, + NULL, dims, NULL)<0) goto error; /* Write to the hyperslab */ - status = H5Dwrite (dataset, H5T_NATIVE_INT, mem_space, file_space, - H5P_DEFAULT, buf1); - assert (status>=0); - H5Sclose (file_space); + if (H5Dwrite (dataset, H5T_NATIVE_INT, mem_space, file_space, + H5P_DEFAULT, buf1)<0) goto error; + if (H5Sclose (file_space)<0) goto error; } } - H5Sclose (mem_space); - + if (H5Sclose (mem_space)<0) goto error; /* Read the data */ - mem_space = H5Screate_simple (2, half_dims, NULL); - file_space = H5Dget_space (dataset); + if ((mem_space = H5Screate_simple (2, half_dims, NULL))<0) goto error; + if ((file_space = H5Dget_space (dataset))<0) goto error; for (i=0; i<10; i++) { for (j=0; j<10; j++) { /* Select a hyperslab */ offset[0] = i * NX/2; offset[1] = j * NY/2; - assert (file_space>=0); - status = H5Sselect_hyperslab (file_space, H5S_SELECT_SET, offset, NULL, half_dims, NULL); - assert (status>=0); + if (H5Sselect_hyperslab (file_space, H5S_SELECT_SET, offset, + NULL, half_dims, NULL)<0) goto error; /* Read */ - status = H5Dread (dataset, H5T_NATIVE_INT, mem_space, file_space, - H5P_DEFAULT, buf2); - assert (status>=0); + if (H5Dread (dataset, H5T_NATIVE_INT, mem_space, file_space, + H5P_DEFAULT, buf2)<0) goto error; /* Compare */ for (k=0; k<NX/2; k++) { for (m=0; m<NY/2; m++) { - assert (buf2[k][m]==buf1[(i%2)*NX/2+k][(j%2)*NY/2+m]); + if (buf2[k][m]!=buf1[(i%2)*NX/2+k][(j%2)*NY/2+m]) { + FAILED(); + printf(" i=%d, j=%d, k=%d, m=%d\n", i, j, k, m); + goto error; + } } } } } - H5Dclose (dataset); - H5Fclose (file); + if (H5Dclose (dataset)<0) goto error; + if (H5Fclose (file)<0) goto error; + PASSED(); printf("All extend tests passed.\n"); - cleanup(); + h5_cleanup(fapl); return 0; + + error: + printf("*** One or more extend tests failed ***\n"); + return 1; } |