diff options
Diffstat (limited to 'test/th5s.c')
-rw-r--r-- | test/th5s.c | 94 |
1 files changed, 91 insertions, 3 deletions
diff --git a/test/th5s.c b/test/th5s.c index 1029bc0..c3724e2 100644 --- a/test/th5s.c +++ b/test/th5s.c @@ -30,6 +30,10 @@ #define TESTFILE "th5s.h5" #define DATAFILE "th5s1.h5" #define NULLFILE "th5s2.h5" +#define BASICFILE "th5s3.h5" +#define BASICDATASET "basic_dataset" +#define BASICDATASET2 "basic_dataset2" +#define BASICATTR "basic_attribute" #define NULLDATASET "null_dataset" #define NULLATTR "null_attribute" @@ -86,6 +90,7 @@ test_h5s_basic(void) hid_t fid1; /* HDF5 File IDs */ hid_t sid1, sid2; /* Dataspace ID */ hid_t dset1; /* Dataset ID */ + hid_t aid1; /* Attribute ID */ int rank; /* Logical rank of dataspace */ hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; hsize_t dims2[] = {SPACE2_DIM1, SPACE2_DIM2, SPACE2_DIM3, @@ -205,6 +210,90 @@ test_h5s_basic(void) ret = H5Sclose(sid1); CHECK_I(ret, "H5Sclose"); + + /* + * Try writing simple dataspaces without setting their extents + */ + /* Create the file */ + fid1 = H5Fcreate(BASICFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid1, FAIL, "H5Fcreate"); + + dims1[0]=SPACE1_DIM1; + + sid1 = H5Screate(H5S_SIMPLE); + CHECK(sid1, FAIL, "H5Screate"); + sid2 = H5Screate_simple(1, dims1, dims1); + CHECK(sid2, FAIL, "H5Screate"); + + /* This dataset's space has no extent; it should not be created */ + H5E_BEGIN_TRY { + dset1 = H5Dcreate(fid1, BASICDATASET, H5T_NATIVE_INT, sid1, H5P_DEFAULT); + } H5E_END_TRY + VERIFY(dset1, FAIL, "H5Dcreate"); + + dset1 = H5Dcreate(fid1, BASICDATASET2, H5T_NATIVE_INT, sid2, H5P_DEFAULT); + CHECK(dset1, FAIL, "H5Dcreate"); + + /* Try some writes with the bad dataspace (sid1) */ + H5E_BEGIN_TRY { + ret = H5Dwrite(dset1, H5T_NATIVE_INT, sid1, H5S_ALL, H5P_DEFAULT, &n); + } H5E_END_TRY + VERIFY(ret, FAIL, "H5Dwrite"); + + H5E_BEGIN_TRY { + ret = H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, sid1, H5P_DEFAULT, &n); + } H5E_END_TRY + VERIFY(ret, FAIL, "H5Dwrite"); + + H5E_BEGIN_TRY { + ret = H5Dwrite(dset1, H5T_NATIVE_INT, sid1, sid1, H5P_DEFAULT, &n); + } H5E_END_TRY + VERIFY(ret, FAIL, "H5Dwrite"); + + /* Try to iterate using the bad dataspace */ + H5E_BEGIN_TRY { + ret = H5Diterate(&n, H5T_NATIVE_INT, sid1, NULL, NULL); + } H5E_END_TRY + VERIFY(ret, FAIL, "H5Diterate"); + + /* Try to fill using the bad dataspace */ + H5E_BEGIN_TRY { + ret = H5Dfill(NULL, H5T_NATIVE_INT, &n, H5T_NATIVE_INT, sid1); + } H5E_END_TRY + VERIFY(ret, FAIL, "H5Dfill"); + + /* Now use the bad dataspace as the space for an attribute */ + H5E_BEGIN_TRY { + aid1 = H5Acreate(dset1, BASICATTR, + H5T_NATIVE_INT, sid1, H5P_DEFAULT); + } H5E_END_TRY + VERIFY(aid1, FAIL, "H5Acreate"); + + /* Make sure that dataspace reads using the bad dataspace fail */ + H5E_BEGIN_TRY { + ret = H5Dread(dset1, H5T_NATIVE_INT, sid1, H5S_ALL, H5P_DEFAULT, &n); + } H5E_END_TRY + VERIFY(ret, FAIL, "H5Dread"); + + H5E_BEGIN_TRY { + ret = H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, sid1, H5P_DEFAULT, &n); + } H5E_END_TRY + VERIFY(ret, FAIL, "H5Dread"); + + H5E_BEGIN_TRY { + ret = H5Dread(dset1, H5T_NATIVE_INT, sid1, sid1, H5P_DEFAULT, &n); + } H5E_END_TRY + VERIFY(ret, FAIL, "H5Dread"); + + /* Clean up */ + ret = H5Dclose(dset1); + CHECK(ret, FAIL, "H5Dclose"); + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(sid2); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Fclose(fid1); + CHECK(ret, FAIL, "H5Fclose"); } /* test_h5s_basic() */ /**************************************************************** @@ -345,7 +434,7 @@ test_h5s_null(void) /* Close the dataspace */ ret = H5Sclose(sid); CHECK(ret, FAIL, "H5Sclose"); - + /* Close the file */ ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); @@ -435,7 +524,6 @@ test_h5s_null(void) static void test_h5s_encode(void) { - hid_t fid1; /* HDF5 File IDs */ hid_t sid1, sid2, sid3; /* Dataspace ID */ hid_t decoded_sid1, decoded_sid2, decoded_sid3; int rank; /* Logical rank of dataspace */ @@ -443,7 +531,6 @@ test_h5s_encode(void) size_t sbuf_size=0, null_size=0, scalar_size=0; unsigned char *sbuf=NULL, *null_sbuf=NULL, *scalar_buf=NULL; hsize_t tdims[4]; /* Dimension array to test with */ - hsize_t tmax[4]; hssize_t n; /* Number of dataspace elements */ hssize_t start[] = {0, 0, 0}; hsize_t stride[] = {2, 5, 3}; @@ -993,4 +1080,5 @@ void cleanup_h5s(void) { remove(DATAFILE); + remove(BASICFILE); } |