diff options
author | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2009-09-02 21:27:03 (GMT) |
---|---|---|
committer | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2009-09-02 21:27:03 (GMT) |
commit | 42be1460e464fc1d3d2c843ff9a2841cb9767d15 (patch) | |
tree | ef534736944298a20a076c1111c9e30bd2d8e5f5 /c++/test | |
parent | c1d205d282137c93dc8f2cac757045960075ca2c (diff) | |
download | hdf5-42be1460e464fc1d3d2c843ff9a2841cb9767d15.zip hdf5-42be1460e464fc1d3d2c843ff9a2841cb9767d15.tar.gz hdf5-42be1460e464fc1d3d2c843ff9a2841cb9767d15.tar.bz2 |
[svn-r17443] Description:
Merged changes from the trunk into the branch:
svn merge -r17188:17442 https://svn.hdfgroup.uiuc.edu/hdf5/trunk
Tested: smirom (icc, gcc)
Diffstat (limited to 'c++/test')
-rw-r--r-- | c++/test/Makefile.in | 90 | ||||
-rw-r--r-- | c++/test/tvlstr.cpp | 465 |
2 files changed, 364 insertions, 191 deletions
diff --git a/c++/test/Makefile.in b/c++/test/Makefile.in index 0452ea0..3dff900 100644 --- a/c++/test/Makefile.in +++ b/c++/test/Makefile.in @@ -1,8 +1,9 @@ -# Makefile.in generated by automake 1.10.2 from Makefile.am. +# Makefile.in generated by automake 1.11 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -32,8 +33,9 @@ # VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c @@ -61,6 +63,7 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ mkinstalldirs = $(SHELL) $(top_srcdir)/bin/mkinstalldirs CONFIG_HEADER = $(top_builddir)/src/H5config.h CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = am__EXEEXT_1 = dsets$(EXEEXT) testhdf5$(EXEEXT) am_dsets_OBJECTS = dsets.$(OBJEXT) h5cpputil.$(OBJEXT) dsets_OBJECTS = $(am_dsets_OBJECTS) @@ -76,6 +79,7 @@ testhdf5_DEPENDENCIES = $(LIBH5TEST) $(LIBH5CPP) $(LIBHDF5) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/bin/depcomp am__depfiles_maybe = depfiles +am__mv = mv -f CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ @@ -89,6 +93,8 @@ SOURCES = $(dsets_SOURCES) $(testhdf5_SOURCES) DIST_SOURCES = $(dsets_SOURCES) $(testhdf5_SOURCES) ETAGS = etags CTAGS = ctags +am__tty_colors = \ +red=; grn=; lgn=; blu=; std= DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = /home1/packages/automake/automake-1.9.6/bin/aclocal-1.9 -I /afs/ncsa/projects/hdf/packages/libtool_1.5.14/Linux_2.4/share/aclocal ADD_PARALLEL_FILES = @ADD_PARALLEL_FILES@ @@ -203,6 +209,7 @@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PARALLEL = @PARALLEL@ PATH_SEPARATOR = @PATH_SEPARATOR@ @@ -294,6 +301,7 @@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ @@ -387,9 +395,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign c++/test/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --foreign c++/test/Makefile + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign c++/test/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign c++/test/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ @@ -407,13 +415,16 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): clean-checkPROGRAMS: - @list='$(check_PROGRAMS)'; for p in $$list; do \ - f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ - echo " rm -f $$p $$f"; \ - rm -f $$p $$f ; \ - done + @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list dsets$(EXEEXT): $(dsets_OBJECTS) $(dsets_DEPENDENCIES) @rm -f dsets$(EXEEXT) $(CXXLINK) $(dsets_OBJECTS) $(dsets_LDADD) $(LIBS) @@ -441,21 +452,21 @@ distclean-compile: .cpp.o: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< .cpp.obj: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .cpp.lo: @am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< @@ -478,7 +489,7 @@ tags: TAGS TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) - tags=; \ + set x; \ here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ @@ -486,29 +497,34 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ - if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ fi ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) - tags=; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ + test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique + $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags @@ -529,13 +545,17 @@ distdir: $(DISTFILES) if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done @@ -565,6 +585,7 @@ clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @@ -586,6 +607,8 @@ dvi-am: html: html-am +html-am: + info: info-am info-am: @@ -594,18 +617,28 @@ install-data-am: install-dvi: install-dvi-am +install-dvi-am: + install-exec-am: install-html: install-html-am +install-html-am: + install-info: install-info-am +install-info-am: + install-man: install-pdf: install-pdf-am +install-pdf-am: + install-ps: install-ps-am +install-ps-am: + installcheck-am: maintainer-clean: maintainer-clean-am @@ -628,7 +661,7 @@ ps-am: uninstall-am: -.MAKE: install-am install-strip +.MAKE: check-am install-am install-strip .PHONY: CTAGS GTAGS all all-am all-local check check-TESTS check-am \ clean clean-checkPROGRAMS clean-generic clean-libtool ctags \ @@ -858,6 +891,7 @@ check-vfd: $(LIB) $(PROGS) $(TESTS) HDF5_DRIVER=$$vfd $(MAKE) $(AM_MAKEFLAGS) check || exit 1; \ fi; \ done + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/c++/test/tvlstr.cpp b/c++/test/tvlstr.cpp index 2c22903..9722331 100644 --- a/c++/test/tvlstr.cpp +++ b/c++/test/tvlstr.cpp @@ -18,7 +18,6 @@ tvlstr.cpp - HDF5 C++ testing the Variable-Length String functionality EXTERNAL ROUTINES/VARIABLES: - These routines are in the test directory of the C library: ***************************************************************************/ @@ -40,7 +39,7 @@ #include "H5Cpp.h" // C++ API header file #ifndef H5_NO_NAMESPACE -using namespace H5; + using namespace H5; #endif #include "h5cpputil.h" // C++ utilility header file @@ -52,36 +51,36 @@ const H5std_string FILENAME("tvlstr.h5"); const int SPACE1_RANK = 1; const hsize_t SPACE1_DIM1 = 4; -// Utility functions +// Utility functions - not used now, later though. 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. It is passed into setVlenMemManager. +** allocation routines. This routine just uses malloc to +** allocate the memory and increments the amount of memory +** allocated. It is passed into setVlenMemManager. ** ** Note: exact copy from the C version. ** ****************************************************************/ void *test_vlstr_alloc_custom(size_t size, void *info) { - void *ret_value = NULL; // Pointer to return - size_t *mem_used = (size_t *)info; // Get the pointer to the memory used - size_t extra; // Extra space needed + void *ret_value=NULL; // Pointer to return + size_t *mem_used=(size_t *)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(size_t)); + extra=MAX(sizeof(void *),sizeof(size_t)); - if((ret_value = HDmalloc(extra + size)) != NULL) { - *(size_t *)ret_value = size; - *mem_used += size; + if((ret_value=HDmalloc(extra+size))!=NULL) { + *(size_t *)ret_value=size; + *mem_used+=size; } // end if ret_value = ((unsigned char *)ret_value) + extra; @@ -91,9 +90,9 @@ void *test_vlstr_alloc_custom(size_t size, void *info) /**************************************************************** ** ** 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. It is passed into setVlenMemManager. +** allocation routines. This routine just uses free to +** release the memory and decrements the amount of memory +** allocated. It is passed into setVlenMemManager. ** ** Note: exact copy from the C version. ** @@ -102,7 +101,7 @@ void test_vlstr_free_custom(void *_mem, void *info) { unsigned char *mem; size_t *mem_used=(size_t *)info; // Get the pointer to the memory used - size_t extra; // Extra space needed + size_t extra; // Extra space needed /* * This weird contortion is required on the DEC Alpha to keep the @@ -119,9 +118,9 @@ void test_vlstr_free_custom(void *_mem, void *info) } /*------------------------------------------------------------------------- - * Function: test_vlstrings_basic + * Function: test_vlstring_dataset * - * Purpose: Test simple VL string I/O. + * Purpose: Test writing/reading VL strings on datasets. * * Return: None * @@ -130,98 +129,171 @@ void test_vlstr_free_custom(void *_mem, void *info) * *------------------------------------------------------------------------- */ -static void test_vlstrings_basic() +// String for testing datasets +static char *dynstring_ds_write=NULL; +static char stastring_ds_write[1]={'A'}; + +// Info for a string dataset +const H5std_string DSET1_NAME("String_ds"); +const H5std_string DSET1_DATA("String Dataset"); + +static void test_vlstring_dataset() +{ + // Output message about test being performed + SUBTEST("Testing VL String on Datasets"); + + try { + // Open the file + H5File file1(FILENAME, H5F_ACC_TRUNC); + + // Create a datatype to refer to. + StrType vlst(0, H5T_VARIABLE); + + // Open the root group. + Group root = file1.openGroup("/"); + + // Create dataspace for the dataset. + DataSpace ds_space (H5S_SCALAR); + + // Create an dataset in the root group. + DataSet dset1 = root.createDataSet(DSET1_NAME, vlst, ds_space); + + // Write data to the dataset. + dset1.write(DSET1_DATA, vlst); + + // Read and verify the dataset string as a string of chars. + char *string_ds_check; + dset1.read(&string_ds_check, vlst); + if(HDstrcmp(string_ds_check, DSET1_DATA.c_str())!=0) + TestErrPrintf("Line %d: Attribute data different: DSET1_DATA=%s,string_ds_check=%s\n",__LINE__, DSET1_DATA.c_str(), string_ds_check); + + HDfree(string_ds_check); // note: no need for std::string test + + // Read and verify the dataset string as an std::string. + H5std_string read_str; + dset1.read(read_str, vlst); + if (read_str != DSET1_DATA) + TestErrPrintf("Line %d: Attribute data different: DSET1_DATA=%s,read_str=%s\n",__LINE__, DSET1_DATA.c_str(), read_str.c_str()); + + // Close the dataset. + dset1.close(); + + // Test scalar type dataset with 1 value. + dset1 = root.createDataSet("test_scalar_small", vlst, ds_space); + + dynstring_ds_write = (char*)HDcalloc(1, sizeof(char)); + HDmemset(dynstring_ds_write, 'A', 1); + + // Write data to the dataset, then read it back. + dset1.write(&dynstring_ds_write, vlst); + dset1.read(&string_ds_check, vlst); + + // Verify data read. + if(HDstrcmp(string_ds_check,dynstring_ds_write)!=0) + TestErrPrintf("VL string datasets don't match!, dynstring_ds_write=%s, string_ds_check=%s\n",dynstring_ds_write,string_ds_check); + HDfree(string_ds_check); + dset1.close(); + + // Open dataset DSET1_NAME again. + dset1 = root.openDataSet(DSET1_NAME); + + // Close dataset and file + dset1.close(); + file1.close(); + + PASSED(); + } // end try block + + // Catch all exceptions. + catch (Exception E) { + issue_fail_msg("test_vlstring_dataset()", __LINE__, __FILE__, E.getCDetailMsg()); + } +} // test_vlstring_dataset() + +/*------------------------------------------------------------------------- + * Function: test_vlstring_array_dataset + * + * Purpose: Test writing/reading VL string array to/from datasets. + * + * Return: None + * + * Programmer: Binh-Minh Ribler + * July, 2009 + * + *------------------------------------------------------------------------- + */ +const H5std_string DSSTRARR_NAME("StringArray_dset"); +static void test_vlstring_array_dataset() { - 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." + const char *string_ds_array[SPACE1_DIM1]= { + "Line 1", "Line 2", "Line 3", "Line 4" }; // Information to write // Output message about test being performed - SUBTEST("Testing Basic VL String Functionality"); + SUBTEST("Testing VL String Array on Datasets"); - H5File* file1 = NULL; + H5File* file1; try { // Create file. - file1 = new H5File (FILENAME, H5F_ACC_TRUNC); + file1 = new H5File (FILENAME, H5F_ACC_RDWR); - // Create dataspace for datasets. - hsize_t dims1[] = {SPACE1_DIM1}; - DataSpace sid1(SPACE1_RANK, dims1); + // Create dataspace for datasets. + hsize_t dims1[] = {SPACE1_DIM1}; + DataSpace ds_space(SPACE1_RANK, dims1); // Create a datatype to refer to. - StrType tid1(0, H5T_VARIABLE); + StrType vlst(0, H5T_VARIABLE); // Create and write a dataset. - DataSet dataset(file1->createDataSet("Dataset1", tid1, sid1)); - dataset.write(wdata, tid1); + DataSet dataset(file1->createDataSet(DSSTRARR_NAME, vlst, ds_space)); + dataset.write(string_ds_array, vlst); + + // Read and verify the dataset using strings of chars as buffer. + // Note: reading by array of H5std_string doesn't work yet. + char *string_ds_check[SPACE1_DIM1]; + dataset.read(string_ds_check, vlst); + + int ii; + for (ii = 0; ii < SPACE1_DIM1; ii++) + { + if(HDstrcmp(string_ds_check[ii], string_ds_array[ii])!=0) + TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n",__LINE__, string_ds_array[ii], string_ds_check[ii]); + + HDfree(string_ds_check[ii]); + } + + // Close objects that are no longer needed. + dataset.close(); + ds_space.close(); + + // + // Test with scalar data space. + // // Create H5S_SCALAR data space. DataSpace scalar_space; // Create and write another dataset. - DataSet dataset2(file1->createDataSet("Dataset2", tid1, scalar_space)); + DataSet dataset2(file1->createDataSet("Dataset2", vlst, scalar_space)); char *wdata2 = (char*)HDcalloc(65534, sizeof(char)); HDmemset(wdata2, 'A', 65533); - dataset2.write(&wdata2, tid1); + dataset2.write(&wdata2, vlst); + + char *rdata2 = (char*)HDcalloc(65534, sizeof(char)); + HDmemset(rdata2, 0, 65533); + dataset2.read(&rdata2, vlst); + if (HDstrcmp(wdata2, rdata2)!=0) + TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n",__LINE__, wdata2, rdata2); // Release resources from second dataset operation. scalar_space.close(); dataset2.close(); HDfree(wdata2); - - // Change to the custom memory allocation routines for reading - // VL string. - DSetMemXferPropList xfer; - size_t mem_used = 0; // Memory used during allocation - xfer.setVlenMemManager(test_vlstr_alloc_custom, &mem_used, test_vlstr_free_custom, &mem_used); - - // Make certain the correct amount of memory will be used. - hsize_t vlsize = dataset.getVlenBufSize(tid1, sid1); - - // Count the actual number of bytes used by the strings. - size_t str_used; // String data in memory - hsize_t i; // counting variable - for (i=0,str_used=0; i<SPACE1_DIM1; i++) - str_used+=HDstrlen(wdata[i])+1; - - // Compare against the strings actually written. - verify_val((int)vlsize,str_used,"DataSet::getVlenBufSize", __LINE__, __FILE__); - - // Read dataset from disk. - char *rdata[SPACE1_DIM1]; // Data read in - dataset.read(rdata, tid1, DataSpace::ALL, DataSpace::ALL, xfer); - - // Make certain the correct amount of memory has been used. - verify_val(mem_used, str_used, "DataSet::read", __LINE__, __FILE__); - - // Compare data read in. - for(i = 0; i < SPACE1_DIM1; i++) { - size_t wlen = HDstrlen(wdata[i]); - size_t rlen = HDstrlen(rdata[i]); - if(wlen != rlen) { - TestErrPrintf("VL data lengths don't match!, strlen(wdata[%d])=%u, strlen(rdata[%d])=%u\n", (int)i, (unsigned)wlen, (int)i, (unsigned)rlen); - continue; - } // end if - if(HDstrcmp(wdata[i], rdata[i]) != 0) { - TestErrPrintf("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. - DataSet::vlenReclaim((void *)rdata, tid1, sid1, xfer); - - // Make certain the VL memory has been freed. - verify_val(mem_used, 0, "DataSet::vlenReclaim", __LINE__, __FILE__); + HDfree(rdata2); // Close objects and file. - dataset.close(); - tid1.close(); - sid1.close(); - xfer.close(); + dataset2.close(); + vlst.close(); file1->close(); PASSED(); @@ -230,11 +302,10 @@ static void test_vlstrings_basic() // Catch all exceptions. catch (Exception E) { - issue_fail_msg("test_vlstrings_basic()", __LINE__, __FILE__, E.getCDetailMsg()); - if (file1 != NULL) // clean up - delete file1; + issue_fail_msg("test_vlstring_array_dataset()", __LINE__, __FILE__, E.getCDetailMsg()); + delete file1; } -} // end test_vlstrings_basic() +} // end test_vlstring_array_dataset() /*------------------------------------------------------------------------- * Function: test_vlstrings_special @@ -267,26 +338,26 @@ static void test_vlstrings_special() DataSpace sid1(SPACE1_RANK, dims1); // Create a datatype to refer to. - StrType tid1(0, H5T_VARIABLE); + StrType vlst(0, H5T_VARIABLE); // Create a dataset. - DataSet dataset(file1.createDataSet("Dataset3", tid1, sid1)); + DataSet dataset(file1.createDataSet("Dataset3", vlst, sid1)); // Read from the dataset before writing data. - dataset.read(rdata, tid1); + dataset.read(rdata, vlst); // Check data read in. hsize_t i; // counting variable - for(i = 0; i < SPACE1_DIM1; i++) - if(rdata[i] != NULL) + for (i=0; i<SPACE1_DIM1; i++) + if(rdata[i]!=NULL) TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i,rdata[i]); // Write dataset to disk, then read it back. - dataset.write(wdata, tid1); - dataset.read(rdata, tid1); + dataset.write(wdata, vlst); + dataset.read(rdata, vlst); // Compare data read in. - for(i = 0; i < SPACE1_DIM1; i++) { + for (i = 0; i < SPACE1_DIM1; i++) { size_t wlen = HDstrlen(wdata[i]); size_t rlen = HDstrlen(rdata[i]); if(wlen != rlen) { @@ -300,7 +371,7 @@ static void test_vlstrings_special() } // end for // Reclaim the read VL data. - DataSet::vlenReclaim((void *)rdata, tid1, sid1); + DataSet::vlenReclaim((void *)rdata, vlst, sid1); // Close Dataset. dataset.close(); @@ -313,25 +384,25 @@ static void test_vlstrings_special() // dataset. DSetCreatPropList dcpl; char *fill = NULL; // Fill value - dcpl.setFillValue(tid1, &fill); - dataset = file1.createDataSet("Dataset4", tid1, sid1, dcpl); + dcpl.setFillValue(vlst, &fill); + dataset = file1.createDataSet("Dataset4", vlst, sid1, dcpl); // Close dataset creation property list. dcpl.close(); // Read from dataset before writing data. - dataset.read(rdata, tid1); + dataset.read(rdata, vlst); // Check data read in. for (i=0; i<SPACE1_DIM1; i++) - if(rdata[i] != NULL) - TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i, rdata[i]); + if(rdata[i]!=NULL) + TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i,rdata[i]); // Try to write nil strings to disk. - dataset.write(wdata2, tid1); + dataset.write(wdata2, vlst); // Read nil strings back from disk. - dataset.read(rdata, tid1); + dataset.read(rdata, vlst); // Check data read in. for (i=0; i<SPACE1_DIM1; i++) @@ -340,7 +411,7 @@ static void test_vlstrings_special() // Close objects and file. dataset.close(); - tid1.close(); + vlst.close(); sid1.close(); file1.close(); @@ -350,7 +421,7 @@ static void test_vlstrings_special() // Catch all exceptions. catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vlstrings_special()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_vlstrings_special @@ -370,7 +441,7 @@ const H5std_string VLSTR_TYPE("vl_string_type"); static void test_vlstring_type() { // Output message about test being performed. - SUBTEST("Testing VL String type"); + SUBTEST("Testing VL String Type"); H5File* file1 = NULL; try { @@ -378,55 +449,55 @@ static void test_vlstring_type() file1 = new H5File(FILENAME, H5F_ACC_RDWR); // Create a datatype to refer to. - StrType vlstr_type(PredType::C_S1); + StrType vlst(PredType::C_S1); // Change padding and verify it. - vlstr_type.setStrpad(H5T_STR_NULLPAD); - H5T_str_t pad = vlstr_type.getStrpad(); + vlst.setStrpad(H5T_STR_NULLPAD); + H5T_str_t pad = vlst.getStrpad(); verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); // Convert to variable-length string. - vlstr_type.setSize(H5T_VARIABLE); + vlst.setSize(H5T_VARIABLE); // Check if datatype is VL string. - H5T_class_t type_class = vlstr_type.getClass(); + H5T_class_t type_class = vlst.getClass(); verify_val(type_class, H5T_STRING, "DataType::getClass", __LINE__, __FILE__); - bool is_variable_str = vlstr_type.isVariableStr(); - verify_val(is_variable_str, TRUE, "DataType::isVariableStr", __LINE__, __FILE__); + bool is_variable_str = vlst.isVariableStr(); + verify_val(is_variable_str, true, "DataType::isVariableStr", __LINE__, __FILE__); // Check default character set and padding. - H5T_cset_t cset = vlstr_type.getCset(); + H5T_cset_t cset = vlst.getCset(); verify_val(cset, H5T_CSET_ASCII, "StrType::getCset", __LINE__, __FILE__); - pad = vlstr_type.getStrpad(); + pad = vlst.getStrpad(); verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); // Commit variable-length string datatype to storage. - vlstr_type.commit(*file1, VLSTR_TYPE); + vlst.commit(*file1, VLSTR_TYPE); // Close datatype. - vlstr_type.close(); + vlst.close(); // Try opening datatype again. - vlstr_type = file1->openStrType(VLSTR_TYPE); + vlst = file1->openStrType(VLSTR_TYPE); // Close datatype and file. - vlstr_type.close(); + vlst.close(); file1->close(); // Open file. file1 = new H5File(FILENAME, H5F_ACC_RDWR); // Open the variable-length string datatype just created - vlstr_type = file1->openStrType(VLSTR_TYPE); + vlst = file1->openStrType(VLSTR_TYPE); // Verify character set and padding - cset = vlstr_type.getCset(); + cset = vlst.getCset(); verify_val(cset, H5T_CSET_ASCII, "StrType::getCset", __LINE__, __FILE__); - pad = vlstr_type.getStrpad(); + pad = vlst.getStrpad(); verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); // Close datatype and file - vlstr_type.close(); + vlst.close(); file1->close(); PASSED(); @@ -436,6 +507,7 @@ static void test_vlstring_type() catch (Exception E) { issue_fail_msg("test_vlstring_type()", __LINE__, __FILE__, E.getCDetailMsg()); + delete file1; } } // end test_vlstring_type() @@ -454,7 +526,7 @@ static void test_vlstring_type() static void test_compact_vlstring() { // Output message about test being performed - SUBTEST("Testing VL Strings in compact dataset"); + SUBTEST("Testing VL Strings on Compact Dataset"); try { // Create file @@ -465,22 +537,22 @@ static void test_compact_vlstring() DataSpace sid1(SPACE1_RANK, dims1); // Create a datatype to refer to - StrType tid1(0, H5T_VARIABLE); + StrType vlst(0, H5T_VARIABLE); // Create dataset create property list and set layout DSetCreatPropList plist; plist.setLayout(H5D_COMPACT); // Create a dataset - DataSet dataset(file1.createDataSet("Dataset5", tid1, sid1, plist)); + DataSet dataset(file1.createDataSet("Dataset5", vlst, sid1, plist)); // Write dataset to disk const char *wdata[SPACE1_DIM1] = {"one", "two", "three", "four"}; - dataset.write(wdata, tid1); + dataset.write(wdata, vlst); // Read dataset from disk char *rdata[SPACE1_DIM1]; // Information read in - dataset.read(rdata, tid1); + dataset.read(rdata, vlst); // Compare data read in hsize_t i; @@ -496,11 +568,11 @@ static void test_compact_vlstring() } // end for // Reclaim the read VL data - DataSet::vlenReclaim((void *)rdata, tid1, sid1); + DataSet::vlenReclaim((void *)rdata, vlst, sid1); // Close objects and file dataset.close(); - tid1.close(); + vlst.close(); sid1.close(); plist.close(); file1.close(); @@ -516,9 +588,9 @@ static void test_compact_vlstring() } // test_compact_vlstrings /*------------------------------------------------------------------------- - * Function: test_write_vl_string_attribute + * Function: test_vlstring_attribute * - * Purpose: Test writing VL strings as attributes. + * Purpose: Test writing/reading VL strings on attributes. * * Return: None * @@ -527,24 +599,24 @@ static void test_compact_vlstring() * *------------------------------------------------------------------------- */ -// String for testing attributes +// String for writing to attribute static char *string_att_write=NULL; // Info for a string attribute const H5std_string ATTRSTR_NAME("String_attr"); const H5std_string ATTRSTR_DATA("String Attribute"); -static void test_write_vl_string_attribute() +static void test_vlstring_attribute() { // Output message about test being performed - SUBTEST("Testing writing VL String as attributes"); + SUBTEST("Testing VL String on Attributes"); try { // Open the file H5File file1(FILENAME, H5F_ACC_RDWR); // Create a datatype to refer to. - StrType tid1(0, H5T_VARIABLE); + StrType vlst(0, H5T_VARIABLE); // Open the root group. Group root = file1.openGroup("/"); @@ -553,14 +625,14 @@ static void test_write_vl_string_attribute() DataSpace att_space (H5S_SCALAR); // Create an attribute for the root group. - Attribute gr_attr = root.createAttribute(ATTRSTR_NAME, tid1, att_space); + Attribute gr_attr = root.createAttribute(ATTRSTR_NAME, vlst, att_space); // Write data to the attribute. - gr_attr.write(tid1, ATTRSTR_DATA); + gr_attr.write(vlst, ATTRSTR_DATA); // Read and verify the attribute string as a string of chars. char *string_att_check; - gr_attr.read(tid1, &string_att_check); + gr_attr.read(vlst, &string_att_check); if(HDstrcmp(string_att_check, ATTRSTR_DATA.c_str())!=0) TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,string_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), string_att_check); @@ -568,7 +640,7 @@ static void test_write_vl_string_attribute() // Read and verify the attribute string as an std::string. H5std_string read_str; - gr_attr.read(tid1, read_str); + gr_attr.read(vlst, read_str); if (read_str != ATTRSTR_DATA) TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_str=%s\n",__LINE__, ATTRSTR_DATA.c_str(), read_str.c_str()); @@ -576,28 +648,22 @@ static void test_write_vl_string_attribute() gr_attr.close(); // Test creating a "large" sized string attribute - gr_attr = root.createAttribute("test_scalar_large", tid1, att_space); + gr_attr = root.createAttribute("test_scalar_large", vlst, att_space); string_att_write = (char*)HDcalloc(8192, sizeof(char)); HDmemset(string_att_write, 'A', 8191); // Write data to the attribute, then read it back. - gr_attr.write(tid1, &string_att_write); - gr_attr.read(tid1, &string_att_check); + gr_attr.write(vlst, &string_att_write); + gr_attr.read(vlst, &string_att_check); // Verify data read. if(HDstrcmp(string_att_check,string_att_write)!=0) TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check); - HDfree(string_att_check); - gr_attr.close(); - // Open attribute ATTRSTR_NAME again. - gr_attr = root.openAttribute(ATTRSTR_NAME); - - // The attribute string written is freed below, in the - // test_read_vl_string_attribute() test - - // Close attribute and file + // Release resources. + HDfree(string_att_check); + HDfree(string_att_write); gr_attr.close(); file1.close(); @@ -606,9 +672,9 @@ static void test_write_vl_string_attribute() // Catch all exceptions. catch (Exception E) { - issue_fail_msg("test_string_attr()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vlstring_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); } -} // test_string_attr() +} // test_vlstring_attribute() /*------------------------------------------------------------------------- * Function: test_read_vl_string_attribute @@ -633,7 +699,7 @@ static void test_read_vl_string_attribute() H5File file1(FILENAME, H5F_ACC_RDONLY); // Create a datatype to refer to. - StrType tid1(0, H5T_VARIABLE); + StrType vlst(0, H5T_VARIABLE); // Open the root group and its attribute named ATTRSTR_NAME. Group root = file1.openGroup("/"); @@ -641,7 +707,7 @@ static void test_read_vl_string_attribute() // Test reading "normal" sized string attribute char *string_att_check; - att.read(tid1, &string_att_check); + att.read(vlst, &string_att_check); if(HDstrcmp(string_att_check,ATTRSTR_DATA.c_str())!=0) TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",ATTRSTR_DATA.c_str(),string_att_check); HDfree(string_att_check); @@ -649,7 +715,7 @@ static void test_read_vl_string_attribute() // Test reading "large" sized string attribute att = root.openAttribute("test_scalar_large"); - att.read(tid1, &string_att_check); + att.read(vlst, &string_att_check); if(HDstrcmp(string_att_check,string_att_write)!=0) TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check); HDfree(string_att_check); @@ -657,7 +723,7 @@ static void test_read_vl_string_attribute() // Close objects and file. att.close(); - tid1.close(); + vlst.close(); root.close(); file1.close(); @@ -670,6 +736,76 @@ static void test_read_vl_string_attribute() } } // test_read_vl_string_attribute +/*------------------------------------------------------------------------- + * Function: test_vlstring_array_attribute + * + * Purpose: Test writing/reading VL string array to/from attributes. + * + * Return: None + * + * Programmer: Binh-Minh Ribler + * July, 2009 + * + *------------------------------------------------------------------------- + */ +const H5std_string ATTRSTRARR_NAME("StringArray_attr"); + +static void test_vlstring_array_attribute() +{ + const char *string_att_array[SPACE1_DIM1]= { + "Line 1", "Line 2", "Line 3", "Line 4" + }; // Information to write + + // Output message about test being performed + SUBTEST("Testing VL String Array on Attributes"); + + try { + // Open the file + H5File file1(FILENAME, H5F_ACC_RDWR); + + // Create a datatype to refer to. + StrType vlst(0, H5T_VARIABLE); + + // Open the root group. + Group root = file1.openGroup("/"); + + // Create dataspace for datasets. + hsize_t dims1[] = {SPACE1_DIM1}; + DataSpace att_space(SPACE1_RANK, dims1); + + // Create an attribute for the root group. + Attribute gr_attr = root.createAttribute(ATTRSTRARR_NAME, vlst, att_space); + + // Write data to the attribute. + gr_attr.write(vlst, string_att_array); + + // Read and verify the attribute string as a string of chars. + // Note: reading by array of H5std_string doesn't work yet. + char *string_att_check[SPACE1_DIM1]; + gr_attr.read(vlst, &string_att_check); + + int ii; + for (ii = 0; ii < SPACE1_DIM1; ii++) + { + if(HDstrcmp(string_att_check[ii], string_att_array[ii])!=0) + TestErrPrintf("Line %d: Attribute data different: written=%s,read=%s\n",__LINE__, string_att_check[ii], string_att_check[ii]); + + HDfree(string_att_check[ii]); // note: no need for std::string test + } + + // Close group's attribute. + gr_attr.close(); + file1.close(); + + PASSED(); + } // end try block + + // Catch all exceptions. + catch (Exception E) { + issue_fail_msg("test_vlstring_array_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); + } +} // test_vlstring_array_attribute() + /* Helper routine for test_vl_rewrite() */ static void write_scalar_dset(H5File& file, DataType& type, DataSpace& space, char *name, char *data) @@ -814,14 +950,17 @@ void test_vlstrings() // These tests use the same file // Test basic VL string datatype - test_vlstrings_basic(); + test_vlstring_dataset(); test_vlstrings_special(); test_vlstring_type(); test_compact_vlstring(); // Test using VL strings in attributes - test_write_vl_string_attribute(); - test_read_vl_string_attribute(); + test_vlstring_attribute(); + + // Test using VL string array in attributes and datasets + test_vlstring_array_attribute(); + test_vlstring_array_dataset(); // Test writing VL datasets in files with lots of unlinking test_vl_rewrite(); |