summaryrefslogtreecommitdiffstats
path: root/c++/test
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2015-03-30 21:57:37 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2015-03-30 21:57:37 (GMT)
commitea029945f5b663cb5dc3aeda447e3d34a77632e0 (patch)
tree54e1cd65c7b2168d3685cbad4f1b6e76dec13047 /c++/test
parentd2c5e2bf5780be51159d70cc1aec6496099a5f91 (diff)
downloadhdf5-ea029945f5b663cb5dc3aeda447e3d34a77632e0.zip
hdf5-ea029945f5b663cb5dc3aeda447e3d34a77632e0.tar.gz
hdf5-ea029945f5b663cb5dc3aeda447e3d34a77632e0.tar.bz2
[svn-r26667] Purpose: Fixed HDFFV-8766
Description: Per user Jason Newton request, the following constructor is added: H5File(hid_t existing_id); Also, fixed H5File::openFile to close current file first before re-using the object. Platforms tested: Linux/64 (platypus) Linux/32 2.6 (jam gnu and Intel 15.0) SunOS 5.11 (emu)
Diffstat (limited to 'c++/test')
-rw-r--r--c++/test/tfile.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp
index 6d5dc23..f3bbb16 100644
--- a/c++/test/tfile.cpp
+++ b/c++/test/tfile.cpp
@@ -330,6 +330,32 @@ static void test_file_open()
verify_val(iparm1, F2_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__);
verify_val(iparm2, F2_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__);
+ // Test H5File constructor with existing file id
+ H5File file2(file1.getId());
+ file1.close();
+
+ // Try truncating the file, and it should fail because the file is
+ // still opened with file2.
+ try {
+ H5File file3 (FILE2, H5F_ACC_TRUNC); // should throw E
+
+ // Should FAIL but didn't, so throw an invalid action exception
+ throw InvalidActionException("H5File constructor", "Attempt truncating an opened file.");
+ }
+ catch( FileIException E ) // catching H5F_ACC_TRUNC on opened file
+ {} // do nothing, FAIL expected
+
+ // Now, really close the file.
+ file2.close();
+
+ // Truncating should succeed now.
+ H5File file3(FILE2, H5F_ACC_TRUNC);
+
+ // Opening another file to file3 object, FILE2 should be closed, so
+ // the next attempt to truncate FILE2 should succeed.
+ file3.openFile(FILE1, H5F_ACC_RDONLY);
+ H5File file4(FILE2, H5F_ACC_TRUNC);
+
PASSED();
} // end of try block