diff options
author | Raymond Lu <songyulu@hdfgroup.org> | 2009-07-13 19:04:09 (GMT) |
---|---|---|
committer | Raymond Lu <songyulu@hdfgroup.org> | 2009-07-13 19:04:09 (GMT) |
commit | 2228b81fa28f583b2358a479242329e1ba969eda (patch) | |
tree | d928c08d148d0d646d0d9d21e1f2442f09af31b7 /test | |
parent | 8a56b4d081a9804f07878f1fe3578f5e2e1b7ef5 (diff) | |
download | hdf5-2228b81fa28f583b2358a479242329e1ba969eda.zip hdf5-2228b81fa28f583b2358a479242329e1ba969eda.tar.gz hdf5-2228b81fa28f583b2358a479242329e1ba969eda.tar.bz2 |
[svn-r17178] 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, smirom, linew.
Diffstat (limited to 'test')
-rw-r--r-- | test/dtypes.c | 144 |
1 files changed, 131 insertions, 13 deletions
diff --git a/test/dtypes.c b/test/dtypes.c index c83cdfd..9138b50 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -4903,8 +4903,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 @@ -4916,14 +4917,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"); @@ -4934,7 +4937,7 @@ test_encode(void) goto error; /*----------------------------------------------------------------------- - * Create compound and enumerate datatypes + * Create compound, enumerate, and VL string datatypes *----------------------------------------------------------------------- */ /* Create a compound datatype */ @@ -4996,8 +4999,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 */ @@ -5092,8 +5107,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 */ @@ -5134,13 +5185,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(); @@ -5180,10 +5255,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(); @@ -5226,6 +5297,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 *----------------------------------------------------------------------- @@ -5241,6 +5347,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(); @@ -5252,6 +5363,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(); @@ -5269,8 +5385,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; |