From 6a09c9086b97477b5c931db81a8a0041cff991af Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Wed, 11 Dec 2002 11:19:52 -0500 Subject: [svn-r6196] Purpose: more tests. Description: a few more test cases. Platforms tested: modi4, eirene, arabica --- test/ntypes.c | 484 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 477 insertions(+), 7 deletions(-) diff --git a/test/ntypes.c b/test/ntypes.c index 13ec6bf..e24e3dd 100644 --- a/test/ntypes.c +++ b/test/ntypes.c @@ -21,10 +21,13 @@ const char *FILENAME[] = { #define DSET_ATOMIC_NAME_2 "atomic_type_2" #define DSET_ATOMIC_NAME_3 "atomic_type_3" #define DSET_ATOMIC_NAME_4 "atomic_type_4" +#define DSET_ATOMIC_NAME_5 "atomic_type_5" #define DSET_COMPOUND_NAME "compound_type" #define DSET_COMPOUND_NAME_2 "compound_type_2" +#define DSET_COMPOUND_NAME_3 "compound_type_3" #define DSET_ENUM_NAME "enum_type" #define DSET_ARRAY_NAME "array_type" +#define DSET_ARRAY2_NAME "array_type_2" #define DSET_VL_NAME "vl_type" #define DSET_VLSTR_NAME "vlstr_type" #define DSET_OPAQUE_NAME "opaque_type" @@ -32,6 +35,9 @@ const char *FILENAME[] = { #define SPACE1_DIM1 4 #define SPACE1_RANK 1 +#define SPACE2_RANK 2 +#define SPACE2_DIM1 10 +#define SPACE2_DIM2 10 /*------------------------------------------------------------------------- @@ -185,6 +191,27 @@ test_atomic_dtype(hid_t file) if(H5Tclose(dtype)<0) TEST_ERROR; + /* Create the dataset of H5T_IEEE_F64BE */ + if ((dataset = H5Dcreate(file, DSET_ATOMIC_NAME_5, H5T_IEEE_F64BE, space, + H5P_DEFAULT))<0) TEST_ERROR; + + if((dtype=H5Dget_type(dataset))<0) TEST_ERROR; + + if((native_type=H5Tget_native_type(dtype, H5T_DIR_DESCEND))<0) + TEST_ERROR; + + /* Verify the datatype retrieved and converted */ + if(H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_DOUBLE)) + TEST_ERROR; + if(sizeof(double)!=H5Tget_size(native_type)) + TEST_ERROR; + if(H5T_FLOAT!=H5Tget_class(native_type)) + TEST_ERROR; + + if(H5Dclose(dataset)<0) TEST_ERROR; + if(H5Tclose(dtype)<0) TEST_ERROR; + + /* Close dataspace */ if(H5Sclose(space)<0) TEST_ERROR; @@ -197,7 +224,7 @@ test_atomic_dtype(hid_t file) /*------------------------------------------------------------------------- - * Function: test_compound_dtype_2 + * Function: test_compound_dtype2 * * Purpose: Test H5Tget_native_type for compound datatype * @@ -213,7 +240,7 @@ test_atomic_dtype(hid_t file) *------------------------------------------------------------------------- */ static herr_t -test_compound_dtype_2(hid_t file) +test_compound_dtype2(hid_t file) { typedef struct s2 { short c2; @@ -497,6 +524,144 @@ test_compound_dtype(hid_t file) /*------------------------------------------------------------------------- + * Function: test_compound_dtype3 + * + * Purpose: Test H5Tget_native_type for compound datatype + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Raymond Lu + * October 15, 2002 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +test_compound_dtype3(hid_t file) +{ + typedef struct { + char c; + int a[5]; + long_long l; + } s1; + hid_t dataset, space; + hid_t dtype, native_type, tid, tid2, tid_m, tid_m2; + hsize_t array_dims[1]={5}; + int i, j, k, n; + hsize_t dims[2]; + s1 points[100][200], check[100][200]; + + TESTING("compound datatype"); + + /* Initialize the dataset */ + for (i = n = 0; i < 100; i++) { + for (j = 0; j < 200; j++) { + (points[i][j]).c = 't'; + for (k = 0; k < 5; k++) + (points[i][j]).a[k] = n++; + (points[i][j]).l = (i*10+j*100)*n; + } + } + + /* Create the data space */ + dims[0] = 100; + dims[1] = 200; + if ((space = H5Screate_simple(2, dims, NULL))<0) TEST_ERROR; + + /* Create array datatype */ + if((tid2=H5Tarray_create(H5T_STD_I32LE, 1, array_dims, NULL))<0) TEST_ERROR; + + /* Create compound datatype for disk storage */ + if((tid=H5Tcreate(H5T_COMPOUND, 29))<0) TEST_ERROR; + + /* Insert members */ + if(H5Tinsert(tid, "c", 0, H5T_NATIVE_CHAR)<0) TEST_ERROR; + if(H5Tinsert(tid, "a", 1, tid2)<0) TEST_ERROR; + if(H5Tinsert(tid, "l", 21, H5T_STD_I64BE)<0) TEST_ERROR; + + /* Create the dataset */ + if ((dataset = H5Dcreate(file, DSET_COMPOUND_NAME_3, tid, space, + H5P_DEFAULT))<0) TEST_ERROR; + + /* Create array datatype */ + if((tid_m2=H5Tarray_create(H5T_NATIVE_INT, 1, array_dims, NULL))<0) TEST_ERROR; + + /* Create compound datatype for datatype in memory */ + if((tid_m=H5Tcreate(H5T_COMPOUND, sizeof(s1)))<0) TEST_ERROR; + if(H5Tinsert(tid_m, "c", HOFFSET(s1, c), H5T_NATIVE_CHAR)<0) TEST_ERROR; + if(H5Tinsert(tid_m, "a", HOFFSET(s1, a), tid_m2)<0) TEST_ERROR; + if(H5Tinsert(tid_m, "l", HOFFSET(s1, l), H5T_NATIVE_LLONG)<0) TEST_ERROR; + + /* Write the data to the dataset */ + if (H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points)<0) + TEST_ERROR; + + /* Close dataset */ + if(H5Dclose(dataset)<0) TEST_ERROR; + + /* Close datatype */ + if(H5Tclose(tid)<0) TEST_ERROR; + if(H5Tclose(tid2)<0) TEST_ERROR; + + /* Close dataspace */ + if(H5Sclose(space)<0) TEST_ERROR; + + + /* Open dataset again to check H5Tget_native_type */ + if((dataset=H5Dopen(file, DSET_COMPOUND_NAME_3))<0) TEST_ERROR; + + if((dtype=H5Dget_type(dataset))<0) TEST_ERROR; + + if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0) + TEST_ERROR; + + if(sizeof(s1)!=H5Tget_size(native_type)) + TEST_ERROR; + if(!H5Tequal(native_type, tid_m)) + TEST_ERROR; + + /* Read the dataset back */ + if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, check)<0) + TEST_ERROR; + + /* Check that the values read are the same as the values written */ + for (i = 0; i < 100; i++) { + for (j = 0; j < 200; j++) { + if ((points[i][j]).c != (check[i][j]).c || + (points[i][j]).l != (check[i][j]).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++) { + if((points[i][j]).a[k] != (check[i][j]).a[k]) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); + goto error; + } + } + } + } + + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid_m); + H5Tclose(tid_m2); + PASSED(); + return 0; + + error: + return -1; +} + +/*------------------------------------------------------------------------- * Function: test_enum_dtype * * Purpose: Test H5Tget_native_type for enumerate datatype @@ -521,7 +686,7 @@ test_enum_dtype(hid_t file) hsize_t dims[2]; short points[100][200], check[100][200]; short colors[8]; - const char *mname[] = { "RED", + const char *mname[] = { "RED", "GREEN", "BLUE", "YELLOW", @@ -646,7 +811,7 @@ test_array_dtype(hid_t file) s1 *temp_point, *temp_check; s1 *points=NULL, *check=NULL; - TESTING("array datatype"); + TESTING("array of compound datatype"); /* Allocate space for the points & check arrays */ if((points=malloc(sizeof(s1)*100*200*5))==NULL) @@ -760,6 +925,114 @@ error: /*------------------------------------------------------------------------- + * Function: test_array_dtype2 + * + * Purpose: Test H5Tget_native_type for array datatype + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Raymond Lu + * October 15, 2002 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +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}; + int points[100][200][5], check[100][200][5]; + + TESTING("array of atomic datatype"); + + /* Initialize the dataset */ + for(i = n = 0;i < 100; i++) + for(j = 0; j < 200; j++) + for(k = 0; k < 5; k++) + points[i][j][k] = n++; + + /* Create the data space */ + space_dims[0] = 100; + space_dims[1] = 200; + if ((space = H5Screate_simple(2, space_dims, NULL))<0) TEST_ERROR; + + /* Create array datatype for disk storage */ + if((tid=H5Tarray_create(H5T_STD_I32LE, 1, array_dims, NULL))<0) TEST_ERROR; + + /* Create the dataset */ + if ((dataset = H5Dcreate(file, DSET_ARRAY2_NAME, tid, space, + H5P_DEFAULT))<0) TEST_ERROR; + + /* Create array datatype for memory */ + if((tid_m=H5Tarray_create(H5T_NATIVE_INT, 1, array_dims, NULL))<0) TEST_ERROR; + + /* Write the data to the dataset */ + if (H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points)<0) + TEST_ERROR; + + /* Close dataset */ + if(H5Dclose(dataset)<0) TEST_ERROR; + + /* Close datatype */ + if(H5Tclose(tid)<0) TEST_ERROR; + + /* Close dataspace */ + if(H5Sclose(space)<0) TEST_ERROR; + + + /* Open dataset again to check H5Tget_native_type */ + if((dataset=H5Dopen(file, DSET_ARRAY2_NAME))<0) TEST_ERROR; + + if((dtype=H5Dget_type(dataset))<0) TEST_ERROR; + + if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0) + TEST_ERROR; + + if(!H5Tequal(tid_m, native_type)) TEST_ERROR; + + /* Read the dataset back */ + if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, check)<0) + TEST_ERROR; + + /* Check that the values read are the same as the values written */ + for (i = 0; i < 100; i++) { + for (j = 0; j < 200; j++) { + for (k = 0; k < 5; k++) { + if(check[i][j][k] != points[i][j][k]) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); + goto error; + } + } + } + } + + /* Close HDF5 objects */ + if(H5Dclose(dataset)) TEST_ERROR; + if(H5Tclose(native_type)) TEST_ERROR; + if(H5Tclose(dtype)) TEST_ERROR; + if(H5Tclose(tid_m)<0) TEST_ERROR; + + PASSED(); + return 0; + +error: + if(points!=NULL) + free(points); + if(check!=NULL) + free(check); + return -1; +} + + +/*------------------------------------------------------------------------- * Function: test_vl_dtype * * Purpose: Test H5Tget_native_type for variable length datatype @@ -979,12 +1252,14 @@ test_vlstr_dtype(hid_t file) for(i=0; i