summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2002-01-27 05:23:11 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2002-01-27 05:23:11 (GMT)
commitf4bc9f929e9d7742540722bb19f009382c909d8f (patch)
tree5ca3f34d9c40254c7b68995197c189b40f279083
parent0a612f0a6133363cecf86afe7c872706a200876e (diff)
downloadhdf5-f4bc9f929e9d7742540722bb19f009382c909d8f.zip
hdf5-f4bc9f929e9d7742540722bb19f009382c909d8f.tar.gz
hdf5-f4bc9f929e9d7742540722bb19f009382c909d8f.tar.bz2
[svn-r4869] Purpose:
Add regression tests Description: Added regression test for using a VL-datatype in two separate files. Platforms tested: FreeBSD 4.5 (sleipnir)
-rw-r--r--test/Makefile.in3
-rw-r--r--test/tmisc.c185
2 files changed, 181 insertions, 7 deletions
diff --git a/test/Makefile.in b/test/Makefile.in
index 0dc0b2e..528329c 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -48,7 +48,8 @@ MOSTLYCLEAN=cmpd_dset.h5 dataset.h5 extend.h5 istore.h5 tfile1.h5 tfile2.h5 \
tattr.h5 tselect.h5 mtime.h5 unlink.h5 \
fillval_[0-9].h5 fillval.raw mount_[0-9].h5 testmeta.h5 \
ttime.h5 trefer[12].h5 tvltypes.h5 tvlstr.h5 flush.h5 enum1.h5 \
- titerate.h5 ttsafe.h5 tarray1.h5 tgenprop.h5 tmisc.h5
+ titerate.h5 ttsafe.h5 tarray1.h5 tgenprop.h5 tmisc.h5 tmisc2a.h5 \
+ tmisc2b.h5
CLEAN=$(TIMINGS)
## Source and object files for programs... The TEST_SRC list contains all the
diff --git a/test/tmisc.c b/test/tmisc.c
index 6476c32..b5682c5 100644
--- a/test/tmisc.c
+++ b/test/tmisc.c
@@ -25,13 +25,22 @@
#include "hdf5.h"
#include "testhdf5.h"
-#define FILE "tmisc.h5"
-
/* Definitions for misc. test #1 */
+#define MISC1_FILE "tmisc.h5"
#define MISC1_VAL (13417386) /* 0xccbbaa */
#define MISC1_VAL2 (15654348) /* 0xeeddcc */
#define MISC1_DSET_NAME "/scalar_set"
+/* Definitions for misc. test #2 */
+#define MISC2_FILE_1 "tmisc2a.h5"
+#define MISC2_FILE_2 "tmisc2b.h5"
+#define MISC2_ATT_NAME_1 "scalar_att_1"
+#define MISC2_ATT_NAME_2 "scalar_att_2"
+
+typedef struct {
+ char *string;
+} misc2_struct;
+
/****************************************************************
**
** test_misc1(): test unlinking a dataset from a group and immediately
@@ -49,7 +58,7 @@ test_misc1(void)
/* Output message about test being performed */
MESSAGE(5, ("Testing Unlinking Dataset and Re-creating It\n"));
- file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ file = H5Fcreate(MISC1_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(file, FAIL, "H5Fcreate");
dataspace = H5Screate(H5S_SCALAR);
@@ -88,7 +97,7 @@ test_misc1(void)
CHECK(ret, FAIL, "H5Fclose");
/* Now, check the value written to the dataset, after it was re-created */
- file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
+ file = H5Fopen(MISC1_FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(file, FAIL, "H5Fopen");
dataspace = H5Screate(H5S_SCALAR);
@@ -112,6 +121,168 @@ test_misc1(void)
} /* end test_misc1() */
+static hid_t misc2_create_type(void)
+{
+ hid_t type, type_tmp;
+ herr_t ret;
+
+ type_tmp = H5Tcopy (H5T_C_S1);
+ CHECK(type_tmp, FAIL, "H5Tcopy");
+
+ ret = H5Tset_size (type_tmp, H5T_VARIABLE);
+ CHECK(ret, FAIL, "H5Tset_size");
+
+ type = H5Tcreate (H5T_COMPOUND, sizeof(misc2_struct));
+ CHECK(type, FAIL, "H5Tcreate");
+
+ ret = H5Tinsert (type, "string", offsetof(misc2_struct, string), type_tmp);
+ CHECK(ret, FAIL, "H5Tinsert");
+
+ ret = H5Tclose(type_tmp);
+ CHECK(ret, FAIL, "H5Tclose");
+
+ return type;
+}
+
+static void test_misc2_write_attribute(void)
+{
+ hid_t file1, file2, root1, root2, dataspace, att1, att2;
+ hid_t type;
+ herr_t ret;
+ misc2_struct data, data_check;
+ char *string_att1 = HDstrdup("string attribute in file one");
+ char *string_att2 = HDstrdup("string attribute in file two");
+
+ type = misc2_create_type();
+
+ dataspace = H5Screate(H5S_SCALAR);
+ CHECK(dataspace, FAIL, "H5Screate");
+
+ file2 = H5Fcreate(MISC2_FILE_2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(file2, FAIL, "H5Fcreate");
+
+ file1 = H5Fcreate(MISC2_FILE_1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(file1, FAIL, "H5Fcreate");
+
+ root1 = H5Gopen(file1, "/");
+ CHECK(root1, FAIL, "H5Gopen");
+
+ att1 = H5Acreate(root1, MISC2_ATT_NAME_1, type, dataspace, H5P_DEFAULT);
+ CHECK(att1, FAIL, "H5Acreate");
+
+ data.string = string_att1;
+
+ ret = H5Awrite(att1, type, &data);
+ CHECK(ret, FAIL, "H5Awrite");
+
+ ret = H5Aread(att1, type, &data_check);
+ CHECK(ret, FAIL, "H5Aread");
+
+ free(data_check.string);
+
+ ret = H5Aclose(att1);
+ CHECK(ret, FAIL, "HAclose");
+
+ ret = H5Gclose(root1);
+ CHECK(ret, FAIL, "H5Gclose");
+
+ ret = H5Fclose(file1);
+ CHECK(ret, FAIL, "H5Fclose");
+
+
+
+ root2 = H5Gopen(file2, "/");
+ CHECK(root2, FAIL, "H5Gopen");
+
+ att2 = H5Acreate(root2, MISC2_ATT_NAME_2, type, dataspace, H5P_DEFAULT);
+ CHECK(att2, FAIL, "H5Acreate");
+
+ data.string = string_att2;
+
+ ret = H5Awrite(att2, type, &data);
+ CHECK(ret, FAIL, "H5Awrite");
+
+ ret = H5Aread(att2, type, &data_check);
+ CHECK(ret, FAIL, "H5Aread");
+
+ free(data_check.string);
+
+ ret = H5Aclose(att2);
+ CHECK(ret, FAIL, "HAclose");
+
+ ret = H5Gclose(root2);
+ CHECK(ret, FAIL, "H5Gclose");
+
+ ret = H5Tclose(type);
+ CHECK(ret, FAIL, "H5Tclose");
+
+ ret = H5Sclose(dataspace);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ ret = H5Fclose(file2);
+ CHECK(ret, FAIL, "H5Fclose");
+
+ free(string_att1);
+ free(string_att2);
+ return;
+}
+
+
+static void test_misc2_read_attribute(const char *filename, const char *att_name)
+{
+ hid_t file, root, att;
+ hid_t type;
+ herr_t ret;
+ misc2_struct data_check;
+
+ type = misc2_create_type();
+
+ file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
+ CHECK(file, FAIL, "H5Fopen");
+
+ root = H5Gopen(file, "/");
+ CHECK(root, FAIL, "H5Gopen");
+
+ att = H5Aopen_name(root, att_name);
+ CHECK(att, FAIL, "H5Aopen_name");
+
+ ret = H5Aread(att, type, &data_check);
+ CHECK(ret, FAIL, "H5Aread");
+
+ free(data_check.string);
+
+ ret = H5Aclose(att);
+ CHECK(ret, FAIL, "HAclose");
+
+ ret = H5Tclose(type);
+ CHECK(ret, FAIL, "H5Tclose");
+
+ ret = H5Gclose(root);
+ CHECK(ret, FAIL, "H5Gclose");
+
+ ret = H5Fclose(file);
+ CHECK(ret, FAIL, "H5Fclose");
+
+ return;
+}
+/****************************************************************
+**
+** test_misc2(): test using the same VL-derived datatype in two
+** different files, which was causing problems with the
+** datatype conversion functions
+**
+****************************************************************/
+static void
+test_misc2(void)
+{
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing VL datatype in two different files\n"));
+
+ test_misc2_write_attribute();
+ test_misc2_read_attribute(MISC2_FILE_1, MISC2_ATT_NAME_1);
+ test_misc2_read_attribute(MISC2_FILE_2, MISC2_ATT_NAME_2);
+} /* end test_misc2() */
+
/****************************************************************
**
** test_misc(): Main misc. test routine.
@@ -123,8 +294,8 @@ test_misc(void)
/* Output message about test being performed */
MESSAGE(5, ("Testing Miscellaneous Routines\n"));
- /* Various tests, using the same test file */
test_misc1(); /* Test unlinking a dataset & immediately re-using name */
+ test_misc2(); /* Test storing a VL-derived datatype in two different files */
} /* test_misc() */
@@ -146,5 +317,7 @@ test_misc(void)
void
cleanup_misc(void)
{
- remove(FILE);
+ remove(MISC1_FILE);
+ remove(MISC2_FILE_1);
+ remove(MISC2_FILE_2);
}