Skip to content

Commit

Permalink
Test creating unseekable file
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Aug 16, 2024
1 parent 819e00d commit 63407cd
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/tfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8100,6 +8100,49 @@ test_min_dset_ohdr(void)
CHECK(ret, FAIL, "H5Fclose");
} /* end test_min_dset_ohdr() */

/****************************************************************
**
** test_unseekable_file():
** Test that attempting to open an unseekable file fails gracefully
** without a segfault (see hdf5#1498)
****************************************************************/
static void
test_unseekable_file(void)
{
hid_t file_id = H5I_INVALID_HID; /* File ID */

/* Output message about test being performed */
MESSAGE(5, ("Testing creating/opening an unseekable file\n"));

/* Creation */
#ifdef H5_HAVE_WIN32_API
file_id = H5Fcreate("NUL", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
#else
file_id = H5Fcreate("/dev/null", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
#endif

H5Fclose(file_id);

/* Open, truncate */
#ifdef H5_HAVE_WIN32_API
file_id = H5Fopen("NUL", H5F_ACC_TRUNC, H5P_DEFAULT);
#else
file_id = H5Fopen("/dev/null", H5F_ACC_TRUNC, H5P_DEFAULT);
#endif

H5Fclose(file_id);

/* Open, RDWR */
#ifdef H5_HAVE_WIN32_API
file_id = H5Fopen("NUL", H5F_ACC_RDWR, H5P_DEFAULT);
#else
file_id = H5Fopen("/dev/null", H5F_ACC_RDWR, H5P_DEFAULT);
#endif

H5Fclose(file_id);

exit(EXIT_SUCCESS);
}
/****************************************************************
**
** test_deprec():
Expand Down Expand Up @@ -8423,6 +8466,7 @@ test_file(void)
test_libver_macros2(); /* Test the macros for library version comparison */
test_incr_filesize(); /* Test H5Fincrement_filesize() and H5Fget_eoa() */
test_min_dset_ohdr(); /* Test dataset object header minimization */
test_unseekable_file(); /* Test attempting to open/create an unseekable file */
#ifndef H5_NO_DEPRECATED_SYMBOLS
test_file_ishdf5(driver_name); /* Test detecting HDF5 files correctly */
test_deprec(driver_name); /* Test deprecated routines */
Expand Down

0 comments on commit 63407cd

Please sign in to comment.