summaryrefslogtreecommitdiffstats
path: root/tools/h5copy
diff options
context:
space:
mode:
authorVailin Choi <vchoi@hdfgroup.org>2016-08-19 20:58:16 (GMT)
committerVailin Choi <vchoi@jam.ad.hdfgroup.org>2016-09-04 23:38:03 (GMT)
commit13e2f178c8832792bd0e30fc69e362306ce9f205 (patch)
tree4157795f7d4ec5ab95b8c67e22bbc502a9f9c67e /tools/h5copy
parent156d6de33bc7d63483c80acfe005aa874597e2b2 (diff)
downloadhdf5-13e2f178c8832792bd0e30fc69e362306ce9f205.zip
hdf5-13e2f178c8832792bd0e30fc69e362306ce9f205.tar.gz
hdf5-13e2f178c8832792bd0e30fc69e362306ce9f205.tar.bz2
Merge fix for HDFFV-7991 from trunk to 1.18
[svn-r30308] Fix for HDFFV-7991--error when copying dataset with attribute which is a compound datatype consisting of a variable length string. Tested on mayll, platypus, osx1010test, emu, kituo, kite, quail, moohan, ostrich.
Diffstat (limited to 'tools/h5copy')
-rw-r--r--tools/h5copy/h5copygentest.c84
-rw-r--r--tools/h5copy/testfiles/h5copytst.h5bin30448 -> 31856 bytes
-rw-r--r--tools/h5copy/testh5copy.sh.in2
3 files changed, 86 insertions, 0 deletions
diff --git a/tools/h5copy/h5copygentest.c b/tools/h5copy/h5copygentest.c
index 49204f5..f15a2d8 100644
--- a/tools/h5copy/h5copygentest.c
+++ b/tools/h5copy/h5copygentest.c
@@ -34,9 +34,12 @@
#define DATASET_COMPRESSED "compressed"
#define DATASET_NAMED_VL "named_vl"
#define DATASET_NESTED_VL "nested_vl"
+#define DATASET_ATTR "dset_attr"
+#define ATTR "attr"
#define GROUP_EMPTY "grp_empty"
#define GROUP_DATASETS "grp_dsets"
#define GROUP_NESTED "grp_nested"
+#define GROUP_ATTR "grp_attr"
/* Obj reference */
#define OBJ_REF_DS "Dset1"
@@ -322,6 +325,86 @@ static void gent_nested_vl(hid_t loc_id)
/*-------------------------------------------------------------------------
+ * Function: gent_att_compound_vlstr
+ *
+ * Purpose: Generate a dataset and a group.
+ * Both has an attribute with a compound datatype consisting
+ * of a variable length string
+ *
+ *-------------------------------------------------------------------------
+ */
+static void gent_att_compound_vlstr(hid_t loc_id)
+{
+ typedef struct { /* Compound structure for the attribute */
+ int i;
+ char *v;
+ } s1;
+ hsize_t dim[1] = {1}; /* Dimension size */
+ hid_t sid = -1; /* Dataspace ID */
+ hid_t tid = -1; /* Datatype ID */
+ hid_t aid = -1; /* Attribute ID */
+ hid_t did = -1; /* Dataset ID */
+ hid_t gid = -1; /* Group ID */
+ hid_t vl_str_tid = -1; /* Variable length datatype ID */
+ hid_t cmpd_tid = -1; /* Compound datatype ID */
+ hid_t null_sid = -1; /* Null dataspace ID */
+ s1 buf; /* Buffer */
+
+ buf.i = 9;
+ buf.v = "ThisIsAString";
+
+ /* Create an integer datatype */
+ tid = H5Tcopy(H5T_NATIVE_INT);
+
+ /* Create a variable length string */
+ vl_str_tid = H5Tcopy(H5T_C_S1);
+ H5Tset_size(vl_str_tid, H5T_VARIABLE);
+
+ /* Create a compound datatype with a variable length string and an integer */
+ cmpd_tid = H5Tcreate(H5T_COMPOUND, sizeof(s1));
+ H5Tinsert(cmpd_tid, "i", HOFFSET(s1, i), tid);
+ H5Tinsert(cmpd_tid, "v", HOFFSET(s1, v), vl_str_tid);
+
+ /* Create a dataset */
+ null_sid = H5Screate(H5S_NULL);
+ did = H5Dcreate2(loc_id, DATASET_ATTR, H5T_NATIVE_INT, null_sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ /* Attach an attribute with the compound datatype to the dataset */
+ sid = H5Screate_simple(1, dim, dim);
+ aid = H5Acreate2(did, ATTR, cmpd_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
+
+ /* Write the attribute */
+ buf.i = 9;
+ buf.v = "ThisIsAString";
+ H5Awrite(aid, cmpd_tid, &buf);
+
+ /* Close the dataset and its attribute */
+ H5Dclose(did);
+ H5Aclose(aid);
+
+ /* Create a group */
+ gid = H5Gcreate2(loc_id, GROUP_ATTR, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ /* Attach an attribute with the compound datatype to the group */
+ aid = H5Acreate2(gid, ATTR, cmpd_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
+ H5Awrite(aid, cmpd_tid, &buf);
+
+ /* Close the group and its attribute */
+ H5Aclose(aid);
+ H5Gclose(gid);
+
+ /* Close dataspaces */
+ H5Sclose(sid);
+ H5Sclose(null_sid);
+
+ /* Close datatypes */
+ H5Tclose(tid);
+ H5Tclose(vl_str_tid);
+ H5Tclose(cmpd_tid);
+
+} /* gen_att_compound_vlstr() */
+
+/*-------------------------------------------------------------------------
* Function: gent_datasets
*
* Purpose: Generate all datasets in a particular location
@@ -658,6 +741,7 @@ static void Test_Obj_Copy(void)
gent_empty_group(fid);
gent_nested_datasets(fid);
gent_nested_group(fid);
+ gent_att_compound_vlstr(fid);
out:
/*-----------------------------------------------------------------------
diff --git a/tools/h5copy/testfiles/h5copytst.h5 b/tools/h5copy/testfiles/h5copytst.h5
index f407f82..759ffa7 100644
--- a/tools/h5copy/testfiles/h5copytst.h5
+++ b/tools/h5copy/testfiles/h5copytst.h5
Binary files differ
diff --git a/tools/h5copy/testh5copy.sh.in b/tools/h5copy/testh5copy.sh.in
index 77c64c4..d8abfd9 100644
--- a/tools/h5copy/testh5copy.sh.in
+++ b/tools/h5copy/testh5copy.sh.in
@@ -490,6 +490,7 @@ COPY_OBJECTS()
TOOLTEST -i $TESTFILE -o $TESTDIR/compressed.out.h5 -v -s compressed -d compressed
TOOLTEST -i $TESTFILE -o $TESTDIR/named_vl.out.h5 -v -s named_vl -d named_vl
TOOLTEST -i $TESTFILE -o $TESTDIR/nested_vl.out.h5 -v -s nested_vl -d nested_vl
+ TOOLTEST -i $TESTFILE -o $TESTDIR/dset_attr.out.h5 -v -s /dset_attr -d /dset_attr
echo "Test copying dataset within group in source file to root of destination"
TOOLTEST -i $TESTFILE -o $TESTDIR/simple_top.out.h5 -v -s grp_dsets/simple -d simple_top
@@ -501,6 +502,7 @@ COPY_OBJECTS()
TOOLTEST -i $TESTFILE -o $TESTDIR/grp_empty.out.h5 -v -s grp_empty -d grp_empty
TOOLTEST -i $TESTFILE -o $TESTDIR/grp_dsets.out.h5 -v -s grp_dsets -d grp_dsets
TOOLTEST -i $TESTFILE -o $TESTDIR/grp_nested.out.h5 -v -s grp_nested -d grp_nested
+ TOOLTEST -i $TESTFILE -o $TESTDIR/grp_attr.out.h5 -v -s grp_attr -d grp_attr
echo "Test copying dataset within group in source file to group in destination"
TOOLTEST_PREFILL -i $TESTFILE -o $TESTDIR/simple_group.out.h5 grp_dsets grp_dsets /grp_dsets/simple /grp_dsets/simple_group