summaryrefslogtreecommitdiffstats
path: root/test/ntypes.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/ntypes.c')
-rw-r--r--test/ntypes.c187
1 files changed, 114 insertions, 73 deletions
diff --git a/test/ntypes.c b/test/ntypes.c
index 37a63a4..318fe2f 100644
--- a/test/ntypes.c
+++ b/test/ntypes.c
@@ -26,10 +26,6 @@ const char *FILENAME[] = {"ntypes", NULL};
#define DIM1 200
#define DIM3 20
-int ipoints2[DIM0][DIM1], icheck2[DIM0][DIM1];
-short spoints2[DIM0][DIM1], scheck2[DIM0][DIM1];
-int ipoints3[DIM0][DIM1][5], icheck3[DIM0][DIM1][5];
-
#define DSET_ATOMIC_NAME_1 "atomic_type_1"
#define DSET_ATOMIC_NAME_2 "atomic_type_2"
#define DSET_ATOMIC_NAME_3 "atomic_type_3"
@@ -80,13 +76,24 @@ test_atomic_dtype(hid_t file)
int i, j, n;
hsize_t dims[2];
void * tmp = NULL;
+ struct {
+ int arr[DIM0][DIM1];
+ } *ipoints2 = NULL;
+ struct {
+ int arr[DIM0][DIM1];
+ } *icheck2 = NULL;
TESTING("atomic datatype");
+ if (NULL == (ipoints2 = HDcalloc(1, sizeof(*ipoints2))))
+ TEST_ERROR;
+ if (NULL == (icheck2 = HDcalloc(1, sizeof(*icheck2))))
+ TEST_ERROR;
+
/* Initialize the dataset */
for (i = n = 0; i < DIM0; i++)
for (j = 0; j < DIM1; j++)
- ipoints2[i][j] = n++;
+ ipoints2->arr[i][j] = n++;
/* Create the data space */
dims[0] = DIM0;
@@ -129,7 +136,7 @@ test_atomic_dtype(hid_t file)
/* Read the dataset back. The temporary buffer is for special platforms
* like Cray. */
if (NULL == (tmp = HDmalloc((size_t)(DIM0 * DIM1 * H5Tget_size(native_type)))))
- TEST_ERROR
+ TEST_ERROR;
if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
TEST_ERROR;
@@ -146,7 +153,7 @@ test_atomic_dtype(hid_t file)
/* 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 (ipoints2[i][j] != icheck2[i][j]) {
+ if (ipoints2->arr[i][j] != icheck2->arr[i][j]) {
H5_FAILED();
HDprintf(" Read different values than written.\n");
HDprintf(" At index %d,%d\n", i, j);
@@ -270,6 +277,9 @@ test_atomic_dtype(hid_t file)
if (H5Sclose(space) < 0)
TEST_ERROR;
+ HDfree(ipoints2);
+ HDfree(icheck2);
+
PASSED();
return 0;
@@ -287,6 +297,9 @@ error:
}
H5E_END_TRY;
+ HDfree(ipoints2);
+ HDfree(icheck2);
+
return -1;
}
@@ -540,7 +553,7 @@ test_compound_dtype2(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
if (NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
- TEST_ERROR
+ TEST_ERROR;
if (NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1)))
TEST_ERROR;
@@ -763,9 +776,9 @@ test_compound_dtype(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
if (NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
- TEST_ERROR
+ TEST_ERROR;
if (NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1)))
- TEST_ERROR
+ TEST_ERROR;
if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
TEST_ERROR;
@@ -1328,13 +1341,24 @@ test_enum_dtype(hid_t file)
short colors[8];
unsigned char sub_colors[16];
const char * mname[] = {"RED", "GREEN", "BLUE", "YELLOW", "PINK", "PURPLE", "ORANGE", "WHITE"};
+ struct {
+ short arr[DIM0][DIM1];
+ } *spoints2 = NULL;
+ struct {
+ short arr[DIM0][DIM1];
+ } *scheck2 = NULL;
TESTING("enum datatype");
+ if (NULL == (spoints2 = HDcalloc(1, sizeof(*spoints2))))
+ TEST_ERROR;
+ if (NULL == (scheck2 = HDcalloc(1, sizeof(*scheck2))))
+ TEST_ERROR;
+
/* 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->arr[i][j] = (short)((i * 10 + j * 100 + n) % 8);
/* Create the data space */
dims[0] = DIM0;
@@ -1396,14 +1420,12 @@ test_enum_dtype(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
if (NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
- TEST_ERROR
+ TEST_ERROR;
if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
TEST_ERROR;
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)
TEST_ERROR;
@@ -1411,11 +1433,11 @@ test_enum_dtype(hid_t file)
/* 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]) {
+ if (spoints2->arr[i][j] != scheck2->arr[i][j]) {
H5_FAILED();
HDprintf(" Read different values than written.\n");
HDprintf(" At index %d,%d\n", i, j);
- HDprintf(" spoints2[i][j]=%hd, scheck2[i][j]=%hd\n", spoints2[i][j], scheck2[i][j]);
+ HDprintf(" spoints2[i][j]=%hd, scheck2[i][j]=%hd\n", spoints2->arr[i][j], scheck2->arr[i][j]);
goto error;
} /* end if */
@@ -1423,13 +1445,19 @@ test_enum_dtype(hid_t file)
H5Tclose(dtype);
H5Tclose(native_type);
H5Tclose(tid_m);
+
+ HDfree(tmp);
+ HDfree(spoints2);
+ HDfree(scheck2);
+
PASSED();
return 0;
error:
/* Free memory for test data */
- if (tmp)
- HDfree(tmp);
+ HDfree(tmp);
+ HDfree(spoints2);
+ HDfree(scheck2);
H5E_BEGIN_TRY
{
@@ -1565,7 +1593,7 @@ test_array_dtype(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
if (NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
- TEST_ERROR
+ TEST_ERROR;
if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
TEST_ERROR;
@@ -1657,14 +1685,25 @@ test_array_dtype2(hid_t file)
int i, j, k, n;
hsize_t space_dims[2], array_dims[1] = {5};
void * tmp = NULL;
+ struct {
+ int arr[DIM0][DIM1][5];
+ } *ipoints3 = NULL;
+ struct {
+ int arr[DIM0][DIM1][5];
+ } *icheck3 = NULL;
TESTING("array of atomic datatype");
+ if (NULL == (ipoints3 = HDcalloc(1, sizeof(*ipoints3))))
+ goto error;
+ if (NULL == (icheck3 = HDcalloc(1, sizeof(*icheck3))))
+ goto error;
+
/* Initialize the dataset */
for (i = n = 0; i < DIM0; i++)
for (j = 0; j < DIM1; j++)
for (k = 0; k < 5; k++)
- ipoints3[i][j][k] = n++;
+ ipoints3->arr[i][j][k] = n++;
/* Create the data space */
space_dims[0] = DIM0;
@@ -1713,7 +1752,7 @@ test_array_dtype2(hid_t file)
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
if (NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
- TEST_ERROR
+ TEST_ERROR;
if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0)
TEST_ERROR;
@@ -1729,7 +1768,7 @@ test_array_dtype2(hid_t file)
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]) {
+ if (icheck3->arr[i][j][k] != ipoints3->arr[i][j][k]) {
H5_FAILED();
HDprintf(" Read different values than written.\n");
HDprintf(" At index %d,%d\n", i, j);
@@ -1746,6 +1785,9 @@ test_array_dtype2(hid_t file)
if (H5Tclose(tid_m) < 0)
TEST_ERROR;
+ HDfree(ipoints3);
+ HDfree(icheck3);
+
PASSED();
return 0;
@@ -1765,6 +1807,9 @@ error:
}
H5E_END_TRY;
+ HDfree(ipoints3);
+ HDfree(icheck3);
+
return -1;
}
@@ -1830,7 +1875,7 @@ test_vl_dtype(hid_t file)
/* Create a VL datatype for disk storage */
if ((tid = H5Tvlen_create(tid2)) < 0)
- TEST_ERROR
+ TEST_ERROR;
/* Create a dataset */
if ((dataset = H5Dcreate2(file, DSET_VL_NAME, tid, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
@@ -1898,7 +1943,7 @@ test_vl_dtype(hid_t file)
/* use temporary buffer to convert datatype. This is for special
* platforms like Cray */
if (NULL == (tmp = (void **)HDmalloc(t2->len * sizeof(unsigned int))))
- TEST_ERROR
+ 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) < 0)
@@ -2276,9 +2321,9 @@ test_refer_dtype(hid_t file)
/* Allocate write & read buffers */
if (NULL == (wbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t)))))
- TEST_ERROR
+ TEST_ERROR;
if (NULL == (rbuf = (hobj_ref_t *)HDmalloc(MAX(sizeof(unsigned), sizeof(hobj_ref_t)))))
- TEST_ERROR
+ TEST_ERROR;
/* Create dataspace for datasets */
if ((sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL)) < 0)
@@ -2286,7 +2331,7 @@ test_refer_dtype(hid_t file)
/* Create a group */
if ((group = H5Gcreate2(file, "Group1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* Create a datatype to refer to */
if ((tid1 = H5Tcreate(H5T_COMPOUND, sizeof(s1_t))) < 0)
@@ -2451,9 +2496,9 @@ test_refer_dtype2(hid_t file)
/* Allocate write & read buffers */
if (NULL == (dwbuf = (uint8_t *)HDmalloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2)))
- TEST_ERROR
+ TEST_ERROR;
if (NULL == (drbuf = (uint8_t *)HDcalloc(sizeof(uint8_t), SPACE2_DIM1 * SPACE2_DIM2)))
- TEST_ERROR
+ TEST_ERROR;
/* Create dataspace for datasets */
if ((sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL)) < 0)
@@ -2912,8 +2957,7 @@ test_ninteger(void)
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;
@@ -2929,33 +2973,33 @@ test_ninteger(void)
*/
/* create a file using default properties */
if ((fid1 = H5Fcreate("tstint1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* create a data space */
if ((sid1 = H5Screate_simple(rank, dims, NULL)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* create dcpl */
if ((dcpl1 = H5Pcreate(H5P_DATASET_CREATE)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* create a dataset */
if ((did1 = H5Dcreate2(fid1, "dset", H5T_NATIVE_INT, sid1, H5P_DEFAULT, dcpl1, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* write */
if (H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* close */
if (H5Sclose(sid1) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Pclose(dcpl1) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Dclose(did1) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Fclose(fid1) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/*-------------------------------------------------------------------------
* step 2: open and create another file copying the data from file1
@@ -2964,81 +3008,78 @@ test_ninteger(void)
/* open */
if ((fid1 = H5Fopen("tstint1.h5", H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* open dataset */
if ((did1 = H5Dopen2(fid1, "dset", H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if ((sid1 = H5Dget_space(did1)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* get dcpl */
if ((dcpl1 = H5Dget_create_plist(did1)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* get file datatype */
if ((tid1 = H5Dget_type(did1)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* get native datatype */
if ((nid1 = H5Tget_native_type(tid1, H5T_DIR_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* get size */
if (H5Tget_size(nid1) == 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* get rank */
if ((rank = H5Sget_simple_extent_ndims(sid1)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
HDmemset(dims, 0, sizeof dims);
/* get dimension */
if (H5Sget_simple_extent_dims(sid1, dims, NULL) < 0)
- FAIL_STACK_ERROR
- nelmts = 1;
- for (i = 0; i < rank; i++)
- nelmts *= dims[i];
+ FAIL_STACK_ERROR;
/* read */
if (H5Dread(did1, nid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, chk) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* create a file using default properties */
if ((fid2 = H5Fcreate("tstint2.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* create a dataset using the native type */
if ((did2 = H5Dcreate2(fid2, "dset", nid1, sid1, H5P_DEFAULT, dcpl1, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* write */
if (H5Dwrite(did2, nid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, chk) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* get dcpl */
if ((dcpl2 = H5Dget_create_plist(did2)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* get file datatype */
if ((tid2 = H5Dget_type(did2)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* get native datatype */
if ((nid2 = H5Tget_native_type(tid2, H5T_DIR_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
/* check */
if (H5Tget_precision(nid1) != H5Tget_precision(nid2)) {
HDprintf(" Precision differ.\n");
- TEST_ERROR
+ TEST_ERROR;
} /* end if */
/* compare dataset creation property lists */
if (H5Pequal(dcpl1, dcpl2) <= 0) {
HDprintf(" Property lists differ.\n");
- TEST_ERROR
+ TEST_ERROR;
} /* end if */
/* check */
@@ -3047,32 +3088,32 @@ test_ninteger(void)
H5_FAILED();
HDprintf(" Read different values than written.\n");
HDprintf(" At index %d\n", i);
- TEST_ERROR
+ TEST_ERROR;
} /* end if */
/* close */
if (H5Sclose(sid1) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Pclose(dcpl1) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Pclose(dcpl2) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Tclose(tid1) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Tclose(tid2) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Tclose(nid1) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Tclose(nid2) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Dclose(did1) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Dclose(did2) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Fclose(fid1) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
if (H5Fclose(fid2) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR;
PASSED();
return 0;