summaryrefslogtreecommitdiffstats
path: root/c++/test
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2007-01-30 17:18:23 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2007-01-30 17:18:23 (GMT)
commit5eaedeaaeb5e35126e05bbb15441e8f4f11d4cad (patch)
tree06703771610e0bc7e7c7c88cd1cdf480703f7368 /c++/test
parented25baa0f15f539cc47be0b232b39103fe9bb7fc (diff)
downloadhdf5-5eaedeaaeb5e35126e05bbb15441e8f4f11d4cad.zip
hdf5-5eaedeaaeb5e35126e05bbb15441e8f4f11d4cad.tar.gz
hdf5-5eaedeaaeb5e35126e05bbb15441e8f4f11d4cad.tar.bz2
[svn-r13221] 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++/test')
-rw-r--r--c++/test/Makefile.in4
-rw-r--r--c++/test/dsets.cpp36
-rw-r--r--c++/test/h5cpputil.cpp37
-rw-r--r--c++/test/h5cpputil.h52
-rw-r--r--c++/test/testhdf5.cpp6
-rw-r--r--c++/test/tfilter.cpp339
-rw-r--r--c++/test/trefer.cpp19
7 files changed, 441 insertions, 52 deletions
diff --git a/c++/test/Makefile.in b/c++/test/Makefile.in
index 07d808a..85b9985 100644
--- a/c++/test/Makefile.in
+++ b/c++/test/Makefile.in
@@ -39,8 +39,8 @@ LT_LINK_LIB=$(LT) --mode=link $(CXX) -rpath $(libdir)
## executed, generally most specific tests to least specific tests.
RUNTEST=$(LT_RUN)
-TESTHDF5_SRC=testhdf5.cpp tattr.cpp tfile.cpp th5s.cpp trefer.cpp \
- tvlstr.cpp h5cpputil.cpp
+TESTHDF5_SRC=testhdf5.cpp tattr.cpp tfile.cpp tfilter.cpp th5s.cpp \
+ trefer.cpp tvlstr.cpp h5cpputil.cpp
TESTHDF5_OBJ=$(TESTHDF5_SRC:.cpp=.lo)
TEST_SRC=dsets.cpp $(TESTHDF5_SRC)
diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp
index 7cb0587..1b08874 100644
--- a/c++/test/dsets.cpp
+++ b/c++/test/dsets.cpp
@@ -180,41 +180,7 @@ test_create( H5File& file)
return -1;
}
} // 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
diff --git a/c++/test/h5cpputil.cpp b/c++/test/h5cpputil.cpp
index 3ca0d5c..7fa32d0 100644
--- a/c++/test/h5cpputil.cpp
+++ b/c++/test/h5cpputil.cpp
@@ -96,13 +96,46 @@ int test_report( int nerrors, const H5std_string& testname )
void issue_fail_msg(const char* where, int line, const char* file_name,
const char* message)
{
- if (GetTestVerbosity()>=VERBO_HI)
+ //if (GetTestVerbosity()>=VERBO_HI)
{
- cerr << "--> From " << where << " at line " << line
+ cerr << "ERROR>>> From " << where << " at line " << line
<< " in " << file_name << " - " << message << endl << endl;
}
}
+/*-------------------------------------------------------------------------
+ * 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 7d029e5..a86326d 100644
--- a/c++/test/h5cpputil.h
+++ b/c++/test/h5cpputil.h
@@ -30,13 +30,14 @@ using namespace H5;
#endif
#ifndef H5_NO_STD
-int test_report (int, const H5std_string&);
using std::cerr;
using std::endl;
-#else
-int test_report (int, const H5std_string&);
#endif
+#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="");
@@ -69,6 +70,22 @@ template <class Type1, class Type2>
}
}
+template <class Type1, class Type2>
+ void verify_val_noteq(Type1 x, Type2 value, const char* where, int line, const char* file_name)
+{
+ if (GetTestVerbosity()>=VERBO_HI)
+ {
+ cerr << " Call to routine: " << where << " at line " << line
+ << " in " << file_name << " had value " << x << endl;
+ }
+ if (x == value)
+ {
+ cerr << "*** UNEXPECTED VALUE from " << where << " should not be "
+ << value << " at line " << line << " in " << file_name << endl;
+ IncTestNumErrs();
+ }
+}
+
class InvalidActionException : public Exception {
public:
InvalidActionException(const H5std_string func_name, const H5std_string message = DEFAULT_MSG);
@@ -76,4 +93,33 @@ class InvalidActionException : public Exception {
virtual ~InvalidActionException();
};
+/* Prototypes for the test routines */
+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);
+void test_vlstrings(void);
+
+/* Prototypes for the cleanup routines */
+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);
+void cleanup_vlstrings(void);
+/* not yet
+void cleanup_select(void);
+void cleanup_time(void);
+void cleanup_vltypes(void);
+void cleanup_iterate(void);
+void cleanup_array(void);
+void cleanup_genprop(void);
+void cleanup_misc(void);
+*/
+
#endif
diff --git a/c++/test/testhdf5.cpp b/c++/test/testhdf5.cpp
index f157000..e55eeac 100644
--- a/c++/test/testhdf5.cpp
+++ b/c++/test/testhdf5.cpp
@@ -63,6 +63,8 @@
using namespace H5;
#endif /* !H5_NO_NAMESPACE */
+#include "h5cpputil.h" // C++ utilility header file
+
int
main(int argc, char *argv[])
{
@@ -79,6 +81,7 @@ main(int argc, char *argv[])
AddTest("reference", test_reference, cleanup_reference, "References", NULL);
// testing variable-length strings in tvlstr.cpp
AddTest("vlstrings", test_vlstrings, cleanup_vlstrings, "Variable-Length Strings", 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);
@@ -86,6 +89,9 @@ main(int argc, char *argv[])
AddTest("iterate", test_iterate, cleanup_iterate, "Group & Attribute Iteration", NULL);
AddTest("array", test_array, cleanup_array, "Array Datatypes", NULL);
AddTest("genprop", test_genprop, cleanup_genprop, "Generic Properties", NULL);
+ AddTest("types", test_types, cleanup_types, "Generic Data Types", NULL);
+ AddTest("compound", test_compound, cleanup_compound, "Compound Data Types", NULL);
+
Comment out tests that are not done yet */
/* Display testing information */
diff --git a/c++/test/tfilter.cpp b/c++/test/tfilter.cpp
new file mode 100644
index 0000000..3dbce4f
--- /dev/null
+++ b/c++/test/tfilter.cpp
@@ -0,0 +1,339 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+
+ Note: This test file is not complete; it is made to test briefly the
+ szip addition to the C++ library. More through tests and organization
+ will be done later - BMR 2007/1/30
+ ***************************************************************************/
+
+#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_FILTER_BOGUS, /* Filter id number */
+ "bogus", /* Filter name for debugging */
+ NULL, /* The "can apply" callback */
+ NULL, /* The "set local" callback */
+ filter_bogus, /* The actual filter function */
+}};
+
+#ifndef H5_WANT_H5_V1_4_COMPAT
+static herr_t can_apply_bogus(hid_t dcpl_id, hid_t type_id, hid_t space_id);
+
+/* This message derives from H5Z */
+const H5Z_class_t H5Z_CAN_APPLY_TEST[1] = {{
+ H5Z_FILTER_BOGUS, /* Filter id number */
+ "bogus", /* Filter name for debugging */
+ can_apply_bogus, /* The "can apply" callback */
+ NULL, /* The "set local" callback */
+ filter_bogus, /* The actual filter function */
+}};
+
+/*-------------------------------------------------------------------------
+ * Function: can_apply_bogus
+ *
+ * Purpose: A bogus 'can apply' callback that returns 0 for H5T_NATIVE_DOUBLE
+ * dataype, but returns 1 for all other datatypes
+ *
+ * Return: Success: Described above
+ * Failure: 0
+ *
+ * Programmer: Quincey Koziol
+ * Friday, April 5, 2003
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+can_apply_bogus(hid_t UNUSED dcpl_id, hid_t type_id, hid_t UNUSED space_id)
+{
+ if(H5Tequal(type_id,H5T_NATIVE_DOUBLE))
+ return 0;
+ else
+ return 1;
+}
+#endif
+
+/*-------------------------------------------------------------------------
+ * 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);
+
+#ifdef H5_WANT_H5_V1_4_COMPAT
+ if (H5Zregister (H5Z_FILTER_BOGUS, "bogus", filter_bogus)<0)
+ throw Exception("test_null_filter", "H5Zregister failed");
+#else /* H5_WANT_H5_V1_4_COMPAT */
+ if (H5Zregister (H5Z_BOGUS)<0)
+ throw Exception("test_null_filter", "H5Zregister failed");
+#endif /* H5_WANT_H5_V1_4_COMPAT */
+
+
+ // 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());
+}
diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp
index 689de03..bf99837 100644
--- a/c++/test/trefer.cpp
+++ b/c++/test/trefer.cpp
@@ -12,13 +12,12 @@
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-/***********************************************************
-*
-* Test program: trefer
-*
-* Test the Reference functionality
-*
-*************************************************************/
+/*****************************************************************************
+ FILE
+ trefer.cpp - HDF5 C++ testing the functionalities associated with the C
+ Reference interface (H5R)
+
+ ***************************************************************************/
#ifdef OLD_HEADER_FILENAME
#include <iostream.h>
@@ -38,7 +37,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
@@ -230,9 +229,9 @@ test_reference_obj(void)
// Dereference group object by ctor and using dataset to specify
// location
Group new_group(dataset, &rbuf[2]);
- H5std_string read_comment3 = group.getComment(".", 10);
+ H5std_string read_comment3 = new_group.getComment(".", 10);
verify_val(read_comment3, write_comment, "Group::getComment", __LINE__, __FILE__);
- group.close();
+ new_group.close();
// Dereference datatype object from the location where 'dataset'
// is located