diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2005-01-31 04:03:36 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2005-01-31 04:03:36 (GMT) |
commit | 31a5ef7b2280fa31a6445b0cc04df3c3bcc0dc3b (patch) | |
tree | 0b72886f6e14ec715c5b940ea10bcd6ea308e940 | |
parent | d388057d0dcaeefc9f87ad32fbd13e17133fd818 (diff) | |
download | hdf5-31a5ef7b2280fa31a6445b0cc04df3c3bcc0dc3b.zip hdf5-31a5ef7b2280fa31a6445b0cc04df3c3bcc0dc3b.tar.gz hdf5-31a5ef7b2280fa31a6445b0cc04df3c3bcc0dc3b.tar.bz2 |
[svn-r9890] 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 - th5s.cpp
+ Added the use of InvalidActionException for when an action
should cause an exception but didn't - th5s.cpp and tfile.cpp
+ Small changes to improve failure reports
Platforms tested:
SunOS 5.7 (arabica)
Linux 2.4 (eirene)
-rw-r--r-- | c++/test/h5cpputil.cpp | 7 | ||||
-rw-r--r-- | c++/test/h5cpputil.h | 3 | ||||
-rw-r--r-- | c++/test/tfile.cpp | 88 | ||||
-rw-r--r-- | c++/test/th5s.cpp | 184 |
4 files changed, 163 insertions, 119 deletions
diff --git a/c++/test/h5cpputil.cpp b/c++/test/h5cpputil.cpp index 4f21c9a..d3f531b 100644 --- a/c++/test/h5cpputil.cpp +++ b/c++/test/h5cpputil.cpp @@ -94,12 +94,13 @@ 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; } } diff --git a/c++/test/h5cpputil.h b/c++/test/h5cpputil.h index df8f139..5caba61 100644 --- a/c++/test/h5cpputil.h +++ b/c++/test/h5cpputil.h @@ -38,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) diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp index e201c1a..ca26abd 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -102,35 +102,30 @@ test_file_create(void) // 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 - + // 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); @@ -141,19 +136,23 @@ test_file_create(void) */ 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 FileCreatPropList tmpl1 = file1->getCreatePlist(); @@ -174,16 +173,22 @@ 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__); - if (file1 != NULL) // clean up - delete file1; + // 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 @@ -198,10 +203,8 @@ test_file_create(void) 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 */ @@ -260,8 +263,10 @@ test_file_create(void) /* Dynamically release file-creation template */ delete tmpl1; } - catch( PropListIException E ) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__); + // catch all exceptions + catch (Exception E) + { + issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); if (tmpl1 != NULL) // clean up delete tmpl1; } @@ -318,7 +323,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() */ @@ -368,7 +373,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. @@ -459,8 +464,9 @@ test_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() */ diff --git a/c++/test/th5s.cpp b/c++/test/th5s.cpp index afa7713..9ddb4e0 100644 --- a/c++/test/th5s.cpp +++ b/c++/test/th5s.cpp @@ -95,6 +95,12 @@ int space5_data = 7; * 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 @@ -121,7 +127,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 @@ -142,7 +148,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 @@ -156,39 +162,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); @@ -198,41 +197,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() */ /*------------------------------------------------------------------------- @@ -247,6 +253,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 @@ -267,7 +279,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(); @@ -289,9 +301,9 @@ test_h5s_scalar_write(void) dataset.write(&space3_data, PredType::NATIVE_UINT); } // end of try block - catch (Exception error) + catch (Exception E) { - issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__); + issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } /* test_h5s_scalar_write() */ @@ -307,6 +319,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 @@ -329,7 +347,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(); @@ -342,10 +360,10 @@ test_h5s_scalar_read(void) dataset.read(&rdata, PredType::NATIVE_UINT); verify_val(rdata, space3_data, "DataSet::read", __LINE__, __FILE__); } // end of try block - catch (Exception error) + catch (Exception E) { // all the exceptions caused by negative returned values by C APIs - issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__); + issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } /* test_h5s_scalar_read() */ @@ -362,6 +380,12 @@ test_h5s_scalar_read(void) * May 18, 2004 * * 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 @@ -382,7 +406,7 @@ test_h5s_null(void) //n = H5Sget_simple_extent_npoints(sid1); hssize_t n; /* Number of dataspace elements */ n = sid1.getSimpleExtentNpoints(); - verify_val(n, 0, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); + verify_val((long)n, 0, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); // Create a dataset DataSet dataset = fid1.createDataSet("Dataset1", PredType::NATIVE_UINT,sid1); @@ -394,9 +418,9 @@ test_h5s_null(void) dataset.read(&space5_data, PredType::NATIVE_INT); verify_val(space5_data, 7, "DataSet::read", __LINE__, __FILE__); } // end of try block - catch (Exception error) + catch (Exception E) { - issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__); + issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } /* test_h5s_null() */ @@ -413,6 +437,12 @@ test_h5s_null(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 @@ -447,7 +477,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(); @@ -462,10 +492,10 @@ test_h5s_compound_scalar_write(void) dataset.write(&space4_data, tid1); } // end of try block - catch (Exception error) + catch (Exception E) { // all the exceptions caused by negative returned values by C APIs - issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__); + issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } /* test_h5s_compound_scalar_write() */ @@ -483,6 +513,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 @@ -504,7 +540,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(); @@ -532,10 +568,10 @@ test_h5s_compound_scalar_read(void) space4_data.c1, rdata.c2); } /* end if */ } // end of try block - catch (Exception error) + catch (Exception E) { // all the exceptions caused by negative returned values by C APIs - issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__); + issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } /* test_h5s_compound_scalar_read() */ |