diff options
author | Raymond Lu <songyulu@hdfgroup.org> | 2004-07-14 21:45:23 (GMT) |
---|---|---|
committer | Raymond Lu <songyulu@hdfgroup.org> | 2004-07-14 21:45:23 (GMT) |
commit | fbc2aaadafb3dfb23842ee4c89bad4bfdb6d3077 (patch) | |
tree | 6c92298234945fc1c59f9b46e0e399a5e26690bc /test/dtypes.c | |
parent | 9b2aafa18b550a34b39acd78d32e04af49c3cbbb (diff) | |
download | hdf5-fbc2aaadafb3dfb23842ee4c89bad4bfdb6d3077.zip hdf5-fbc2aaadafb3dfb23842ee4c89bad4bfdb6d3077.tar.gz hdf5-fbc2aaadafb3dfb23842ee4c89bad4bfdb6d3077.tar.bz2 |
[svn-r8879]
Purpose: New feature
Description: New API H5Tencode and H5Tdecode. Given object ID, H5Tencode encodes object information into a binary form. H5Tdecode decode an object information in a binary form, reconstructs the object and return a new object ID.
Solution: Use object header functions H5O_dtype_decode and H5O_dtype_encode to
facilitate them. The encoded binary is exactly like object header information.
This is the first step checkin. Will check in H5Sencode and H5Sdecode later.
Platforms tested: h5committed and fuss.
Misc. update: will update release.txt after 2nd step checkin.
Diffstat (limited to 'test/dtypes.c')
-rw-r--r-- | test/dtypes.c | 183 |
1 files changed, 166 insertions, 17 deletions
diff --git a/test/dtypes.c b/test/dtypes.c index fc85ad3..dcc14bd 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -65,6 +65,7 @@ const char *FILENAME[] = { "dtypes3", "dtypes4", "dtypes5", + "dtypes6", NULL }; @@ -1859,23 +1860,23 @@ test_compound_10(void) /*------------------------------------------------------------------------- - * Function: test_query + * Function: test_encode * - * Purpose: Tests query functions of compound and enumeration types. + * Purpose: Tests functions of encoding and decoding data type. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Raymond Lu - * Thursday, April 4, 2002 + * July 14, 2004 * * Modifications: * *------------------------------------------------------------------------- */ static int -test_query(void) +test_encode(void) { struct s1 { int a; @@ -1884,17 +1885,25 @@ test_query(void) double d; }; hid_t file=-1, tid1=-1, tid2=-1; + hid_t decoded_tid1, decoded_tid2; char filename[1024]; char compnd_type[]="Compound_type", enum_type[]="Enum_type"; short enum_val; + size_t cmpd_buf_size = 0; + size_t enum_buf_size = 0; + unsigned char *cmpd_buf, *enum_buf; - TESTING("query functions of compound and enumeration types"); + TESTING("functions of encoding and decoding data types"); /* Create File */ - h5_fixname(FILENAME[2], H5P_DEFAULT, filename, sizeof filename); + h5_fixname(FILENAME[5], H5P_DEFAULT, filename, sizeof filename); if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) goto error; + /*----------------------------------------------------------------------- + * Create compound and enumerate data types + *----------------------------------------------------------------------- + */ /* Create a compound datatype */ if((tid1=H5Tcreate(H5T_COMPOUND, sizeof(struct s1)))<0) { H5_FAILED(); @@ -1953,31 +1962,86 @@ test_query(void) printf("Can't insert field into enumeration type\n"); goto error; } /* end if */ + + /*----------------------------------------------------------------------- + * Test encoding and decoding compound and enumerate data types + *----------------------------------------------------------------------- + */ + /* Encode compound type in a buffer */ + if(H5Tencode(tid1, NULL, &cmpd_buf_size)<0) { + H5_FAILED(); + printf("Can't encode compound type\n"); + goto error; + } /* end if */ + + if(cmpd_buf_size>0) + cmpd_buf = (unsigned char*)calloc(1, cmpd_buf_size); + + if(H5Tencode(tid1, cmpd_buf, &cmpd_buf_size)<0) { + H5_FAILED(); + printf("Can't encode compound type\n"); + goto error; + } /* end if */ + + /* Decode from the compound buffer and return an object handle */ + if((decoded_tid1=H5Tdecode(cmpd_buf))<0) { + H5_FAILED(); + printf("Can't decode compound type\n"); + goto error; + } /* end if */ /* Query member number and member index by name, for compound type. */ - if(H5Tget_nmembers(tid1)!=4) { + if(H5Tget_nmembers(decoded_tid1)!=4) { H5_FAILED(); printf("Can't get member number\n"); goto error; } /* end if */ - if(H5Tget_member_index(tid1, "c")!=2) { + if(H5Tget_member_index(decoded_tid1, "c")!=2) { H5_FAILED(); printf("Can't get correct index number\n"); goto error; } /* end if */ + + /* Encode enumerate type in a buffer */ + if(H5Tencode(tid2, NULL, &enum_buf_size)<0) { + H5_FAILED(); + printf("Can't encode enumerate type\n"); + goto error; + } /* end if */ + + if(enum_buf_size>0) + enum_buf = (unsigned char*)calloc(1, enum_buf_size); + + if(H5Tencode(tid2, enum_buf, &enum_buf_size)<0) { + H5_FAILED(); + printf("Can't encode enumerate type\n"); + goto error; + } /* end if */ + + /* Decode from the enumerate buffer and return an object handle */ + if((decoded_tid2=H5Tdecode(enum_buf))<0) { + H5_FAILED(); + printf("Can't decode enumerate type\n"); + goto error; + } /* end if */ + /* Query member number and member index by name, for enumeration type. */ - if(H5Tget_nmembers(tid2)!=5) { + if(H5Tget_nmembers(decoded_tid2)!=5) { H5_FAILED(); printf("Can't get member number\n"); goto error; } /* end if */ - if(H5Tget_member_index(tid2, "ORANGE")!=3) { + if(H5Tget_member_index(decoded_tid2, "ORANGE")!=3) { H5_FAILED(); printf("Can't get correct index number\n"); goto error; } /* end if */ + /*----------------------------------------------------------------------- + * Commit and reopen the compound and enumerate data types + *----------------------------------------------------------------------- + */ /* Commit compound datatype and close it */ if(H5Tcommit(file, compnd_type, tid1)<0) { H5_FAILED(); @@ -1989,6 +2053,13 @@ test_query(void) printf("Can't close datatype\n"); goto error; } /* end if */ + if(H5Tclose(decoded_tid1)<0) { + H5_FAILED(); + printf("Can't close datatype\n"); + goto error; + } /* end if */ + free(cmpd_buf); + cmpd_buf_size = 0; /* Commit enumeration datatype and close it */ if(H5Tcommit(file, enum_type, tid2)<0) { @@ -2001,6 +2072,13 @@ test_query(void) printf("Can't close datatype\n"); goto error; } /* end if */ + if(H5Tclose(decoded_tid2)<0) { + H5_FAILED(); + printf("Can't close datatype\n"); + goto error; + } /* end if */ + free(enum_buf); + enum_buf_size = 0; /* Open the dataytpe for query */ if((tid1=H5Topen(file, compnd_type))<0) { @@ -2014,30 +2092,85 @@ test_query(void) goto error; } /* end if */ - /* Query member number and member index by name, for compound type */ - if(H5Tget_nmembers(tid1)!=4) { + + /* Encode compound type in a buffer */ + if(H5Tencode(tid1, NULL, &cmpd_buf_size)<0) { + H5_FAILED(); + printf("Can't encode compound type\n"); + goto error; + } /* end if */ + + if(cmpd_buf_size>0) + cmpd_buf = (unsigned char*)calloc(1, cmpd_buf_size); + + if(H5Tencode(tid1, cmpd_buf, &cmpd_buf_size)<0) { + H5_FAILED(); + printf("Can't encode compound type\n"); + goto error; + } /* end if */ + + /* Decode from the compound buffer and return an object handle */ + if((decoded_tid1=H5Tdecode(cmpd_buf))<0) { + H5_FAILED(); + printf("Can't decode compound type\n"); + goto error; + } /* end if */ + + /* Query member number and member index by name, for compound type. */ + if(H5Tget_nmembers(decoded_tid1)!=4) { H5_FAILED(); printf("Can't get member number\n"); goto error; } /* end if */ - if(H5Tget_member_index(tid1, "c")!=2) { + if(H5Tget_member_index(decoded_tid1, "c")!=2) { H5_FAILED(); printf("Can't get correct index number\n"); goto error; } /* end if */ - /* Query member number and member index by name, for enumeration type */ - if(H5Tget_nmembers(tid2)!=5) { + /*----------------------------------------------------------------------- + * Test encoding and decoding compound and enumerate data types + *----------------------------------------------------------------------- + */ + /* Encode enumerate type in a buffer */ + if(H5Tencode(tid2, NULL, &enum_buf_size)<0) { + H5_FAILED(); + printf("Can't encode enumerate type\n"); + goto error; + } /* end if */ + + if(enum_buf_size>0) + enum_buf = (unsigned char*)calloc(1, enum_buf_size); + + if(H5Tencode(tid2, enum_buf, &enum_buf_size)<0) { + H5_FAILED(); + printf("Can't encode enumerate type\n"); + goto error; + } /* end if */ + + /* Decode from the enumerate buffer and return an object handle */ + if((decoded_tid2=H5Tdecode(enum_buf))<0) { + H5_FAILED(); + printf("Can't decode enumerate type\n"); + goto error; + } /* end if */ + + /* Query member number and member index by name, for enumeration type. */ + if(H5Tget_nmembers(decoded_tid2)!=5) { H5_FAILED(); printf("Can't get member number\n"); goto error; } /* end if */ - if(H5Tget_member_index(tid2, "ORANGE")!=3) { + if(H5Tget_member_index(decoded_tid2, "ORANGE")!=3) { H5_FAILED(); printf("Can't get correct index number\n"); goto error; } /* end if */ + /*----------------------------------------------------------------------- + * Close and release + *----------------------------------------------------------------------- + */ /* Close data type and file */ if(H5Tclose(tid1)<0) { H5_FAILED(); @@ -2050,12 +2183,26 @@ test_query(void) goto error; } /* end if */ + if(H5Tclose(decoded_tid1)<0) { + H5_FAILED(); + printf("Can't close datatype\n"); + goto error; + } /* end if */ + if(H5Tclose(decoded_tid2)<0) { + H5_FAILED(); + printf("Can't close datatype\n"); + goto error; + } /* end if */ + if(H5Fclose(file)<0) { H5_FAILED(); printf("Can't close file\n"); goto error; } /* end if */ + free(cmpd_buf); + free(enum_buf); + PASSED(); return 0; @@ -2063,6 +2210,8 @@ test_query(void) H5E_BEGIN_TRY { H5Tclose (tid1); H5Tclose (tid2); + H5Tclose (decoded_tid1); + H5Tclose (decoded_tid2); H5Fclose (file); } H5E_END_TRY; return 1; @@ -6182,9 +6331,9 @@ main(void) nerrors += test_copy(); nerrors += test_detect(); nerrors += test_compound_1(); - nerrors += test_query(); nerrors += test_transient (fapl); nerrors += test_named (fapl); + nerrors += test_encode(); h5_cleanup(FILENAME, fapl); /*must happen before first reset*/ reset_hdf5(); |