summaryrefslogtreecommitdiffstats
path: root/test/dsets.c
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2004-03-11 00:25:31 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2004-03-11 00:25:31 (GMT)
commit472394a0e97c34269969956c316ae2cf8acc6cf1 (patch)
tree555e8c3b110538d4a8fccce3d2ed83d7f6c51358 /test/dsets.c
parent5ca872006352d1a586d3d3f0d9770e122393a573 (diff)
downloadhdf5-472394a0e97c34269969956c316ae2cf8acc6cf1.zip
hdf5-472394a0e97c34269969956c316ae2cf8acc6cf1.tar.gz
hdf5-472394a0e97c34269969956c316ae2cf8acc6cf1.tar.bz2
[svn-r8252] Purpose:
bug fix new test Description: the fletcher filter used a temporary 2 byte word buffer to compute the checksum. this is non portable between big-endian/little endian. added a test that reads 2 pre-saved files (one LE, other BE) with that filter enabled Solution: replaced with a buffer of 1 byte type Platforms tested: linux solaris solaris 64 bit AIX windows Misc. update:
Diffstat (limited to 'test/dsets.c')
-rw-r--r--test/dsets.c234
1 files changed, 214 insertions, 20 deletions
diff --git a/test/dsets.c b/test/dsets.c
index 84c48fe..9ce6604 100644
--- a/test/dsets.c
+++ b/test/dsets.c
@@ -23,6 +23,8 @@
#include <time.h>
#include "h5test.h"
+#include "H5private.h"
+
/*
* This file needs to access private datatypes from the H5Z package.
@@ -3093,23 +3095,23 @@ error:
static herr_t
test_filter_delete(hid_t file)
{
- H5Z_filter_t filtn; /* filter identification number */
- hid_t dsid; /* dataset ID */
- hid_t sid; /* dataspace ID */
- hid_t dcpl; /* dataset creation property list ID */
- hid_t dcpl1; /* dataset creation property list ID */
- hsize_t dims[2] = {20,20}; /* dataspace dimensions */
- hsize_t chunk_dims[2] = {10,10}; /* chunk dimensions */
- size_t nfilters; /* number of filters in DCPL */
- size_t i;
- herr_t ret; /* Generic return value */
+ H5Z_filter_t filtn; /* filter identification number */
+ hid_t dsid; /* dataset ID */
+ hid_t sid; /* dataspace ID */
+ hid_t dcpl; /* dataset creation property list ID */
+ hid_t dcpl1; /* dataset creation property list ID */
+ hsize_t dims[2]={20,20}; /* dataspace dimensions */
+ hsize_t chunk_dims[2]={10,10}; /* chunk dimensions */
+ int nfilters; /* number of filters in DCPL */
+ herr_t ret; /* generic return value */
+ int i;
TESTING("filter deletion");
- /* Create the data space */
+ /* create the data space */
if ((sid = H5Screate_simple(2, dims, NULL))<0) goto error;
- /* Create dcpl */
+ /* create dcpl */
if((dcpl = H5Pcreate(H5P_DATASET_CREATE))<0) goto error;
if(H5Pset_chunk(dcpl, 2, chunk_dims)<0) goto error;
@@ -3125,13 +3127,13 @@ test_filter_delete(hid_t file)
if (H5Pset_shuffle (dcpl)<0) goto error;
#endif
- /* Create a dataset */
+ /* create a dataset */
if ((dsid = H5Dcreate(file,"dsetdel", H5T_NATIVE_INT, sid, dcpl)) <0) goto error;
- /* Get copy of dataset's dataset creation property list */
+ /* get copy of dataset's dataset creation property list */
if ((dcpl1=H5Dget_create_plist(dsid))<0) goto error;
- /*----------------------------------------------------------------------
+ /*----------------------------------------------------------------------
* delete the deflate filter
*----------------------------------------------------------------------
*/
@@ -3144,12 +3146,12 @@ test_filter_delete(hid_t file)
/* check if filter was deleted */
for (i=0; i<nfilters; i++) {
- filtn = H5Pget_filter(dcpl1,i,0,0,0,0,0);
+ filtn = H5Pget_filter(dcpl1,(unsigned)i,0,0,0,0,0);
if (H5Z_FILTER_DEFLATE==filtn)
goto error;
}
- /* Try to delete the deflate filter again */
+ /* try to delete the deflate filter again */
H5E_BEGIN_TRY {
ret=H5Premove_filter(dcpl1,H5Z_FILTER_DEFLATE);
} H5E_END_TRY;
@@ -3161,7 +3163,7 @@ test_filter_delete(hid_t file)
#endif /*H5_HAVE_FILTER_DEFLATE*/
- /*----------------------------------------------------------------------
+ /*----------------------------------------------------------------------
* delete all filters
*----------------------------------------------------------------------
*/
@@ -3174,7 +3176,7 @@ test_filter_delete(hid_t file)
/* check if filters were deleted */
if (nfilters)goto error;
- /*----------------------------------------------------------------------
+ /*----------------------------------------------------------------------
* close
*----------------------------------------------------------------------
*/
@@ -3198,6 +3200,198 @@ error:
return -1;
} /* end test_filter_delete() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: auxread_fdata
+ *
+ * Purpose: reads a dataset "NAME" from FID
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ * Programmer: Pedro Vicente
+ * Monday, March 8, 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+auxread_fdata(hid_t fid, const char *name)
+{
+ hid_t dset_id; /* dataset ID */
+ hid_t dcpl_id; /* dataset creation property list ID */
+ hid_t space_id; /* space ID */
+ hid_t ftype_id; /* file data type ID */
+ hid_t mtype_id; /* memory data type ID */
+ size_t msize; /* memory size of memory type */
+ void *buf=NULL; /* data buffer */
+ hsize_t nelmts; /* number of elements in dataset */
+ int rank; /* rank of dataset */
+ hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */
+ int i;
+
+ if ((dset_id=H5Dopen(fid,name))<0)
+ goto error;
+ if ((space_id=H5Dget_space(dset_id))<0)
+ goto error;
+ if ((ftype_id=H5Dget_type (dset_id))<0)
+ goto error;
+ if ((dcpl_id=H5Dget_create_plist(dset_id))<0)
+ goto error;
+ if ( (rank=H5Sget_simple_extent_ndims(space_id))<0)
+ goto error;
+ HDmemset(dims, 0, sizeof dims);
+ if ( H5Sget_simple_extent_dims(space_id,dims,NULL)<0)
+ goto error;
+ nelmts=1;
+ for (i=0; i<rank; i++)
+ nelmts*=dims[i];
+ if ((mtype_id=H5Tget_native_type(ftype_id,H5T_DIR_DEFAULT))<0)
+ goto error;
+ if ((msize=H5Tget_size(mtype_id))==0)
+ goto error;
+
+ if (nelmts)
+ {
+ buf=(void *) HDmalloc((unsigned)(nelmts*msize));
+ if ( buf==NULL){
+ printf( "cannot read into memory\n" );
+ goto error;
+ }
+ if (H5Dread(dset_id,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
+ goto error;
+ }
+
+ if (H5Pclose(dcpl_id)<0)
+ goto error;
+ if (H5Sclose(space_id)<0)
+ goto error;
+ if (H5Dclose(dset_id)<0)
+ goto error;
+ if (buf)
+ free(buf);
+
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Pclose(dcpl_id);
+ H5Sclose(space_id);
+ H5Dclose(dset_id);
+ H5Tclose(ftype_id);
+ H5Tclose(mtype_id);
+ if (buf)
+ free(buf);
+ } H5E_END_TRY;
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_filters_endianess
+ *
+ * Purpose: Reads/writes data with filters (big-endian/little-endian data)
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ * Programmer: Pedro Vicente
+ * Monday, March 8, 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_filters_endianess(void)
+{
+ hid_t fid; /* file ID */
+ hid_t dsid; /* dataset ID */
+ hid_t sid; /* dataspace ID */
+ hid_t dcpl; /* dataset creation property list ID */
+ hsize_t dims[1]={2}; /* dataspace dimensions */
+ hsize_t chunk_dims[1]={2}; /* chunk dimensions */
+ int buf[2];
+ int rank=1;
+ int i;
+
+ for (i=0; i<2; i++){
+ buf[i]=1;
+ }
+
+ TESTING("filters with big-endian/little-endian data");
+
+ /*-------------------------------------------------------------------------
+ * step1: create a file
+ *-------------------------------------------------------------------------
+ */
+ /* create a file using default properties */
+ fid=H5Fcreate("test_filters.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
+
+ /* create a data space */
+ if ((sid = H5Screate_simple(rank,dims,NULL))<0) goto error;
+
+ /* create dcpl */
+ if((dcpl = H5Pcreate(H5P_DATASET_CREATE))<0) goto error;
+ if(H5Pset_chunk(dcpl,rank,chunk_dims)<0) goto error;
+
+#if defined H5_HAVE_FILTER_FLETCHER32
+ if (H5Pset_fletcher32 (dcpl)<0) goto error;
+#endif
+
+ /* create a dataset */
+ if ((dsid = H5Dcreate(fid,"dset",H5T_NATIVE_INT,sid,dcpl)) <0) goto error;
+
+ if(H5Dwrite(dsid,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
+ goto error;
+
+ /* close */
+ if (H5Pclose (dcpl)<0) goto error;
+ if (H5Dclose (dsid)<0) goto error;
+ if (H5Sclose (sid)<0) goto error;
+ if (H5Fclose (fid)<0) goto error;
+ /*-------------------------------------------------------------------------
+ * step 2: open a file written on a little-endian machine in step 1
+ *-------------------------------------------------------------------------
+ */
+ /* open */
+ if ((fid=H5Fopen("test_filters_le.hdf5",H5F_ACC_RDONLY,H5P_DEFAULT))<0)
+ goto error;
+
+ /* read */
+ if (auxread_fdata(fid,"dset")<0) goto error;
+
+ /* close */
+ if (H5Fclose(fid)<0) goto error;
+ /*-------------------------------------------------------------------------
+ * step 3: open a file written on a big-endian machine in step 1
+ *-------------------------------------------------------------------------
+ */
+ /* open */
+ if ((fid=H5Fopen("test_filters_be.hdf5",H5F_ACC_RDONLY,H5P_DEFAULT))<0)
+ goto error;
+
+ /* read */
+ if (auxread_fdata(fid,"dset")<0) goto error;
+
+ /* close */
+ if (H5Fclose(fid)<0) goto error;
+
+ PASSED();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Pclose(dcpl);
+ H5Dclose(dsid);
+ H5Sclose(sid);
+ H5Fclose(fid);
+ } H5E_END_TRY;
+ return -1;
+} /* end test_filters_endianess() */
+
/*-------------------------------------------------------------------------
* Function: main
@@ -3247,7 +3441,6 @@ main(void)
if (H5Gset_comment(grp, ".", "Causes diagnostic messages to be emitted")<0)
goto error;
if (H5Gclose (grp)<0) goto error;
-
nerrors += test_create(file)<0 ?1:0;
nerrors += test_simple_io(fapl)<0 ?1:0;
nerrors += test_compact_io(fapl)<0 ?1:0;
@@ -3265,6 +3458,7 @@ main(void)
nerrors += test_can_apply_szip(file)<0 ?1:0;
nerrors += test_compare_dcpl(file)<0 ?1:0;
nerrors += test_filter_delete(file)<0 ?1:0;
+ nerrors += test_filters_endianess()<0 ?1:0;
if (H5Fclose(file)<0) goto error;
if (nerrors) goto error;