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 /c++/test/th5s.cpp | |
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)
Diffstat (limited to 'c++/test/th5s.cpp')
-rw-r--r-- | c++/test/th5s.cpp | 184 |
1 files changed, 110 insertions, 74 deletions
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() */ |