[svn-r17179] I added a test of H5Tencode/decode for variable-length string type. This test is for

the bug fix of #1585 in last round of checkin.

Tested on jam.  I used h5committest for the same change in the trunk.
This commit is contained in:
Raymond Lu
2009-07-13 14:08:00 -05:00
parent 75800cf6b5
commit 71d75b40ee

View File

@@ -4904,8 +4904,9 @@ opaque_funcs(void)
* Programmer: Raymond Lu
* July 14, 2004
*
* Modifications:
*
* Modifications: Raymond Lu
* July 13, 2009
* Added the test for VL string types.
*-------------------------------------------------------------------------
*/
static int
@@ -4917,14 +4918,16 @@ test_encode(void)
long c;
double d;
};
hid_t file=-1, tid1=-1, tid2=-1;
hid_t decoded_tid1=-1, decoded_tid2=-1;
hid_t file=-1, tid1=-1, tid2=-1, tid3=-1;
hid_t decoded_tid1=-1, decoded_tid2=-1, decoded_tid3=-1;
char filename[1024];
char compnd_type[]="Compound_type", enum_type[]="Enum_type";
char vlstr_type[]="VLstring_type";
short enum_val;
size_t cmpd_buf_size = 0;
size_t enum_buf_size = 0;
unsigned char *cmpd_buf=NULL, *enum_buf=NULL;
size_t vlstr_buf_size = 0;
unsigned char *cmpd_buf=NULL, *enum_buf=NULL, *vlstr_buf=NULL;
herr_t ret;
TESTING("functions of encoding and decoding datatypes");
@@ -4935,7 +4938,7 @@ test_encode(void)
goto error;
/*-----------------------------------------------------------------------
* Create compound and enumerate datatypes
* Create compound, enumerate, and VL string datatypes
*-----------------------------------------------------------------------
*/
/* Create a compound datatype */
@@ -4997,8 +5000,20 @@ test_encode(void)
goto error;
} /* end if */
/* Create a variable-length string type */
if((tid3 = H5Tcopy(H5T_C_S1)) < 0) {
H5_FAILED();
printf("Can't copy a string type\n");
goto error;
} /* end if */
if(H5Tset_size(tid3, H5T_VARIABLE) < 0) {
H5_FAILED();
printf("Can't the string type to be variable-length\n");
goto error;
} /* end if */
/*-----------------------------------------------------------------------
* Test encoding and decoding compound and enumerate datatypes
* Test encoding and decoding compound, enumerate, and VL string datatypes
*-----------------------------------------------------------------------
*/
/* Encode compound type in a buffer */
@@ -5093,8 +5108,44 @@ test_encode(void)
goto error;
} /* end if */
/* Encode VL string type in a buffer */
if(H5Tencode(tid3, NULL, &vlstr_buf_size) < 0) {
H5_FAILED();
printf("Can't encode VL string type\n");
goto error;
} /* end if */
if(vlstr_buf_size>0)
vlstr_buf = (unsigned char*)calloc(1, vlstr_buf_size);
if(H5Tencode(tid3, vlstr_buf, &vlstr_buf_size) < 0) {
H5_FAILED();
printf("Can't encode VL string type\n");
goto error;
} /* end if */
/* Decode from the VL string buffer and return an object handle */
if((decoded_tid3=H5Tdecode(vlstr_buf)) < 0) {
H5_FAILED();
printf("Can't decode VL string type\n");
goto error;
} /* end if */
/* Verify that the datatype was copied exactly */
if(H5Tequal(decoded_tid3, tid3)<=0) {
H5_FAILED();
printf("Datatype wasn't encoded & decoded identically\n");
goto error;
} /* end if */
if(!H5Tis_variable_str(decoded_tid3)) {
H5_FAILED();
printf("Datatype wasn't encoded & decoded identically\n");
goto error;
} /* end if */
/*-----------------------------------------------------------------------
* Commit and reopen the compound and enumerate datatypes
* Commit and reopen the compound, enumerate, VL string datatypes
*-----------------------------------------------------------------------
*/
/* Commit compound datatype and close it */
@@ -5135,13 +5186,37 @@ test_encode(void)
free(enum_buf);
enum_buf_size = 0;
/* Commit enumeration datatype and close it */
if(H5Tcommit2(file, vlstr_type, tid3, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
H5_FAILED();
printf("Can't commit vl string datatype\n");
goto error;
} /* end if */
if(H5Tclose(tid3) < 0) {
H5_FAILED();
printf("Can't close datatype\n");
goto error;
} /* end if */
if(H5Tclose(decoded_tid3) < 0) {
H5_FAILED();
printf("Can't close datatype\n");
goto error;
} /* end if */
free(vlstr_buf);
vlstr_buf_size = 0;
/* Open the dataytpe for query */
if((tid1 = H5Topen2(file, compnd_type, H5P_DEFAULT)) < 0)
FAIL_STACK_ERROR
if((tid2 = H5Topen2(file, enum_type, H5P_DEFAULT)) < 0)
FAIL_STACK_ERROR
if((tid3 = H5Topen2(file, vlstr_type, H5P_DEFAULT)) < 0)
FAIL_STACK_ERROR
/*-----------------------------------------------------------------------
* Test encoding and decoding compound, enumerate, and vl string datatypes
*-----------------------------------------------------------------------
*/
/* Encode compound type in a buffer */
if(H5Tencode(tid1, NULL, &cmpd_buf_size) < 0) {
H5_FAILED();
@@ -5181,10 +5256,6 @@ test_encode(void)
goto error;
} /* end if */
/*-----------------------------------------------------------------------
* Test encoding and decoding compound and enumerate datatypes
*-----------------------------------------------------------------------
*/
/* Encode enumerate type in a buffer */
if(H5Tencode(tid2, NULL, &enum_buf_size) < 0) {
H5_FAILED();
@@ -5227,6 +5298,41 @@ test_encode(void)
goto error;
} /* end if */
/* Encode VL string type in a buffer */
if(H5Tencode(tid3, NULL, &vlstr_buf_size) < 0) {
H5_FAILED();
printf("Can't encode VL string type\n");
goto error;
} /* end if */
if(vlstr_buf_size>0)
vlstr_buf = (unsigned char*)calloc(1, vlstr_buf_size);
if(H5Tencode(tid3, vlstr_buf, &vlstr_buf_size) < 0) {
H5_FAILED();
printf("Can't encode VL string type\n");
goto error;
} /* end if */
/* Decode from the VL string buffer and return an object handle */
if((decoded_tid3=H5Tdecode(vlstr_buf)) < 0) {
H5_FAILED();
printf("Can't decode VL string type\n");
goto error;
} /* end if */
/* Verify that the datatype was copied exactly */
if(H5Tequal(decoded_tid3, tid3)<=0) {
H5_FAILED();
printf("Datatype wasn't encoded & decoded identically\n");
goto error;
} /* end if */
if(!H5Tis_variable_str(decoded_tid3)) {
H5_FAILED();
printf("Datatype wasn't encoded & decoded identically\n");
goto error;
} /* end if */
/*-----------------------------------------------------------------------
* Close and release
*-----------------------------------------------------------------------
@@ -5242,6 +5348,11 @@ test_encode(void)
printf("Can't close datatype\n");
goto error;
} /* end if */
if(H5Tclose(tid3) < 0) {
H5_FAILED();
printf("Can't close datatype\n");
goto error;
} /* end if */
if(H5Tclose(decoded_tid1) < 0) {
H5_FAILED();
@@ -5253,6 +5364,11 @@ test_encode(void)
printf("Can't close datatype\n");
goto error;
} /* end if */
if(H5Tclose(decoded_tid3) < 0) {
H5_FAILED();
printf("Can't close datatype\n");
goto error;
} /* end if */
if(H5Fclose(file) < 0) {
H5_FAILED();
@@ -5270,8 +5386,10 @@ test_encode(void)
H5E_BEGIN_TRY {
H5Tclose (tid1);
H5Tclose (tid2);
H5Tclose (tid3);
H5Tclose (decoded_tid1);
H5Tclose (decoded_tid2);
H5Tclose (decoded_tid3);
H5Fclose (file);
} H5E_END_TRY;
return 1;