diff options
author | Raymond Lu <songyulu@hdfgroup.org> | 2008-06-30 19:00:44 (GMT) |
---|---|---|
committer | Raymond Lu <songyulu@hdfgroup.org> | 2008-06-30 19:00:44 (GMT) |
commit | 2b1ee377c33c1f6cedb4e3eeda9fcf4634acabb8 (patch) | |
tree | da802861f997f3a441f7c3706cdf96584a5e40f4 /test | |
parent | 372af0302f8acea869d8f02b7633176d3985a1ec (diff) | |
download | hdf5-2b1ee377c33c1f6cedb4e3eeda9fcf4634acabb8.zip hdf5-2b1ee377c33c1f6cedb4e3eeda9fcf4634acabb8.tar.gz hdf5-2b1ee377c33c1f6cedb4e3eeda9fcf4634acabb8.tar.bz2 |
[svn-r15297] Bug fix for H5Tpack. The problem was that H5Tpack didn't act correctly with nested
compound datatype. The size of compound type's member type wasn't updated. It's
fixed in this commit.
Tested on smirom. The same change was tested on three systems for v1.9.
Diffstat (limited to 'test')
-rw-r--r-- | test/dtypes.c | 108 |
1 files changed, 104 insertions, 4 deletions
diff --git a/test/dtypes.c b/test/dtypes.c index 3dc5338..8a8c108 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -30,7 +30,7 @@ /* Number of elements in each test */ #define NTESTELEM 100000 -/* For test_compound_10 */ +/* For test_compound_8 and test_compound_10 */ #define ARRAY_DIM 4 /* Epsilon for floating-point comparisons */ @@ -1354,7 +1354,10 @@ test_compound_7(void) * Wednesday, January 7, 1998 * * Modifications: - * + * Raymond Lu + * 27 June 2008 + * Added verification of compound type size for H5Tpack and + * test for array of nested compound type. *------------------------------------------------------------------------- */ static int @@ -1370,11 +1373,16 @@ test_compound_8(void) s1 d; } s2; - hid_t tid1, tid2, tid3; + hid_t tid1, tid1_copy, tid2, tid2_copy, tid3, arr_tid; + size_t tsize; + hsize_t dims[1] = {ARRAY_DIM}; herr_t ret; TESTING("packing compound datatypes"); + /*------------------------------------------------------------ + * Test H5Tpack for compound type + */ /* Create first compound datatype */ if((tid1 = H5Tcreate( H5T_COMPOUND, sizeof(struct s1))) < 0) { H5_FAILED(); AT(); @@ -1394,6 +1402,13 @@ test_compound_8(void) goto error; } /* end if */ + /* Make a copy of the type for later use */ + if((tid1_copy = H5Tcopy(tid1)) < 0) { + H5_FAILED(); AT(); + printf("Can't copy type #1\n"); + goto error; + } /* end if */ + /* Test H5Tpack for the first compound type */ if(H5Tpack(tid1) < 0) { H5_FAILED(); AT(); @@ -1414,7 +1429,22 @@ test_compound_8(void) goto error; } /* end if */ + /* Verify the size of packed compound type */ + if((tsize = H5Tget_size(tid1)) == 0) { + H5_FAILED(); AT(); + printf("Can't get size of the compound datatype\n"); + goto error; + } /* end if */ + + if(tsize != (sizeof(char) + sizeof(int))) { + H5_FAILED(); AT(); + printf("The size of the packed compound datatype is incorrect\n"); + goto error; + } /* end if */ + /*------------------------------------------------------------ + * Test H5Tpack for nested compound type + */ /* Create second compound datatype */ if((tid2 = H5Tcreate( H5T_COMPOUND, sizeof(struct s2))) < 0) { H5_FAILED(); AT(); @@ -1428,7 +1458,8 @@ test_compound_8(void) goto error; } /* end if */ - if(H5Tinsert(tid2,"d",HOFFSET(struct s2,d),tid1) < 0) { + /* Insert the member of unpacked compound type */ + if(H5Tinsert(tid2,"d",HOFFSET(struct s2,d),tid1_copy) < 0) { H5_FAILED(); AT(); printf("Can't insert field 'd'\n"); goto error; @@ -1441,6 +1472,13 @@ test_compound_8(void) goto error; } /* end if */ + /* Make a copy of the type for later */ + if((tid2_copy = H5Tcopy(tid2)) < 0) { + H5_FAILED(); AT(); + printf("Can't copy type #2\n"); + goto error; + } /* end if */ + /* Test H5Tpack for the second compound type */ if(H5Tpack(tid2) < 0) { H5_FAILED(); AT(); @@ -1478,6 +1516,68 @@ test_compound_8(void) goto error; } /* end if */ + /* Verify the size of packed compound type */ + if((tsize = H5Tget_size(tid2)) == 0) { + H5_FAILED(); AT(); + printf("Can't get size of the compound datatype\n"); + goto error; + } /* end if */ + + if(tsize != (sizeof(char) + sizeof(char) + sizeof(int))) { + H5_FAILED(); AT(); + printf("The size of the packed compound datatype is incorrect\n"); + goto error; + } /* end if */ + + /*------------------------------------------------------------ + * Test H5Tpack for array type of nested compound type + */ + /* Create an array type of compound type */ + if((arr_tid = H5Tarray_create(tid2_copy, 1, dims)) < 0) { + H5_FAILED(); AT(); + printf("Can't create an array datatype\n"); + goto error; + } /* end if */ + + /* Test H5Tpack for the array type */ + if(H5Tpack(arr_tid) < 0) { + H5_FAILED(); AT(); + printf("Can't pack the array datatype\n"); + goto error; + } /* end if */ + + /* Verify the size of packed compound type */ + if((tsize = H5Tget_size(arr_tid)) == 0) { + H5_FAILED(); AT(); + printf("Can't get size of the array datatype\n"); + goto error; + } /* end if */ + + if(tsize != ARRAY_DIM * (sizeof(char) + sizeof(char) + sizeof(int))) { + H5_FAILED(); AT(); + printf("The size of the packed array datatype is incorrect\n"); + goto error; + } /* end if */ + + + if(H5Tclose(tid1_copy) < 0) { + H5_FAILED(); AT(); + printf("Can't close the compound datatype\n"); + goto error; + } /* end if */ + + if(H5Tclose(tid2_copy) < 0) { + H5_FAILED(); AT(); + printf("Can't close the compound datatype\n"); + goto error; + } /* end if */ + + if(H5Tclose(arr_tid) < 0) { + H5_FAILED(); AT(); + printf("Can't close the array datatype\n"); + goto error; + } /* end if */ + /* Can't release resources - they are locked */ PASSED(); |