summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.in6
-rw-r--r--test/testhdf5.c1
-rw-r--r--test/testhdf5.h2
-rw-r--r--test/tvlstr.c259
4 files changed, 265 insertions, 3 deletions
diff --git a/test/Makefile.in b/test/Makefile.in
index f438e6a..04c374b 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -47,7 +47,7 @@ MOSTLYCLEAN=cmpd_dset.h5 dataset.h5 extend.h5 istore.h5 tfile1.h5 tfile2.h5 \
big.data big[0-9][0-9][0-9][0-9][0-9].h5 dtypes1.h5 dtypes2.h5 \
tattr.h5 tselect.h5 mtime.h5 ragged.h5 unlink.h5 overhead.h5 \
fillval_[0-9].h5 fillval.raw mount_[0-9].h5 trefer[12].h5 \
- tvltypes.h5 flush.h5 enum1.h5
+ tvltypes.h5 tvlstr.h5 flush.h5 enum1.h5
CLEAN=$(TIMINGS)
## Source and object files for programs... The TEST_SRC list contains all the
@@ -58,7 +58,7 @@ TEST_SRC=big.c bittests.c chunk.c cmpd_dset.c dsets.c dtypes.c extend.c \
external.c fillval.c flush1.c flush2.c gheap.c h5test.c hyperslab.c \
iopipe.c istore.c lheap.c links.c mount.c mtime.c ohdr.c overhead.c \
ragged.c stab.c tattr.c testhdf5.c tfile.c th5s.c tmeta.c trefer.c \
- tselect.c tvltypes.c unlink.c enum.c gass_write.c gass_read.c \
+ tselect.c tvltypes.c tvlstr.c unlink.c enum.c gass_write.c gass_read.c \
gass_append.c
TEST_OBJ=$(TEST_SRC:.c=.lo)
@@ -78,7 +78,7 @@ timings _timings: $(TIMINGS)
## How to build the tests... They all depend on the test and hdf5 libraries.
$(TEST_PROGS): $(LIB) $(LIBHDF5)
-TESTHDF5_OBJ=testhdf5.lo tattr.lo tfile.lo tmeta.lo trefer.lo tselect.lo tvltypes.lo th5s.lo
+TESTHDF5_OBJ=testhdf5.lo tattr.lo tfile.lo tmeta.lo trefer.lo tselect.lo tvltypes.lo tvlstr.lo th5s.lo
testhdf5: $(TESTHDF5_OBJ)
@$(LT_LINK_EXE) $(CFLAGS) -o $@ $(TESTHDF5_OBJ) $(LIB) $(LIBHDF5) $(LDFLAGS) $(LIBS)
diff --git a/test/testhdf5.c b/test/testhdf5.c
index 8774a88..2312584 100644
--- a/test/testhdf5.c
+++ b/test/testhdf5.c
@@ -169,6 +169,7 @@ main(int argc, char *argv[])
InitTest("select", test_select, cleanup_select, "Selections");
InitTest("reference", test_reference, cleanup_reference, "References");
InitTest("vltypes", test_vltypes, cleanup_vltypes, "Variable-Length Datatypes");
+ InitTest("vlstrings", test_vlstrings, cleanup_vlstrings, "Variable-Length Strings");
Verbosity = 4; /* Default Verbosity is Low */
H5get_libversion(&major, &minor, &release);
diff --git a/test/testhdf5.h b/test/testhdf5.h
index 574bfeb..d2d4a9b 100644
--- a/test/testhdf5.h
+++ b/test/testhdf5.h
@@ -126,6 +126,7 @@ void test_attr(void);
void test_select(void);
void test_reference(void);
void test_vltypes(void);
+void test_vlstrings(void);
/* Prototypes for the cleanup routines */
void cleanup_metadata(void);
@@ -135,5 +136,6 @@ void cleanup_attr(void);
void cleanup_select(void);
void cleanup_reference(void);
void cleanup_vltypes(void);
+void cleanup_vlstrings(void);
#endif /* HDF5cleanup_H */
diff --git a/test/tvlstr.c b/test/tvlstr.c
new file mode 100644
index 0000000..a227aa6
--- /dev/null
+++ b/test/tvlstr.c
@@ -0,0 +1,259 @@
+/****************************************************************************
+ * NCSA HDF *
+ * Software Development Group *
+ * National Center for Supercomputing Applications *
+ * University of Illinois at Urbana-Champaign *
+ * 605 E. Springfield, Champaign IL 61820 *
+ * *
+ * For conditions of distribution and use, see the accompanying *
+ * hdf/COPYING file. *
+ * *
+ ****************************************************************************/
+
+#ifdef RCSID
+static char RcsId[] = "$Revision$";
+#endif
+
+/* $Id$ */
+
+/***********************************************************
+*
+* Test program: tvlstr
+*
+* Test the Variable-Length String functionality
+*
+*************************************************************/
+
+#include <testhdf5.h>
+
+#include <hdf5.h>
+
+#define FILE "tvlstr.h5"
+
+/* 1-D dataset with fixed dimensions */
+#define SPACE1_NAME "Space1"
+#define SPACE1_RANK 1
+#define SPACE1_DIM1 4
+
+/* 2-D dataset with fixed dimensions */
+#define SPACE2_NAME "Space2"
+#define SPACE2_RANK 2
+#define SPACE2_DIM1 10
+#define SPACE2_DIM2 10
+
+void *test_vlstr_alloc_custom(size_t size, void *info);
+void test_vlstr_free_custom(void *mem, void *info);
+
+/****************************************************************
+**
+** test_vlstr_alloc_custom(): Test VL datatype custom memory
+** allocation routines. This routine just uses malloc to
+** allocate the memory and increments the amount of memory
+** allocated.
+**
+****************************************************************/
+void *test_vlstr_alloc_custom(size_t size, void *info)
+{
+ void *ret_value=NULL; /* Pointer to return */
+ int *mem_used=(int *)info; /* Get the pointer to the memory used */
+ size_t extra; /* Extra space needed */
+
+ /*
+ * This weird contortion is required on the DEC Alpha to keep the
+ * alignment correct - QAK
+ */
+ extra=MAX(sizeof(void *),sizeof(int));
+
+ if((ret_value=HDmalloc(extra+size))!=NULL) {
+ *(int *)ret_value=size;
+ *mem_used+=size;
+ } /* end if */
+ ret_value=((unsigned char *)ret_value)+extra;
+ return(ret_value);
+}
+
+/****************************************************************
+**
+** test_vlstr_free_custom(): Test VL datatype custom memory
+** allocation routines. This routine just uses free to
+** release the memory and decrements the amount of memory
+** allocated.
+**
+****************************************************************/
+void test_vlstr_free_custom(void *_mem, void *info)
+{
+ unsigned char *mem;
+ int *mem_used=(int *)info; /* Get the pointer to the memory used */
+ size_t extra; /* Extra space needed */
+
+ /*
+ * This weird contortion is required on the DEC Alpha to keep the
+ * alignment correct - QAK
+ */
+ extra=MAX(sizeof(void *),sizeof(int));
+
+ if(_mem!=NULL) {
+ mem=((unsigned char *)_mem)-extra;
+ *mem_used-=*(int *)mem;
+ HDfree(mem);
+ } /* end if */
+}
+
+/****************************************************************
+**
+** test_vlstrings_basic(): Test basic VL string code.
+** Tests simple VL string I/O
+**
+****************************************************************/
+static void
+test_vlstrings_basic(void)
+{
+ const char *wdata[SPACE1_DIM1]= {
+ "Four score and seven years ago our forefathers brought forth on this continent a new nation,",
+ "conceived in liberty and dedicated to the proposition that all men are created equal.",
+ "Now we are engaged in a great civil war,",
+ "testing whether that nation or any nation so conceived and so dedicated can long endure."
+ }; /* Information to write */
+ char *rdata[SPACE1_DIM1]; /* Information read in */
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1; /* Datatype ID */
+ hid_t xfer_pid; /* Dataset transfer property list ID */
+ hsize_t dims1[] = {SPACE1_DIM1};
+ hsize_t size; /* Number of bytes which will be used */
+ uintn i; /* counting variable */
+ int str_used; /* String data in memory */
+ int mem_used=0; /* Memory used during allocation */
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Basic VL String Functionality\n"));
+
+ /* Create file */
+ fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(fid1, FAIL, "H5Fcreate");
+
+ /* Create dataspace for datasets */
+ sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
+ CHECK(sid1, FAIL, "H5Screate_simple");
+
+ /* Create a datatype to refer to */
+ tid1 = H5Tcopy (H5T_C_S1);
+ CHECK(tid1, FAIL, "H5Tcopy");
+
+ ret = H5Tset_size (tid1,H5T_VARIABLE);
+ CHECK(ret, FAIL, "H5Tset_size");
+
+ /* Create a dataset */
+ dataset=H5Dcreate(fid1,"Dataset1",tid1,sid1,H5P_DEFAULT);
+ CHECK(dataset, FAIL, "H5Dcreate");
+
+ /* Write dataset to disk */
+ ret=H5Dwrite(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
+ CHECK(ret, FAIL, "H5Dwrite");
+
+ /* Change to the custom memory allocation routines for reading VL string */
+ xfer_pid=H5Pcreate(H5P_DATA_XFER);
+ CHECK(xfer_pid, FAIL, "H5Pcreate");
+
+ ret=H5Pset_vlen_mem_manager(xfer_pid,test_vlstr_alloc_custom,&mem_used,test_vlstr_free_custom,&mem_used);
+ CHECK(ret, FAIL, "H5Pset_vlen_mem_manager");
+
+ /* Make certain the correct amount of memory will be used */
+ ret=H5Dvlen_get_buf_size(dataset,tid1,sid1,&size);
+ CHECK(ret, FAIL, "H5Dvlen_get_buf_size");
+
+ /* Count the actual number of bytes used by the strings */
+ for(i=0,str_used=0; i<SPACE1_DIM1; i++)
+ str_used+=strlen(wdata[i])+1;
+
+ /* Compare against the strings actually written */
+ VERIFY(size,(hsize_t)str_used,"H5Dvlen_get_buf_size");
+
+ /* Read dataset from disk */
+ ret=H5Dread(dataset,tid1,H5S_ALL,H5S_ALL,xfer_pid,rdata);
+ CHECK(ret, FAIL, "H5Dread");
+
+ /* Make certain the correct amount of memory has been used */
+ VERIFY(mem_used,str_used,"H5Dread");
+
+ /* Compare data read in */
+ for(i=0; i<SPACE1_DIM1; i++) {
+ if(strlen(wdata[i])!=strlen(rdata[i])) {
+ num_errs++;
+ printf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,strlen(wdata[i]),(int)i,strlen(rdata[i]));
+ continue;
+ } /* end if */
+ if( strcmp(wdata[i],rdata[i]) != 0 ) {
+ num_errs++;
+ printf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",(int)i,wdata[i],(int)i,rdata[i]);
+ continue;
+ } /* end if */
+ } /* end for */
+
+ /* Reclaim the read VL data */
+ ret=H5Dvlen_reclaim(tid1,sid1,xfer_pid,rdata);
+ CHECK(ret, FAIL, "H5Dvlen_reclaim");
+
+ /* Make certain the VL memory has been freed */
+ VERIFY(mem_used,0,"H5Dvlen_reclaim");
+
+ /* Close Dataset */
+ ret = H5Dclose(dataset);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ /* Close datatype */
+ ret = H5Tclose(tid1);
+ CHECK(ret, FAIL, "H5Tclose");
+
+ /* Close disk dataspace */
+ ret = H5Sclose(sid1);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /* Close dataset transfer property list */
+ ret = H5Pclose(xfer_pid);
+ CHECK(ret, FAIL, "H5Pclose");
+
+ /* Close file */
+ ret = H5Fclose(fid1);
+ CHECK(ret, FAIL, "H5Fclose");
+
+} /* end test_vlstrings_basic() */
+
+/****************************************************************
+**
+** test_vlstrings(): Main VL string testing routine.
+**
+****************************************************************/
+void
+test_vlstrings(void)
+{
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Variable-Length Strings\n"));
+
+ /* These next tests use the same file */
+ test_vlstrings_basic(); /* Test basic VL string datatype */
+} /* test_vlstrings() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: cleanup_vlstrings
+ *
+ * Purpose: Cleanup temporary test files
+ *
+ * Return: none
+ *
+ * Programmer: Quincey Koziol
+ * September 10, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+cleanup_vlstrings(void)
+{
+ remove(FILE);
+}
+