[svn-r12322] Purpose: Test some functions

Description: Test some data type functions that are and aren't supposed to work
with some data types.


Platforms tested: h5committest and fuss.
This commit is contained in:
Raymond Lu 2006-05-02 14:42:41 -05:00
parent 720f6cb065
commit 1acc676fcf
4 changed files with 733 additions and 5 deletions

View File

@ -478,8 +478,17 @@ error:
static int
test_compound_1(void)
{
complex_t tmp;
hid_t complex_id;
complex_t tmp;
hid_t complex_id;
hid_t super;
size_t size;
H5T_pad_t lsb, msb;
H5T_cset_t cset;
H5T_str_t strpad;
H5T_order_t order;
H5T_sign_t sign;
char* tag;
int offset;
herr_t ret;
TESTING("compound data types");
@ -503,6 +512,116 @@ test_compound_1(void)
if (H5Tinsert(complex_id, "imaginary", HOFFSET(complex_t, im),
H5T_NATIVE_DOUBLE)<0) goto error;
/* Test some functions that aren't supposed to work for compound type */
H5E_BEGIN_TRY {
size=H5Tget_precision(complex_id);
} H5E_END_TRY;
if (size>0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
size = 128;
H5E_BEGIN_TRY {
ret = H5Tset_precision(complex_id, size);
} H5E_END_TRY;
if (ret>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
ret = H5Tget_pad(complex_id, &lsb, &msb);
} H5E_END_TRY;
if (ret>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
size = H5Tget_ebias(complex_id);
} H5E_END_TRY;
if (size>0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
lsb = H5Tget_inpad(complex_id);
} H5E_END_TRY;
if (lsb>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
cset = H5Tget_cset(complex_id);
} H5E_END_TRY;
if (cset>-1) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
strpad = H5Tget_strpad(complex_id);
} H5E_END_TRY;
if (strpad>-1) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
offset = H5Tget_offset(complex_id);
} H5E_END_TRY;
if (offset>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
order = H5Tget_order(complex_id);
} H5E_END_TRY;
if (order>-1) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
sign = H5Tget_sign(complex_id);
} H5E_END_TRY;
if (sign>-1) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
tag = H5Tget_tag(complex_id);
} H5E_END_TRY;
if (tag) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
super = H5Tget_super(complex_id);
} H5E_END_TRY;
if (super>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
if (H5Tclose (complex_id)<0) goto error;
PASSED();
return 0;
@ -2984,6 +3103,125 @@ test_conv_str_2(void)
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: test_conv_str_3
*
* Purpose: Tests some functions that are or aren't supposed to work
* for string type.
*
* Return: Success: 0
*
* Failure: number of errors
*
* Programmer: Raymond Lu
* Tuesday, April 4, 2006
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
test_conv_str_3(void)
{
char *buf=NULL;
hid_t type, super;
const size_t nelmts = NTESTELEM;
size_t i, j, nchars;
int ret_value = 1;
int size;
H5T_pad_t inpad;
H5T_cset_t cset;
H5T_sign_t sign;
char* tag;
herr_t ret;
TESTING("some type functions for string");
/*
* Initialize types and buffer.
*/
type = mkstr(8, H5T_STR_NULLPAD);
buf = (char*)HDcalloc(nelmts, 8);
for (i=0; i<nelmts; i++) {
nchars = HDrand() % 8;
for (j=0; j<nchars; j++)
buf[i*8+j] = 'a' + HDrand()%26;
while (j<nchars)
buf[i*8+j++] = '\0';
}
if ((size=H5Tget_precision(type))==0) goto error;
if ((size=H5Tget_size(type))==0) goto error;
if (H5Tset_pad(type, H5T_PAD_ZERO, H5T_PAD_ONE)<0) goto error;
if ((cset=H5Tget_cset(type))<0) goto error;
if (H5Tget_strpad(type)<0) goto error;
if (H5Tset_offset(type, 0)<0) goto error;
if (H5Tget_order(type)<0) goto error;
H5E_BEGIN_TRY {
ret=H5Tset_precision(type, nelmts);
} H5E_END_TRY;
if (ret>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
size=H5Tget_ebias(type);
} H5E_END_TRY;
if (size>0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
inpad=H5Tget_inpad(type);
} H5E_END_TRY;
if (inpad>-1) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
sign=H5Tget_sign(type);
} H5E_END_TRY;
if (sign>-1) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
tag = H5Tget_tag(type);
} H5E_END_TRY;
if (tag) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
super = H5Tget_super(type);
} H5E_END_TRY;
if (super>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
PASSED();
ret_value = 0;
error:
if (buf) HDfree(buf);
reset_hdf5();
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: test_conv_enum_1
@ -3237,6 +3475,136 @@ test_conv_bitfield(void)
return 1;
}
/*-------------------------------------------------------------------------
* Function: test_bitfield_funcs
*
* Purpose: Test some data type functions that are and aren't supposed
* work for bitfield type.
*
* Return: Success: 0
*
* Failure: number of errors
*
* Programmer: Raymond Lu
* Wednesday, April 5, 2006
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
test_bitfield_funcs(void)
{
hid_t type=-1, super=-1;
int size;
char* tag;
H5T_pad_t inpad;
H5T_cset_t cset;
H5T_str_t strpad;
herr_t ret;
TESTING("some type functions for bitfield");
/*
* First create a bitfield type.
*/
if((type = H5Tcopy(H5T_STD_B32LE))<0) goto error;
/*
* Offset a 12-byte value in the middle of a 16 and 32 byte
* field. Pad unused bits with ones.
* ____ ____ __10 1010 1010 10__ ____ ____
*/
if(H5Tset_precision(type, 12)<0) goto error;
if(H5Tset_offset(type, 10)<0) goto error;
if(H5Tset_pad(type, H5T_PAD_ONE, H5T_PAD_ONE)) goto error;
if((size=H5Tget_size(type))==0) goto error;
if(H5Tset_order(type, H5T_ORDER_BE)<0) goto error;
H5E_BEGIN_TRY {
size=H5Tget_ebias(type);
} H5E_END_TRY;
if (size>0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
inpad=H5Tget_inpad(type);
} H5E_END_TRY;
if (inpad>-1) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
cset=H5Tget_cset(type);
} H5E_END_TRY;
if (cset>-1) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
strpad=H5Tget_strpad(type);
} H5E_END_TRY;
if (strpad>-1) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
ret=H5Tset_sign(type, H5T_SGN_2);
} H5E_END_TRY;
if(ret>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
tag = H5Tget_tag(type);
} H5E_END_TRY;
if (tag) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
super = H5Tget_super(type);
} H5E_END_TRY;
if (super>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
super = H5Tget_native_type(type, H5T_DIR_ASCEND);
} H5E_END_TRY;
if (super>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5Tclose(type);
PASSED();
reset_hdf5();
return 0;
error:
H5Tclose(type);
reset_hdf5();
return 1;
}
/*-------------------------------------------------------------------------
* Function: convert_opaque
@ -3294,6 +3662,8 @@ test_opaque(void)
num_errors += opaque_check(1);
/* Test named opaque types with very long tag */
num_errors += opaque_long();
/* Test some type functions with opaque type */
num_errors += opaque_funcs();
if(num_errors)
goto error;
@ -3302,7 +3672,6 @@ test_opaque(void)
return 0;
error:
H5_FAILED();
return num_errors;
}
@ -3437,6 +3806,130 @@ opaque_long(void)
return 1;
}
/*-------------------------------------------------------------------------
* Function: opaque_funcs
*
* Purpose: Test some type functions that are and aren't supposed to
* work with opaque type.
*
* Return: Success: 0
*
* Failure: number of errors
*
* Programmer: Raymond Lu
* Wednesday, April 5, 2006
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
opaque_funcs(void)
{
hid_t type = -1, super=-1;
int size;
H5T_pad_t inpad;
H5T_cset_t cset;
H5T_str_t strpad;
H5T_sign_t sign;
herr_t ret;
/* Build opaque type */
if ((type=H5Tcreate(H5T_OPAQUE, 4))<0) TEST_ERROR
if (H5Tset_tag(type, "opaque source type")<0) TEST_ERROR
if ((size=H5Tget_size(type))==0) goto error;
H5E_BEGIN_TRY {
ret=H5Tset_precision(type, 32);
} H5E_END_TRY;
if (ret>=0) {
printf("Operation not allowed for this type.\n");
TEST_ERROR
} /* end if */
H5E_BEGIN_TRY {
ret=H5Tset_pad(type, H5T_PAD_ZERO, H5T_PAD_ONE);
} H5E_END_TRY;
if (ret>=0) {
printf("Operation not allowed for this type.\n");
TEST_ERROR
} /* end if */
H5E_BEGIN_TRY {
size=H5Tget_ebias(type);
} H5E_END_TRY;
if (size>0) {
printf("Operation not allowed for this type.\n");
TEST_ERROR
} /* end if */
H5E_BEGIN_TRY {
inpad=H5Tget_inpad(type);
} H5E_END_TRY;
if (inpad>-1) {
printf("Operation not allowed for this type.\n");
TEST_ERROR
} /* end if */
H5E_BEGIN_TRY {
cset=H5Tget_cset(type);
} H5E_END_TRY;
if (cset>-1) {
printf("Operation not allowed for this type.\n");
TEST_ERROR
} /* end if */
H5E_BEGIN_TRY {
strpad=H5Tget_strpad(type);
} H5E_END_TRY;
if (strpad>-1) {
printf("Operation not allowed for this type.\n");
TEST_ERROR
} /* end if */
H5E_BEGIN_TRY {
ret=H5Tset_offset(type, 16);
} H5E_END_TRY;
if (ret>=0) {
printf("Operation not allowed for this type.\n");
TEST_ERROR
} /* end if */
H5E_BEGIN_TRY {
ret=H5Tset_order(type, H5T_ORDER_BE);
} H5E_END_TRY;
if (ret>=0) {
printf("Operation not allowed for this type.\n");
TEST_ERROR
} /* end if */
H5E_BEGIN_TRY {
sign = H5Tget_sign(type);
} H5E_END_TRY;
if (sign>-1) {
printf("Operation not allowed for this type.\n");
TEST_ERROR
} /* end if */
H5E_BEGIN_TRY {
super = H5Tget_super(type);
} H5E_END_TRY;
if (super>=0) {
printf("Operation not allowed for this type.\n");
TEST_ERROR
} /* end if */
/* Close datatype */
if(H5Tclose(type) < 0) TEST_ERROR
return 0;
error:
if (type>0) H5Tclose(type);
return 1;
}
/*-------------------------------------------------------------------------
* Function: test_encode
@ -4053,6 +4546,7 @@ main(void)
nerrors += test_conv_str_1();
nerrors += test_conv_str_2();
nerrors += test_conv_str_3();
nerrors += test_compound_2();
nerrors += test_compound_3();
nerrors += test_compound_4();
@ -4067,6 +4561,7 @@ main(void)
nerrors += test_conv_enum_1();
nerrors += test_conv_enum_2();
nerrors += test_conv_bitfield();
nerrors += test_bitfield_funcs();
nerrors += test_opaque();
if (nerrors) {
@ -4077,4 +4572,3 @@ main(void)
printf("All data type tests passed.\n");
return 0;
}

View File

@ -424,6 +424,118 @@ test_value_dsnt_exist(void)
return 1;
}
/*-------------------------------------------------------------------------
* Function: test_funcs
*
* Purpose: Create an enumeration data type and test some functions
* that are or aren't supposed to work with it.
*
* Return: Success: 0
*
* Failure: number of errors
*
* Programmer: Raymond Lu
* Tuesday, April 4, 2006
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static int
test_funcs(void)
{
hid_t type=-1, cwg=-1;
c_e1 val;
signed char val8;
int size;
H5T_pad_t inpad;
H5T_cset_t cset;
herr_t ret;
TESTING("some functions with enumeration types");
/* A native integer */
if ((type = H5Tcreate(H5T_ENUM, sizeof(c_e1)))<0) goto error;
if (H5Tenum_insert(type, "RED", CPTR(val, E1_RED ))<0) goto error;
if (H5Tenum_insert(type, "GREEN", CPTR(val, E1_GREEN))<0) goto error;
if (H5Tenum_insert(type, "BLUE", CPTR(val, E1_BLUE ))<0) goto error;
if (H5Tenum_insert(type, "WHITE", CPTR(val, E1_WHITE))<0) goto error;
if (H5Tenum_insert(type, "BLACK", CPTR(val, E1_BLACK))<0) goto error;
if ((size=H5Tget_precision(type))==0) goto error;
if ((size=H5Tget_size(type))==0) goto error;
if ((size=H5Tget_offset(type))<0) goto error;
if (H5Tget_sign(type)<0) goto error;
if (H5Tget_super(type)<0) goto error;
H5E_BEGIN_TRY {
ret=H5Tset_pad(type, H5T_PAD_ZERO, H5T_PAD_ONE);
} H5E_END_TRY;
if (ret>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
size=H5Tget_ebias(type);
} H5E_END_TRY;
if (size>0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
inpad=H5Tget_inpad(type);
} H5E_END_TRY;
if (inpad>-1) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
cset=H5Tget_cset(type);
} H5E_END_TRY;
if (cset>-1) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
size = 16;
H5E_BEGIN_TRY {
ret=H5Tset_offset(type, (size_t)size);
} H5E_END_TRY;
if (ret>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
H5E_BEGIN_TRY {
ret=H5Tset_order(type, H5T_ORDER_BE);
} H5E_END_TRY;
if (ret>=0) {
H5_FAILED();
printf("Operation not allowed for this type.\n");
goto error;
} /* end if */
if (H5Tclose(type)<0) goto error;
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
H5Tclose(type);
} H5E_END_TRY;
return 1;
}
/*-------------------------------------------------------------------------
* Function: main
@ -461,8 +573,9 @@ main(void)
nerrors += test_tr1(file);
nerrors += test_tr2(file);
nerrors += test_value_dsnt_exist();
nerrors += test_funcs();
H5Fclose(file);
H5Fclose(file);
if (nerrors) goto error;
puts("All enum tests passed.");

View File

@ -175,6 +175,65 @@ test_array_atomic_1d(void)
} /* end test_array_atomic_1d() */
/****************************************************************
**
** test_array_funcs(): Test some type functions that are and
** aren't supposed to work with array type.
**
****************************************************************/
static void
test_array_funcs(void)
{
hid_t type; /* Datatype ID */
hsize_t tdims1[] = {ARRAY1_DIM1};
int size;
H5T_pad_t inpad;
H5T_norm_t norm;
H5T_sign_t sign;
H5T_cset_t cset;
H5T_str_t strpad;
herr_t ret; /* Generic return value */
/* Create a datatype to refer to */
type = H5Tarray_create (H5T_IEEE_F32BE,ARRAY1_RANK,tdims1,NULL);
CHECK(type, FAIL, "H5Tarray_create");
size=H5Tget_precision(type);
CHECK(size, FAIL, "H5Tget_precision");
size=H5Tget_size(type);
CHECK(size, FAIL, "H5Tget_size");
size=H5Tget_ebias(type);
CHECK(size, FAIL, "H5Tget_ebias");
ret=H5Tset_pad(type, H5T_PAD_ZERO, H5T_PAD_ONE);
CHECK(ret, FAIL, "H5Tset_pad");
inpad=H5Tget_inpad(type);
CHECK(inpad, FAIL, "H5Tget_inpad");
norm=H5Tget_norm(type);
CHECK(norm, FAIL, "H5Tget_norm");
ret=H5Tset_offset(type, 16);
CHECK(ret, FAIL, "H5Tset_offset");
H5E_BEGIN_TRY {
cset=H5Tget_cset(type);
} H5E_END_TRY;
VERIFY(cset, FAIL, "H5Tget_cset");
H5E_BEGIN_TRY {
strpad=H5Tget_strpad(type);
} H5E_END_TRY;
VERIFY(strpad, FAIL, "H5Tget_strpad");
/* Close datatype */
ret = H5Tclose(type);
CHECK(ret, FAIL, "H5Tclose");
} /* end test_array_funcs */
/****************************************************************
**
** test_array_atomic_3d(): Test basic array datatype code.
@ -2068,6 +2127,7 @@ test_array(void)
test_array_compound_array(); /* Test 1-D array of compound datatypes (with array fields) */
test_array_vlen_atomic(); /* Test 1-D array of atomic VL datatypes */
test_array_vlen_array(); /* Test 1-D array of 1-D array VL datatypes */
test_array_funcs(); /* Test type functions with array types */
test_array_bkg(); /* Read compound datatype with array fields and background fields read */

