summaryrefslogtreecommitdiffstats
path: root/c++/test/tfile.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2005-01-31 04:03:36 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2005-01-31 04:03:36 (GMT)
commit31a5ef7b2280fa31a6445b0cc04df3c3bcc0dc3b (patch)
tree0b72886f6e14ec715c5b940ea10bcd6ea308e940 /c++/test/tfile.cpp
parentd388057d0dcaeefc9f87ad32fbd13e17133fd818 (diff)
downloadhdf5-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/tfile.cpp')
-rw-r--r--c++/test/tfile.cpp88
1 files changed, 47 insertions, 41 deletions
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() */