summaryrefslogtreecommitdiffstats
path: root/hl/test/test_ds.c
diff options
context:
space:
mode:
Diffstat (limited to 'hl/test/test_ds.c')
-rw-r--r--hl/test/test_ds.c259
1 files changed, 228 insertions, 31 deletions
diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c
index e4d4260..48f149a 100644
--- a/hl/test/test_ds.c
+++ b/hl/test/test_ds.c
@@ -24,11 +24,13 @@
static herr_t verify_scale(hid_t dset, unsigned dim, hid_t scale, void *visitor_data);
static herr_t read_scale(hid_t dset, unsigned dim, hid_t scale, void *visitor_data);
static herr_t match_dim_scale(hid_t did, unsigned dim, hid_t dsid, void *visitor_data);
-static herr_t op_bogus(hid_t did, unsigned dim, hid_t dsid, void *visitor_data);
+static herr_t op_continue(hid_t did, unsigned dim, hid_t dsid, void *visitor_data);
+static herr_t op_stop(hid_t did, unsigned dim, hid_t dsid, void *visitor_data);
/* prototypes */
static int test_simple(void);
static int test_errors(void);
+static int test_errors2(void);
static int test_rank(void);
static int test_types(void);
static int test_iterators(void);
@@ -67,6 +69,8 @@ static int read_data( const char* fname, int ndims, hsize_t *dims, float **buf )
#define FILE4 "test_ds4.h5"
#define FILE5 "test_ds5.h5"
#define FILE6 "test_ds6.h5"
+#define FILE7 "test_ds7.h5"
+
@@ -84,6 +88,7 @@ int main(void)
nerrors += test_iterators() < 0 ?1:0;
nerrors += test_types() < 0 ?1:0;
nerrors += test_data() < 0 ?1:0;
+ nerrors += test_errors2() < 0 ?1:0;
if(nerrors) goto error;
printf("All dimension scales tests passed.\n");
@@ -116,13 +121,13 @@ error:
static int test_simple(void)
{
- hid_t fid; /* file ID */
+ hid_t fid = -1; /* file ID */
hid_t did = -1; /* dataset ID */
- hid_t dsid; /* DS dataset ID */
- hid_t sid; /* space ID */
- hid_t gid; /* group ID */
- int rank = RANK; /* rank of data dataset */
- int rankds = 1; /* rank of DS dataset */
+ hid_t dsid = -1; /* DS dataset ID */
+ hid_t sid = -1; /* space ID */
+ hid_t gid = -1; /* group ID */
+ int rank = RANK; /* rank of data dataset */
+ int rankds = 1; /* rank of DS dataset */
hsize_t dims[RANK] = {DIM1_SIZE,DIM2_SIZE}; /* size of data dataset */
int buf[DIM_DATA] = {1,2,3,4,5,6,7,8,9,10,11,12}; /* data of data dataset */
hsize_t s1_dim[1] = {DIM1_SIZE}; /* size of DS 1 dataset */
@@ -1434,11 +1439,15 @@ static int test_simple(void)
return 0;
- /* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
+ H5E_BEGIN_TRY
+ {
H5Dclose(did);
+ H5Dclose(dsid);
H5Fclose(fid);
+ H5Sclose(sid);
+ H5Gclose(gid);
} H5E_END_TRY;
H5_FAILED();
return FAIL;
@@ -1508,7 +1517,7 @@ static herr_t verify_scale(hid_t dset, unsigned dim, hid_t scale_id, void *visit
static herr_t read_scale(hid_t dset, unsigned dim, hid_t scale_id, void *visitor_data)
{
int ret = 0; /* define a default zero value for return. This will cause the iterator to continue */
- hid_t sid; /* space ID */
+ hid_t sid = -1; /* space ID */
hid_t tid = -1; /* file type ID */
hid_t mtid = -1; /* memory type ID */
hssize_t nelmts; /* number of data elements */
@@ -1568,14 +1577,17 @@ static herr_t read_scale(hid_t dset, unsigned dim, hid_t scale_id, void *visitor
return ret;
- /* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
+ H5E_BEGIN_TRY
+ {
H5Sclose(sid);
H5Tclose(tid);
H5Tclose(mtid);
if(buf)
+ {
free(buf);
+ }
} H5E_END_TRY;
return FAIL;
@@ -1657,7 +1669,8 @@ static herr_t match_dim_scale(hid_t did, unsigned dim, hid_t dsid, void *visitor
return ret;
out:
- H5E_BEGIN_TRY {
+ H5E_BEGIN_TRY
+ {
H5Sclose(sid);
} H5E_END_TRY;
return FAIL;
@@ -1665,7 +1678,7 @@ out:
/*-------------------------------------------------------------------------
- * Function: op_bogus
+ * Function: op_continue
*
* Purpose: example operator function used by H5DSiterate_scales, that does nothing
*
@@ -1680,7 +1693,7 @@ out:
*-------------------------------------------------------------------------
*/
-static herr_t op_bogus(hid_t dset, unsigned dim, hid_t scale_id, void *visitor_data)
+static herr_t op_continue(hid_t dset, unsigned dim, hid_t scale_id, void *visitor_data)
{
/* Stop compiler from whining about "unused parameters" */
dset = dset;
@@ -1693,6 +1706,36 @@ static herr_t op_bogus(hid_t dset, unsigned dim, hid_t scale_id, void *visitor_d
}
+/*-------------------------------------------------------------------------
+ * Function: op_stop
+ *
+ * Purpose: example operator function used by H5DSiterate_scales, that does nothing
+ *
+ * Return:
+ * The return values from an operator are:
+ * Zero causes the iterator to continue, returning zero when all group members have been processed.
+ * Positive causes the iterator to immediately return that positive value, indicating
+ * short-circuit success. The iterator can be restarted at the next group member.
+ * Negative causes the iterator to immediately return that value, indicating failure.
+ * The iterator can be restarted at the next group member.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static herr_t op_stop(hid_t dset, unsigned dim, hid_t scale_id, void *visitor_data)
+{
+ /* Stop compiler from whining about "unused parameters" */
+ dset = dset;
+ dim = dim;
+ scale_id = scale_id;
+ visitor_data = visitor_data;
+
+ /* define a default 1 value for return. This will cause the iterator to stop */
+ return 1;
+}
+
+
+
/*-------------------------------------------------------------------------
* test error conditions
@@ -2057,9 +2100,10 @@ static int test_errors(void)
return 0;
- /* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
+ H5E_BEGIN_TRY
+ {
H5Sclose(sid);
H5Sclose(sidds);
H5Dclose(did);
@@ -2086,8 +2130,8 @@ static int test_iterators(void)
hsize_t dims[RANK] = {DIM1_SIZE,DIM2_SIZE}; /* size of data dataset */
hsize_t s1_dim[1] = {DIM1_SIZE}; /* size of DS 1 dataset */
hid_t gid = -1; /* group ID */
- hid_t did; /* dataset ID */
- hid_t dsid; /* scale ID */
+ hid_t did = -1; /* dataset ID */
+ hid_t dsid = -1; /* scale ID */
char dname[30]; /* dataset name */
int i;
@@ -2186,7 +2230,7 @@ static int test_iterators(void)
}
/* iterate trough the 1st dimension of "dset_a" */
- if(H5DSiterate_scales(did,0,NULL,op_bogus,NULL) < 0)
+ if(H5DSiterate_scales(did,0,NULL,op_continue,NULL) < 0)
goto out;
/* close */
@@ -2232,7 +2276,7 @@ static int test_iterators(void)
goto out;
/* iterate */
- if(H5DSiterate_scales(did, 0, NULL, op_bogus, NULL) == SUCCEED)
+ if(H5DSiterate_scales(did, 0, NULL, op_continue, NULL) == SUCCEED)
goto out;
/* close */
@@ -2248,10 +2292,12 @@ static int test_iterators(void)
return 0;
- /* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
+ H5E_BEGIN_TRY
+ {
H5Gclose(gid);
+ H5Dclose(did);
H5Fclose(fid);
} H5E_END_TRY;
H5_FAILED();
@@ -2269,8 +2315,8 @@ static int test_rank(void)
hid_t fid; /* file ID */
hid_t did = -1; /* dataset ID */
hid_t dsid = -1; /* scale ID */
- hid_t sid; /* space ID */
- hid_t sidds; /* space ID */
+ hid_t sid = -1; /* space ID */
+ hid_t sidds = -1; /* space ID */
hsize_t dims1[1] = {DIM1_SIZE}; /* size of data dataset */
hsize_t dims2[2] = {DIM1_SIZE,DIM2_SIZE}; /* size of data dataset */
hsize_t dims3[3] = {DIM1_SIZE,DIM2_SIZE,DIM3_SIZE}; /* size of data dataset */
@@ -2455,11 +2501,14 @@ static int test_rank(void)
return 0;
- /* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
+ H5E_BEGIN_TRY
+ {
H5Dclose(did);
H5Dclose(dsid);
+ H5Sclose(sidds);
+ H5Sclose(sid);
H5Fclose(fid);
} H5E_END_TRY;
H5_FAILED();
@@ -2632,9 +2681,10 @@ static int test_types(void)
return 0;
- /* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
+ H5E_BEGIN_TRY
+ {
H5Dclose(did);
H5Dclose(dsid);
H5Fclose(fid);
@@ -2790,9 +2840,10 @@ static int test_data(void)
return 0;
- /* error zone, gracefully close */
+ /* error zone */
out:
- H5E_BEGIN_TRY {
+ H5E_BEGIN_TRY
+ {
H5Dclose(did);
H5Dclose(dsid);
H5Fclose(fid);
@@ -2882,3 +2933,149 @@ static int read_data( const char* fname,
}
+/*-------------------------------------------------------------------------
+ * test parameter errors
+ *-------------------------------------------------------------------------
+ */
+
+static int test_errors2(void)
+{
+ hid_t fid; /* file ID */
+ hid_t did = -1; /* dataset ID */
+ hid_t dsid = -1; /* scale ID */
+ hsize_t dimd[2] = {3,3}; /* size of data dataset */
+ hsize_t dims[1] = {3}; /* size of scale dataset */
+ char lbuf[255]; /* label buffer */
+ size_t label_len;
+ int ds_idx;
+
+ printf("Testing parameter errors\n");
+
+ /*-------------------------------------------------------------------------
+ * create a file, a dataset, scales
+ *-------------------------------------------------------------------------
+ */
+
+ /* create a file using default properties */
+ if ((fid=H5Fcreate(FILE7,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT)) < 0)
+ goto out;
+
+ /* make a dataset */
+ if (H5LTmake_dataset_int(fid,"dset",2,dimd,NULL) < 0)
+ goto out;
+
+ /* make a scale dataset */
+ if(H5LTmake_dataset_int(fid,"ds1",1,dims,NULL) < 0)
+ goto out;
+
+
+ /*-------------------------------------------------------------------------
+ * attach with invalid indices
+ *-------------------------------------------------------------------------
+ */
+
+ if ((did = H5Dopen2(fid,"dset", H5P_DEFAULT)) < 0)
+ goto out;
+ if ((dsid = H5Dopen2(fid,"ds1", H5P_DEFAULT)) < 0)
+ goto out;
+ if (H5DSattach_scale(did,dsid,2) == SUCCEED)
+ goto out;
+ if (H5DSattach_scale(did,dsid,0) < 0)
+ goto out;
+ if (H5Dclose(dsid) < 0)
+ goto out;
+ if (H5Dclose(did) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * detach with invalid indices
+ *-------------------------------------------------------------------------
+ */
+ if ((did = H5Dopen2(fid,"dset", H5P_DEFAULT)) < 0)
+ goto out;
+ if ((dsid = H5Dopen2(fid,"ds1", H5P_DEFAULT)) < 0)
+ goto out;
+ if (H5DSdetach_scale(did,dsid,2) == SUCCEED)
+ goto out;
+ if (H5DSdetach_scale(did,dsid,0) < 0)
+ goto out;
+ if (H5Dclose(dsid) < 0)
+ goto out;
+ if (H5Dclose(did) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * set/get label invalid indices
+ *-------------------------------------------------------------------------
+ */
+ if ((did = H5Dopen2(fid,"dset", H5P_DEFAULT)) < 0)
+ goto out;
+ if (H5DSset_label(did,2,"label")== SUCCEED)
+ goto out;
+ if (H5DSset_label(did,0,"label") < 0)
+ goto out;
+ if (H5DSget_label(did,2,lbuf,sizeof(lbuf)) == SUCCEED)
+ goto out;
+ if ((label_len=H5DSget_label(did,0,NULL,0)) < 0)
+ goto out;
+ if ( label_len != strlen("label") )
+ goto out;
+ if (H5DSget_label(did,0,lbuf,sizeof(lbuf)) < 0)
+ goto out;
+ if (H5Dclose(did) < 0)
+ goto out;
+
+
+ /*-------------------------------------------------------------------------
+ * iterate_scales invalid indices
+ *-------------------------------------------------------------------------
+ */
+ if ((did = H5Dopen2(fid,"dset", H5P_DEFAULT)) < 0)
+ goto out;
+ if ((dsid = H5Dopen2(fid,"ds1", H5P_DEFAULT)) < 0)
+ goto out;
+ if (H5DSattach_scale(did,dsid,0) < 0)
+ goto out;
+ if (H5Dclose(dsid) < 0)
+ goto out;
+
+
+ if (H5DSiterate_scales(did,2,NULL,op_continue,NULL)== SUCCEED)
+ goto out;
+ ds_idx = 2; /* invalid */
+ if (H5DSiterate_scales(did,0,&ds_idx,op_continue,NULL)== SUCCEED)
+ goto out;
+ if (H5DSiterate_scales(did,0,NULL,op_continue,NULL) < 0)
+ goto out;
+ ds_idx = 0;
+ /* stop at first scale iteration and return ds_idx*/
+ if (H5DSiterate_scales(did,0,&ds_idx,op_stop,NULL) < 0)
+ goto out;
+ if ( ds_idx != 0 )
+ {
+ goto out;
+ }
+
+ if (H5Dclose(did) < 0)
+ goto out;
+
+ /*-------------------------------------------------------------------------
+ * close
+ *-------------------------------------------------------------------------
+ */
+ if(H5Fclose(fid) < 0)
+ goto out;
+
+ return 0;
+
+ /* error zone */
+out:
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Dclose(dsid);
+ H5Fclose(fid);
+ } H5E_END_TRY;
+ H5_FAILED();
+ return FAIL;
+} \ No newline at end of file