diff options
author | James Laird <jlaird@hdfgroup.org> | 2004-07-27 16:56:19 (GMT) |
---|---|---|
committer | James Laird <jlaird@hdfgroup.org> | 2004-07-27 16:56:19 (GMT) |
commit | 52563e6fa8c56bc68051c50e9e847293da30a008 (patch) | |
tree | d6c2acb4013c54be48da0449c5ae3695cf6e421c /test | |
parent | 6dae05b645086f67a45d4a3d3ab91f303a3362c0 (diff) | |
download | hdf5-52563e6fa8c56bc68051c50e9e847293da30a008.zip hdf5-52563e6fa8c56bc68051c50e9e847293da30a008.tar.gz hdf5-52563e6fa8c56bc68051c50e9e847293da30a008.tar.bz2 |
[svn-r8954]
Purpose:
Bug fix
Description:
When a simple dataspace is created, its extent should be set before using it,
or it will silently function as a NULL dataspace.
Solution:
Added checks on user-supplied dataspaces. Now dataspaces without extents set
will throw errors; users must explicitly set a dataspace to be NULL.
Platforms tested:
sleipnir, windows
Diffstat (limited to 'test')
-rw-r--r-- | test/th5s.c | 89 | ||||
-rw-r--r-- | test/tvltypes.c | 18 |
2 files changed, 107 insertions, 0 deletions
diff --git a/test/th5s.c b/test/th5s.c index f283b81..3bcc3b4 100644 --- a/test/th5s.c +++ b/test/th5s.c @@ -30,6 +30,7 @@ #define TESTFILE "th5s.h5" #define DATAFILE "th5s1.h5" #define NULLFILE "tnullspace.h5" +#define BASICFILE "th5s3.h5" /* 3-D dataset with fixed dimensions */ #define SPACE1_NAME "Space1" @@ -75,7 +76,10 @@ struct space4_struct { /* NULL dataspace info */ #define NULLDATASET "null_dataset" +#define BASICDATASET "basic_dataset" +#define BASICDATASET2 "basic_dataset2" #define NULLATTR "null_attribute" +#define BASICATTR "basic_attribute" /**************************************************************** ** @@ -88,6 +92,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, @@ -207,6 +212,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() */ /**************************************************************** diff --git a/test/tvltypes.c b/test/tvltypes.c index 3662927..f2f95de 100644 --- a/test/tvltypes.c +++ b/test/tvltypes.c @@ -180,6 +180,7 @@ test_vltypes_vlen_atomic(void) hid_t fid1; /* HDF5 File IDs */ hid_t dataset; /* Dataset ID */ hid_t sid1; /* Dataspace ID */ + hid_t sid2; /* ID of bad dataspace (no extent set */ hid_t tid1; /* Datatype ID */ hid_t dcpl_pid; /* Dataset creation property list ID */ hid_t xfer_pid; /* Dataset transfer property list ID */ @@ -405,6 +406,10 @@ test_vltypes_vlen_atomic(void) tid1 = H5Dget_type(dataset); CHECK(tid1, FAIL, "H5Dget_type"); + /* Create a "bad" dataspace with no extent set */ + sid2 = H5Screate(H5S_SIMPLE); + CHECK(sid2, FAIL, "H5Screate"); + /* Change to the custom memory allocation routines for reading VL data */ xfer_pid=H5Pcreate(H5P_DATASET_XFER); CHECK(xfer_pid, FAIL, "H5Pcreate"); @@ -416,6 +421,12 @@ test_vltypes_vlen_atomic(void) ret=H5Dvlen_get_buf_size(dataset,tid1,sid1,&size); CHECK(ret, FAIL, "H5Dvlen_get_buf_size"); + /* Try to call H5Dvlen_get_buf with bad dataspace */ + H5E_BEGIN_TRY { + ret=H5Dvlen_get_buf_size(dataset,tid1,sid2,&size); + } H5E_END_TRY + VERIFY(ret, FAIL, "H5Dvlen_get_buf_size"); + /* 10 elements allocated = 1 + 2 + 3 + 4 elements for each array position */ VERIFY(size,((SPACE1_DIM1*(SPACE1_DIM1+1))/2)*sizeof(unsigned int),"H5Dvlen_get_buf_size"); @@ -441,6 +452,13 @@ test_vltypes_vlen_atomic(void) } /* end for */ } /* end for */ + /* Try to reclaim read data using "bad" dataspace with no extent + * Should fail */ + H5E_BEGIN_TRY { + ret=H5Dvlen_reclaim(tid1,sid2,xfer_pid,rdata); + } H5E_END_TRY + VERIFY(ret, FAIL, "H5Dvlen_reclaim"); + /* Reclaim the read VL data */ ret=H5Dvlen_reclaim(tid1,sid1,xfer_pid,rdata); CHECK(ret, FAIL, "H5Dvlen_reclaim"); |