summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2005-01-31 04:10:37 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2005-01-31 04:10:37 (GMT)
commit907b69fa636715660c0a4e1b7130d0d2bf8c9b53 (patch)
tree804fcdc0adead921d08c98ba8b10a0a514a0d64a /c++
parent29f00f779ddc337639d208e64378ad7f789e72e1 (diff)
downloadhdf5-907b69fa636715660c0a4e1b7130d0d2bf8c9b53.zip
hdf5-907b69fa636715660c0a4e1b7130d0d2bf8c9b53.tar.gz
hdf5-907b69fa636715660c0a4e1b7130d0d2bf8c9b53.tar.bz2
[svn-r9891] Purpose: Clean up tests
Description: + C tests' macro VERIFY casts values to 'long' for all cases. Since there are no operator<< for 'long long' or int64 in VS C++ ostream, I casted the hsize_t/hssize_t values passed to verify_val to 'long' as well. If problems arise later, this may have to be specificly handled with an overload - tfile.cpp and th5s.cpp + Added the use of InvalidActionException for when an action should cause an exception but didn't + Properly cleanup dynamically allocated memory in failure cases, for in some cases, the execution continues on after the failures were reported. + Small changes to improve failure reports Platforms tested: SunOS 5.7 (arabica) Linux 2.4 (eirene)
Diffstat (limited to 'c++')
-rw-r--r--c++/test/dsets.cpp159
-rw-r--r--c++/test/h5cpputil.cpp47
-rw-r--r--c++/test/h5cpputil.h21
-rw-r--r--c++/test/tfile.cpp224
-rw-r--r--c++/test/th5s.cpp156
5 files changed, 361 insertions, 246 deletions
diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp
index 8903cd7..3f3be4b 100644
--- a/c++/test/dsets.cpp
+++ b/c++/test/dsets.cpp
@@ -21,7 +21,6 @@
These routines are in the test directory of the C library:
h5_reset() -- in h5test.c, resets the library by closing it
h5_fileaccess() -- in h5test.c, returns a file access template
- h5_fixname() -- in h5test.c, create a file name from a file base name
h5_cleanup() -- in h5test.c, cleanup temporary test files
***************************************************************************/
@@ -78,72 +77,64 @@ test_create( H5File& file)
{
TESTING("create, open, close");
+ // Setting this to NULL for cleaning up in failure situations
+ DataSet *dataset = NULL;
try {
- /* Create the data space */
+ // Create the data space
hsize_t dims[2];
dims[0] = 256;
dims[1] = 512;
DataSpace space (2, dims, NULL);
- /*
- * Create a dataset using the default dataset creation properties.
- * We're not sure what they are, so we won't check.
- */
+ // Create a dataset using the default dataset creation properties.
+ // We're not sure what they are, so we won't check.
DataSet *dataset = new DataSet (file.createDataSet
(DSET_DEFAULT_NAME, PredType::NATIVE_DOUBLE, space));
- /* Close the dataset */
+ // Close the dataset
delete dataset;
+ dataset = NULL;
- /* Add a comment to the dataset */
+ // Add a comment to the dataset
file.setComment (DSET_DEFAULT_NAME, "This is a dataset");
- /*
- * Try creating a dataset that already exists. This should fail since a
- * dataset can only be created once. If an exception is not thrown
- * for this action by createDataSet, then display failure information
- * and jump to label error: to return.
- */
+ // Try creating a dataset that already exists. This should fail since a
+ // dataset can only be created once. If an exception is not thrown
+ // for this action by createDataSet, then display failure information
+ // and throw an exception.
try {
dataset = new DataSet (file.createDataSet
(DSET_DEFAULT_NAME, PredType::NATIVE_DOUBLE, space));
// continuation here, that means no exception has been thrown
- H5_FAILED();
- cerr << " Library allowed overwrite of existing dataset." << endl;
- goto error;
+ throw InvalidActionException("H5File::createDataSet", "Library allowed overwrite of existing dataset");
}
catch (FileIException E ) // catching invalid creating dataset
- {
- // Exception is expected. Do nothing here.
- }
- /*
- * Open the dataset we created above and then close it. This is how
- * existing datasets are accessed.
- */
+ {} // do nothing, exception expected
+
+ // Open the dataset we created above and then close it. This is how
+ // existing datasets are accessed.
dataset = new DataSet (file.openDataSet (DSET_DEFAULT_NAME));
+
+ // Close the dataset when accessing is completed
delete dataset;
-
- /*
- * Try opening a non-existent dataset. This should fail so if an
- * exception is not thrown for this action by openDataSet, then
- * display failure information and jump to label error: to return.
- */
+
+ // This is another way to open an existing dataset for accessing.
+ DataSet another_dataset(file.openDataSet (DSET_DEFAULT_NAME));
+
+ // Try opening a non-existent dataset. This should fail so if an
+ // exception is not thrown for this action by openDataSet, then
+ // display failure information and throw an exception.
try {
dataset = new DataSet (file.openDataSet( "does_not_exist" ));
+
// continuation here, that means no exception has been thrown
- H5_FAILED();
- cerr << " Opened a non-existent dataset." << endl;
- goto error;
+ throw InvalidActionException("H5File::openDataSet", "Attempted to open a non-existent dataset");
}
catch (FileIException E ) // catching creating non-existent dataset
- {
- // Exception is expected. Do nothing here.
- }
+ {} // do nothing, exception expected
- /*
- * Create a new dataset that uses chunked storage instead of the default
- * layout.
- */
+ // Create a new dataset that uses chunked storage instead of the default
+ // layout.
DSetCreatPropList create_parms;
hsize_t csize[2];
csize[0] = 5;
@@ -154,20 +145,33 @@ test_create( H5File& file)
(DSET_CHUNKED_NAME, PredType::NATIVE_DOUBLE, space, create_parms));
// Note: this one has no error message in C when failure occurs?
- /*
- * Close the chunked dataset.
- */
+ // clean up and return with success
delete dataset;
PASSED();
return 0;
} // outer most try block
- // catch all dataset, file, space, plist exceptions
- catch (Exception E) { goto error; }
-
- error:
- return -1;
+ catch (InvalidActionException E)
+ {
+ cerr << " FAILED" << endl;
+ cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl;
+
+ // clean up and return with failure
+ if (dataset != NULL)
+ delete dataset;
+ return -1;
+ }
+ // catch all other exceptions
+ catch (Exception E)
+ {
+ issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__);
+
+ // clean up and return with failure
+ if (dataset != NULL)
+ delete dataset;
+ return -1;
+ }
}
/*-------------------------------------------------------------------------
@@ -235,7 +239,7 @@ test_simple_io( H5File& file)
int check[100][200];
int i, j, n;
- /* Initialize the dataset */
+ // Initialize the dataset
for (i = n = 0; i < 100; i++)
{
for (j = 0; j < 200; j++) {
@@ -246,27 +250,27 @@ test_simple_io( H5File& file)
char* tconv_buf = new char [1000];
try
{
- /* Create the data space */
+ // Create the data space
hsize_t dims[2];
dims[0] = 100;
dims[1] = 200;
DataSpace space (2, dims, NULL);
- /* Create a small conversion buffer to test strip mining */
+ // Create a small conversion buffer to test strip mining
DSetMemXferPropList xfer;
xfer.setBuffer (1000, tconv_buf, NULL);
- /* Create the dataset */
+ // Create the dataset
DataSet dataset (file.createDataSet (DSET_SIMPLE_IO_NAME, PredType::NATIVE_INT, space));
- /* Write the data to the dataset */
+ // Write the data to the dataset
dataset.write ((void*) points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
- /* Read the dataset back */
+ // Read the dataset back
dataset.read ((void*) check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
- /* Check that the values read are the same as the values written */
+ // Check that the values read are the same as the values written
for (i = 0; i < 100; i++)
for (j = 0; j < 200; j++)
{
@@ -317,7 +321,7 @@ test_tconv( H5File& file)
TESTING("data type conversion");
- /* Initialize the dataset */
+ // Initialize the dataset
for (int i = 0; i < 1000000; i++) {
out[i*4+0] = 0x11;
out[i*4+1] = 0x22;
@@ -327,21 +331,21 @@ test_tconv( H5File& file)
try
{
- /* Create the data space */
+ // Create the data space
hsize_t dims[1];
dims[0] = 1000000;
DataSpace space (1, dims, NULL);
- /* Create the data set */
+ // Create the data set
DataSet dataset (file.createDataSet (DSET_TCONV_NAME, PredType::STD_I32LE, space));
- /* Write the data to the dataset */
+ // Write the data to the dataset
dataset.write ((void*) out, PredType::STD_I32LE);
- /* Read data with byte order conversion */
+ // Read data with byte order conversion
dataset.read ((void*) in, PredType::STD_I32BE);
- /* Check */
+ // Check
for (int i = 0; i < 1000000; i++) {
if (in[4*i+0]!=out[4*i+3] ||
in[4*i+1]!=out[4*i+2] ||
@@ -436,7 +440,7 @@ test_compression(H5File& file)
int check[100][200];
hsize_t i, j, n;
- /* Initialize the dataset */
+ // Initialize the dataset
for (i = n = 0; i < 100; i++)
{
for (j = 0; j < 200; j++) {
@@ -448,18 +452,16 @@ test_compression(H5File& file)
try
{
const hsize_t size[2] = {100, 200};
- /* Create the data space */
+ // Create the data space
DataSpace space1(2, size, NULL);
- /*
- * Create a small conversion buffer to test strip mining. We
- * might as well test all we can!
- */
+ // Create a small conversion buffer to test strip mining. We
+ // might as well test all we can!
DSetMemXferPropList xfer;
xfer.setBuffer (1000, tconv_buf, NULL);
- /* Use chunked storage with compression */
+ // Use chunked storage with compression
DSetCreatPropList dscreatplist;
const hsize_t chunk_size[2] = {2, 25};
@@ -471,7 +473,7 @@ test_compression(H5File& file)
#ifdef H5_HAVE_FILTER_DEFLATE
TESTING("compression (setup)");
- /* Create the dataset */
+ // Create the dataset
dataset = new DataSet (file.createDataSet
(DSET_COMPRESS_NAME, PredType::NATIVE_INT, space1, dscreatplist));
@@ -523,10 +525,10 @@ test_compression(H5File& file)
*/
TESTING("compression (read)");
- /* Read the dataset back */
+ // Read the dataset back
dataset->read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
- /* Check that the values read are the same as the values written */
+ // 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++)
{
@@ -554,10 +556,10 @@ test_compression(H5File& file)
}
dataset->write ((void*)points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
- /* Read the dataset back and check it */
+ // Read the dataset back and check it
dataset->read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
- /* Check that the values read are the same as the values written */
+ // 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++)
{
@@ -580,7 +582,7 @@ test_compression(H5File& file)
dataset = new DataSet (file.openDataSet (DSET_COMPRESS_NAME));
dataset->read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
- /* Check that the values read are the same as the values written */
+ // 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++)
{
@@ -610,7 +612,7 @@ test_compression(H5File& file)
dataset->write ((void*)points, PredType::NATIVE_INT, space1, space1, xfer);
dataset->read ((void*)check, PredType::NATIVE_INT, space1, space1, xfer);
- /* Check that the values read are the same as the values written */
+ // Check that the values read are the same as the values written
for (i=0; i<hs_size[0]; i++) {
for (j=0; j<hs_size[1]; j++) {
if (points[hs_offset[0]+i][hs_offset[1]+j] !=
@@ -658,7 +660,7 @@ test_compression(H5File& file)
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 */
+ // 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++)
{
@@ -738,7 +740,7 @@ test_multiopen (H5File& file)
cur_size[0] = 20;
dset1.extend (cur_size);
- /* Get the size from the second handle */
+ // Get the size from the second handle
space = new DataSpace (dset2.getSpace());
hsize_t tmp_size[1];
@@ -804,6 +806,7 @@ test_types(H5File& file)
// Test copying a user-defined type using DataType::copy
DataType copied_type;
copied_type.copy(type);
+
// Test copying a user-defined type using DataType::operator=
DataType another_copied_type;
another_copied_type = type;
@@ -1051,5 +1054,5 @@ void
cleanup_dsets(void)
{
remove(FILE1.c_str());
-} /* cleanup_dsets */
+} // cleanup_dsets
diff --git a/c++/test/h5cpputil.cpp b/c++/test/h5cpputil.cpp
index 8bb0d85..d3f531b 100644
--- a/c++/test/h5cpputil.cpp
+++ b/c++/test/h5cpputil.cpp
@@ -27,12 +27,22 @@
#endif
#include <string>
+#include "h5test.h"
+#include "H5Exception.h"
+#include "h5cpputil.h"
+
+#ifndef H5_NO_NAMESPACE
+namespace H5 {
+#ifndef H5_NO_STD
+ using namespace std;
+#endif // H5_NO_STD
+#endif
+/*
#ifndef H5_NO_STD
using namespace std;
#endif
+*/
-#include "h5test.h"
-#include "h5cpputil.h"
/*-------------------------------------------------------------------------
* Function: test_report
@@ -84,12 +94,39 @@ int test_report( int nerrors, const string& testname )
*
*-------------------------------------------------------------------------
*/
-void issue_fail_msg(const char* where, int line, const char* file_name)
+void issue_fail_msg(const char* where, int line, const char* file_name,
+ const char* message)
{
if (GetTestVerbosity()>=VERBO_HI)
{
- cerr << " Call to routine: " << where << " at line " << line
- << " in " << file_name << "has failed" << endl;
+ cerr << "--> From " << where << " at line " << line
+ << " in " << file_name << " - " << message << endl << endl;
}
}
+//--------------------------------------------------------------------------
+// Function: InvalidActionException default constructor
+//--------------------------------------------------------------------------
+InvalidActionException::InvalidActionException():Exception(){}
+
+//--------------------------------------------------------------------------
+// Function: InvalidActionException overloaded constructor
+//
+// Purpose: Creates an InvalidActionException with the name of the function,
+// which the failure should have occurred but didn't, and a
+// message explaining why it should fail.
+// Parameters
+// func_name - IN: Name of the function where failure should occur
+// message - IN: Message
+//--------------------------------------------------------------------------
+InvalidActionException::InvalidActionException(const string func_name, const string message) : Exception(func_name, message) {}
+
+//--------------------------------------------------------------------------
+// Function: InvalidActionException destructor
+//--------------------------------------------------------------------------
+InvalidActionException::~InvalidActionException() {}
+
+#ifndef H5_NO_NAMESPACE
+} // end namespace
+#endif
+
diff --git a/c++/test/h5cpputil.h b/c++/test/h5cpputil.h
index 93ba1b9..5caba61 100644
--- a/c++/test/h5cpputil.h
+++ b/c++/test/h5cpputil.h
@@ -23,6 +23,13 @@
#ifndef _h5cpputil_h
#define _h5cpputil_h
+#ifndef H5_NO_NAMESPACE
+namespace H5 {
+#ifndef H5_NO_STD
+ using namespace std;
+#endif // H5_NO_STD
+#endif
+
#ifndef H5_NO_STD
int test_report (int, const std::string&);
using std::cerr;
@@ -31,7 +38,8 @@ using std::endl;
int test_report (int, const string&);
#endif
-void issue_fail_msg(const char* where, int line, const char* file_name);
+void issue_fail_msg(const char* where, int line, const char* file_name,
+ const char* message="");
template <class Type1, class Type2>
void verify_val(Type1 x, Type2 value, const char* where, int line, const char* file_name)
@@ -50,4 +58,15 @@ template <class Type1, class Type2>
}
}
+class InvalidActionException : public Exception {
+ public:
+ InvalidActionException(const string func_name, const string message = DEFAULT_MSG);
+ InvalidActionException();
+ virtual ~InvalidActionException();
+};
+
+#ifndef H5_NO_NAMESPACE
+}
+#endif
+
#endif
diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp
index e7b51bd..41cc1d3 100644
--- a/c++/test/tfile.cpp
+++ b/c++/test/tfile.cpp
@@ -89,82 +89,90 @@ const string FILE4("tfile4.h5");
* January, 2001
*
* Modifications:
+ * January, 2005: C tests' macro VERIFY casts values to 'long' for all
+ * cases. Since there are no operator<< for 'long long'
+ * or int64 in VS C++ ostream, I casted the hsize_t values
+ * passed to verify_val to 'long' as well. If problems
+ * arises later, this will have to be specificly handled
+ * with a special routine.
*
*-------------------------------------------------------------------------
*/
static void
test_file_create(void)
{
- /* Output message about test being performed */
+ // Output message about test being performed
MESSAGE(5, ("Testing File Creation I/O\n"));
- /* Test create with various sequences of H5F_ACC_EXCL and */
- /* H5F_ACC_TRUNC flags */
+ // Test create with various sequences of H5F_ACC_EXCL and
+ // H5F_ACC_TRUNC flags
- /* Create with H5F_ACC_EXCL */
- /* First ensure the file does not exist */
+ // Create with H5F_ACC_EXCL
+ // First ensure the file does not exist
remove(FILE1.c_str());
+ // Setting this to NULL for cleaning up in failure situations
+ H5File* file1 = NULL;
try {
- H5File* file1 = new H5File (FILE1, H5F_ACC_EXCL);
+ // Create file FILE1
+ file1 = new H5File (FILE1, H5F_ACC_EXCL);
- /*
- * try to create the same file with H5F_ACC_TRUNC. This should fail
- * because file1 is the same file and is currently open.
- */
+ // try to create the same file with H5F_ACC_TRUNC. This should fail
+ // because file1 is the same file and is currently open.
try {
H5File file2 (FILE1, H5F_ACC_TRUNC); // should throw E
- // Should FAIL but didn't - BMR (Note 1): a macro, with a diff
- // name, that skips the comparison b/w the 1st & 2nd args would
- // be more appropriate, but verify_val can be used for now;
- // also, more text about what is testing would be better.
- verify_val(file2.getId(), FAIL, "H5File constructor", __LINE__, __FILE__);
+ // Should FAIL but didn't, so throw an invalid action exception
+ throw InvalidActionException("H5File constructor", "Attempted to create an existing file.");
}
- catch( FileIException E ) {} // do nothing, FAIL expected
-
- // Close file file1
+ catch( FileIException E ) // catch truncating existing file
+ {} // do nothing, FAIL expected
+ // Close file1
delete file1;
+ file1 = NULL;
- /*
- * Try again with H5F_ACC_EXCL. This should fail because the file already
- * exists from the previous steps.
- */
+ // Try again with H5F_ACC_EXCL. This should fail because the file
+ // already exists from the previous steps.
try {
H5File file2(FILE1, H5F_ACC_EXCL); // should throw E
- verify_val(file2.getId(), FAIL, "H5File constructor", __LINE__, __FILE__);
+
+ // Should FAIL but didn't, so throw an invalid action exception
+ throw InvalidActionException("H5File constructor", "File already exists.");
}
- catch( FileIException E ) {} // do nothing, FAIL expected
+ catch( FileIException E ) // catching creating existing file
+ {} // do nothing, FAIL expected
// Test create with H5F_ACC_TRUNC. This will truncate the existing file.
file1 = new H5File (FILE1, H5F_ACC_TRUNC);
- /*
- * Try to truncate first file again. This should fail because file1 is the
- * same file and is currently open.
- */
+ // Try to truncate first file again. This should fail because file1
+ // is the same file and is currently open.
try {
H5File file2 (FILE1, H5F_ACC_TRUNC); // should throw E
- verify_val(file2.getId(), FAIL, "H5File constructor", __LINE__, __FILE__);
+
+ // Should FAIL but didn't, so throw an invalid action exception
+ throw InvalidActionException("H5File constructor", "H5F_ACC_TRUNC attempt on an opened file.");
}
- catch( FileIException E ) {} // do nothing, FAIL expected
+ catch( FileIException E ) // catching truncating opened file
+ {} // do nothing, FAIL expected
- /*
- * Try with H5F_ACC_EXCL. This should fail too because the file already
- * exists.
- */
+ // Try with H5F_ACC_EXCL. This should fail too because the file already
+ // exists.
try {
H5File file3 (FILE1, H5F_ACC_EXCL); // should throw E
- verify_val(file3.getId(), FAIL, "H5File constructor", __LINE__, __FILE__);
+
+ // Should FAIL but didn't, so throw an invalid action exception
+ throw InvalidActionException("H5File constructor", "H5F_ACC_EXCL attempt on an existing file.");
}
- catch( FileIException E ) {} // do nothing, FAIL expected
+ catch( FileIException E ) // catching H5F_ACC_EXCL on existing file
+ {} // do nothing, FAIL expected
- /* Get the file-creation template */
+ // Get the file-creation template
FileCreatPropList tmpl1 = file1->getCreatePlist();
hsize_t ublock = tmpl1.getUserblock();
- verify_val(ublock, F1_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__);
+ verify_val((long)ublock, (long)F1_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__);
size_t parm1, parm2; /*file-creation parameters */
tmpl1.getSizes( parm1, parm2);
@@ -183,78 +191,87 @@ test_file_create(void)
// tmpl1 is automatically closed; if error occurs, it'll be
// caught in the catch block
- /* Close first file */
+ // Close first file
delete file1;
}
- catch( PropListIException E ) {
- issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__);
+
+ catch (InvalidActionException E)
+ {
+ cerr << " FAILED" << endl;
+ cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl;
+ if (file1 != NULL) // clean up
+ delete file1;
}
- catch( FileIException E ) {
- issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__);
+ // catch all other exceptions
+ catch (Exception E)
+ {
+ issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
+ if (file1 != NULL) // clean up
+ delete file1;
}
+ // Setting this to NULL for cleaning up in failure situations
+ FileCreatPropList* tmpl1 = NULL;
try
{
- /* Create a new file with a non-standard file-creation template */
- FileCreatPropList* tmpl1 = new FileCreatPropList;
+ // Create a new file with a non-standard file-creation template
+ tmpl1 = new FileCreatPropList;
- /* Set the new file-creation parameters */
+ // Set the new file-creation parameters
tmpl1->setUserblock (F2_USERBLOCK_SIZE);
tmpl1->setSizes( F2_OFFSET_SIZE, F2_LENGTH_SIZE );
tmpl1->setSymk( F2_SYM_INTERN_K, F2_SYM_LEAF_K );
- /*
- * Try to create second file, with non-standard file-creation template
- * params.
- */
+ // Try to create second file, with non-standard file-creation template
+ // params.
H5File file2( FILE2, H5F_ACC_TRUNC, *tmpl1 );
- /* Release file-creation template */
+ // Release file-creation template
delete tmpl1;
+ tmpl1 = NULL;
- /* Get the file-creation template */
+ // Get the file-creation template
tmpl1 = new FileCreatPropList (file2.getCreatePlist());
- /* Get the file-creation parameters */
+ // Get the file-creation parameters
hsize_t ublock = tmpl1->getUserblock();
- verify_val(ublock, F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__);
+ verify_val((long)ublock, (long)F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__);
- size_t parm1, parm2; /*file-creation parameters */
+ size_t parm1, parm2; // file-creation parameters
tmpl1->getSizes( parm1, parm2);
verify_val(parm1, F2_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__);
verify_val(parm2, F2_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__);
#ifdef H5_WANT_H5_V1_4_COMPAT
- int iparm1, iparm2; /*file-creation parameters */
+ int iparm1, iparm2; // file-creation parameters
#else /* H5_WANT_H5_V1_4_COMPAT */
- unsigned iparm1, iparm2; /*file-creation parameters */
+ unsigned iparm1, iparm2; // file-creation parameters
#endif /* H5_WANT_H5_V1_4_COMPAT */
tmpl1->getSymk( iparm1, iparm2);
verify_val(iparm1, F2_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__);
verify_val(iparm2, F2_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__);
- /* Clone the file-creation template */
+ // Clone the file-creation template
FileCreatPropList tmpl2;
tmpl2.copy (*tmpl1);
- /* Dynamically release file-creation template */
+ // Release file-creation template
delete tmpl1;
+ tmpl1 = NULL;
- /* Set the new file-creation parameter */
+ // Set the new file-creation parameter
tmpl2.setUserblock( F3_USERBLOCK_SIZE );
- /*
- * Try to create second file, with non-standard file-creation template
- * params
- */
+ // Try to create second file, with non-standard file-creation template
+ // params
H5File file3( FILE3, H5F_ACC_TRUNC, tmpl2 );
- /* Get the file-creation template */
+ // Get the file-creation template
tmpl1 = new FileCreatPropList (file3.getCreatePlist());
- /* Get the file-creation parameters */
+ // Get the file-creation parameters
ublock = tmpl1->getUserblock();
- verify_val(ublock, F3_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__);
+ verify_val((long)ublock, (long)F3_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__);
tmpl1->getSizes( parm1, parm2);
verify_val(parm1, F3_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__);
@@ -264,11 +281,13 @@ test_file_create(void)
verify_val(iparm1, F3_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__);
verify_val(iparm2, F3_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__);
- /* Dynamically release file-creation template */
+ // Release file-creation template
delete tmpl1;
}
catch( PropListIException E ) {
- issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__);
+ issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
+ if (tmpl1 != NULL) // clean up
+ delete tmpl1;
}
} /* test_file_create() */
@@ -284,37 +303,43 @@ test_file_create(void)
* January, 2001
*
* Modifications:
+ * January, 2005: C tests' macro VERIFY casts values to 'long' for all
+ * cases. Since there are no operator<< for 'long long'
+ * or int64 in VS C++ ostream, I casted the hsize_t values
+ * passed to verify_val to 'long' as well. If problems
+ * arises later, this will have to be specificly handled
+ * with a special routine.
*
*-------------------------------------------------------------------------
*/
static void
test_file_open(void)
{
- /* Output message about test being performed */
+ // Output message about test being performed
MESSAGE(5, ("Testing File Opening I/O\n"));
try {
- /* Open first file */
+ // Open first file
H5File file1 (FILE2, H5F_ACC_RDWR );
- /* Get the file-creation template */
+ // Get the file-creation template
FileCreatPropList tmpl1 = file1.getCreatePlist();
- /* Get the file-creation parameters */
+ // Get the file-creation parameters
hsize_t ublock = tmpl1.getUserblock();
- verify_val(ublock, F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__);
+ verify_val((long)ublock, (long)F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__);
verify_val(ublock, F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__);
- size_t parm1, parm2; /*file-creation parameters */
+ size_t parm1, parm2; // file-creation parameters
tmpl1.getSizes( parm1, parm2);
verify_val(parm1, F2_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__);
verify_val(parm2, F2_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__);
#ifdef H5_WANT_H5_V1_4_COMPAT
- int iparm1, iparm2; /*file-creation parameters */
+ int iparm1, iparm2; // file-creation parameters
#else /* H5_WANT_H5_V1_4_COMPAT */
- unsigned iparm1, iparm2; /*file-creation parameters */
+ unsigned iparm1, iparm2; // file-creation parameters
#endif /* H5_WANT_H5_V1_4_COMPAT */
tmpl1.getSymk( iparm1, iparm2);
verify_val(iparm1, F2_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__);
@@ -322,7 +347,7 @@ test_file_open(void)
} // end of try block
catch( Exception E ) {
- issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__);
+ issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
} /* test_file_open() */
@@ -344,7 +369,7 @@ test_file_open(void)
static void
test_file_size(void)
{
- /* Output message about test being performed */
+ // Output message about test being performed
MESSAGE(5, ("Testing File Size\n"));
hid_t fapl_id;
@@ -372,7 +397,7 @@ test_file_size(void)
} // end of try block
catch( Exception E ) {
- issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__);
+ issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
// use C test utility routine to close property list.
@@ -403,7 +428,7 @@ const string DSETNAME ("dataset");
const string ATTRNAME ("attribute");
const string DTYPENAME ("compound");
-/* Compound datatype */
+// Compound datatype
typedef struct s1_t {
unsigned int a;
float b;
@@ -412,7 +437,7 @@ typedef struct s1_t {
static void
test_file_name()
{
- /* Output message about test being performed */
+ // Output message about test being performed
MESSAGE(5, ("Testing File Name\n"));
string file_name;
@@ -424,47 +449,48 @@ test_file_name()
file_name = file4.getFileName();
verify_val(file_name, FILE4, "H5File::getFileName", __LINE__, __FILE__);
- /* Create a group in the root group */
+ // Create a group in the root group
Group group(file4.createGroup(GROUPNAME, 0));
- /* Get and verify file name */
+ // Get and verify file name
file_name = group.getFileName();
verify_val(file_name, FILE4, "Group::getFileName", __LINE__, __FILE__);
- /* Create the data space */
+ // Create the data space
hsize_t dims[RANK] = {NX, NY};
DataSpace space(RANK, dims);
- /* Create a new dataset */
+ // Create a new dataset
DataSet dataset(file4.createDataSet (DSETNAME, PredType::NATIVE_INT, space));
- /* Get and verify file name */
+ // Get and verify file name
file_name = dataset.getFileName();
verify_val(file_name, FILE4, "DataSet::getFileName", __LINE__, __FILE__);
- /* Create an attribute for the dataset */
+ // Create an attribute for the dataset
Attribute attr(dataset.createAttribute(ATTRNAME, PredType::NATIVE_INT, space));
- /* Get and verify file name */
+ // Get and verify file name
file_name = attr.getFileName();
verify_val(file_name, FILE4, "Attribute::getFileName", __LINE__, __FILE__);
- /* Create a compound datatype */
+ // Create a compound datatype
CompType comp_type (sizeof(s1_t));
- /* Insert fields */
+ // Insert fields
comp_type.insertMember("a", HOFFSET(s1_t, a), PredType::NATIVE_INT);
comp_type.insertMember("b", HOFFSET(s1_t, b), PredType::NATIVE_FLOAT);
- /* Save it on file */
+ // Save it on file
comp_type.commit(file4, DTYPENAME);
- /* Get and verify file name */
+ // Get and verify file name
comp_type.getFileName();
verify_val(file_name, FILE4, "CompType::getFileName", __LINE__, __FILE__);
} // end of try block
+
catch (Exception E) {
- issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__);
+ issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
} /* test_file_name() */
@@ -487,13 +513,13 @@ test_file_name()
void
test_file(void)
{
- /* Output message about test being performed */
+ // Output message about test being performed
MESSAGE(5, ("Testing File I/O operations\n"));
- test_file_create(); /* Test file creation (also creation templates) */
- test_file_open(); /* Test file opening */
- test_file_size(); /* Test file size */
- test_file_name(); /* Test getting file's name */
+ test_file_create(); // Test file creation (also creation templates)
+ test_file_open(); // Test file opening
+ test_file_size(); // Test file size
+ test_file_name(); // Test getting file's name
} /* test_file() */
diff --git a/c++/test/th5s.cpp b/c++/test/th5s.cpp
index ff7e0bf..190646f 100644
--- a/c++/test/th5s.cpp
+++ b/c++/test/th5s.cpp
@@ -92,6 +92,12 @@ struct space4_struct {
* Mar 2001
*
* Modifications:
+ * January, 2005: C tests' macro VERIFY casts values to 'long' for all
+ * cases. Since there are no operator<< for 'long long'
+ * or int64 in VS C++ ostream, I casted the hssize_t values
+ * passed to verify_val to 'long' as well. If problems
+ * arises later, this will have to be specificly handled
+ * with a special routine.
*-------------------------------------------------------------------------
*/
static void
@@ -118,7 +124,7 @@ test_h5s_basic(void)
// Get simple extent npoints of the dataspace sid1 and verify it
hssize_t n; /* Number of dataspace elements */
n = sid1.getSimpleExtentNpoints();
- verify_val(n, SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3,
+ verify_val((long)n, (long)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3),
"DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Get the logical rank of dataspace sid1 and verify it
@@ -139,7 +145,7 @@ test_h5s_basic(void)
// Get simple extent npoints of dataspace sid2 and verify it
n = sid2.getSimpleExtentNpoints();
- verify_val(n, SPACE2_DIM1 * SPACE2_DIM2 * SPACE2_DIM3 * SPACE2_DIM4,
+ verify_val((long)n, (long)(SPACE2_DIM1 * SPACE2_DIM2 * SPACE2_DIM3 * SPACE2_DIM4),
"DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Get the logical rank of dataspace sid2 and verify it
@@ -153,39 +159,32 @@ test_h5s_basic(void)
"DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
verify_val(HDmemcmp(tmax, max2, SPACE2_RANK * sizeof(unsigned)), 0,
"DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
- } // end of first try block
- catch( DataSpaceIException error )
- {
- issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__);
- }
- /*
- * Check to be sure we can't create a simple data space that has too many
- * dimensions.
- */
- try {
- DataSpace manydims_ds(H5S_MAX_RANK+1, dims3, NULL);
+ // Check to be sure we can't create a simple data space that has too
+ // many dimensions.
+ try {
+ DataSpace manydims_ds(H5S_MAX_RANK+1, dims3, NULL);
- // Should FAIL but didn't, so issue an error message
- issue_fail_msg("DataSpace constructor", __LINE__, __FILE__);
- }
- catch( DataSpaceIException error ) {} // do nothing, FAIL expected
-
- /*
- * Try reading a file that has been prepared that has a dataset with a
- * higher dimensionality than what the library can handle.
- *
- * If this test fails and the H5S_MAX_RANK variable has changed, follow
- * the instructions in space_overflow.c for regenating the th5s.h5 file.
- */
- char testfile[512]="";
- char *srcdir = getenv("srcdir");
- if (srcdir && ((strlen(srcdir) + strlen(TESTFILE.c_str()) + 1) < sizeof(testfile))){
- strcpy(testfile, srcdir);
- strcat(testfile, "/");
- }
- strcat(testfile, TESTFILE.c_str());
- try { // try block for testing higher dimensionality
+ // Should FAIL but didn't, so throw an invalid action exception
+ throw InvalidActionException("DataSpace constructor", "Library allowed overwrite of existing dataset");
+ }
+ catch( DataSpaceIException E ) // Simple data space with too many dims
+ {} // do nothing, exception expected
+
+ /*
+ * Try reading a file that has been prepared that has a dataset with a
+ * higher dimensionality than what the library can handle.
+ *
+ * If this test fails and the H5S_MAX_RANK variable has changed, follow
+ * the instructions in space_overflow.c for regenating the th5s.h5 file.
+ */
+ char testfile[512]="";
+ char *srcdir = getenv("srcdir");
+ if (srcdir && ((strlen(srcdir) + strlen(TESTFILE.c_str()) + 1) < sizeof(testfile))){
+ strcpy(testfile, srcdir);
+ strcat(testfile, "/");
+ }
+ strcat(testfile, TESTFILE.c_str());
// Create file
H5File fid1(testfile, H5F_ACC_RDONLY);
@@ -195,41 +194,48 @@ test_h5s_basic(void)
try {
DataSet dset1 = fid1.openDataSet( "dset" );
- // but didn't, issue an error message
- issue_fail_msg("H5File::openDataSet", __LINE__, __FILE__);
+ // Should FAIL but didn't, so throw an invalid action exception
+ throw InvalidActionException("H5File::openDataSet", "Opening a dataset with higher dimensionality than what the library can handle");
}
- catch( FileIException error ) { } // do nothing, FAIL expected
- } // end of try block for testing higher dimensionality
-
- // catch exception thrown by H5File constructor
- catch( FileIException error ) {
- issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__);
- cerr << "***cannot open the pre-created H5S_MAX_RANK test file" <<
- testfile << endl;
- }
+ catch( FileIException E ) // catching higher dimensionality dataset
+ {} // do nothing, exception expected
// CHECK_I(ret, "H5Fclose"); // leave this here, later, fake a failure
// in the p_close see how this will handle it. - BMR
- /* Verify that incorrect dimensions don't work */
- dims1[0] = 0;
- try {
- DataSpace wrongdim_ds (SPACE1_RANK, dims1);
- verify_val(wrongdim_ds.getId(), FAIL, "DataSpace constructor", __LINE__, __FILE__);
- }
- catch( DataSpaceIException error ) {} // do nothing; FAIL expected
+ // Verify that incorrect dimensions don't work
+ dims1[0] = 0;
+ try {
+ DataSpace wrongdim_ds (SPACE1_RANK, dims1);
+
+ // Should FAIL but didn't, so throw an invalid action exception
+ throw InvalidActionException("DataSpace constructor", "Attempted to use incorrect dimensions");
+ }
+ catch( DataSpaceIException E ) // catching use of incorrect dimensions
+ {} // do nothing, exception expected
- // Create a simple dataspace
- DataSpace sid3 (H5S_SIMPLE);
+ // Another incorrect dimension case
+ DataSpace sid3 (H5S_SIMPLE);
+ try {
+ sid3.setExtentSimple( SPACE1_RANK, dims1 );
- // Attempts to use incorrect dimensions, should fail
- try {
- sid3.setExtentSimple( SPACE1_RANK, dims1 );
+ // Should FAIL but didn't, so throw an invalid action exception
+ throw InvalidActionException("DataSpace::setExtentSimple", "Attempted to use incorrect dimensions");
+ }
+ catch (DataSpaceIException E) // catching use of incorrect dimensions
+ {} // do nothing, exception expected
+ } // end of outer try block
- // but didn't, issue an error message
- issue_fail_msg("DataSpace::setExtentSimple", __LINE__, __FILE__);
+ catch (InvalidActionException E)
+ {
+ cerr << " FAILED" << endl;
+ cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl;
+ }
+ // catch all other exceptions
+ catch (Exception E)
+ {
+ issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
- catch (DataSpaceIException error) {} // do nothing, FAIL expected
} /* test_h5s_basic() */
/*-------------------------------------------------------------------------
@@ -244,6 +250,12 @@ test_h5s_basic(void)
* Mar 2001
*
* Modifications:
+ * January, 2005: C tests' macro VERIFY casts values to 'long' for all
+ * cases. Since there are no operator<< for 'long long'
+ * or int64 in VS C++ ostream, I casted the hssize_t values
+ * passed to verify_val to 'long' as well. If problems
+ * arises later, this will have to be specificly handled
+ * with a special routine.
*-------------------------------------------------------------------------
*/
static void
@@ -264,7 +276,7 @@ test_h5s_scalar_write(void)
//n = H5Sget_simple_extent_npoints(sid1);
hssize_t n; /* Number of dataspace elements */
n = sid1.getSimpleExtentNpoints();
- verify_val(n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
+ verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
int rank; /* Logical rank of dataspace */
rank = sid1.getSimpleExtentNdims();
@@ -304,6 +316,12 @@ test_h5s_scalar_write(void)
* Mar 2001
*
* Modifications:
+ * January, 2005: C tests' macro VERIFY casts values to 'long' for all
+ * cases. Since there are no operator<< for 'long long'
+ * or int64 in VS C++ ostream, I casted the hssize_t values
+ * passed to verify_val to 'long' as well. If problems
+ * arises later, this will have to be specificly handled
+ * with a special routine.
*-------------------------------------------------------------------------
*/
static void
@@ -326,7 +344,7 @@ test_h5s_scalar_read(void)
// Get the number of dataspace elements
hssize_t n = sid1.getSimpleExtentNpoints();
- verify_val(n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
+ verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Get the logical rank of the dataspace
int ndims = sid1.getSimpleExtentNdims();
@@ -360,6 +378,12 @@ test_h5s_scalar_read(void)
* Mar 2001
*
* Modifications:
+ * January, 2005: C tests' macro VERIFY casts values to 'long' for all
+ * cases. Since there are no operator<< for 'long long'
+ * or int64 in VS C++ ostream, I casted the hssize_t values
+ * passed to verify_val to 'long' as well. If problems
+ * arises later, this will have to be specificly handled
+ * with a special routine.
*-------------------------------------------------------------------------
*/
static void
@@ -394,7 +418,7 @@ test_h5s_compound_scalar_write(void)
// Get the number of dataspace elements
hssize_t n = sid1.getSimpleExtentNpoints();
- verify_val(n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
+ verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Get the logical rank of the dataspace
int ndims = sid1.getSimpleExtentNdims();
@@ -430,6 +454,12 @@ test_h5s_compound_scalar_write(void)
* Mar 2001
*
* Modifications:
+ * January, 2005: C tests' macro VERIFY casts values to 'long' for all
+ * cases. Since there are no operator<< for 'long long'
+ * or int64 in VS C++ ostream, I casted the hssize_t values
+ * passed to verify_val to 'long' as well. If problems
+ * arises later, this will have to be specificly handled
+ * with a special routine.
*-------------------------------------------------------------------------
*/
static void
@@ -451,7 +481,7 @@ test_h5s_compound_scalar_read(void)
// Get the number of dataspace elements
hssize_t n = sid1.getSimpleExtentNpoints();
- verify_val(n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
+ verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Get the logical rank of the dataspace
int ndims = sid1.getSimpleExtentNdims();