summaryrefslogtreecommitdiffstats
path: root/test/ntypes.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-12-10 17:43:14 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-12-10 17:43:14 (GMT)
commit9d06256018fbebbefa08879ae9f16696a5bbef19 (patch)
treedb84f4d812d122c8c9fafbcc4b828fc12cbf6a8e /test/ntypes.c
parenta4750dfae7e187f95c4515939968e6fce880efed (diff)
downloadhdf5-9d06256018fbebbefa08879ae9f16696a5bbef19.zip
hdf5-9d06256018fbebbefa08879ae9f16696a5bbef19.tar.gz
hdf5-9d06256018fbebbefa08879ae9f16696a5bbef19.tar.bz2
[svn-r17987] Description:
Bring r17945:17986 from trunk to revise_chunks branch (needs to have autotools files regenerated before testing, those will be checked in in a few minutes)
Diffstat (limited to 'test/ntypes.c')
-rw-r--r--test/ntypes.c1315
1 files changed, 784 insertions, 531 deletions
diff --git a/test/ntypes.c b/test/ntypes.c
index a82f051..87484d9 100644
--- a/test/ntypes.c
+++ b/test/ntypes.c
@@ -23,8 +23,8 @@
#include "h5test.h"
const char *FILENAME[] = {
- "ntypes",
- NULL
+ "ntypes",
+ NULL
};
#define DIM0 100
@@ -60,6 +60,7 @@ int ipoints3[DIM0][DIM1][5], icheck3[DIM0][DIM1][5];
#define SPACE2_DIM1 10
#define SPACE2_DIM2 10
+
/*-------------------------------------------------------------------------
* Function: test_atomic_dtype
@@ -80,11 +81,11 @@ int ipoints3[DIM0][DIM1][5], icheck3[DIM0][DIM1][5];
static herr_t
test_atomic_dtype(hid_t file)
{
- hid_t dataset, space;
- hid_t dtype, native_type;
- int i, j, n;
- hsize_t dims[2];
- void *tmp;
+ hid_t dataset = -1, space = -1;
+ hid_t dtype = -1, native_type = -1;
+ int i, j, n;
+ hsize_t dims[2];
+ void *tmp = NULL;
TESTING("atomic datatype");
@@ -101,7 +102,8 @@ test_atomic_dtype(hid_t file)
/*------------------- Test data values ------------------------*/
/* Create the dataset */
if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_1, H5T_STD_I32BE, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
/* Write the data to the dataset */
if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) < 0)
@@ -127,18 +129,20 @@ test_atomic_dtype(hid_t file)
TEST_ERROR;
/* Read the dataset back. The temporary buffer is for special platforms
- * like Cray. */
- tmp = malloc((size_t)(DIM0 * DIM1 * H5Tget_size(native_type)));
+ * like Cray. */
+ if(NULL == (tmp = HDmalloc((size_t)(DIM0 * DIM1 * H5Tget_size(native_type)))))
+ TEST_ERROR
if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
TEST_ERROR;
/* Copy data from temporary buffer to destination buffer */
- memcpy(icheck2, tmp, (size_t)(DIM0 * DIM1 * H5Tget_size(native_type)));
- free(tmp);
+ HDmemcpy(icheck2, tmp, (size_t)(DIM0 * DIM1 * H5Tget_size(native_type)));
+ HDfree(tmp);
+ tmp = NULL;
/* Convert to the integer type */
- if(H5Tconvert(native_type, H5T_NATIVE_INT, (DIM0*DIM1), icheck2, NULL, H5P_DEFAULT) < 0)
+ if(H5Tconvert(native_type, H5T_NATIVE_INT, (DIM0 * DIM1), icheck2, NULL, H5P_DEFAULT) < 0)
TEST_ERROR;
/* Check that the values read are the same as the values written */
@@ -159,7 +163,8 @@ test_atomic_dtype(hid_t file)
/* Create the dataset of H5T_STD_I64LE */
if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_2, H5T_STD_I64LE, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR;
@@ -181,7 +186,8 @@ test_atomic_dtype(hid_t file)
/* Create the dataset of H5T_STD_I8LE */
if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_3, H5T_STD_I8LE, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR;
@@ -203,7 +209,8 @@ test_atomic_dtype(hid_t file)
/* Create the dataset of H5T_IEEE_F32BE */
if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_4, H5T_IEEE_F32BE, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR;
@@ -225,7 +232,8 @@ test_atomic_dtype(hid_t file)
/* Create the dataset of H5T_IEEE_F64BE */
if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_5, H5T_IEEE_F64BE, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR;
@@ -253,6 +261,16 @@ test_atomic_dtype(hid_t file)
return 0;
error:
+ if(tmp)
+ HDfree(tmp);
+
+ H5E_BEGIN_TRY {
+ H5Dclose(dataset);
+ H5Tclose(native_type);
+ H5Tclose(dtype);
+ H5Sclose(space);
+ } H5E_END_TRY;
+
return -1;
}
@@ -286,14 +304,14 @@ test_compound_dtype2(hid_t file)
s2 st;
unsigned long long l;
} s1;
- hid_t dataset, space;
- hid_t dtype, native_type, tid, tid2, tid_m, tid_m2,
- mem_id, nest_mem_id;
- int i, j, n;
- hsize_t dims[2];
- s1 *temp_point, *temp_check;
- s1 *points=NULL, *check=NULL;
- void *tmp, *bkg;
+ hid_t dataset = -1, space = -1;
+ hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid_m = -1,
+ tid_m2 = -1, mem_id = -1, nest_mem_id = -1;
+ int i, j, n;
+ hsize_t dims[2];
+ s1 *temp_point = NULL, *temp_check = NULL;
+ s1 *points = NULL, *check = NULL;
+ void *tmp = NULL, *bkg = NULL;
TESTING("nested compound datatype");
@@ -304,15 +322,15 @@ test_compound_dtype2(hid_t file)
TEST_ERROR;
/* Initialize the dataset */
- for (i = n = 0, temp_point=points; i < DIM0; i++) {
- for (j = 0; j < DIM1; j++,temp_point++) {
- temp_point->c = 't';
- temp_point->i = n++;
- temp_point->st.c2 = (short)(i + j);
- temp_point->st.l2 = (i * 5 + j * 50) * n;
- temp_point->l = (unsigned long long)((i * 10 + j * 100) * n);
- }
- }
+ for(i = n = 0, temp_point = points; i < DIM0; i++) {
+ for(j = 0; j < DIM1; j++, temp_point++) {
+ temp_point->c = 't';
+ temp_point->i = n++;
+ temp_point->st.c2 = (short)(i + j);
+ temp_point->st.l2 = (i * 5 + j * 50) * n;
+ temp_point->l = (unsigned long long)((i * 10 + j * 100) * n);
+ } /* end for */
+ } /* end for */
/* Create the data space */
dims[0] = DIM0;
@@ -353,7 +371,8 @@ test_compound_dtype2(hid_t file)
/* Create the dataset */
if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME_2, tid, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
/* Create compound datatype for memory */
if((tid_m2 = H5Tcreate(H5T_COMPOUND, sizeof(s2))) < 0) TEST_ERROR;
@@ -369,7 +388,7 @@ test_compound_dtype2(hid_t file)
/* Write the data to the dataset */
if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0)
- TEST_ERROR;
+ TEST_ERROR;
/* Close dataset */
if(H5Dclose(dataset) < 0) TEST_ERROR;
@@ -451,36 +470,39 @@ test_compound_dtype2(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
- tmp = malloc(DIM0*DIM1*H5Tget_size(native_type));
- if((bkg=calloc(sizeof(s1),DIM0*DIM1))==NULL)
+ if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
+ TEST_ERROR
+ if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1)))
TEST_ERROR;
if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
- TEST_ERROR;
+ TEST_ERROR;
- memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type));
- free(tmp);
+ HDmemcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type));
+ HDfree(tmp);
+ tmp = NULL;
- if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT))
+ if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0)
TEST_ERROR;
- free(bkg);
+ HDfree(bkg);
+ bkg = NULL;
/* Check that the values read are the same as the values written */
- for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) {
- for (j = 0; j < DIM1; j++, temp_point++,temp_check++) {
- if(temp_point->c != temp_check->c ||
- temp_point->i != temp_check->i ||
- temp_point->st.c2 != temp_check->st.c2 ||
- temp_point->st.l2 != temp_check->st.l2 ||
- temp_point->l != temp_check->l ) {
- H5_FAILED();
- printf(" Read different values than written.\n");
- printf(" At index %d,%d\n", i, j);
- goto error;
- }
- }
- }
+ for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++) {
+ for(j = 0; j < DIM1; j++, temp_point++, temp_check++) {
+ if(temp_point->c != temp_check->c ||
+ temp_point->i != temp_check->i ||
+ temp_point->st.c2 != temp_check->st.c2 ||
+ temp_point->st.l2 != temp_check->st.l2 ||
+ temp_point->l != temp_check->l ) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
+ goto error;
+ } /* end if */
+ } /* end for */
+ } /* end for */
/* Close temporary datatypes */
if(H5Tclose(tid2) < 0) TEST_ERROR;
@@ -494,17 +516,35 @@ test_compound_dtype2(hid_t file)
H5Tclose(tid_m);
/* Free memory for test data */
- free(points);
- free(check);
+ HDfree(points);
+ HDfree(check);
PASSED();
return 0;
error:
- if(points!=NULL)
- free(points);
- if(check!=NULL)
- free(check);
+ if(tmp)
+ HDfree(tmp);
+ if(bkg)
+ HDfree(bkg);
+ if(points)
+ HDfree(points);
+ if(check)
+ HDfree(check);
+
+ H5E_BEGIN_TRY {
+ H5Tclose(tid);
+ H5Tclose(tid2);
+ H5Tclose(tid_m);
+ H5Tclose(tid_m2);
+ H5Sclose(space);
+ H5Tclose(mem_id);
+ H5Tclose(nest_mem_id);
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ } H5E_END_TRY;
+
return -1;
}
@@ -533,17 +573,19 @@ test_compound_dtype(hid_t file)
unsigned int i;
long long l;
} s1;
- hid_t dataset, space;
- hid_t dtype, native_type, tid, tid2, mem_id;
- int i, j, n;
- hsize_t dims[2];
- s1 *temp_point, *temp_check;
- s1 *points, *check;
- void *tmp, *bkg;
+ hid_t dataset = -1, space = -1;
+ hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, mem_id = -1;
+ int i, j, n;
+ hsize_t dims[2];
+ s1 *temp_point = NULL;
+ s1 *temp_check = NULL;
+ s1 *points = NULL;
+ s1 *check = NULL;
+ void *tmp = NULL;
+ void *bkg = NULL;
TESTING("compound datatype");
-
/* Allocate space for the points & check arrays */
if(NULL == (points = (s1 *)HDmalloc(sizeof(s1) * DIM0 * DIM1)))
TEST_ERROR;
@@ -551,12 +593,12 @@ test_compound_dtype(hid_t file)
TEST_ERROR;
/* Initialize the dataset */
- for(i = n = 0, temp_point=points; i < DIM0; i++)
- for(j = 0; j < DIM1; j++,temp_point++) {
- temp_point->c = 't';
- temp_point->i = (unsigned int)(n++);
- temp_point->l = (i*10+j*100)*n;
- } /* end for */
+ for(i = n = 0, temp_point = points; i < DIM0; i++)
+ for(j = 0; j < DIM1; j++, temp_point++) {
+ temp_point->c = 't';
+ temp_point->i = (unsigned int)(n++);
+ temp_point->l = (i * 10 + j * 100) * n;
+ } /* end for */
/* Create the data space */
dims[0] = DIM0;
@@ -573,7 +615,8 @@ test_compound_dtype(hid_t file)
/* Create the dataset */
if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME, tid, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
/* Create compound datatype for datatype in memory */
if((tid2 = H5Tcreate(H5T_COMPOUND, sizeof(s1))) < 0) TEST_ERROR;
@@ -583,7 +626,7 @@ test_compound_dtype(hid_t file)
/* Write the data to the dataset */
if(H5Dwrite(dataset, tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0)
- TEST_ERROR;
+ TEST_ERROR;
/* Close dataset */
if(H5Dclose(dataset) < 0) TEST_ERROR;
@@ -633,33 +676,35 @@ test_compound_dtype(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
- tmp = malloc(DIM0*DIM1*H5Tget_size(native_type));
- bkg = calloc(sizeof(s1),DIM0*DIM1);
+ if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
+ TEST_ERROR
+ if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1)))
+ TEST_ERROR
if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
- TEST_ERROR;
+ TEST_ERROR;
- memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type));
- free(tmp);
+ HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type));
+ HDfree(tmp);
+ tmp = NULL;
- if(H5Tconvert(native_type, tid2, (DIM0*DIM1), check, bkg, H5P_DEFAULT) < 0)
+ if(H5Tconvert(native_type, tid2, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0)
TEST_ERROR;
- free(bkg);
+ HDfree(bkg);
+ bkg = NULL;
/* Check that the values read are the same as the values written */
- for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) {
- for (j = 0; j < DIM1; j++, temp_point++,temp_check++) {
- if(temp_point->c != temp_check->c ||
- temp_point->i != temp_check->i ||
- temp_point->l != temp_check->l ) {
- H5_FAILED();
- printf(" Read different values than written.\n");
- printf(" At index %d,%d\n", i, j);
- goto error;
- }
- }
- }
+ for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++)
+ for(j = 0; j < DIM1; j++, temp_point++, temp_check++)
+ if(temp_point->c != temp_check->c ||
+ temp_point->i != temp_check->i ||
+ temp_point->l != temp_check->l ) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
+ goto error;
+ } /* end if */
/* Close datatype */
if(H5Tclose(tid) < 0) TEST_ERROR;
@@ -670,13 +715,33 @@ test_compound_dtype(hid_t file)
H5Tclose(tid2);
/* Free memory for test data */
- free(points);
- free(check);
+ HDfree(points);
+ HDfree(check);
PASSED();
return 0;
- error:
+error:
+ /* Free memory for test data */
+ if(tmp)
+ HDfree(tmp);
+ if(bkg)
+ HDfree(bkg);
+ if(points)
+ HDfree(points);
+ if(check)
+ HDfree(check);
+
+ H5E_BEGIN_TRY {
+ H5Tclose(tid);
+ H5Sclose(space);
+ H5Tclose(mem_id);
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(tid2);
+ } H5E_END_TRY;
+
return -1;
}
@@ -705,15 +770,15 @@ test_compound_dtype3(hid_t file)
int a[5];
long long l;
} s1;
- hid_t dataset, space;
- hid_t dtype, native_type, tid, tid2, tid_m, tid_m2,
- mem_id, nest_mem_id;
- hsize_t array_dims[1]={5};
- int i, j, k, n;
- hsize_t dims[2];
- s1 *temp_point, *temp_check;
- s1 *points=NULL, *check=NULL;
- void *tmp, *bkg;
+ hid_t dataset = -1, space = -1;
+ hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid_m = -1,
+ tid_m2 = -1, mem_id = -1, nest_mem_id = -1;
+ hsize_t array_dims[1] = {5};
+ int i, j, k, n;
+ hsize_t dims[2];
+ s1 *temp_point = NULL, *temp_check = NULL;
+ s1 *points = NULL, *check = NULL;
+ void *tmp = NULL, *bkg = NULL;
TESTING("compound datatype with array as field");
@@ -724,13 +789,13 @@ test_compound_dtype3(hid_t file)
TEST_ERROR;
/* Initialize the dataset */
- for(i = n = 0, temp_point=points; i < DIM0; i++)
- for(j = 0; j < DIM1; j++,temp_point++) {
- temp_point->c = 't';
- temp_point->l = (i*10+j*100)*n;
- for(k = 0; k < 5; k++)
- (temp_point->a)[k] = n++;
- } /* end for */
+ for(i = n = 0, temp_point = points; i < DIM0; i++)
+ for(j = 0; j < DIM1; j++, temp_point++) {
+ temp_point->c = 't';
+ temp_point->l = (i * 10 + j * 100) * n;
+ for(k = 0; k < 5; k++)
+ (temp_point->a)[k] = n++;
+ } /* end for */
/* Create the data space */
dims[0] = DIM0;
@@ -750,7 +815,8 @@ test_compound_dtype3(hid_t file)
/* Create the dataset */
if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME_3, tid, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
/* Create array datatype */
if((tid_m2 = H5Tarray_create2(H5T_NATIVE_INT, 1, array_dims)) < 0) TEST_ERROR;
@@ -763,7 +829,7 @@ test_compound_dtype3(hid_t file)
/* Write the data to the dataset */
if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0)
- TEST_ERROR;
+ TEST_ERROR;
/* Close dataset */
if(H5Dclose(dataset) < 0) TEST_ERROR;
@@ -825,42 +891,44 @@ test_compound_dtype3(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
- tmp = malloc(DIM0*DIM1*H5Tget_size(native_type));
- if((bkg=calloc(sizeof(s1),DIM0*DIM1))==NULL)
+ if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
+ TEST_ERROR;
+ if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1)))
TEST_ERROR;
if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
- TEST_ERROR;
+ TEST_ERROR;
- memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type));
- free(tmp);
+ HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type));
+ HDfree(tmp);
+ tmp = NULL;
- if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT))
+ if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0)
TEST_ERROR;
- free(bkg);
+ HDfree(bkg);
+ bkg = NULL;
/* Check that the values read are the same as the values written */
- for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) {
- for (j = 0; j < DIM1; j++, temp_point++,temp_check++) {
- if(temp_point->c != temp_check->c ||
- temp_point->l != temp_check->l ) {
- H5_FAILED();
- printf(" Read different values than written.\n");
- printf(" At index %d,%d\n", i, j);
- goto error;
- }
-
- for (k = 0; k < 5; k++) {
+ for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++)
+ for(j = 0; j < DIM1; j++, temp_point++, temp_check++) {
+ if(temp_point->c != temp_check->c ||
+ temp_point->l != temp_check->l ) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
+ goto error;
+ } /* end if */
+
+ for(k = 0; k < 5; k++) {
if(temp_point->a[k] != temp_check->a[k]) {
- H5_FAILED();
- printf(" Read different values than written.\n");
- printf(" At index %d,%d,%d\n", i, j, k);
- goto error;
- }
- }
- }
- }
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d,%d\n", i, j, k);
+ goto error;
+ } /* end if */
+ } /* end for */
+ } /* end for */
H5Dclose(dataset);
H5Tclose(dtype);
@@ -869,13 +937,36 @@ test_compound_dtype3(hid_t file)
H5Tclose(tid_m2);
/* Free memory for test data */
- free(points);
- free(check);
+ HDfree(points);
+ HDfree(check);
PASSED();
return 0;
- error:
+error:
+ /* Free memory for test data */
+ if(tmp)
+ HDfree(tmp);
+ if(bkg)
+ HDfree(bkg);
+ if(points)
+ HDfree(points);
+ if(check)
+ HDfree(check);
+
+ H5E_BEGIN_TRY {
+ H5Sclose(space);
+ H5Tclose(mem_id);
+ H5Tclose(nest_mem_id);
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(tid);
+ H5Tclose(tid2);
+ H5Tclose(tid_m);
+ H5Tclose(tid_m2);
+ } H5E_END_TRY;
+
return -1;
}
@@ -904,14 +995,14 @@ test_compound_opaque(hid_t file)
unsigned char o[5];
long long l;
} s1;
- hid_t dataset, space;
- hid_t dtype, native_type, tid, tid2, tid_m,
- mem_id;
- int i, j, k, n;
- hsize_t dims[2];
- s1 *temp_point, *temp_check;
- s1 *points=NULL, *check=NULL;
- void *tmp, *bkg;
+ hid_t dataset = -1, space = -1;
+ hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid_m = -1,
+ mem_id = -1;
+ int i, j, k, n;
+ hsize_t dims[2];
+ s1 *temp_point = NULL, *temp_check = NULL;
+ s1 *points = NULL, *check = NULL;
+ void *tmp = NULL, *bkg = NULL;
TESTING("compound datatype with opaque field");
@@ -922,13 +1013,13 @@ test_compound_opaque(hid_t file)
TEST_ERROR;
/* Initialize the dataset */
- for(i = n = 0, temp_point=points; i < DIM0; i++)
- for(j = 0; j < DIM1; j++,temp_point++) {
- temp_point->c = 't';
- temp_point->l = (i*10+j*100)*n;
- for(k = 0; k < 5; k++)
- (temp_point->o)[k] = (unsigned char)(n++);
- } /* end for */
+ for(i = n = 0, temp_point = points; i < DIM0; i++)
+ for(j = 0; j < DIM1; j++, temp_point++) {
+ temp_point->c = 't';
+ temp_point->l = (i * 10 + j * 100) * n;
+ for(k = 0; k < 5; k++)
+ (temp_point->o)[k] = (unsigned char)(n++);
+ } /* end for */
/* Create the data space */
dims[0] = DIM0;
@@ -949,7 +1040,8 @@ test_compound_opaque(hid_t file)
/* Create the dataset */
if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME_4, tid, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
/* Create compound datatype for datatype in memory */
if((tid_m = H5Tcreate(H5T_COMPOUND, sizeof(s1))) < 0) TEST_ERROR;
@@ -959,7 +1051,7 @@ test_compound_opaque(hid_t file)
/* Write the data to the dataset */
if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0)
- TEST_ERROR;
+ TEST_ERROR;
/* Close dataset */
if(H5Dclose(dataset) < 0) TEST_ERROR;
@@ -1014,42 +1106,44 @@ test_compound_opaque(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
- tmp = HDmalloc(DIM0*DIM1*H5Tget_size(native_type));
- if((bkg=HDcalloc(sizeof(s1),DIM0*DIM1))==NULL)
+ if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
+ TEST_ERROR;
+ if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1)))
TEST_ERROR;
if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
- TEST_ERROR;
+ TEST_ERROR;
- HDmemcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type));
+ HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type));
HDfree(tmp);
+ tmp = NULL;
- if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT))
+ if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0)
TEST_ERROR;
HDfree(bkg);
+ bkg = NULL;
/* Check that the values read are the same as the values written */
- for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) {
- for (j = 0; j < DIM1; j++, temp_point++,temp_check++) {
- if(temp_point->c != temp_check->c ||
- temp_point->l != temp_check->l ) {
- H5_FAILED();
- printf(" Read different values than written.\n");
- printf(" At index %d,%d\n", i, j);
- goto error;
- }
-
- for (k = 0; k < 5; k++) {
+ for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++)
+ for(j = 0; j < DIM1; j++, temp_point++, temp_check++) {
+ if(temp_point->c != temp_check->c ||
+ temp_point->l != temp_check->l ) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
+ goto error;
+ } /* end if */
+
+ for(k = 0; k < 5; k++) {
if(temp_point->o[k] != temp_check->o[k]) {
- H5_FAILED();
- printf(" Read different values than written.\n");
- printf(" At index %d,%d,%d\n", i, j, k);
- goto error;
- }
- }
- }
- }
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d,%d\n", i, j, k);
+ goto error;
+ } /* end if */
+ } /* end for */
+ } /* end for */
H5Dclose(dataset);
H5Tclose(dtype);
@@ -1063,7 +1157,28 @@ test_compound_opaque(hid_t file)
PASSED();
return 0;
- error:
+error:
+ /* Free memory for test data */
+ if(tmp)
+ HDfree(tmp);
+ if(bkg)
+ HDfree(bkg);
+ if(points)
+ HDfree(points);
+ if(check)
+ HDfree(check);
+
+ H5E_BEGIN_TRY {
+ H5Sclose(space);
+ H5Tclose(mem_id);
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(tid);
+ H5Tclose(tid2);
+ H5Tclose(tid_m);
+ } H5E_END_TRY;
+
return -1;
}
@@ -1087,28 +1202,28 @@ test_compound_opaque(hid_t file)
static herr_t
test_enum_dtype(hid_t file)
{
- hid_t dataset, space;
- hid_t tid, tid_m, dtype, native_type;
- int i, j, n;
- hsize_t dims[2];
- void *tmp;
- short colors[8];
- unsigned char sub_colors[16];
- const char *mname[] = { "RED",
- "GREEN",
- "BLUE",
- "YELLOW",
- "PINK",
- "PURPLE",
- "ORANGE",
- "WHITE" };
+ hid_t dataset = -1, space = -1;
+ hid_t tid = -1, tid_m = -1, dtype = -1, native_type = -1;
+ int i, j, n;
+ hsize_t dims[2];
+ void *tmp = NULL;
+ short colors[8];
+ unsigned char sub_colors[16];
+ const char *mname[] = { "RED",
+ "GREEN",
+ "BLUE",
+ "YELLOW",
+ "PINK",
+ "PURPLE",
+ "ORANGE",
+ "WHITE" };
TESTING("enum datatype");
/* Initialize the dataset */
for(i = 0; i < DIM0; i++)
for(j = 0, n = 0; j < DIM1; j++, n++)
- spoints2[i][j] = (short)((i * 10 + j * 100 + n) % 8);
+ spoints2[i][j] = (short)((i * 10 + j * 100 + n) % 8);
/* Create the data space */
dims[0] = DIM0;
@@ -1126,7 +1241,8 @@ test_enum_dtype(hid_t file)
/* Create the dataset */
if((dataset = H5Dcreate2(file, DSET_ENUM_NAME, tid, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
/* Construct enum type based on native type in memory */
if((tid_m = H5Tenum_create(H5T_NATIVE_SHORT)) < 0) TEST_ERROR;
@@ -1138,7 +1254,7 @@ test_enum_dtype(hid_t file)
/* Write the data to the dataset */
if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, spoints2) < 0)
- TEST_ERROR;
+ TEST_ERROR;
/* Close dataset */
if(H5Dclose(dataset) < 0) TEST_ERROR;
@@ -1159,30 +1275,30 @@ test_enum_dtype(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
- tmp = malloc(DIM0 * DIM1 * H5Tget_size(native_type));
+ if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
+ TEST_ERROR
if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
- TEST_ERROR;
+ TEST_ERROR;
- memcpy(scheck2, tmp, DIM0 * DIM1 * H5Tget_size(native_type));
- free(tmp);
+ HDmemcpy(scheck2, tmp, DIM0 * DIM1 * H5Tget_size(native_type));
+ HDfree(tmp);
+ tmp = NULL;
- if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), scheck2, NULL, H5P_DEFAULT) < 0)
+ if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), scheck2, NULL, H5P_DEFAULT) < 0)
TEST_ERROR;
/* Check that the values read are the same as the values written */
- for (i = 0; i < DIM0; i++) {
- for (j = 0; j < DIM1; j++) {
- if(spoints2[i][j] != scheck2[i][j]) {
- H5_FAILED();
- printf(" Read different values than written.\n");
- printf(" At index %d,%d\n", i, j);
+ for(i = 0; i < DIM0; i++)
+ for(j = 0; j < DIM1; j++)
+ if(spoints2[i][j] != scheck2[i][j]) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
printf(" spoints2[i][j]=%hd, scheck2[i][j]=%hd\n", spoints2[i][j],
scheck2[i][j]);
- goto error;
- }
- }
- }
+ goto error;
+ } /* end if */
H5Dclose(dataset);
H5Tclose(dtype);
@@ -1191,7 +1307,20 @@ test_enum_dtype(hid_t file)
PASSED();
return 0;
- error:
+error:
+ /* Free memory for test data */
+ if(tmp)
+ HDfree(tmp);
+
+ H5E_BEGIN_TRY {
+ H5Sclose(space);
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(tid);
+ H5Tclose(tid_m);
+ } H5E_END_TRY;
+
return -1;
}
@@ -1220,13 +1349,13 @@ test_array_dtype(hid_t file)
int i;
long long l;
} s1;
- hid_t dataset, space;
- hid_t dtype, native_type, tid, tid2, tid3, tid_m;
- int i, j, k, n;
- hsize_t space_dims[2], array_dims[1]={5};
- s1 *temp_point, *temp_check;
- s1 *points=NULL, *check=NULL;
- void *tmp;
+ hid_t dataset = -1, space = -1;
+ hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid3 = -1, tid_m = -1;
+ int i, j, k, n;
+ hsize_t space_dims[2], array_dims[1]={5};
+ s1 *temp_point = NULL, *temp_check = NULL;
+ s1 *points = NULL, *check = NULL;
+ void *tmp = NULL;
TESTING("array of compound datatype");
@@ -1237,13 +1366,13 @@ test_array_dtype(hid_t file)
TEST_ERROR;
/* Initialize the dataset */
- for(i = n = 0, temp_point=points; i < DIM0; i++)
- for(j = 0; j < DIM1; j++)
+ for(i = n = 0, temp_point = points; i < DIM0; i++)
+ for(j = 0; j < DIM1; j++)
for(k = 0; k < 5; k++,temp_point++) {
temp_point->c= 't';
temp_point->i= n++;
- temp_point->l= (i*10+j*100)*n;
- }
+ temp_point->l= (i * 10 + j * 100) * n;
+ } /* end for */
/* Create the data space */
space_dims[0] = DIM0;
@@ -1263,7 +1392,8 @@ test_array_dtype(hid_t file)
/* Create the dataset */
if((dataset = H5Dcreate2(file, DSET_ARRAY_NAME, tid, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
/* Create compound datatype for datatype in memory */
if((tid3 = H5Tcreate(H5T_COMPOUND, sizeof(s1))) < 0) TEST_ERROR;
@@ -1276,7 +1406,7 @@ test_array_dtype(hid_t file)
/* Write the data to the dataset */
if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0)
- TEST_ERROR;
+ TEST_ERROR;
/* Close dataset */
if(H5Dclose(dataset) < 0) TEST_ERROR;
@@ -1298,32 +1428,31 @@ test_array_dtype(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
- tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type));
+ if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
+ TEST_ERROR
if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
- TEST_ERROR;
+ TEST_ERROR;
- memcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type));
- free(tmp);
+ HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type));
+ HDfree(tmp);
+ tmp = NULL;
- if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, NULL, H5P_DEFAULT) < 0)
+ if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, NULL, H5P_DEFAULT) < 0)
TEST_ERROR;
/* Check that the values read are the same as the values written */
- for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) {
- for (j = 0; j < DIM1; j++) {
- for (k = 0; k < 5; k++, temp_point++,temp_check++) {
+ for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++)
+ for(j = 0; j < DIM1; j++)
+ for(k = 0; k < 5; k++, temp_point++, temp_check++)
if(temp_point->c != temp_check->c ||
- temp_point->i != temp_check->i ||
- temp_point->l != temp_check->l ) {
+ temp_point->i != temp_check->i ||
+ temp_point->l != temp_check->l ) {
H5_FAILED();
printf(" Read different values than written.\n");
printf(" At index %d,%d\n", i, j);
goto error;
- }
- }
- }
- }
+ } /* end if */
/* Close HDF5 objects */
if(H5Dclose(dataset)) TEST_ERROR;
@@ -1333,17 +1462,32 @@ test_array_dtype(hid_t file)
if(H5Tclose(tid3) < 0) TEST_ERROR;
/* Free memory for test data */
- free(points);
- free(check);
+ HDfree(points);
+ HDfree(check);
PASSED();
return 0;
error:
- if(points!=NULL)
- free(points);
- if(check!=NULL)
- free(check);
+ /* Free memory for test data */
+ if(tmp)
+ HDfree(tmp);
+ if(points)
+ HDfree(points);
+ if(check)
+ HDfree(check);
+
+ H5E_BEGIN_TRY {
+ H5Sclose(space);
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(tid);
+ H5Tclose(tid2);
+ H5Tclose(tid3);
+ H5Tclose(tid_m);
+ } H5E_END_TRY;
+
return -1;
}
@@ -1367,17 +1511,17 @@ error:
static herr_t
test_array_dtype2(hid_t file)
{
- hid_t dataset, space;
- hid_t dtype, native_type, tid, tid_m;
- int i, j, k, n;
- hsize_t space_dims[2], array_dims[1]={5};
- void *tmp;
+ hid_t dataset = -1, space = -1;
+ hid_t dtype = -1, native_type = -1, tid = -1, tid_m = -1;
+ int i, j, k, n;
+ hsize_t space_dims[2], array_dims[1] = {5};
+ void *tmp = NULL;
TESTING("array of atomic datatype");
/* Initialize the dataset */
for(i = n = 0;i < DIM0; i++)
- for(j = 0; j < DIM1; j++)
+ for(j = 0; j < DIM1; j++)
for(k = 0; k < 5; k++)
ipoints3[i][j][k] = n++;
@@ -1391,14 +1535,15 @@ test_array_dtype2(hid_t file)
/* Create the dataset */
if((dataset = H5Dcreate2(file, DSET_ARRAY2_NAME, tid, space,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
/* Create array datatype for memory */
if((tid_m = H5Tarray_create2(H5T_NATIVE_INT, 1, array_dims)) < 0) TEST_ERROR;
/* Write the data to the dataset */
if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints3) < 0)
- TEST_ERROR;
+ TEST_ERROR;
/* Close dataset */
if(H5Dclose(dataset) < 0) TEST_ERROR;
@@ -1409,7 +1554,6 @@ test_array_dtype2(hid_t file)
/* Close dataspace */
if(H5Sclose(space) < 0) TEST_ERROR;
-
/* Open dataset again to check H5Tget_native_type */
if((dataset = H5Dopen2(file, DSET_ARRAY2_NAME, H5P_DEFAULT)) < 0) TEST_ERROR;
@@ -1420,30 +1564,29 @@ test_array_dtype2(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
- tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type));
+ if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
+ TEST_ERROR
if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
- TEST_ERROR;
+ TEST_ERROR;
- memcpy(icheck3, tmp, DIM0 * DIM1 * H5Tget_size(native_type));
- free(tmp);
+ HDmemcpy(icheck3, tmp, DIM0 * DIM1 * H5Tget_size(native_type));
+ HDfree(tmp);
+ tmp = NULL;
- if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), icheck3, NULL, H5P_DEFAULT) < 0)
+ if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), icheck3, NULL, H5P_DEFAULT) < 0)
TEST_ERROR;
/* Check that the values read are the same as the values written */
- for (i = 0; i < DIM0; i++) {
- for (j = 0; j < DIM1; j++) {
- for (k = 0; k < 5; k++) {
+ for(i = 0; i < DIM0; i++)
+ for(j = 0; j < DIM1; j++)
+ for(k = 0; k < 5; k++)
if(icheck3[i][j][k] != ipoints3[i][j][k]) {
H5_FAILED();
printf(" Read different values than written.\n");
printf(" At index %d,%d\n", i, j);
goto error;
- }
- }
- }
- }
+ } /* end if */
/* Close HDF5 objects */
if(H5Dclose(dataset)) TEST_ERROR;
@@ -1455,6 +1598,19 @@ test_array_dtype2(hid_t file)
return 0;
error:
+ /* Free memory for test data */
+ if(tmp)
+ HDfree(tmp);
+
+ H5E_BEGIN_TRY {
+ H5Sclose(space);
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(tid);
+ H5Tclose(tid_m);
+ } H5E_END_TRY;
+
return -1;
}
@@ -1478,37 +1634,36 @@ error:
static herr_t
test_vl_dtype(hid_t file)
{
- hvl_t wdata[SPACE1_DIM1]; /* Information to write */
- hvl_t rdata[SPACE1_DIM1]; /* Information read in */
- hvl_t *t1, *t2; /* Temporary pointer to VL information */
- hsize_t dims1[] = {SPACE1_DIM1};
- hid_t dataset, space;
- hid_t dtype, native_type, nat_super_type, tid, tid2, tid_m, tid_m2;
- size_t i, j, k;
- void* *tmp;
+ hvl_t wdata[SPACE1_DIM1]; /* Information to write */
+ hvl_t rdata[SPACE1_DIM1]; /* Information read in */
+ hvl_t *t1, *t2; /* Temporary pointer to VL information */
+ hsize_t dims1[] = {SPACE1_DIM1};
+ hid_t dataset = -1, space = -1;
+ hid_t dtype = -1, native_type = -1, nat_super_type = -1, tid = -1, tid2 = -1, tid_m = -1, tid_m2 = -1;
+ size_t i, j, k;
+ void **tmp = NULL;
TESTING("variable length datatype");
/* Allocate and initialize VL data to write */
- for(i=0; i<SPACE1_DIM1; i++) {
+ for(i = 0; i < SPACE1_DIM1; i++) {
wdata[i].p = HDmalloc((i + 1) * sizeof(hvl_t));
- if(wdata[i].p==NULL) {
+ if(NULL == wdata[i].p) {
H5_FAILED();
printf(" Cannot allocate memory for VL data! i=%u\n",(unsigned)i);
goto error;
} /* end if */
- wdata[i].len=i+1;
+ wdata[i].len = i + 1;
for(t1 = (hvl_t *)wdata[i].p, j = 0; j < (i + 1); j++, t1++) {
t1->p = HDmalloc((j + 1) * sizeof(unsigned int));
- if(t1->p==NULL) {
+ if(NULL == t1->p) {
H5_FAILED();
printf(" Cannot allocate memory for VL data! i=%u, j=%u\n",(unsigned)i,(unsigned)j);
goto error;
} /* end if */
- t1->len=j+1;
- for(k=0; k<(j+1); k++) {
- ((unsigned int *)t1->p)[k]=(unsigned int)(i*100+j*10+k);
- }
+ t1->len = j + 1;
+ for(k = 0; k < (j + 1); k++)
+ ((unsigned int *)t1->p)[k] = (unsigned int)(i * 100 + j * 10 + k);
} /* end for */
} /* end for */
@@ -1566,7 +1721,7 @@ test_vl_dtype(hid_t file)
printf(" VL data length don't match!, wdata[%d].len=%d, rdata[%d].len=%d\n",(int)i,(int)wdata[i].len,(int)i,(int)rdata[i].len);
goto error;
} /* end if */
- for(t1 = (hvl_t *)wdata[i].p, t2 = (hvl_t *)rdata[i].p, j = 0; j<rdata[i].len; j++, t1++, t2++) {
+ for(t1 = (hvl_t *)wdata[i].p, t2 = (hvl_t *)rdata[i].p, j = 0; j < rdata[i].len; j++, t1++, t2++) {
if(t1->len != t2->len) {
H5_FAILED();
printf(" VL data length don't match!, wdata[%d].len=%d, rdata[%d].len=%d\n",(int)i,(int)wdata[i].len,(int)i,(int)rdata[i].len);
@@ -1575,36 +1730,38 @@ test_vl_dtype(hid_t file)
/* use temporary buffer to convert datatype. This is for special
* platforms like Cray */
- tmp = (void **)HDmalloc(t2->len * sizeof(unsigned int));
+ if(NULL == (tmp = (void **)HDmalloc(t2->len * sizeof(unsigned int))))
+ TEST_ERROR
HDmemcpy(tmp, t2->p, t2->len * H5Tget_size(nat_super_type));
- if(H5Tconvert(nat_super_type, H5T_NATIVE_UINT, t2->len, tmp, NULL, H5P_DEFAULT))
+ if(H5Tconvert(nat_super_type, H5T_NATIVE_UINT, t2->len, tmp, NULL, H5P_DEFAULT) < 0)
TEST_ERROR;
- for(k=0; k<t2->len; k++) {
- if( ((unsigned int *)t1->p)[k] != ((unsigned int *)tmp)[k] ) {
+ for(k = 0; k < t2->len; k++) {
+ if(((unsigned int *)t1->p)[k] != ((unsigned int *)tmp)[k]) {
H5_FAILED();
printf(" VL data don't match!, wdata[%u].p=%d, rdata[%u].p=%u\n",
- (unsigned)i,((unsigned int*)t1->p)[k],(unsigned)i,((unsigned int*)tmp)[k]);
+ (unsigned)i, ((unsigned int*)t1->p)[k], (unsigned)i, ((unsigned int*)tmp)[k]);
goto error;
- }
+ } /* end if */
} /* end for */
- free(tmp);
+ HDfree(tmp);
} /* end for */
} /* end for */
/* Reclaim the read VL data */
- if(H5Dvlen_reclaim(native_type,space,H5P_DEFAULT,rdata) < 0) TEST_ERROR;
+ if(H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, rdata) < 0) TEST_ERROR;
/* Reclaim the write VL data */
- if(H5Dvlen_reclaim(native_type,space,H5P_DEFAULT,wdata) < 0) TEST_ERROR;
+ if(H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, wdata) < 0) TEST_ERROR;
/* Close Dataset */
if(H5Dclose(dataset) < 0) TEST_ERROR;
/* Close datatype */
if(H5Tclose(native_type) < 0) TEST_ERROR;
+ native_type = -1; /* reset so that error handling can check for VL reclaim */
if(H5Tclose(dtype) < 0) TEST_ERROR;
if(H5Tclose(tid_m) < 0) TEST_ERROR;
if(H5Tclose(tid_m2) < 0) TEST_ERROR;
@@ -1616,7 +1773,27 @@ test_vl_dtype(hid_t file)
PASSED();
return 0;
- error:
+error:
+ /* Free memory for test data */
+ if(tmp)
+ HDfree(tmp);
+
+ H5E_BEGIN_TRY {
+ if(native_type > 0) {
+ H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, rdata);
+ H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, wdata);
+ } /* end if */
+ H5Sclose(space);
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(nat_super_type);
+ H5Tclose(tid);
+ H5Tclose(tid2);
+ H5Tclose(tid_m);
+ H5Tclose(tid_m2);
+ } H5E_END_TRY;
+
return -1;
} /* end test_vl_type() */
@@ -1641,17 +1818,18 @@ static herr_t
test_vlstr_dtype(hid_t file)
{
const char *wdata[SPACE1_DIM1]= {
- "Four score and seven years ago our forefathers brought forth on this continent a new nation,",
- "conceived in liberty and dedicated to the proposition that all men are created equal.",
- "Now we are engaged in a great civil war,",
- "testing whether that nation or any nation so conceived and so dedicated can long endure."
- }; /* Information to write */
- char *rdata[SPACE1_DIM1]; /* Information read in */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1,dtype,native_type; /* Datatype ID */
- hsize_t dims1[] = {SPACE1_DIM1};
- unsigned i; /* counting variable */
+ "Four score and seven years ago our forefathers brought forth on this continent a new nation,",
+ "conceived in liberty and dedicated to the proposition that all men are created equal.",
+ "Now we are engaged in a great civil war,",
+ "testing whether that nation or any nation so conceived and so dedicated can long endure."
+ }; /* Information to write */
+ char *rdata[SPACE1_DIM1]; /* Information read in */
+ hbool_t rdata_alloc = FALSE; /* Whether the read data is allocated */
+ hid_t dataset = -1; /* Dataset ID */
+ hid_t sid1 = -1; /* Dataspace ID */
+ hid_t tid1 = -1, dtype = -1, native_type = -1; /* Datatype ID */
+ hsize_t dims1[] = {SPACE1_DIM1};
+ unsigned i; /* counting variable */
/* Output message about test being performed */
TESTING("variable length string datatype");
@@ -1691,19 +1869,20 @@ test_vlstr_dtype(hid_t file)
/* Read dataset from disk */
if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata) < 0) TEST_ERROR;
+ rdata_alloc = TRUE;
/* Compare data read in */
for(i = 0; i < SPACE1_DIM1; i++) {
if(HDstrlen(wdata[i]) != HDstrlen(rdata[i])) {
H5_FAILED();
printf(" VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",
- (int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i]));
+ (int)i, (int)HDstrlen(wdata[i]), (int)i, (int)HDstrlen(rdata[i]));
goto error;
} /* end if */
if(HDstrcmp(wdata[i], rdata[i]) != 0 ) {
H5_FAILED();
printf(" VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",
- (int)i,wdata[i],(int)i,rdata[i]);
+ (int)i, wdata[i], (int)i, rdata[i]);
goto error;
} /* end if */
} /* end for */
@@ -1719,14 +1898,28 @@ test_vlstr_dtype(hid_t file)
if(H5Sclose(sid1) < 0) TEST_ERROR;
/* Free memory for rdata */
- for(i=0; i<SPACE1_DIM1; i++) {
+ for(i = 0; i < SPACE1_DIM1; i++)
HDfree(rdata[i]);
- }
+ rdata_alloc = FALSE;
PASSED();
return 0;
error:
+ if(rdata_alloc) {
+ /* Free memory for rdata */
+ for(i = 0; i < SPACE1_DIM1; i++)
+ HDfree(rdata[i]);
+ } /* end if */
+
+ H5E_BEGIN_TRY {
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(sid1);
+ H5Tclose(tid1);
+ } H5E_END_TRY;
+
return -1;
} /* end test_vlstr_dtype() */
@@ -1750,18 +1943,18 @@ error:
static herr_t
test_str_dtype(hid_t file)
{
- const char wdata[SPACE1_DIM1][4]= {
- "one",
- "two",
- "3rd",
- "4th"
- }; /* Information to write */
- char rdata[SPACE1_DIM1][4]; /* Information read in */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1,dtype,native_type; /* Datatype ID */
- hsize_t dims1[] = {SPACE1_DIM1};
- unsigned i; /* counting variable */
+ const char wdata[SPACE1_DIM1][4]= {
+ "one",
+ "two",
+ "3rd",
+ "4th"
+ }; /* Information to write */
+ char rdata[SPACE1_DIM1][4]; /* Information read in */
+ hid_t dataset = -1; /* Dataset ID */
+ hid_t sid1 = -1; /* Dataspace ID */
+ hid_t tid1 = -1, dtype = -1, native_type = -1; /* Datatype ID */
+ hsize_t dims1[] = {SPACE1_DIM1};
+ unsigned i; /* counting variable */
/* Output message about test being performed */
TESTING("fixed-length string datatype");
@@ -1806,13 +1999,13 @@ test_str_dtype(hid_t file)
if(HDstrlen(wdata[i]) != HDstrlen(rdata[i])) {
H5_FAILED();
printf(" data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",
- (int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i]));
+ (int)i, (int)HDstrlen(wdata[i]), (int)i, (int)HDstrlen(rdata[i]));
goto error;
} /* end if */
if(HDstrcmp(wdata[i], rdata[i]) != 0 ) {
H5_FAILED();
printf(" data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",
- (int)i,wdata[i],(int)i,rdata[i]);
+ (int)i, wdata[i], (int)i, rdata[i]);
goto error;
} /* end if */
} /* end for */
@@ -1831,11 +2024,17 @@ test_str_dtype(hid_t file)
return 0;
error:
+ H5E_BEGIN_TRY {
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(tid1);
+ H5Tclose(sid1);
+ } H5E_END_TRY;
+
return -1;
} /* end test_str_dtype() */
-
-
/*-------------------------------------------------------------------------
* Function: test_refer_dtype
@@ -1856,7 +2055,6 @@ error:
static herr_t
test_refer_dtype(hid_t file)
{
-
/* Compound datatype */
typedef struct s1_t {
unsigned int a;
@@ -1864,21 +2062,23 @@ test_refer_dtype(hid_t file)
float c;
} s1_t;
- hid_t dataset; /* Dataset ID */
- hid_t group; /* Group ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1, dtype, native_type; /* Datatype ID */
- hsize_t dims1[] = {1};
- H5O_type_t obj_type; /* Object type */
- hobj_ref_t *wbuf, /* buffer to write to disk */
- *rbuf; /* buffer read from disk */
+ hid_t dataset = -1; /* Dataset ID */
+ hid_t group = -1; /* Group ID */
+ hid_t sid1 = -1; /* Dataspace ID */
+ hid_t tid1 = -1, dtype = -1, native_type = -1; /* Datatype ID */
+ hsize_t dims1[] = {1};
+ H5O_type_t obj_type; /* Object type */
+ hobj_ref_t *wbuf = NULL, /* buffer to write to disk */
+ *rbuf = NULL; /* buffer read from disk */
/* Output message about test being performed */
TESTING("reference datatype");
/* Allocate write & read buffers */
- wbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t)));
- rbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t)));
+ if(NULL == (wbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t)))))
+ TEST_ERROR
+ if(NULL == (rbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t)))))
+ TEST_ERROR
/* Create dataspace for datasets */
if((sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL)) < 0)
@@ -1937,7 +2137,6 @@ test_refer_dtype(hid_t file)
if(H5Dclose(dataset) < 0)
TEST_ERROR;
-
/* Open the dataset */
if((dataset = H5Dopen2(file, "/Dataset3", H5P_DEFAULT)) < 0)
TEST_ERROR;
@@ -1973,19 +2172,36 @@ test_refer_dtype(hid_t file)
if(H5Tclose(tid1) < 0)
TEST_ERROR;
+ if(H5Tclose(native_type) < 0)
+ TEST_ERROR;
+
/* Close Dataset */
if(H5Dclose(dataset) < 0)
TEST_ERROR;
/* Free memory buffers */
- free(wbuf);
- free(rbuf);
+ HDfree(wbuf);
+ HDfree(rbuf);
PASSED();
return 0;
error:
+ if(wbuf)
+ HDfree(wbuf);
+ if(rbuf)
+ HDfree(rbuf);
+
+ H5E_BEGIN_TRY {
+ H5Sclose(sid1);
+ H5Gclose(group);
+ H5Tclose(tid1);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Dclose(dataset);
+ } H5E_END_TRY;
+
return -1;
} /* test_refer_dtype() */
@@ -2009,38 +2225,40 @@ error:
static herr_t
test_refer_dtype2(hid_t file)
{
- hid_t dset1, /* Dataset ID */
- dset2; /* Dereferenced dataset ID */
- hid_t sid1, /* Dataspace ID #1 */
- sid2; /* Dataspace ID #2 */
- hid_t dtype, native_type;
- hsize_t dims1[] = {1},
- dims2[] = {SPACE2_DIM1, SPACE2_DIM2};
- hsize_t start[SPACE2_RANK]; /* Starting location of hyperslab */
- hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */
- hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */
- hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */
- hdset_reg_ref_t wbuf, /* buffer to write to disk */
- rbuf; /* buffer read from disk */
- uint8_t *dwbuf, /* Buffer for writing numeric data to disk */
- *drbuf; /* Buffer for reading numeric data from disk */
- uint8_t *tu8; /* Temporary pointer to uint8 data */
- H5O_type_t obj_type; /* Object type */
- int i; /* counting variables */
+ hid_t dset1 = -1, /* Dataset ID */
+ dset2 = -1; /* Dereferenced dataset ID */
+ hid_t sid1 = -1, /* Dataspace ID #1 */
+ sid2 = -1; /* Dataspace ID #2 */
+ hid_t dtype = -1, native_type = -1;
+ hsize_t dims1[] = { 1 }, dims2[] = { SPACE2_DIM1, SPACE2_DIM2 };
+ hsize_t start[SPACE2_RANK]; /* Starting location of hyperslab */
+ hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */
+ hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */
+ hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */
+ hdset_reg_ref_t wbuf, /* buffer to write to disk */
+ rbuf; /* buffer read from disk */
+ uint8_t *dwbuf = NULL, /* Buffer for writing numeric data to disk */
+ *drbuf = NULL; /* Buffer for reading numeric data from disk */
+ uint8_t *tu8 = NULL; /* Temporary pointer to uint8 data */
+ H5O_type_t obj_type; /* Object type */
+ int i; /* counting variables */
/* Output message about test being performed */
TESTING("dataset region reference");
/* Allocate write & read buffers */
- dwbuf = (uint8_t *)HDmalloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2);
- drbuf = (uint8_t *)HDcalloc(sizeof(uint8_t), SPACE2_DIM1 * SPACE2_DIM2);
+ if(NULL == (dwbuf = (uint8_t *)HDmalloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2)))
+ TEST_ERROR
+ if(NULL == (drbuf = (uint8_t *)HDcalloc(sizeof(uint8_t), SPACE2_DIM1 * SPACE2_DIM2)))
+ TEST_ERROR
/* Create dataspace for datasets */
if((sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL)) < 0)
TEST_ERROR;
/* Create a dataset */
- if((dset2 = H5Dcreate2(file, "Dataset2", H5T_STD_U8LE, sid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ if((dset2 = H5Dcreate2(file, "Dataset2", H5T_STD_U8LE, sid2, H5P_DEFAULT,
+ H5P_DEFAULT, H5P_DEFAULT)) < 0)
TEST_ERROR;
for(tu8 = dwbuf, i = 0; i < SPACE2_DIM1 * SPACE2_DIM2; i++)
@@ -2054,21 +2272,25 @@ test_refer_dtype2(hid_t file)
if(H5Dclose(dset2) < 0)
TEST_ERROR;
-
/* Create dataspace for the reference dataset */
if((sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL)) < 0)
TEST_ERROR;
/* Create a reference dataset */
- if((dset1 = H5Dcreate2(file, "Dataset1", H5T_STD_REF_DSETREG, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ if((dset1 = H5Dcreate2(file, "Dataset1", H5T_STD_REF_DSETREG, sid1,
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
TEST_ERROR;
/* Create references */
/* Select 6x6 hyperslab for first reference */
- start[0] = 2; start[1] = 2;
- stride[0] = 1; stride[1] = 1;
- count[0] = 1; count[1] = 1;
- block[0] = 6; block[1] = 6;
+ start[0] = 2;
+ start[1] = 2;
+ stride[0] = 1;
+ stride[1] = 1;
+ count[0] = 1;
+ count[1] = 1;
+ block[0] = 6;
+ block[1] = 6;
if(H5Sselect_hyperslab(sid2, H5S_SELECT_SET, start, stride, count, block) < 0)
TEST_ERROR;
@@ -2100,9 +2322,6 @@ test_refer_dtype2(hid_t file)
if(H5Sclose(sid2) < 0)
TEST_ERROR;
-
-
-
/* Open the dataset */
if((dset1 = H5Dopen2(file, "/Dataset1", H5P_DEFAULT)) < 0)
TEST_ERROR;
@@ -2175,13 +2394,28 @@ test_refer_dtype2(hid_t file)
TEST_ERROR;
/* Free memory buffers */
- free(dwbuf);
- free(drbuf);
+ HDfree(dwbuf);
+ HDfree(drbuf);
PASSED();
return 0;
-error:
+error:
+ /* Free memory buffers */
+ if(dwbuf)
+ HDfree(dwbuf);
+ if(drbuf)
+ HDfree(drbuf);
+
+ H5E_BEGIN_TRY {
+ H5Sclose(sid2);
+ H5Sclose(sid1);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Dclose(dset2);
+ H5Dclose(dset1);
+ } H5E_END_TRY;
+
return -1;
} /* test_refer_dtype2() */
@@ -2205,21 +2439,21 @@ error:
static herr_t
test_opaque_dtype(hid_t file)
{
- hid_t type=-1, space=-1, dset=-1;
- hid_t dataset, dtype, native_type;
- size_t i;
- unsigned char wbuf[32], rbuf[32];
- hsize_t nelmts;
+ hid_t type = -1, space = -1, dset = -1;
+ hid_t dataset = -1, dtype = -1, native_type = -1;
+ size_t i;
+ unsigned char wbuf[32], rbuf[32];
+ hsize_t nelmts;
TESTING("opaque datatype");
/* opaque_1 */
nelmts = sizeof(wbuf);
- if((type = H5Tcreate(H5T_OPAQUE, 1)) < 0 ||
- H5Tset_tag(type, "testing 1-byte opaque type") < 0 ||
- (space = H5Screate_simple(1, &nelmts, NULL)) < 0 ||
- (dset = H5Dcreate2(file, DSET_OPAQUE_NAME, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- TEST_ERROR;
+ if((type = H5Tcreate(H5T_OPAQUE, 1)) < 0) TEST_ERROR;
+ if(H5Tset_tag(type, "testing 1-byte opaque type") < 0) TEST_ERROR;
+ if((space = H5Screate_simple(1, &nelmts, NULL)) < 0) TEST_ERROR;
+ if((dset = H5Dcreate2(file, DSET_OPAQUE_NAME, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
for(i = 0; i < sizeof(wbuf); i++)
wbuf[i] = (unsigned char)0xff ^ (unsigned char)i;
@@ -2243,11 +2477,11 @@ test_opaque_dtype(hid_t file)
TEST_ERROR;
for(i = 0; i < sizeof(rbuf); i++)
- if(rbuf[i] != wbuf[i]) {
- H5_FAILED();
- printf(" Read different values than written.\n");
+ if(rbuf[i] != wbuf[i]) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
printf(" At index %u\n", (unsigned)i);
- goto error;
+ goto error;
} /* end if */
if(H5Tclose(type) < 0) TEST_ERROR;
@@ -2259,6 +2493,15 @@ test_opaque_dtype(hid_t file)
return 0;
error:
+ H5E_BEGIN_TRY {
+ H5Sclose(space);
+ H5Tclose(type);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Dclose(dset);
+ H5Dclose(dataset);
+ } H5E_END_TRY;
+
return -1;
} /* test_opaque_dtype */
@@ -2282,20 +2525,20 @@ error:
static herr_t
test_bitfield_dtype(hid_t file)
{
- hid_t type=-1, space=-1, dset=-1;
- hid_t dataset, dtype, native_type;
- size_t i;
- unsigned char wbuf[32];
- hsize_t nelmts;
+ hid_t type = -1, space = -1, dset = -1;
+ hid_t dataset = -1, dtype = -1, native_type = -1;
+ size_t i;
+ unsigned char wbuf[32];
+ hsize_t nelmts;
TESTING("bitfield datatype");
/* opaque_1 */
nelmts = sizeof(wbuf);
- if((type = H5Tcopy(H5T_STD_B8LE)) < 0 ||
- (space = H5Screate_simple(1, &nelmts, NULL)) < 0 ||
- (dset = H5Dcreate2(file, DSET_BITFIELD_NAME, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- TEST_ERROR;
+ if((type = H5Tcopy(H5T_STD_B8LE)) < 0) TEST_ERROR;
+ if((space = H5Screate_simple(1, &nelmts, NULL)) < 0) TEST_ERROR;
+ if((dset = H5Dcreate2(file, DSET_BITFIELD_NAME, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
for(i = 0; i < sizeof(wbuf); i++)
wbuf[i] = (unsigned char)0xff ^ (unsigned char)i;
@@ -2327,6 +2570,15 @@ test_bitfield_dtype(hid_t file)
return 0;
error:
+ H5E_BEGIN_TRY {
+ H5Sclose(space);
+ H5Tclose(type);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Dclose(dset);
+ H5Dclose(dataset);
+ } H5E_END_TRY;
+
return -1;
} /* test_bitfield_dtype */
@@ -2350,176 +2602,166 @@ error:
static herr_t
test_ninteger(void)
{
- hid_t fid1=(-1); /* file ID */
- hid_t fid2=(-1); /* file ID */
- hid_t did1=(-1); /* dataset ID */
- hid_t did2=(-1); /* dataset ID */
- hid_t sid1=(-1); /* dataspace ID */
- hid_t dcpl1=(-1); /* dataset creation property list ID */
- hid_t dcpl2=(-1); /* dataset creation property list ID */
- hid_t tid1=(-1); /* file datatype */
- hid_t tid2=(-1); /* file datatype */
- hid_t nid1=(-1); /* native datatype */
- hid_t nid2=(-1); /* native datatype */
- hsize_t dims[1]={DIM3}; /* dataspace dimensions */
+ hid_t fid1 = -1; /* file ID */
+ hid_t fid2 = -1; /* file ID */
+ hid_t did1 = -1; /* dataset ID */
+ hid_t did2 = -1; /* dataset ID */
+ hid_t sid1 = -1; /* dataspace ID */
+ hid_t dcpl1 = -1; /* dataset creation property list ID */
+ hid_t dcpl2 = -1; /* dataset creation property list ID */
+ hid_t tid1 = -1; /* file datatype */
+ hid_t tid2 = -1; /* file datatype */
+ hid_t nid1 = -1; /* native datatype */
+ hid_t nid2 = -1; /* native datatype */
+ hsize_t dims[1] = {DIM3}; /* dataspace dimensions */
hsize_t nelmts; /* number of elements in dataset */
- int rank=1; /* rank of dataset */
+ int rank = 1; /* rank of dataset */
int buf[DIM3];
int chk[DIM3];
int i;
- for (i=0; i<DIM3; i++){
- buf[i]=i;
- }
-
TESTING("native integer ");
- /*-------------------------------------------------------------------------
- * step1: create a file
- *-------------------------------------------------------------------------
- */
+ for(i = 0; i < DIM3; i++)
+ buf[i] = i;
+
+ /*-------------------------------------------------------------------------
+ * step1: create a file
+ *-------------------------------------------------------------------------
+ */
/* create a file using default properties */
- if((fid1=H5Fcreate("tstint1.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT)) < 0)
- goto error;
+ if((fid1 = H5Fcreate("tstint1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ FAIL_STACK_ERROR
/* create a data space */
- if((sid1 = H5Screate_simple(rank,dims,NULL)) < 0) goto error;
+ if((sid1 = H5Screate_simple(rank, dims, NULL)) < 0) FAIL_STACK_ERROR
/* create dcpl */
- if((dcpl1 = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error;
+ if((dcpl1 = H5Pcreate(H5P_DATASET_CREATE)) < 0) FAIL_STACK_ERROR
/* create a dataset */
- if((did1 = H5Dcreate2(fid1, "dset", H5T_NATIVE_INT, sid1, H5P_DEFAULT, dcpl1, H5P_DEFAULT)) < 0) goto error;
+ if((did1 = H5Dcreate2(fid1, "dset", H5T_NATIVE_INT, sid1, H5P_DEFAULT, dcpl1, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
/* write */
- if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
- goto error;
+ if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) FAIL_STACK_ERROR
/* close */
- if(H5Sclose(sid1) < 0) goto error;
- if(H5Pclose(dcpl1) < 0) goto error;
- if(H5Dclose(did1) < 0) goto error;
- if(H5Fclose(fid1) < 0) goto error;
+ if(H5Sclose(sid1) < 0) FAIL_STACK_ERROR
+ if(H5Pclose(dcpl1) < 0) FAIL_STACK_ERROR
+ if(H5Dclose(did1) < 0) FAIL_STACK_ERROR
+ if(H5Fclose(fid1) < 0) FAIL_STACK_ERROR
- /*-------------------------------------------------------------------------
- * step 2: open and create another file copying the data from file1
- *-------------------------------------------------------------------------
- */
+ /*-------------------------------------------------------------------------
+ * step 2: open and create another file copying the data from file1
+ *-------------------------------------------------------------------------
+ */
- /* open */
- if((fid1 = H5Fopen("tstint1.h5", H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) goto error;
+ /* open */
+ if((fid1 = H5Fopen("tstint1.h5", H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
/* open dataset */
- if((did1 = H5Dopen2(fid1, "dset", H5P_DEFAULT)) < 0) goto error;
+ if((did1 = H5Dopen2(fid1, "dset", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
- if((sid1 = H5Dget_space(did1)) < 0) goto error;
+ if((sid1 = H5Dget_space(did1)) < 0) FAIL_STACK_ERROR
/* get dcpl */
- if((dcpl1 = H5Dget_create_plist(did1)) < 0) goto error;
+ if((dcpl1 = H5Dget_create_plist(did1)) < 0) FAIL_STACK_ERROR
/* get file datatype */
- if((tid1 = H5Dget_type(did1)) < 0) goto error;
+ if((tid1 = H5Dget_type(did1)) < 0) FAIL_STACK_ERROR
/* get native datatype */
- if((nid1 = H5Tget_native_type(tid1, H5T_DIR_DEFAULT)) < 0) goto error;
+ if((nid1 = H5Tget_native_type(tid1, H5T_DIR_DEFAULT)) < 0) FAIL_STACK_ERROR
/* get size */
- if(H5Tget_size(nid1) == 0) goto error;
+ if(H5Tget_size(nid1) == 0) FAIL_STACK_ERROR
/* get rank */
- if((rank = H5Sget_simple_extent_ndims(sid1)) < 0) goto error;
+ if((rank = H5Sget_simple_extent_ndims(sid1)) < 0) FAIL_STACK_ERROR
HDmemset(dims, 0, sizeof dims);
/* get dimension */
- if(H5Sget_simple_extent_dims(sid1, dims, NULL) < 0) goto error;
+ if(H5Sget_simple_extent_dims(sid1, dims, NULL) < 0) FAIL_STACK_ERROR
nelmts = 1;
for(i = 0; i < rank; i++)
- nelmts *= dims[i];
+ nelmts *= dims[i];
/* read */
- if(H5Dread(did1, nid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, chk) < 0)
- goto error;
+ if(H5Dread(did1, nid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, chk) < 0) FAIL_STACK_ERROR
/* create a file using default properties */
- if((fid2 = H5Fcreate("tstint2.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
+ if((fid2 = H5Fcreate("tstint2.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
/* create a dataset using the native type */
- if((did2 = H5Dcreate2(fid2, "dset", nid1, sid1, H5P_DEFAULT, dcpl1, H5P_DEFAULT)) < 0) goto error;
+ if((did2 = H5Dcreate2(fid2, "dset", nid1, sid1, H5P_DEFAULT, dcpl1, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
/* write */
- if(H5Dwrite(did2, nid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, chk) < 0)
- goto error;
+ if(H5Dwrite(did2, nid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, chk) < 0) FAIL_STACK_ERROR
/* get dcpl */
- if((dcpl2 = H5Dget_create_plist(did2)) < 0)
- goto error;
+ if((dcpl2 = H5Dget_create_plist(did2)) < 0) FAIL_STACK_ERROR
/* get file datatype */
- if((tid2 = H5Dget_type(did2)) < 0)
- goto error;
+ if((tid2 = H5Dget_type(did2)) < 0) FAIL_STACK_ERROR
/* get native datatype */
- if((nid2 = H5Tget_native_type(tid2, H5T_DIR_DEFAULT)) < 0)
- goto error;
+ if((nid2 = H5Tget_native_type(tid2, H5T_DIR_DEFAULT)) < 0) FAIL_STACK_ERROR
/* check */
if(H5Tget_precision(nid1) != H5Tget_precision(nid2)) {
- printf(" Precision differ.\n");
- goto error;
- }
+ printf(" Precision differ.\n");
+ TEST_ERROR
+ } /* end if */
/* compare dataset creation property lists */
if(H5Pequal(dcpl1, dcpl2) <= 0) {
- printf(" Property lists differ.\n");
- goto error;
- }
+ printf(" Property lists differ.\n");
+ TEST_ERROR
+ } /* end if */
/* check */
- for (i = 0; i < DIM3; i++) {
- if(buf[i] != chk[i]) {
- H5_FAILED();
- printf(" Read different values than written.\n");
- printf(" At index %d\n", i);
- goto error;
- }
- }
+ for(i = 0; i < DIM3; i++)
+ if(buf[i] != chk[i]) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d\n", i);
+ TEST_ERROR
+ } /* end if */
/* close */
- if(H5Sclose (sid1) < 0) goto error;
- if(H5Pclose (dcpl1) < 0) goto error;
- if(H5Pclose (dcpl2) < 0) goto error;
- if(H5Tclose (tid1) < 0) goto error;
- if(H5Tclose (tid2) < 0) goto error;
- if(H5Tclose (nid1) < 0) goto error;
- if(H5Tclose (nid2) < 0) goto error;
- if(H5Dclose (did1) < 0) goto error;
- if(H5Dclose (did2) < 0) goto error;
- if(H5Fclose (fid1) < 0) goto error;
- if(H5Fclose (fid2) < 0) goto error;
-
+ if(H5Sclose(sid1) < 0) FAIL_STACK_ERROR
+ if(H5Pclose(dcpl1) < 0) FAIL_STACK_ERROR
+ if(H5Pclose(dcpl2) < 0) FAIL_STACK_ERROR
+ if(H5Tclose(tid1) < 0) FAIL_STACK_ERROR
+ if(H5Tclose(tid2) < 0) FAIL_STACK_ERROR
+ if(H5Tclose(nid1) < 0) FAIL_STACK_ERROR
+ if(H5Tclose(nid2) < 0) FAIL_STACK_ERROR
+ if(H5Dclose(did1) < 0) FAIL_STACK_ERROR
+ if(H5Dclose(did2) < 0) FAIL_STACK_ERROR
+ if(H5Fclose(fid1) < 0) FAIL_STACK_ERROR
+ if(H5Fclose(fid2) < 0) FAIL_STACK_ERROR
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
- H5Pclose(dcpl1);
- H5Pclose(dcpl2);
- H5Tclose(tid1);
- H5Tclose(tid2);
- H5Tclose(nid1);
- H5Tclose(nid2);
- H5Dclose(did1);
- H5Dclose(did2);
- H5Sclose(sid1);
- H5Fclose(fid1);
- H5Fclose(fid2);
+ H5Pclose(dcpl1);
+ H5Pclose(dcpl2);
+ H5Tclose(tid1);
+ H5Tclose(tid2);
+ H5Tclose(nid1);
+ H5Tclose(nid2);
+ H5Dclose(did1);
+ H5Dclose(did2);
+ H5Sclose(sid1);
+ H5Fclose(fid1);
+ H5Fclose(fid2);
} H5E_END_TRY;
+
return -1;
} /* end test_ninteger() */
-
/*-------------------------------------------------------------------------
* Function: main
@@ -2536,43 +2778,54 @@ error:
int
main(void)
{
- hid_t file, fapl;
- int nerrors=0;
- char filename[1024];
+ hid_t file, fapl;
+ int nerrors = 0;
+ char filename[1024];
h5_reset();
fapl = h5_fileaccess();
h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
- if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
- goto error;
-
- nerrors += test_atomic_dtype(file) < 0 ?1:0;
- nerrors += test_compound_dtype(file) < 0 ?1:0;
- nerrors += test_compound_dtype2(file) < 0 ?1:0;
- nerrors += test_compound_dtype3(file) < 0 ?1:0;
- nerrors += test_compound_opaque(file) < 0 ?1:0;
- nerrors += test_enum_dtype(file) < 0 ?1:0;
- nerrors += test_array_dtype(file) < 0 ?1:0;
- nerrors += test_array_dtype2(file) < 0 ?1:0;
- nerrors += test_vl_dtype(file) < 0 ?1:0;
- nerrors += test_vlstr_dtype(file) < 0 ?1:0;
- nerrors += test_str_dtype(file) < 0 ?1:0;
- nerrors += test_refer_dtype(file) < 0 ?1:0;
- nerrors += test_refer_dtype2(file) < 0 ?1:0;
- nerrors += test_opaque_dtype(file) < 0 ?1:0;
- nerrors += test_bitfield_dtype(file) < 0 ?1:0;
- nerrors += test_ninteger() < 0 ?1:0;
-
- if(H5Fclose(file) < 0) goto error;
- if(nerrors) goto error;
+ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
+ goto error;
+
+ nerrors += test_atomic_dtype(file) < 0 ? 1 : 0;
+ nerrors += test_compound_dtype(file) < 0 ? 1 : 0;
+ nerrors += test_compound_dtype2(file) < 0 ? 1 : 0;
+ nerrors += test_compound_dtype3(file) < 0 ? 1 : 0;
+ nerrors += test_compound_opaque(file) < 0 ? 1 : 0;
+ nerrors += test_enum_dtype(file) < 0 ? 1 : 0;
+ nerrors += test_array_dtype(file) < 0 ? 1 : 0;
+ nerrors += test_array_dtype2(file) < 0 ? 1 : 0;
+ nerrors += test_vl_dtype(file) < 0 ? 1 : 0;
+ nerrors += test_vlstr_dtype(file) < 0 ? 1 : 0;
+ nerrors += test_str_dtype(file) < 0 ? 1 : 0;
+ nerrors += test_refer_dtype(file) < 0 ? 1 : 0;
+ nerrors += test_refer_dtype2(file) < 0 ? 1 : 0;
+ nerrors += test_opaque_dtype(file) < 0 ? 1 : 0;
+ nerrors += test_bitfield_dtype(file) < 0 ? 1 : 0;
+ nerrors += test_ninteger() < 0 ? 1 : 0;
+
+ if(H5Fclose(file) < 0)
+ goto error;
+ if(nerrors)
+ goto error;
+
printf("All native datatype tests passed.\n");
h5_cleanup(FILENAME, fapl);
+
return 0;
- error:
+error:
+ H5E_BEGIN_TRY {
+ H5Fclose(file);
+ h5_cleanup(FILENAME, fapl);
+ } H5E_END_TRY;
+
nerrors = MAX(1, nerrors);
printf("***** %d DATASET TEST%s FAILED! *****\n",
- nerrors, 1 == nerrors ? "" : "S");
+ nerrors, 1 == nerrors ? "" : "S");
+
return 1;
}
+