summaryrefslogtreecommitdiffstats
path: root/test/tfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/tfile.c')
-rw-r--r--test/tfile.c152
1 files changed, 138 insertions, 14 deletions
diff --git a/test/tfile.c b/test/tfile.c
index 6c3746c..7d26c63 100644
--- a/test/tfile.c
+++ b/test/tfile.c
@@ -1263,6 +1263,79 @@ test_file_perm(void)
/****************************************************************
**
+** test_file_perm2(): low-level file test routine.
+** This test verifies that no object can be created in a
+** file that is opened for read-only.
+**
+*****************************************************************/
+static void
+test_file_perm2(void)
+{
+ hid_t file; /* File opened with read-write permission */
+ hid_t filero; /* Same file opened with read-only permission */
+ hid_t dspace; /* Dataspace ID */
+ hid_t group; /* Group ID */
+ hid_t dset; /* Dataset ID */
+ hid_t type; /* Datatype ID */
+ hid_t attr; /* Attribute ID */
+ herr_t ret;
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Low-Level File Permissions again\n"));
+
+ dspace = H5Screate(H5S_SCALAR);
+ CHECK(dspace, FAIL, "H5Screate");
+
+ /* Create the file (with read-write permission) */
+ file = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(file, FAIL, "H5Fcreate");
+
+ ret = H5Fclose(file);
+ CHECK(ret, FAIL, "H5Fclose");
+
+ /* Open the file (with read-only permission) */
+ filero = H5Fopen(FILE2, H5F_ACC_RDONLY, H5P_DEFAULT);
+ CHECK(filero, FAIL, "H5Fopen");
+
+ /* Create a group with the read-only file handle (should fail) */
+ H5E_BEGIN_TRY {
+ group = H5Gcreate2(filero, "MY_GROUP", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ } H5E_END_TRY;
+ VERIFY(group, FAIL, "H5Gcreate2");
+
+ /* Create a dataset with the read-only file handle (should fail) */
+ H5E_BEGIN_TRY {
+ dset = H5Dcreate2(filero, F2_DSET, H5T_NATIVE_INT, dspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ } H5E_END_TRY;
+ VERIFY(dset, FAIL, "H5Dcreate2");
+
+ /* Create an attribute with the read-only file handle (should fail) */
+ H5E_BEGIN_TRY {
+ attr = H5Acreate2(filero, "MY_ATTR", H5T_NATIVE_INT, dspace, H5P_DEFAULT, H5P_DEFAULT);
+ } H5E_END_TRY;
+ VERIFY(attr, FAIL, "H5Acreate2");
+
+ type = H5Tcopy(H5T_NATIVE_SHORT);
+ CHECK(type, FAIL, "H5Tcopy");
+
+ /* Commit a datatype with the read-only file handle (should fail) */
+ H5E_BEGIN_TRY {
+ ret = H5Tcommit2(filero, "MY_DTYPE", type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ } H5E_END_TRY;
+ VERIFY(ret, FAIL, "H5Tcommit2");
+
+ ret = H5Tclose(type);
+ CHECK(ret, FAIL, "H5Tclose");
+
+ ret = H5Fclose(filero);
+ CHECK(ret, FAIL, "H5Fclose");
+
+ ret = H5Sclose(dspace);
+ CHECK(ret, FAIL, "H5Sclose");
+} /* end test_file_perm2() */
+
+/****************************************************************
+**
** test_file_freespace(): low-level file test routine.
** This test checks the free space available in a file in various
** situations.
@@ -3057,63 +3130,113 @@ test_filespace_compatible(void)
/****************************************************************
**
-** test_libver_bounds():
-** Verify that a file created with "LATEST, LATEST" can be
-** opened later, with no setting. (Further testing welcome)
+** test_libver_bounds_real():
+** Verify that a file created and modified with the
+** specified libver bounds has the specified object header
+** versions for the right objects.
**
****************************************************************/
static void
-test_libver_bounds(void)
+test_libver_bounds_real(H5F_libver_t libver_create, unsigned oh_vers_create,
+ H5F_libver_t libver_mod, unsigned oh_vers_mod)
{
hid_t file, group; /* Handles */
hid_t fapl; /* File access property list */
- herr_t ret; /* Return value */
-
- /* Output message about test being performed */
- MESSAGE(5, ("Testing setting library version bounds\n"));
+ H5O_info_t oinfo; /* Object info */
+ herr_t ret; /* Return value */
/*
- * Create a new file using the default properties.
+ * Create a new file using the creation properties.
*/
fapl = H5Pcreate(H5P_FILE_ACCESS);
CHECK(fapl, FAIL, "H5Pcreate");
- ret = H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
+ ret = H5Pset_libver_bounds(fapl, libver_create, H5F_LIBVER_LATEST);
CHECK(ret, FAIL, "H5Pset_libver_bounds");
file = H5Fcreate("tfile5.h5", H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
CHECK(file, FAIL, "H5Fcreate");
+ /*
+ * Make sure the root group has the correct object header version
+ */
+ ret = H5Oget_info_by_name(file, "/", &oinfo, H5P_DEFAULT);
+ CHECK(ret, FAIL, "H5Oget_info_by_name");
+ VERIFY(oinfo.hdr.version, oh_vers_create, "H5Oget_info_by_name");
+
+ /*
+ * Reopen the file and make sure the root group still has the correct version
+ */
ret = H5Fclose(file);
CHECK(ret, FAIL, "H5Fclose");
- ret = H5Pset_libver_bounds(fapl, H5F_LIBVER_EARLIEST, H5F_LIBVER_LATEST);
+ ret = H5Pset_libver_bounds(fapl, libver_mod, H5F_LIBVER_LATEST);
CHECK(ret, FAIL, "H5Pset_libver_bounds");
file = H5Fopen("tfile5.h5", H5F_ACC_RDWR, fapl);
CHECK(file, FAIL, "H5Fopen");
+ ret = H5Oget_info_by_name(file, "/", &oinfo, H5P_DEFAULT);
+ CHECK(ret, FAIL, "H5Oget_info_by_name");
+ VERIFY(oinfo.hdr.version, oh_vers_create, "H5Oget_info_by_name");
+
/*
- * Create a group named "G1" in the file.
+ * Create a group named "G1" in the file, and make sure it has the correct
+ * object header version
*/
group = H5Gcreate2(file, "/G1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(group, FAIL, "H5Gcreate");
+ ret = H5Oget_info(group, &oinfo);
+ CHECK(ret, FAIL, "H5Oget_info_by_name");
+ VERIFY(oinfo.hdr.version, oh_vers_mod, "H5Oget_info_by_name");
+
ret = H5Gclose(group);
CHECK(ret, FAIL, "H5Gclose");
/*
- * Create a group named "/G1/G3" in the file.
+ * Create a group named "/G1/G3" in the file, and make sure it has the
+ * correct object header version
*/
group = H5Gcreate2(file, "/G1/G3", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(group, FAIL, "H5Gcreate");
+ ret = H5Oget_info(group, &oinfo);
+ CHECK(ret, FAIL, "H5Oget_info_by_name");
+ VERIFY(oinfo.hdr.version, oh_vers_mod, "H5Oget_info_by_name");
+
ret = H5Gclose(group);
CHECK(ret, FAIL, "H5Gclose");
+ /*
+ * Make sure the root group still has the correct object header version
+ */
+ ret = H5Oget_info_by_name(file, "/", &oinfo, H5P_DEFAULT);
+ CHECK(ret, FAIL, "H5Oget_info_by_name");
+ VERIFY(oinfo.hdr.version, oh_vers_create, "H5Oget_info_by_name");
+
ret = H5Fclose(file);
CHECK(ret, FAIL, "H5Fclose");
-} /* test_libver_bounds() */
+} /* end test_libver_bounds_real() */
+
+/****************************************************************
+**
+** test_libver_bounds():
+** Verify that a file created and modified with various
+** libver bounds is handled correctly. (Further testing
+** welcome)
+**
+****************************************************************/
+static void
+test_libver_bounds(void)
+{
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing setting library version bounds\n"));
+
+ /* Run the tests */
+ test_libver_bounds_real(H5F_LIBVER_EARLIEST, 1, H5F_LIBVER_LATEST, 2);
+ test_libver_bounds_real(H5F_LIBVER_LATEST, 2, H5F_LIBVER_EARLIEST, 1);
+} /* end test_libver_bounds() */
/****************************************************************
**
@@ -3581,6 +3704,7 @@ test_file(void)
#endif /* H5_NO_SHARED_WRITING */
test_get_file_id(); /* Test H5Iget_file_id */
test_file_perm(); /* Test file access permissions */
+ test_file_perm2(); /* Test file access permission again */
test_file_freespace(); /* Test file free space information */
test_file_ishdf5(); /* Test detecting HDF5 files correctly */
test_file_open_dot(); /* Test opening objects with "." for a name */