summaryrefslogtreecommitdiffstats
path: root/test/dtypes.c
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2009-01-14 15:30:51 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2009-01-14 15:30:51 (GMT)
commit6564dbcfaa09da479cc5e393693799e329fc1330 (patch)
tree820621ac55441e10978dca5aa155e170ccebc6b4 /test/dtypes.c
parenta365f0e6aabfa6a13b008e0263e6a2d6c86d5d7e (diff)
downloadhdf5-6564dbcfaa09da479cc5e393693799e329fc1330.zip
hdf5-6564dbcfaa09da479cc5e393693799e329fc1330.tar.gz
hdf5-6564dbcfaa09da479cc5e393693799e329fc1330.tar.bz2
[svn-r16308] Purpose: Fix problem with H5Tpack
Description: If a compound type was packed except for some extra space at the end, H5Tpack would not modify the type and the extra space would remain. Changed H5T_is_packed to fix this behaviour. Tested: jam, smirom (h5committest - linew down)
Diffstat (limited to 'test/dtypes.c')
-rw-r--r--test/dtypes.c126
1 files changed, 124 insertions, 2 deletions
diff --git a/test/dtypes.c b/test/dtypes.c
index f5bc930..3aad1a7 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -2958,8 +2958,6 @@ test_compound_16(void)
} cmpd_struct;
cmpd_struct wdata1 = {1254, 5471};
- cmpd_struct rdata;
- int wdata2[2] = {1, 2};
int obj_count;
hid_t file;
hid_t cmpd_m_tid, cmpd_f_tid, int_id;
@@ -3026,6 +3024,129 @@ error:
/*-------------------------------------------------------------------------
+ * Function: test_compound_17
+ *
+ * Purpose: Tests that compound types are packed correctly when they
+ * only have extra space at the end. The compounds are
+ * "hidden" inside arrays to make sure that they are still
+ * detected correctly.
+ *
+ * Return: Success: 0
+ *
+ * Failure: number of errors
+ *
+ * Programmer: Neil Fortner
+ * Tuesday, January 13, 2009
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_compound_17(void)
+{
+ hid_t file;
+ hid_t cmpd_int, arr_int, cmpd_ext, arr_ext, tmp_dt;
+ hsize_t dims[1] = {2};
+ char filename[1024];
+
+ TESTING("that H5Tpack removes trailing bytes");
+
+ /* Create inner compound datatype. This type will be "packed" according
+ * to the internal field, but will have trailing space at the end. */
+ if((cmpd_int = H5Tcreate(H5T_COMPOUND, 4)) < 0) TEST_ERROR
+ if(H5Tinsert(cmpd_int, "c", 0, H5T_NATIVE_CHAR) < 0) TEST_ERROR
+
+ /* Create inner array datatype */
+ if((arr_int = H5Tarray_create2(cmpd_int, 1, dims)) < 0) TEST_ERROR
+
+ /* Create outer compound datatype. This type will be truly packed, with no
+ * trailing space. However, the internal compound contained within is not
+ * packed. */
+ if((cmpd_ext = H5Tcreate(H5T_COMPOUND, 8)) < 0) TEST_ERROR
+ if(H5Tinsert(cmpd_ext, "arr", 0, arr_int) < 0) TEST_ERROR
+
+ /* Create outer array datatype */
+ if((arr_ext = H5Tarray_create2(cmpd_ext, 1, dims)) < 0) TEST_ERROR
+
+ /* Try packing the internal array. Size should be 2 after packing. */
+ if((tmp_dt = H5Tcopy(arr_int)) < 0) TEST_ERROR
+ if(H5Tpack(tmp_dt) < 0) TEST_ERROR
+ if(2 != H5Tget_size(tmp_dt)) {
+ H5_FAILED(); AT();
+ printf(" Size after packing: %d; expected: 2\n", H5Tget_size(tmp_dt));
+ goto error;
+ }
+ if(H5Tclose(tmp_dt) < 0) TEST_ERROR
+
+ /* Try packing the external array. Size should be 4 after packing. */
+ if((tmp_dt = H5Tcopy(arr_ext)) < 0) TEST_ERROR
+ if(H5Tpack(tmp_dt) < 0) TEST_ERROR
+ if(4 != H5Tget_size(tmp_dt)) {
+ H5_FAILED(); AT();
+ printf(" Size after packing: %d; expected: 4\n", H5Tget_size(tmp_dt));
+ goto error;
+ }
+ if(H5Tclose(tmp_dt) < 0) TEST_ERROR
+
+ /* Now we will commit arr_int and arr_ext to a file, and verify that they
+ * are still packed correctly after opening them from the file */
+ /* Create File */
+ h5_fixname(FILENAME[3], H5P_DEFAULT, filename, sizeof filename);
+ if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
+
+ /* Commit the datatypes. Note that they are still unpacked. */
+ if(H5Tcommit2(file, "arr_int", arr_int, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
+ if(H5Tcommit2(file, "arr_ext", arr_ext, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
+
+ /* Close IDs */
+ if(H5Tclose(cmpd_int) < 0) TEST_ERROR
+ if(H5Tclose(arr_int) < 0) TEST_ERROR
+ if(H5Tclose(cmpd_ext) < 0) TEST_ERROR
+ if(H5Tclose(arr_ext) < 0) TEST_ERROR
+ if(H5Fclose(file) < 0) TEST_ERROR
+
+ /* Reopen file */
+ if((file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) TEST_ERROR
+
+ /* Open committed array datatypes */
+ if((arr_int = H5Topen2(file, "arr_int", H5P_DEFAULT)) < 0) TEST_ERROR
+ if((arr_ext = H5Topen2(file, "arr_ext", H5P_DEFAULT)) < 0) TEST_ERROR
+
+ /* Try packing the internal array. Size should be 2 after packing. */
+ if((tmp_dt = H5Tcopy(arr_int)) < 0) TEST_ERROR
+ if(H5Tpack(tmp_dt) < 0) TEST_ERROR
+ if(2 != H5Tget_size(tmp_dt)) {
+ H5_FAILED(); AT();
+ printf(" Size after packing: %d; expected: 2\n", H5Tget_size(tmp_dt));
+ goto error;
+ }
+ if(H5Tclose(tmp_dt) < 0) TEST_ERROR
+
+ /* Try packing the external array. Size should be 4 after packing. */
+ if((tmp_dt = H5Tcopy(arr_ext)) < 0) TEST_ERROR
+ if(H5Tpack(tmp_dt) < 0) TEST_ERROR
+ if(4 != H5Tget_size(tmp_dt)) {
+ H5_FAILED(); AT();
+ printf(" Size after packing: %d; expected: 4\n", H5Tget_size(tmp_dt));
+ goto error;
+ }
+ if(H5Tclose(tmp_dt) < 0) TEST_ERROR
+
+ /* Close IDs */
+ if(H5Tclose(arr_int) < 0) TEST_ERROR
+ if(H5Tclose(arr_ext) < 0) TEST_ERROR
+ if(H5Fclose(file) < 0) TEST_ERROR
+
+ PASSED();
+ return 0;
+
+error:
+ return 1;
+} /* end test_compound_17() */
+
+
+/*-------------------------------------------------------------------------
* Function: test_query
*
* Purpose: Tests query functions of compound and enumeration types.
@@ -5719,6 +5840,7 @@ main(void)
nerrors += test_compound_14();
nerrors += test_compound_15();
nerrors += test_compound_16();
+ nerrors += test_compound_17();
nerrors += test_conv_enum_1();
nerrors += test_conv_enum_2();
nerrors += test_conv_bitfield();