summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNeil Fortner <fortnern@gmail.com>2022-08-24 16:36:23 (GMT)
committerGitHub <noreply@github.com>2022-08-24 16:36:23 (GMT)
commit3cc7265e7727534eafbb2261768edfc0b6b3db82 (patch)
treec0eb64d73add3f4158ce85c93de289e7917eeaba /test
parent955ac6a29eb9094e3c155de3d9cd222ccc8ccf57 (diff)
downloadhdf5-3cc7265e7727534eafbb2261768edfc0b6b3db82.zip
hdf5-3cc7265e7727534eafbb2261768edfc0b6b3db82.tar.gz
hdf5-3cc7265e7727534eafbb2261768edfc0b6b3db82.tar.bz2
Fix bug in attribute type conversion wiith compound types - merge to 1.12 (#2061)
* Fix bug in attribute type conversion wiith compound types (#2016) * Fix bug in attribute type conversion where the background buffer would not be initialized with the destination contents when necessary. Other minor simplification. * Committing clang-format changes * Fix warnings. * Address review comments. Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Add note to RELEASE.txt for GitHub #2016 (#2030) * Fix bug in attribute type conversion where the background buffer would not be initialized with the destination contents when necessary. Other minor simplification. * Committing clang-format changes * Fix warnings. * Address review comments. * Add RELEASE.txt note for PR #2016 * Add GitHub number to release note Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'test')
-rw-r--r--test/dtypes.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/test/dtypes.c b/test/dtypes.c
index eaa7627..c72fce0 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -3363,6 +3363,136 @@ error:
} /* end test_compound_15() */
/*-------------------------------------------------------------------------
+ * Function: test_compound_15_attr
+ *
+ * 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. This one tests on attribute while
+ * test_compound_15() tests on dataset. That's the only
+ * difference.
+ *
+ * Return: Success: 0
+ *
+ * Failure: number of errors
+ *
+ * Programmer: Ray Lu
+ * 14 July 2022
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_compound_15_attr(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 = H5I_INVALID_HID;
+ hid_t cmpd_m_tid = H5I_INVALID_HID;
+ hid_t cmpd_f_tid = H5I_INVALID_HID;
+ hid_t space_id = H5I_INVALID_HID;
+ hid_t attr_id = H5I_INVALID_HID;
+ hsize_t dim1[1];
+ char filename[1024];
+
+ TESTING("compound subset conversion with extra space in source for attribute");
+
+ /* Create File */
+ h5_fixname(FILENAME[3], H5P_DEFAULT, filename, sizeof(filename));
+ if ((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ FAIL_PUTS_ERROR("Can't create file!\n");
+
+ /* Create file compound datatype */
+ if ((cmpd_f_tid = H5Tcreate(H5T_COMPOUND, sizeof(struct cmpd_struct))) < 0)
+ FAIL_PUTS_ERROR("Can't create datatype!\n");
+
+ if (H5Tinsert(cmpd_f_tid, "i1", HOFFSET(struct cmpd_struct, i1), H5T_NATIVE_INT) < 0)
+ FAIL_PUTS_ERROR("Can't insert field 'i1'\n");
+
+ if (H5Tinsert(cmpd_f_tid, "i2", HOFFSET(struct cmpd_struct, i2), H5T_NATIVE_INT) < 0)
+ FAIL_PUTS_ERROR("Can't insert field 'i2'\n");
+
+ /* Create memory compound datatype */
+ if ((cmpd_m_tid = H5Tcreate(H5T_COMPOUND, sizeof(struct cmpd_struct))) < 0)
+ FAIL_PUTS_ERROR("Can't create datatype!\n");
+
+ if (H5Tinsert(cmpd_m_tid, "i1", (size_t)0, H5T_NATIVE_INT) < 0)
+ FAIL_PUTS_ERROR("Can't insert field 'i1'\n");
+
+ /* Create space, dataset, write wdata1 */
+ dim1[0] = 1;
+ if ((space_id = H5Screate_simple(1, dim1, NULL)) < 0)
+ FAIL_PUTS_ERROR("Can't create space\n");
+
+ if ((attr_id = H5Acreate_by_name(file, ".", "attr_cmpd", cmpd_f_tid, space_id, H5P_DEFAULT, H5P_DEFAULT,
+ H5P_DEFAULT)) < 0)
+ FAIL_PUTS_ERROR("Can't create dataset\n");
+
+ if (H5Awrite(attr_id, cmpd_f_tid, &wdata1) < 0)
+ FAIL_PUTS_ERROR("Can't write data\n");
+
+ /* Write wdata2. The use of cmpd_m_tid here should cause only the first
+ * element of wdata2 to be written. */
+ if (H5Awrite(attr_id, cmpd_m_tid, &wdata2) < 0)
+ FAIL_PUTS_ERROR("Can't write data\n");
+
+ /* Read data */
+ if (H5Aread(attr_id, cmpd_f_tid, &rdata) < 0)
+ FAIL_PUTS_ERROR("Can't read data\n");
+
+ /* Check for correctness of read data */
+ if (rdata.i1 != wdata2[0] || rdata.i2 != wdata1.i2)
+ FAIL_PUTS_ERROR("incorrect read data\n");
+
+ /* 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 (H5Aread(attr_id, cmpd_m_tid, &rdata) < 0)
+ FAIL_PUTS_ERROR("Can't read data\n");
+
+ /* Check for correctness of read data */
+ if (rdata.i1 != wdata2[0] || rdata.i2 != wdata2[1])
+ FAIL_PUTS_ERROR("incorrect read data\n");
+
+ /* Close */
+ if (H5Aclose(attr_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:
+ H5E_BEGIN_TRY
+ {
+ H5Aclose(attr_id);
+ H5Tclose(cmpd_f_tid);
+ H5Tclose(cmpd_m_tid);
+ H5Sclose(space_id);
+ H5Fclose(file);
+ }
+ H5E_END_TRY;
+
+ return 1;
+} /* end test_compound_15_attr() */
+
+/*-------------------------------------------------------------------------
* Function: test_compound_16
*
* Purpose: Tests that committed types that can be registered during
@@ -8829,6 +8959,7 @@ main(void)
nerrors += test_compound_13();
nerrors += test_compound_14();
nerrors += test_compound_15();
+ nerrors += test_compound_15_attr();
nerrors += test_compound_16();
nerrors += test_compound_17();
nerrors += test_compound_18();