View File

@ -162,6 +162,66 @@ test_vltypes_dataset_create(void)
CHECK(ret, FAIL, "H5Fclose");
}
/****************************************************************
**
** test_vltypes_funcs(): Test some type functions that are and
** aren't supposed to work with VL type.
**
****************************************************************/
static void
test_vltypes_funcs(void)
{
hid_t type; /* Datatype ID */
int size;
H5T_pad_t inpad;
H5T_norm_t norm;
H5T_cset_t cset;
H5T_str_t strpad;
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing some type functions for VL\n"));
/* Create a datatype to refer to */
type = H5Tvlen_create (H5T_IEEE_F32BE);
CHECK(type, FAIL, "H5Tvlen_create");
size=H5Tget_precision(type);
CHECK(size, FAIL, "H5Tget_precision");
size=H5Tget_size(type);
CHECK(size, FAIL, "H5Tget_size");
size=H5Tget_ebias(type);
CHECK(size, FAIL, "H5Tget_ebias");
ret=H5Tset_pad(type, H5T_PAD_ZERO, H5T_PAD_ONE);
CHECK(ret, FAIL, "H5Tset_pad");
inpad=H5Tget_inpad(type);
CHECK(inpad, FAIL, "H5Tget_inpad");
norm=H5Tget_norm(type);
CHECK(norm, FAIL, "H5Tget_norm");
ret=H5Tset_offset(type, 16);
CHECK(ret, FAIL, "H5Tset_offset");
H5E_BEGIN_TRY {
cset=H5Tget_cset(type);
} H5E_END_TRY;
VERIFY(cset, FAIL, "H5Tget_cset");
H5E_BEGIN_TRY {
strpad=H5Tget_strpad(type);
} H5E_END_TRY;
VERIFY(strpad, FAIL, "H5Tget_strpad");
/* Close datatype */
ret = H5Tclose(type);
CHECK(ret, FAIL, "H5Tclose");
}
/****************************************************************
**
** test_vltypes_vlen_atomic(): Test basic VL datatype code.
@ -2042,6 +2102,7 @@ test_vltypes(void)
/* These next tests use the same file */
test_vltypes_dataset_create(); /* Check dataset of VL when fill value
* won't be rewritten to it.*/
test_vltypes_funcs(); /* Test functions with VL types */
test_vltypes_vlen_atomic(); /* Test VL atomic datatypes */
rewrite_vltypes_vlen_atomic(); /* Check VL memory leak */
test_vltypes_vlen_compound(); /* Test VL compound datatypes */