diff options
Diffstat (limited to 'hl')
-rw-r--r-- | hl/src/H5DS.c | 3 | ||||
-rw-r--r-- | hl/test/test_ds.c | 586 |
2 files changed, 462 insertions, 127 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index 552de73..8dfdc10 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -1013,7 +1013,6 @@ int H5DSget_num_scales(hid_t did, /* error zone, gracefully close */ out: H5E_BEGIN_TRY { - H5Dclose(did); H5Sclose(sid); H5Aclose(aid); H5Tclose(tid); @@ -1964,8 +1963,6 @@ out: H5Sclose(sid); H5Aclose(aid); H5Tclose(tid); - H5Dclose(did); - H5Dclose(dsid); } H5E_END_TRY; return FAIL; } diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c index c6d9b34..5e6b2fc 100644 --- a/hl/test/test_ds.c +++ b/hl/test/test_ds.c @@ -24,12 +24,16 @@ static herr_t verifiy_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); + /* prototypes */ static int test_simple(void); static int test_errors(void); static int test_rank(void); +static int test_iterators(void); + @@ -73,6 +77,7 @@ int main(void) nerrors += test_simple()<0 ?1:0; nerrors += test_errors()<0 ?1:0; nerrors += test_rank()<0 ?1:0; + nerrors += test_iterators()<0 ?1:0; if (nerrors) goto error; printf("All dimension scales tests passed.\n"); @@ -96,6 +101,8 @@ error: * H5DSset_scale * H5DSget_scale_name * H5DSis_scale + * H5DSiterate_scales + * H5DSget_num_scales * *------------------------------------------------------------------------- */ @@ -1613,6 +1620,247 @@ out: } +/*------------------------------------------------------------------------- + * Function: op_bogus + * + * 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_bogus(hid_t dset, unsigned dim, hid_t scale_id, void *visitor_data) +{ + /* define a default zero value for return. This will cause the iterator to continue */ + int ret = 0; + + /* unused */ + dset=dset; + dim=dim; + visitor_data=visitor_data; + + return ret; +} + + + + +/*------------------------------------------------------------------------- + * test several rank and types + *------------------------------------------------------------------------- + */ + +static int test_rank(void) +{ + hid_t fid; /* file ID */ + hid_t did; /* dataset ID */ + hid_t dsid; /* scale ID */ + int rank = 3; /* rank of data dataset */ + hsize_t dims[3] = {DIM1_SIZE,DIM2_SIZE,DIM3_SIZE}; /* size of data dataset */ + char name[30]; /* dataset name buffer */ + char names[30]; /* dataset scale name buffer */ + char namel[30]; /* dataset label name buffer */ + int i; + + printf("Testing ranks\n"); + +/*------------------------------------------------------------------------- + * create a file, a dataset, scales + *------------------------------------------------------------------------- + */ + + /* create a file using default properties */ + if ((fid=H5Fcreate("test_ds3.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0) + goto out; + + /* make a dataset */ + if (H5LTmake_dataset_int(fid,"dset_a",rank,dims,NULL)<0) + goto out; + + /* make scale datasets */ + for (i=0; i<rank; i++) + { + sprintf(name,"ds_a_%d",i); + if (H5LTmake_dataset_int(fid,name,(rank-i),&dims[i],NULL)<0) + goto out; + } + + +/*------------------------------------------------------------------------- + * attach + *------------------------------------------------------------------------- + */ + + TESTING2("attach"); + + if ((did = H5Dopen(fid,"dset_a"))<0) + goto out; + + for (i=0; i<rank; i++) + { + sprintf(name,"ds_a_%d",i); + if((dsid = H5Dopen(fid,name))<0) + goto out; + if(H5DSattach_scale(did,dsid,i)<0) + goto out; + if (H5DSis_attached(did,dsid,i)<=0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + } + + if (H5Dclose(did)<0) + goto out; + + PASSED(); + + +/*------------------------------------------------------------------------- + * detach + *------------------------------------------------------------------------- + */ + + TESTING2("detach"); + + if ((did = H5Dopen(fid,"dset_a"))<0) + goto out; + + for (i=0; i<rank; i++) + { + sprintf(name,"ds_a_%d",i); + if((dsid = H5Dopen(fid,name))<0) + goto out; + if(H5DSdetach_scale(did,dsid,i)<0) + goto out; + if (H5DSis_attached(did,dsid,i)!=0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + } + + if (H5Dclose(did)<0) + goto out; + + PASSED(); + + +/*------------------------------------------------------------------------- + * attach, set, get names, labels + *------------------------------------------------------------------------- + */ + + TESTING2("attach, set, get names, labels"); + + if ((did = H5Dopen(fid,"dset_a"))<0) + goto out; + + for (i=0; i<rank; i++) + { + sprintf(name,"ds_a_%d",i); + if((dsid = H5Dopen(fid,name))<0) + goto out; + if (H5DSset_scale(dsid,name)<0) + goto out; + if(H5DSattach_scale(did,dsid,i)<0) + goto out; + if (H5DSis_attached(did,dsid,i)<=0) + goto out; + if (H5DSget_scale_name(dsid,names,sizeof(names))<0) + goto out; + if (H5Dclose(dsid)<0) + goto out; + if (H5DSset_label(did,i,name)<0) + goto out; + if (H5DSget_label(did,i,namel,sizeof(namel))<0) + goto out; + if (strcmp(name,names)!=0) + goto out; + if (strcmp(name,namel)!=0) + goto out; + } + + if (H5Dclose(did)<0) + goto out; + + PASSED(); + + +/*------------------------------------------------------------------------- + * create a dataset and attach only to 1 dimension + *------------------------------------------------------------------------- + */ + + TESTING2("attach only to 1 dimension"); + + /* make a dataset */ + if (H5LTmake_dataset_int(fid,"dset_b",rank,dims,NULL)<0) + goto out; + + if ((did = H5Dopen(fid,"dset_b"))<0) + goto out; + + /* attach a DS to dimension 1 */ + sprintf(name,"ds_a_%d",1); + if((dsid = H5Dopen(fid,name))<0) + goto out; + if(H5DSattach_scale(did,dsid,DIM1)<0) + goto out; + if (H5DSis_attached(did,dsid,DIM1)<=0) + goto out; + + + /* try to detach all dimensions. for dimensions 0 and 2, it is an error */ + for (i=0; i<rank; i++) + { + if ( i==1 ) + { + if(H5DSdetach_scale(did,dsid,i)<0) + goto out; + } + else + { + if(H5DSdetach_scale(did,dsid,i)!=FAIL) + goto out; + } + } + + if (H5Dclose(dsid)<0) + goto out; + if (H5Dclose(did)<0) + goto out; + + PASSED(); + + + +/*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + if (H5Fclose(fid)<0) + goto out; + + return 0; + + /* error zone, gracefully close */ +out: + H5E_BEGIN_TRY { + H5Dclose(did); + H5Dclose(dsid); + H5Fclose(fid); + } H5E_END_TRY; + H5_FAILED(); + return FAIL; +} + + /*------------------------------------------------------------------------- * test error conditions @@ -1772,6 +2020,24 @@ static int test_errors(void) if (H5Dclose(did)<0) goto out; + /* open the previous written "ds_a" */ + if ((did = H5Dopen(fid,"ds_a"))<0) + goto out; + + /* open the previous written "ds_b" */ + if ((dsid = H5Dopen(fid,"ds_b"))<0) + goto out; + + /* detach "ds_b" to "ds_a" */ + if(H5DSdetach_scale(did,dsid,0)<0) + goto out; + + /* close */ + if (H5Dclose(dsid)<0) + goto out; + if (H5Dclose(did)<0) + goto out; + PASSED(); /*------------------------------------------------------------------------- @@ -1836,6 +2102,124 @@ static int test_errors(void) PASSED(); +/*------------------------------------------------------------------------- + * is scale + *------------------------------------------------------------------------- + */ + + TESTING2("is scale"); + + /* open a non scale dataset */ + if ((did = H5Dopen(fid,"dset_a"))<0) + goto out; + + /* verify that it is not a dimension scale dataset */ + if ((H5DSis_scale(did))==1) + goto out; + + /* close */ + if (H5Dclose(did)<0) + goto out; + + /* open the group. */ + if ((gid = H5Gopen(fid,"grp"))<0) + goto out; + + /* verify that it is not a dimension scale dataset */ + if ((H5DSis_scale(gid))==1) + goto out; + + /* close */ + if (H5Gclose(gid)<0) + goto out; + + PASSED(); + + +/*------------------------------------------------------------------------- + * detach + *------------------------------------------------------------------------- + */ + + TESTING2("detach scale from dataset it is not attached to"); + + /* open the previous written "ds_a" */ + if ((dsid = H5Dopen(fid,"ds_a"))<0) + goto out; + + /* open the previous written "dset_a" */ + if ((did = H5Dopen(fid,"dset_a"))<0) + goto out; + + /* try to detach "ds_a" from "dset_a" */ + if(H5DSdetach_scale(did,dsid,0)==SUCCESS) + goto out; + + /* close */ + if (H5Dclose(dsid)<0) + goto out; + if (H5Dclose(did)<0) + goto out; + + PASSED(); + + +/*------------------------------------------------------------------------- + * detach + *------------------------------------------------------------------------- + */ + + TESTING2("detach scale from group"); + + /* open the previous written "ds_a" */ + if ((dsid = H5Dopen(fid,"ds_a"))<0) + goto out; + + /* open the group. */ + if ((gid = H5Gopen(fid,"grp"))<0) + goto out; + + /* try to detach "ds_a" from "grp" */ + if(H5DSdetach_scale(gid,dsid,0)==SUCCESS) + goto out; + + /* close */ + if (H5Dclose(dsid)<0) + goto out; + if (H5Gclose(gid)<0) + goto out; + + PASSED(); + + +/*------------------------------------------------------------------------- + * detach + *------------------------------------------------------------------------- + */ + + TESTING2("detach scale when scale is group"); + + /* open the previous written "dset_a" */ + if ((did = H5Dopen(fid,"dset_a"))<0) + goto out; + + /* open the group. */ + if ((gid = H5Gopen(fid,"grp"))<0) + goto out; + + /* try to detach "grp" from "dset_a" */ + if(H5DSdetach_scale(did,gid,0)==SUCCESS) + goto out; + + /* close */ + if (H5Dclose(did)<0) + goto out; + if (H5Gclose(gid)<0) + goto out; + + PASSED(); + + /* close */ if (H5Fclose(fid)<0) goto out; @@ -1858,199 +2242,152 @@ out: - /*------------------------------------------------------------------------- - * test several rank and types + * test iterators *------------------------------------------------------------------------- */ -static int test_rank(void) +static int test_iterators(void) { hid_t fid; /* file 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 */ + hsize_t s1_dim[1] = {DIM1_SIZE}; /* size of DS 1 dataset */ + hid_t gid; /* group ID */ hid_t did; /* dataset ID */ hid_t dsid; /* scale ID */ - int rank = 3; /* rank of data dataset */ - hsize_t dims[3] = {DIM1_SIZE,DIM2_SIZE,DIM3_SIZE}; /* size of data dataset */ - char name[30]; /* dataset name buffer */ - char names[30]; /* dataset scale name buffer */ - char namel[30]; /* dataset label name buffer */ + char dname[30]; /* dataset name */ int i; - - printf("Testing ranks\n"); + + printf("Testing iterators\n"); /*------------------------------------------------------------------------- - * create a file, a dataset, scales + * create a file, spaces, dataset and group ids *------------------------------------------------------------------------- */ /* create a file using default properties */ - if ((fid=H5Fcreate("test_ds3.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0) + if ((fid=H5Fcreate("test_ds4.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0) + goto out; + /* create a group */ + if ((gid=H5Gcreate(fid,"grp",0))<0) + goto out; + /* close */ + if (H5Gclose(gid)<0) goto out; - /* make a dataset */ if (H5LTmake_dataset_int(fid,"dset_a",rank,dims,NULL)<0) goto out; + /* make a DS dataset */ + if (H5LTmake_dataset_int(fid,"ds_a",rankds,s1_dim,NULL)<0) + goto out; - /* make scale datasets */ - for (i=0; i<rank; i++) - { - sprintf(name,"ds_a_%d",i); - if (H5LTmake_dataset_int(fid,name,(rank-i),&dims[i],NULL)<0) - goto out; - } - - /*------------------------------------------------------------------------- - * attach + * iterate when the dataset has no scales *------------------------------------------------------------------------- */ - TESTING2("attach"); - + TESTING2("iterate when the dataset has no scales "); + + /* get the dataset id for "dset_a" */ if ((did = H5Dopen(fid,"dset_a"))<0) goto out; - - for (i=0; i<rank; i++) - { - sprintf(name,"ds_a_%d",i); - if((dsid = H5Dopen(fid,name))<0) - goto out; - if(H5DSattach_scale(did,dsid,i)<0) - goto out; - if (H5DSis_attached(did,dsid,i)<=0) - goto out; - if (H5Dclose(dsid)<0) - goto out; - } - + + /* try to iterate trough the 1st dimension of "dset_a", return error */ + if (H5DSiterate_scales(did,0,NULL,verifiy_scale,NULL)==SUCCESS) + goto out; + + /* close */ if (H5Dclose(did)<0) goto out; - + PASSED(); - + /*------------------------------------------------------------------------- - * detach + * iterate on dimension that is outside the rank *------------------------------------------------------------------------- */ - TESTING2("detach"); - + TESTING2("iterate on dimension that is outside the rank "); + + /* get the dataset id for "dset_a" */ if ((did = H5Dopen(fid,"dset_a"))<0) goto out; - - for (i=0; i<rank; i++) - { - sprintf(name,"ds_a_%d",i); - if((dsid = H5Dopen(fid,name))<0) - goto out; - if(H5DSdetach_scale(did,dsid,i)<0) - goto out; - if (H5DSis_attached(did,dsid,i)!=0) - goto out; - if (H5Dclose(dsid)<0) - goto out; - } - + + /* try to iterate trough the 3rd dimension of "dset_a", return error */ + if (H5DSiterate_scales(did,3,NULL,verifiy_scale,NULL)==SUCCESS) + goto out; + + /* close */ if (H5Dclose(did)<0) goto out; - - PASSED(); + PASSED(); /*------------------------------------------------------------------------- - * attach, set, get names, labels + * iterate for dimension with many scales *------------------------------------------------------------------------- */ - TESTING2("attach, set, get names, labels"); - + TESTING2("iterate for dimension with many scales "); + + /* open the previously written "dset_a" */ if ((did = H5Dopen(fid,"dset_a"))<0) goto out; - - for (i=0; i<rank; i++) + + for (i=0; i<100; i++) { - sprintf(name,"ds_a_%d",i); - if((dsid = H5Dopen(fid,name))<0) - goto out; - if (H5DSset_scale(dsid,name)<0) + /* make a DS */ + sprintf(dname,"ds_%d",i); + if (H5LTmake_dataset_int(fid,dname,rankds,s1_dim,NULL)<0) goto out; - if(H5DSattach_scale(did,dsid,i)<0) + /* open */ + if ((dsid = H5Dopen(fid,dname))<0) goto out; - if (H5DSis_attached(did,dsid,i)<=0) - goto out; - if (H5DSget_scale_name(dsid,names,sizeof(names))<0) + /* attach */ + if(H5DSattach_scale(did,dsid,0)<0) goto out; + /* close */ if (H5Dclose(dsid)<0) goto out; - if (H5DSset_label(did,i,name)<0) - goto out; - if (H5DSget_label(did,i,namel,sizeof(namel))<0) - goto out; - if (strcmp(name,names)!=0) - goto out; - if (strcmp(name,namel)!=0) - goto out; } - if (H5Dclose(did)<0) + /* iterate trough the 1st dimension of "dset_a" */ + if (H5DSiterate_scales(did,0,NULL,op_bogus,NULL)<0) goto out; - PASSED(); + /* close */ + if (H5Dclose(did)<0) + goto out; + PASSED(); /*------------------------------------------------------------------------- - * create a dataset and attach only to 1 dimension + * iterate on group *------------------------------------------------------------------------- - */ + */ - TESTING2("attach only to 1 dimension"); - - /* make a dataset */ - if (H5LTmake_dataset_int(fid,"dset_b",rank,dims,NULL)<0) - goto out; + TESTING2("iterate on group "); - if ((did = H5Dopen(fid,"dset_b"))<0) + /* open */ + if ((gid = H5Gopen(fid,"grp"))<0) goto out; - /* attach a DS to dimension 1 */ - sprintf(name,"ds_a_%d",1); - if((dsid = H5Dopen(fid,name))<0) - goto out; - if(H5DSattach_scale(did,dsid,DIM1)<0) + /* try to iterate, return error */ + if (H5DSiterate_scales(gid,0,NULL,verifiy_scale,NULL)==SUCCESS) goto out; - if (H5DSis_attached(did,dsid,DIM1)<=0) + + /* close */ + if (H5Gclose(gid)<0) goto out; - /* try to detach all dimensions. for dimensions 0 and 2, it is an error */ - for (i=0; i<rank; i++) - { - if ( i==1 ) - { - if(H5DSdetach_scale(did,dsid,i)<0) - goto out; - } - else - { - if(H5DSdetach_scale(did,dsid,i)!=FAIL) - goto out; - } - } - if (H5Dclose(dsid)<0) - goto out; - if (H5Dclose(did)<0) - goto out; - PASSED(); - - -/*------------------------------------------------------------------------- - * close - *------------------------------------------------------------------------- - */ + /* close */ if (H5Fclose(fid)<0) goto out; @@ -2059,10 +2396,11 @@ static int test_rank(void) /* error zone, gracefully close */ out: H5E_BEGIN_TRY { - H5Dclose(did); - H5Dclose(dsid); + H5Gclose(gid); H5Fclose(fid); } H5E_END_TRY; H5_FAILED(); return FAIL; } + + |