summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2008-09-22 23:41:58 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2008-09-22 23:41:58 (GMT)
commitcf451beffa0cc2df12b23bf6f5f37a702a88fb21 (patch)
treeabb4a6e2739e5386f5fdc71c3a34d6b7a660b4c0 /test
parent299ebc0d7f73620b7f9c793da9dbdd21e2df94f9 (diff)
downloadhdf5-cf451beffa0cc2df12b23bf6f5f37a702a88fb21.zip
hdf5-cf451beffa0cc2df12b23bf6f5f37a702a88fb21.tar.gz
hdf5-cf451beffa0cc2df12b23bf6f5f37a702a88fb21.tar.bz2
[svn-r15683] Purpose: fix bug 1298
Description: The optimized "subset" compound conversion function would improperly copy the "blank" space at the end of compound types. Modified H5T_conv_struct_init to detect when the subset type has extra space at the end, and calculate the size of the data that should be copied into the conversion buffer for each element. Changes to the functions that implement these conversions. Tested: kagiso, linew, smirom (h5committest)
Diffstat (limited to 'test')
-rw-r--r--test/dtypes.c170
1 files changed, 165 insertions, 5 deletions
diff --git a/test/dtypes.c b/test/dtypes.c
index 05b4ffe..fa2f14a 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -2684,10 +2684,10 @@ test_compound_14(void)
} /* end if */
rdata1.c1 = rdata1.c2 = 0;
- if(rdata1.str) free(rdata1.str);
+ if(rdata1.str) HDfree(rdata1.str);
rdata2.c1 = rdata2.c2 = rdata2.l1 = rdata2.l2 = rdata2.l3 = rdata2.l4 = 0;
- if(rdata2.str) free(rdata2.str);
+ if(rdata2.str) HDfree(rdata2.str);
if(H5Dread(dset1_id, cmpd_m1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata1) < 0) {
H5_FAILED(); AT();
@@ -2714,8 +2714,8 @@ test_compound_14(void)
goto error;
} /* end if */
- if(rdata1.str) free(rdata1.str);
- if(rdata2.str) free(rdata2.str);
+ if(rdata1.str) HDfree(rdata1.str);
+ if(rdata2.str) HDfree(rdata2.str);
if(H5Dclose(dset1_id) < 0)
goto error;
@@ -2733,7 +2733,166 @@ test_compound_14(void)
error:
return 1;
-}
+} /* end test_compound_14() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_compound_15
+ *
+ * Purpose: Tests that conversion occurs correctly when the source is
+ * subset of the destination, but there is extra space at the
+ * end of the source type.
+ *
+ * Return: Success: 0
+ *
+ * Failure: number of errors
+ *
+ * Programmer: Neil Fortner
+ * Friday, September 19, 2008
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_compound_15(void)
+{
+ typedef struct cmpd_struct {
+ int i1;
+ int i2;
+ } cmpd_struct;
+
+ cmpd_struct wdata1 = {1254, 5471};
+ cmpd_struct rdata;
+ int wdata2[2] = {1, 2};
+ hid_t file;
+ hid_t cmpd_m_tid, cmpd_f_tid;
+ hid_t space_id;
+ hid_t dset_id;
+ hsize_t dim1[1];
+ char filename[1024];
+
+ TESTING("compound subset conversion with extra space in source");
+
+ /* Create File */
+ h5_fixname(FILENAME[3], H5P_DEFAULT, filename, sizeof filename);
+ if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't create file!\n");
+ goto error;
+ } /* end if */
+
+ /* Create file compound datatype */
+ if((cmpd_f_tid = H5Tcreate( H5T_COMPOUND, sizeof(struct cmpd_struct))) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't create datatype!\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tinsert(cmpd_f_tid,"i1",HOFFSET(struct cmpd_struct,i1),H5T_NATIVE_INT) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't insert field 'i1'\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tinsert(cmpd_f_tid,"i2",HOFFSET(struct cmpd_struct,i2),H5T_NATIVE_INT) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't insert field 'i2'\n");
+ goto error;
+ } /* end if */
+
+ /* Create memory compound datatype */
+ if((cmpd_m_tid = H5Tcreate( H5T_COMPOUND, sizeof(struct cmpd_struct))) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't create datatype!\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tinsert(cmpd_m_tid,"i1",0,H5T_NATIVE_INT) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't insert field 'i1'\n");
+ goto error;
+ } /* end if */
+
+ /* Create space, dataset, write wdata1 */
+ dim1[0] = 1;
+ if((space_id = H5Screate_simple(1, dim1, NULL)) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't create space\n");
+ goto error;
+ } /* end if */
+
+ if((dset_id = H5Dcreate2(file, "Dataset", cmpd_f_tid, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't create dataset\n");
+ goto error;
+ } /* end if */
+
+ if(H5Dwrite(dset_id, cmpd_f_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata1) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't write data\n");
+ goto error;
+ } /* end if */
+
+ /* Write wdata2. The use of cmpd_m_tid here should cause only the first
+ * element of wdata2 to be written. */
+ if(H5Dwrite(dset_id, cmpd_m_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata2) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't write data\n");
+ goto error;
+ } /* end if */
+
+ /* Read data */
+ if(H5Dread(dset_id, cmpd_f_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't read data\n");
+ goto error;
+ } /* end if */
+
+ /* Check for correctness of read data */
+ if(rdata.i1 != wdata2[0] || rdata.i2 != wdata1.i2) {
+ H5_FAILED(); AT();
+ printf("incorrect read data\n");
+ goto error;
+ } /* end if */
+
+ /* Now try reading only the i1 field, verify it does not overwrite i2 in the
+ * read buffer */
+ rdata.i1 = wdata1.i1;
+ rdata.i2 = wdata2[1];
+
+ /* Read data */
+ if(H5Dread(dset_id, cmpd_m_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't read data\n");
+ goto error;
+ } /* end if */
+
+ /* Check for correctness of read data */
+ if(rdata.i1 != wdata2[0] || rdata.i2 != wdata2[1]) {
+ H5_FAILED(); AT();
+ printf("incorrect read data\n");
+ goto error;
+ } /* end if */
+
+ /* Close */
+ if(H5Dclose(dset_id) < 0)
+ goto error;
+ if(H5Tclose(cmpd_f_tid) < 0)
+ goto error;
+ if(H5Tclose(cmpd_m_tid) < 0)
+ goto error;
+ if(H5Sclose(space_id) < 0)
+ goto error;
+ if(H5Fclose(file) < 0)
+ goto error;
+
+ PASSED();
+ return 0;
+
+ error:
+ return 1;
+} /* end test_compound_14() */
/*-------------------------------------------------------------------------
@@ -5428,6 +5587,7 @@ main(void)
nerrors += test_compound_12();
nerrors += test_compound_13();
nerrors += test_compound_14();
+ nerrors += test_compound_15();
nerrors += test_conv_enum_1();
nerrors += test_conv_enum_2();
nerrors += test_conv_bitfield();