summaryrefslogtreecommitdiffstats
path: root/hl/test
diff options
context:
space:
mode:
Diffstat (limited to 'hl/test')
-rw-r--r--hl/test/Makefile.am2
-rw-r--r--hl/test/Makefile.in3
-rw-r--r--hl/test/test_ds.c147
3 files changed, 150 insertions, 2 deletions
diff --git a/hl/test/Makefile.am b/hl/test/Makefile.am
index fc6e969..86e3318 100644
--- a/hl/test/Makefile.am
+++ b/hl/test/Makefile.am
@@ -46,6 +46,6 @@ endif
# Temporary files. These files are the ones created by running `make test'.
CHECK_CLEANFILES+=combine_tables[1-2].h5 test_ds[1-9].h5 test_image[1-3].h5 \
test_lite[1-2].h5 test_table.h5 test_packet_table.h5 \
- test_packet_compress.h5
+ test_packet_compress.h5 test_detach.h5
include $(top_srcdir)/config/conclude.am
diff --git a/hl/test/Makefile.in b/hl/test/Makefile.in
index a625c86..a68831e 100644
--- a/hl/test/Makefile.in
+++ b/hl/test/Makefile.in
@@ -383,7 +383,8 @@ TRACE = perl $(top_srcdir)/bin/trace
# Temporary files. These files are the ones created by running `make test'.
CHECK_CLEANFILES = *.chkexe *.chklog *.clog combine_tables[1-2].h5 \
test_ds[1-9].h5 test_image[1-3].h5 test_lite[1-2].h5 \
- test_table.h5 test_packet_table.h5 test_packet_compress.h5
+ test_table.h5 test_packet_table.h5 test_packet_compress.h5 \
+ test_detach.h5
# The tests depend on the hdf5, hdf5 test, and hdf5_hl libraries
LDADD = $(LIBH5_HL) $(LIBH5TEST) $(LIBHDF5)
diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c
index d1705ec..2477bc0 100644
--- a/hl/test/test_ds.c
+++ b/hl/test/test_ds.c
@@ -71,6 +71,7 @@ static int test_long_scalenames(const char *fileext);
static int test_samelong_scalenames(const char *fileext);
static int test_float_scalenames(const char *fileext);
static int test_foreign_scaleattached(const char *fileforeign);
+static int test_detachscales(void);
static int test_simple(void);
static int test_errors(void);
@@ -136,6 +137,9 @@ static int read_data( const char* fname, int ndims, hsize_t *dims, float **buf )
#define FILE6 "test_ds8.h5"
#define FILE7 "test_ds9.h5"
+#define DIMENSION_LIST "DIMENSION_LIST"
+#define REFERENCE_LIST "REFERENCE_LIST"
+
/*-------------------------------------------------------------------------
* the main program
*-------------------------------------------------------------------------
@@ -169,6 +173,7 @@ int main(void)
nerrors += test_samelong_scalenames("2") < 0 ? 1 : 0;
nerrors += test_foreign_scaleattached(FOREIGN_FILE1) < 0 ? 1 : 0;
nerrors += test_foreign_scaleattached(FOREIGN_FILE2) < 0 ? 1 : 0;
+ nerrors += test_detachscales() < 0 ? 1 : 0;
/* the following tests have not been rewritten to match those above */
nerrors += test_simple() < 0 ?1:0;
@@ -1144,6 +1149,148 @@ herr_t test_cmp_scalename(hid_t fid, hid_t did, const char *name, const char *sc
return ret_value;
}
+static int test_detachscales(void)
+{
+ hid_t fid = -1;
+ hid_t did = -1;
+ hid_t dsid = -1;
+ int rank1 = 1;
+ int rank3 = 3;
+ hsize_t dims[] = {1,2,3}; /*some bogus numbers, not important for the test*/
+ int *buf = NULL;
+ char dname[10];
+ int i;
+
+ /* This tests creates two three dimensional datasets; then it creates
+ four integer datasets that are used as dim. scales; we will attach
+ and detach them to check that at the end there is no attributes
+ REFERENCE_LIST on a dimension scale and DIMENSION_LIST on a dataset */
+
+ TESTING2("test_detachscales");
+
+ if((fid = H5Fcreate("test_detach.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+
+ /* make datasets; they are three dimensional*/
+ for (i=0; i < 2; i++) {
+ sprintf(dname,"D%d", i);
+ if(H5LTmake_dataset_int(fid, dname, rank3, dims, buf) < 0)
+ goto out;
+ }
+ /* create datasets and make them dim. scales */
+
+ for (i=0; i < 4; i++) {
+ sprintf(dname, "DS%d", i);
+ if(H5LTmake_dataset_int(fid, dname, rank1, dims, buf) < 0)
+ goto out;
+ }
+ /* attach scales to the first dataset; first dimension will have
+ two scales attached */
+ if((did = H5Dopen2(fid, "D0", H5P_DEFAULT)) >= 0) {
+ for (i=0; i<4; i++) {
+ sprintf(dname, "DS%d", i);
+ if((dsid = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0)
+ goto out;
+ if(H5DSattach_scale(did, dsid, (unsigned int) i%3) < 0)
+ goto out;
+ if(H5Dclose(dsid) < 0)
+ goto out;
+ }
+ if(H5Dclose(did) < 0)
+ goto out;
+ }
+ else
+ goto out;
+
+ /* attach scales to the second dataset */
+ if((did = H5Dopen2(fid, "D1", H5P_DEFAULT)) >= 0) {
+ for (i=0; i<3; i++) {
+ sprintf(dname, "DS%d", i);
+ if((dsid = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0)
+ goto out;
+ if(H5DSattach_scale(did, dsid, (unsigned int) i) < 0)
+ goto out;
+ if(H5Dclose(dsid) < 0)
+ goto out;
+ }
+ if(H5Dclose(did) < 0)
+ goto out;
+ }
+ else
+ goto out;
+
+ /* detach DS0 from first dimension of D0 and D1; then check
+ that DS0 doesn't have attribute REFERENCE _LIST */
+
+ if((dsid = H5Dopen2(fid, "DS0", H5P_DEFAULT)) < 0)
+ goto out;
+
+ for (i=0; i<2; i++) {
+ sprintf(dname, "D%d", i);
+ if((did = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0)
+ goto out;
+ if(H5DSdetach_scale(did, dsid, (unsigned int)0) < 0)
+ goto out;
+ if(H5Dclose(did) < 0)
+ goto out;
+ }
+ /* Check that attribute "REFERENCE_LIST" doesn't exist anymore */
+ if(H5Aexists(dsid, REFERENCE_LIST)!= 0)
+ goto out;
+ if(H5Dclose(dsid) < 0)
+ goto out;
+ /* Check that DS3 is the only dim. scale attached to the first
+ dimension of D0 */
+ if((did = H5Dopen2(fid, "D0", H5P_DEFAULT)) < 0)
+ goto out;
+ if((dsid = H5Dopen2(fid, "DS3", H5P_DEFAULT)) < 0)
+ goto out;
+ if(H5DSis_attached(did, dsid, (unsigned int) 0) <= 0)
+ goto out;
+ if(H5Dclose(did) < 0)
+ goto out;
+ if(H5Dclose(dsid) < 0)
+ goto out;
+
+ /* Detach the rest of the scales DS3, DS1, DS2 from D0 and make
+ sure that attribute "DIMENSION_LIST" doesn't exist anymore */
+ if((did = H5Dopen2(fid, "D0", H5P_DEFAULT)) >= 0) {
+ for (i=1; i<4; i++) {
+ sprintf(dname, "DS%d", i);
+ if((dsid = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0)
+ goto out;
+ if(H5DSdetach_scale(did, dsid, (unsigned int) i%3) < 0)
+ goto out;
+ if(H5Dclose(dsid) < 0)
+ goto out;
+ }
+ /* Check that attribute "REFERENCE_LIST" doesn't exist anymore */
+ if(H5Aexists(did, DIMENSION_LIST)!= 0)
+ goto out;
+ if(H5Dclose(did) < 0)
+ goto out;
+ }
+ else
+ goto out;
+
+
+ PASSED();
+
+ H5Fclose(fid);
+ return SUCCEED;
+
+out:
+ H5E_BEGIN_TRY {
+ H5Dclose(did);
+ H5Dclose(dsid);
+ H5Fclose(fid);
+ } H5E_END_TRY;
+
+ H5_FAILED();
+
+ return FAIL;
+}
+
static int test_char_attachscales(const char *fileext)
{
hid_t fid = -1;