summaryrefslogtreecommitdiffstats
path: root/test/tfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/tfile.c')
-rw-r--r--test/tfile.c69
1 files changed, 65 insertions, 4 deletions
diff --git a/test/tfile.c b/test/tfile.c
index f0c3930..badf548 100644
--- a/test/tfile.c
+++ b/test/tfile.c
@@ -52,6 +52,9 @@
#define FILE1 "tfile1.h5"
#define SFILE1 "sys_file1"
+#define REOPEN_FILE "tfile_reopen.h5"
+#define REOPEN_DSET "dset"
+
#define F2_USERBLOCK_SIZE (hsize_t)512
#define F2_OFFSET_SIZE 8
#define F2_LENGTH_SIZE 8
@@ -532,6 +535,59 @@ test_file_open(void)
/****************************************************************
**
+** test_file_reopen(): File reopen test routine.
+**
+****************************************************************/
+static void
+test_file_reopen(void)
+{
+ hid_t fid = -1; /* file ID from initial open */
+ hid_t rfid = -1; /* file ID from reopen */
+ hid_t did = -1; /* dataset ID (both opens) */
+ hid_t sid = -1; /* dataspace ID for dataset creation */
+ hsize_t dims = 6; /* dataspace size */
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing File Re-opening\n"));
+
+ /* Create file via first ID */
+ fid = H5Fcreate(REOPEN_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK_I(fid, "H5Fcreate");
+
+ /* Create a dataset in the file */
+ sid = H5Screate_simple(1, &dims, &dims);
+ CHECK_I(sid, "H5Screate_simple")
+ did = H5Dcreate2(fid, REOPEN_DSET, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK_I(did, "H5Dcreate2");
+
+ /* Close dataset and dataspace */
+ ret = H5Sclose(sid);
+ CHECK(ret, FAIL, "H5Sclose");
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ /* Reopen the file with a different file ID */
+ rfid = H5Freopen(fid);
+ CHECK_I(rfid, "H5Freopen");
+
+ /* Reopen the dataset through the reopen file ID */
+ did = H5Dopen2(rfid, REOPEN_DSET, H5P_DEFAULT);
+ CHECK_I(did, "H5Dopen2");
+
+ /* Close and clean up */
+ ret = H5Dclose(did);
+ CHECK(ret, FAIL, "H5Dclose");
+ ret = H5Fclose(fid);
+ CHECK(ret, FAIL, "H5Fclose");
+ ret = H5Fclose(rfid);
+ CHECK(ret, FAIL, "H5Fclose");
+ HDremove(REOPEN_FILE);
+
+} /* test_file_reopen() */
+
+/****************************************************************
+**
** test_file_close(): low-level file close test routine.
** It mainly tests behavior with close degree.
**
@@ -3231,8 +3287,10 @@ test_filespace_compatible(void)
CHECK(fd_new, FAIL, "HDopen");
/* Copy data */
- while((nread = HDread(fd_old, buf, (size_t)READ_OLD_BUFSIZE)) > 0)
- HDwrite(fd_new, buf, (size_t)nread);
+ while((nread = HDread(fd_old, buf, (size_t)READ_OLD_BUFSIZE)) > 0) {
+ ssize_t write_err = HDwrite(fd_new, buf, (size_t)nread);
+ CHECK(write_err, -1, "HDwrite");
+ } /* end while */
/* Close the files */
ret = HDclose(fd_old);
@@ -3686,8 +3744,9 @@ test_file(void)
/* Output message about test being performed */
MESSAGE(5, ("Testing Low-Level File I/O\n"));
- test_file_create(); /* Test file creation(also creation templates)*/
- test_file_open(); /* Test file opening */
+ test_file_create(); /* Test file creation(also creation templates)*/
+ test_file_open(); /* Test file opening */
+ test_file_reopen(); /* Test file reopening */
test_file_close(); /* Test file close behavior */
test_get_file_id(); /* Test H5Iget_file_id */
test_get_obj_ids(); /* Test H5Fget_obj_ids for Jira Issue 8528 */
@@ -3741,5 +3800,7 @@ cleanup_file(void)
HDremove(FILE3);
HDremove(FILE4);
HDremove(FILE5);
+ HDremove(FILE6);
+ HDremove(FILE7);
}