summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2007-01-29 02:41:27 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2007-01-29 02:41:27 (GMT)
commit38480e665742a86bd50fad08360ea3e5bde5db9d (patch)
tree3c128222deda0096e081728aa71f2ba72f2a480f /c++
parentf94e51f7c14f8eb29d96790de4b973d5059902a6 (diff)
downloadhdf5-38480e665742a86bd50fad08360ea3e5bde5db9d.zip
hdf5-38480e665742a86bd50fad08360ea3e5bde5db9d.tar.gz
hdf5-38480e665742a86bd50fad08360ea3e5bde5db9d.tar.bz2
[svn-r13210] Purpose: Adding test
Description: - Added a brief test for DSetCreatPropList::setSzip. More through tests will be added later. - Moved check_values from dsets.cpp into h5cpputil.cpp for sharing with other tests. Platforms tested AIX 5.1 (copper) SunOS 5.8 64-bit (sol) Linux 2.6 (kagiso)
Diffstat (limited to 'c++')
-rw-r--r--c++/test/Makefile.am4
-rw-r--r--c++/test/Makefile.in11
-rw-r--r--c++/test/dsets.cpp35
-rw-r--r--c++/test/h5cpputil.cpp33
-rw-r--r--c++/test/h5cpputil.h3
-rw-r--r--c++/test/testhdf5.cpp1
-rw-r--r--c++/test/tfilter.cpp294
7 files changed, 339 insertions, 42 deletions
diff --git a/c++/test/Makefile.am b/c++/test/Makefile.am
index 103d55b..2c4a7dc 100644
--- a/c++/test/Makefile.am
+++ b/c++/test/Makefile.am
@@ -37,8 +37,8 @@ check_PROGRAMS=$(TEST_PROG)
LDADD=$(LIBH5CPP) $(LIBH5TEST) $(LIBHDF5)
dsets_SOURCES=dsets.cpp h5cpputil.cpp
-testhdf5_SOURCES=testhdf5.cpp tattr.cpp tcompound.cpp tfile.cpp th5s.cpp \
- trefer.cpp ttypes.cpp tvlstr.cpp h5cpputil.cpp
+testhdf5_SOURCES=testhdf5.cpp tattr.cpp tcompound.cpp tfile.cpp tfilter.cpp \
+ th5s.cpp trefer.cpp ttypes.cpp tvlstr.cpp h5cpputil.cpp
# Tell conclude.am that these are C++ tests.
HDF_CXX=yes
diff --git a/c++/test/Makefile.in b/c++/test/Makefile.in
index e9684fd..1e8c5bb 100644
--- a/c++/test/Makefile.in
+++ b/c++/test/Makefile.in
@@ -73,9 +73,9 @@ am__DEPENDENCIES_3 = $(top_builddir)/src/libhdf5.la
dsets_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
$(am__DEPENDENCIES_3)
am_testhdf5_OBJECTS = testhdf5.$(OBJEXT) tattr.$(OBJEXT) \
- tcompound.$(OBJEXT) tfile.$(OBJEXT) th5s.$(OBJEXT) \
- trefer.$(OBJEXT) ttypes.$(OBJEXT) tvlstr.$(OBJEXT) \
- h5cpputil.$(OBJEXT)
+ tcompound.$(OBJEXT) tfile.$(OBJEXT) tfilter.$(OBJEXT) \
+ th5s.$(OBJEXT) trefer.$(OBJEXT) ttypes.$(OBJEXT) \
+ tvlstr.$(OBJEXT) h5cpputil.$(OBJEXT)
testhdf5_OBJECTS = $(am_testhdf5_OBJECTS)
testhdf5_LDADD = $(LDADD)
testhdf5_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
@@ -346,8 +346,8 @@ TEST_PROG = dsets testhdf5
# The tests depend on the hdf5 library, test library, and the c++ library
LDADD = $(LIBH5CPP) $(LIBH5TEST) $(LIBHDF5)
dsets_SOURCES = dsets.cpp h5cpputil.cpp
-testhdf5_SOURCES = testhdf5.cpp tattr.cpp tcompound.cpp tfile.cpp th5s.cpp \
- trefer.cpp ttypes.cpp tvlstr.cpp h5cpputil.cpp
+testhdf5_SOURCES = testhdf5.cpp tattr.cpp tcompound.cpp tfile.cpp tfilter.cpp \
+ th5s.cpp trefer.cpp ttypes.cpp tvlstr.cpp h5cpputil.cpp
# Tell conclude.am that these are C++ tests.
@@ -428,6 +428,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcompound.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testhdf5.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tfile.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tfilter.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/th5s.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/trefer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttypes.Po@am__quote@
diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp
index c82dc7f..602fb57 100644
--- a/c++/test/dsets.cpp
+++ b/c++/test/dsets.cpp
@@ -182,41 +182,6 @@ test_create( H5File& file)
} // test_create
/*-------------------------------------------------------------------------
- * Function: check_values
- *
- * Purpose: Checks a read value against the written value. If they are
- * different, the function will print out a message and the
- * different values. This function is made to reuse the code
- * segment that is used in various places throughout
- * test_compression and in test_simple_io. Where the C version
- * of this code segment "goto error," this function will
- * return -1.
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Binh-Minh Ribler (using C code segment for checking values)
- * Friday, February 6, 2001
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static int
-check_values (hsize_t i, hsize_t j, int apoint, int acheck)
-{
- if (apoint != acheck)
- {
- cerr << " Read different values than written.\n" << endl;
- cerr << " At index " << (unsigned long)i << "," <<
- (unsigned long)j << endl;
- return -1;
- }
- return 0;
-} // check_values
-
-/*-------------------------------------------------------------------------
* Function: test_simple_io
*
* Purpose: Tests simple I/O. That is, reading and writing a complete
diff --git a/c++/test/h5cpputil.cpp b/c++/test/h5cpputil.cpp
index e1c3468..e328d39 100644
--- a/c++/test/h5cpputil.cpp
+++ b/c++/test/h5cpputil.cpp
@@ -104,6 +104,39 @@ void issue_fail_msg(const char* where, int line, const char* file_name,
}
}
+/*-------------------------------------------------------------------------
+ * Function: check_values
+ *
+ * Purpose: Checks a read value against the written value. If they are
+ * different, the function will print out a message and the
+ * different values. This function is made to reuse the code
+ * segment that is used in various places throughout
+ * the test code. Where the C version of this code segment
+ * "goto error," this function will return -1.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Binh-Minh Ribler (using C code segment for checking values)
+ * Friday, February 6, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int check_values (hsize_t i, hsize_t j, int apoint, int acheck)
+{
+ if (apoint != acheck)
+ {
+ cerr << " Read different values than written.\n" << endl;
+ cerr << " At index " << (unsigned long)i << "," <<
+ (unsigned long)j << endl;
+ return -1;
+ }
+ return 0;
+} // check_values
+
//--------------------------------------------------------------------------
// Function: InvalidActionException default constructor
//--------------------------------------------------------------------------
diff --git a/c++/test/h5cpputil.h b/c++/test/h5cpputil.h
index 7aa77a9..ce2f4c7 100644
--- a/c++/test/h5cpputil.h
+++ b/c++/test/h5cpputil.h
@@ -36,6 +36,7 @@ using std::endl;
#define SUBTEST(WHAT) {printf(" Subtest: %-52s",WHAT); fflush(stdout);}
+int check_values (hsize_t i, hsize_t j, int apoint, int acheck);
int test_report (int, const H5std_string&);
void issue_fail_msg(const char* where, int line, const char* file_name,
const char* message="");
@@ -96,6 +97,7 @@ class InvalidActionException : public Exception {
void test_attr(void);
void test_compound(void);
void test_file(void);
+void test_filters(void);
void test_h5s(void);
void test_reference(void);
void test_types(void);
@@ -105,6 +107,7 @@ void test_vlstrings(void);
void cleanup_attr(void);
void cleanup_compound(void);
void cleanup_file(void);
+void cleanup_filters(void);
void cleanup_h5s(void);
void cleanup_reference(void);
void cleanup_types(void);
diff --git a/c++/test/testhdf5.cpp b/c++/test/testhdf5.cpp
index 22d14b1..a802e19 100644
--- a/c++/test/testhdf5.cpp
+++ b/c++/test/testhdf5.cpp
@@ -83,6 +83,7 @@ main(int argc, char *argv[])
AddTest("vlstrings", test_vlstrings, cleanup_vlstrings, "Variable-Length Strings", NULL);
AddTest("types", test_types, cleanup_types, "Generic Data Types", NULL);
AddTest("compound", test_compound, cleanup_compound, "Compound Data Types", NULL);
+ AddTest("filter", test_filters, cleanup_filters, "Various Filters", NULL);
/* Comment out tests that are not done yet. - BMR, Feb 2001
AddTest("select", test_select, cleanup_select, "Selections", NULL);
AddTest("time", test_time, cleanup_time, "Time Datatypes", NULL);
diff --git a/c++/test/tfilter.cpp b/c++/test/tfilter.cpp
new file mode 100644
index 0000000..2f6838b
--- /dev/null
+++ b/c++/test/tfilter.cpp
@@ -0,0 +1,294 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group (THG). *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://www.hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*****************************************************************************
+ FILE
+ tfilter.cpp - HDF5 C++ testing various filters and their combination.
+
+ ***************************************************************************/
+
+#ifdef OLD_HEADER_FILENAME
+#include <iostream.h>
+#else
+#include <iostream>
+#endif
+#include <string>
+
+#ifndef H5_NO_NAMESPACE
+#ifndef H5_NO_STD
+ using std::cerr;
+ using std::endl;
+#endif // H5_NO_STD
+#endif
+
+#include "testhdf5.h" // C test header file
+#include "H5Cpp.h" // C++ API header file
+
+#ifndef H5_NO_NAMESPACE
+ using namespace H5;
+#endif
+
+#include "h5cpputil.h" // C++ utilility header file
+
+#define DSET_DIM1 100
+#define DSET_DIM2 200
+#define FILTER_CHUNK_DIM1 2
+#define FILTER_CHUNK_DIM2 25
+
+// will do this function later or use it as guideline - BMR - 2007/01/26
+static herr_t test_filter_internal(hid_t fid, const char *name, hid_t dcpl,
+ int if_fletcher32, int corrupted, hsize_t *dset_size)
+{
+ cerr << "do nothing right now" << endl;
+ return(0);
+}
+
+/* Temporary filter IDs used for testing */
+#define H5Z_FILTER_BOGUS 305
+static size_t filter_bogus(unsigned int flags, size_t cd_nelmts,
+ const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf);
+/* This message derives from H5Z */
+const H5Z_class_t H5Z_BOGUS[1] = {{
+ H5Z_CLASS_T_VERS, /* H5Z_class_t version */
+ H5Z_FILTER_BOGUS, /* Filter id number */
+ 1, 1, /* Encoding and decoding enabled */
+ "bogus", /* Filter name for debugging */
+ NULL, /* The "can apply" callback */
+ NULL, /* The "set local" callback */
+ filter_bogus, /* The actual filter function */
+}};
+
+/*-------------------------------------------------------------------------
+ * Function: filter_bogus
+ *
+ * Purpose: A bogus compression method that doesn't do anything.
+ *
+ * Return: Success: Data chunk size
+ *
+ * Failure: 0
+ *
+ * Programmer: Robb Matzke
+ * Tuesday, April 21, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static size_t
+filter_bogus(unsigned int UNUSED flags, size_t UNUSED cd_nelmts,
+ const unsigned int UNUSED *cd_values, size_t nbytes,
+ size_t UNUSED *buf_size, void UNUSED **buf)
+{
+ return nbytes;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: test_null_filter
+ *
+ * Purpose: Test null I/O filter by itself.
+ *
+ * Return: None
+ *
+ * Programmer: Binh-Minh Ribler (use C version, from dsets.c/test_filters)
+ * January, 2007
+ *
+ * Modifications:
+ * Note: H5Z interface is not implemented yet.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+// Chunk dimensions
+const hsize_t chunk_size[2] = {FILTER_CHUNK_DIM1, FILTER_CHUNK_DIM2};
+
+static void test_null_filter(void)
+{
+ // Output message about test being performed
+ SUBTEST("'Null' filter");
+
+ try
+ {
+ hsize_t null_size; // Size of dataset with null filter
+
+ // Prepare dataset create property list
+ DSetCreatPropList dsplist;
+ dsplist.setChunk(2, chunk_size);
+
+ if (H5Zregister (H5Z_BOGUS)<0)
+ throw Exception("test_null_filter", "H5Zregister failed");
+
+ // Set some pretent filter
+ dsplist.setFilter(H5Z_FILTER_BOGUS);
+
+ // this function is just a stub right now; will work on it later - BMR
+ //if(test_filter_internal(file,DSET_BOGUS_NAME,dc,DISABLE_FLETCHER32,DATA_NOT_CORRUPTED,&null_size)<0)
+ // throw Exception("test_null_filter", "test_filter_internal failed");
+
+ // Close objects.
+ dsplist.close();
+ PASSED();
+ } // end of try
+
+ // catch all other exceptions
+ catch (Exception E)
+ {
+ issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
+ }
+} // test_null_filter
+
+/*-------------------------------------------------------------------------
+ * Function: test_szip_filter
+ *
+ * Purpose: Test SZIP filter by itself.
+ *
+ * Return: None
+ *
+ * Programmer: Binh-Minh Ribler (partly from dsets.c/test_filters)
+ * January, 2007
+ *
+ * Modifications:
+ * Note: H5Z interface is not implemented yet.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+const H5std_string DSET_SZIP_NAME("szipped dataset");
+
+void test_szip_filter(H5File& file1)
+{
+#ifdef H5_HAVE_FILTER_SZIP
+ int points[DSET_DIM1][DSET_DIM2], check[DSET_DIM1][DSET_DIM2];
+ hsize_t szip_size; /* Size of dataset with szip filter */
+ unsigned szip_options_mask=H5_SZIP_NN_OPTION_MASK;
+ unsigned szip_pixels_per_block=4;
+
+ // Output message about test being performed
+ SUBTEST("szip filter (with encoder)");
+ if ( h5_szip_can_encode() == 1) {
+ char* tconv_buf = new char [1000];
+ try
+ {
+ const hsize_t size[2] = {DSET_DIM1, DSET_DIM2};
+
+ // Create the data space
+ DataSpace space1(2, size, NULL);
+
+ // Create a small conversion buffer to test strip mining (?)
+ DSetMemXferPropList xfer;
+ xfer.setBuffer (1000, tconv_buf, NULL);
+
+ // Prepare dataset create property list
+ DSetCreatPropList dsplist;
+ dsplist.setChunk(2, chunk_size);
+
+ // Set up for szip compression
+ dsplist.setSzip(szip_options_mask, szip_pixels_per_block);
+
+ // Create a dataset with szip compression
+ DataSpace space2 (2, size, NULL);
+ DataSet dataset(file1.createDataSet (DSET_SZIP_NAME, PredType::NATIVE_INT, space2, dsplist));
+
+ hsize_t i, j, n;
+ for (i=n=0; i<size[0]; i++)
+ {
+ for (j=0; j<size[1]; j++)
+ {
+ points[i][j] = n++;
+ }
+ }
+
+ // Write to the dataset then read back the values
+ dataset.write ((void*)points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+ dataset.read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+
+ // Check that the values read are the same as the values written
+ for (i = 0; i < size[0]; i++)
+ for (j = 0; j < size[1]; j++)
+ {
+ int status = check_values (i, j, points[i][j], check[i][j]);
+ if (status == -1)
+ throw Exception("test_szip_filter", "Failed in testing szip method");
+ }
+ dsplist.close();
+ } // end of try
+
+ // catch all other exceptions
+ catch (Exception E)
+ {
+ issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
+ }
+ }
+ else {
+ SKIPPED();
+ }
+
+#else /* H5_HAVE_FILTER_SZIP */
+ SUBTEST("szip filter");
+ SKIPPED();
+ puts(" Szip filter not enabled");
+#endif /* H5_HAVE_FILTER_SZIP */
+} // test_szip_filter
+
+
+/****************************************************************
+**
+** test_filters(): Main routine for testing filters.
+**
+****************************************************************/
+const H5std_string FILE1("tfilters.h5");
+void test_filters(void)
+{
+ // Output message about test being performed
+ MESSAGE(5, ("Testing Various Filters\n"));
+
+ hid_t fapl_id;
+ fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template
+
+ int nerrors=0; // keep track of number of failures occurr
+ try
+ {
+ // Use the file access template id to create a file access prop. list
+ FileAccPropList fapl(fapl_id);
+
+ H5File file1(FILE1, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl);
+
+ // Test basic VL string datatype
+ test_null_filter();
+ test_szip_filter(file1);
+ }
+ catch (Exception E)
+ {
+ issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
+ }
+} // test_filters()
+
+/*-------------------------------------------------------------------------
+ * Function: cleanup_filters
+ *
+ * Purpose: Cleanup temporary test files
+ *
+ * Return: none
+ *
+ * Programmer: Quincey Koziol
+ * September 10, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+cleanup_filters(void)
+{
+ HDremove(FILE1.c_str());
+}