summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2003-10-31 18:48:42 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2003-10-31 18:48:42 (GMT)
commit6f6b6bb5e880b0c8f7472847e9b1b2cf498d4e35 (patch)
tree056612999f41218ac731640d6191a0a36d3ef7e1 /test
parent7948d9eb2667d9040b4d959198648143b7f1f9e4 (diff)
downloadhdf5-6f6b6bb5e880b0c8f7472847e9b1b2cf498d4e35.zip
hdf5-6f6b6bb5e880b0c8f7472847e9b1b2cf498d4e35.tar.gz
hdf5-6f6b6bb5e880b0c8f7472847e9b1b2cf498d4e35.tar.bz2
[svn-r7802] *** empty log message ***
Diffstat (limited to 'test')
-rw-r--r--test/tfile.c121
1 files changed, 79 insertions, 42 deletions
diff --git a/test/tfile.c b/test/tfile.c
index a5ec702..d418b0b 100644
--- a/test/tfile.c
+++ b/test/tfile.c
@@ -53,6 +53,8 @@
#define F3_SYM_INTERN_K F2_SYM_INTERN_K
#define FILE3 "tfile3.h5"
+#define GROUP_NAME "/group"
+#define DSET_NAME "dataset"
#define ATTR_NAME "attr"
#define TYPE_NAME "type"
#define FILE4 "tfile4.h5"
@@ -69,6 +71,8 @@ static void
create_objects(hid_t, hid_t, hid_t *, hid_t *, hid_t *, hid_t *);
static void
test_obj_count_and_id(hid_t, hid_t, hid_t, hid_t, hid_t, hid_t);
+static void
+check_file_id(hid_t, hid_t);
/****************************************************************
**
@@ -827,39 +831,59 @@ create_objects(hid_t fid1, hid_t fid2, hid_t *ret_did, hid_t *ret_gid1,
static void
test_get_file_id(void)
{
- hid_t fid1, fid2;
+ hid_t fid, fid2, fid3;
hid_t datatype_id, dataset_id, dataspace_id, group_id, attr_id;
hid_t plist;
hsize_t dims[F2_RANK];
herr_t ret;
+ int numb;
/* Create a file */
- fid1 = H5Fcreate(FILE4, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- CHECK(fid1, FAIL, "H5Fcreate");
+ fid = H5Fcreate(FILE4, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(fid, FAIL, "H5Fcreate");
- /* Return a duplicated file ID even not expecting user to do it.
- * And close this duplicated ID
- */
- fid2 = H5Iget_file_id(fid1);
- CHECK(fid2, FAIL, "H5Iget_file_id");
- VERIFY(fid2, fid1, "H5Iget_file_id");
-
- ret = H5Fclose(fid2);
- CHECK(ret, FAIL, "H5Fclose");
+ /* Test H5Iget_file_id() */
+ check_file_id(fid, fid);
/* Create a group in the file. Make a duplicated file ID from the group.
* And close this duplicated ID
*/
- group_id = H5Gcreate(fid1, "/group", 0);
+ group_id = H5Gcreate(fid, GROUP_NAME, 0);
CHECK(group_id, FAIL, "H5Gcreate");
-
- fid2 = H5Iget_file_id(group_id);
- CHECK(fid2, FAIL, "H5Iget_file_id");
- VERIFY(fid2, fid1, "H5Iget_file_id");
+
+ /* Test H5Iget_file_id() */
+ check_file_id(fid, group_id);
- ret = H5Fclose(fid2);
+ /* Close the file and get file ID from the group ID */
+ ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
+ /* Test H5Iget_file_id() */
+ check_file_id(-1, group_id);
+
+ ret = H5Gclose(group_id);
+ CHECK(ret, FAIL, "H5Gclose");
+
+ /* Open the file again. Test H5Iget_file_id() */
+ fid = H5Fopen(FILE4, H5F_ACC_RDWR, H5P_DEFAULT);
+ CHECK(fid, FAIL, "H5Fcreate");
+
+ group_id = H5Gopen(fid, GROUP_NAME);
+ CHECK(group_id, FAIL, "H5Gcreate");
+
+ /* Test H5Iget_file_id() */
+ check_file_id(fid, group_id);
+
+ /* Open the file for second time. Test H5Iget_file_id() */
+ fid3 = H5Freopen(fid);
+ CHECK(fid3, FAIL, "H5Freopen");
+
+ /* Test H5Iget_file_id() */
+ check_file_id(fid3, fid3);
+
+ ret = H5Fclose(fid3);
+ CHECK(ret, FAIL, "H5Fclose");
+
/* Create a dataset in the group. Make a duplicated file ID from the
* dataset. And close this duplicated ID.
*/
@@ -868,29 +892,21 @@ test_get_file_id(void)
dataspace_id = H5Screate_simple(F2_RANK, dims, NULL);
CHECK(dataspace_id, FAIL, "H5Screate_simple");
- dataset_id = H5Dcreate(group_id, "/dset", H5T_NATIVE_INT, dataspace_id,
+ dataset_id = H5Dcreate(group_id, DSET_NAME, H5T_NATIVE_INT, dataspace_id,
H5P_DEFAULT);
CHECK(dataset_id, FAIL, "H5Dcreate");
-
- fid2 = H5Iget_file_id(dataset_id);
- CHECK(fid2, FAIL, "H5Iget_file_id");
- VERIFY(fid2, fid1, "H5Iget_file_id");
-
- ret = H5Fclose(fid2);
- CHECK(ret, FAIL, "H5Fclose");
-
+
+ /* Test H5Iget_file_id() */
+ check_file_id(fid, dataset_id);
+
/* Create an attribute for the dataset. Make a duplicated file ID from
* this attribute. And close it.
*/
attr_id=H5Acreate(dataset_id,ATTR_NAME,H5T_NATIVE_INT,dataspace_id,H5P_DEFAULT);
CHECK(ret, FAIL, "H5Acreate");
-
- fid2 = H5Iget_file_id(attr_id);
- CHECK(fid2, FAIL, "H5Iget_file_id");
- VERIFY(fid2, fid1, "H5Iget_file_id");
- ret = H5Fclose(fid2);
- CHECK(ret, FAIL, "H5Fclose");
+ /* Test H5Iget_file_id() */
+ check_file_id(fid, attr_id);
/* Create a named datatype. Make a duplicated file ID from
* this attribute. And close it.
@@ -898,15 +914,11 @@ test_get_file_id(void)
datatype_id=H5Tcopy(H5T_NATIVE_INT);
CHECK(ret, FAIL, "H5Acreate");
- ret = H5Tcommit(fid1, TYPE_NAME, datatype_id);
+ ret = H5Tcommit(fid, TYPE_NAME, datatype_id);
CHECK(ret, FAIL, "H5Tcommit");
-
- fid2 = H5Iget_file_id(datatype_id);
- CHECK(fid2, FAIL, "H5Iget_file_id");
- VERIFY(fid2, fid1, "H5Iget_file_id");
-
- ret = H5Fclose(fid2);
- CHECK(ret, FAIL, "H5Fclose");
+
+ /* Test H5Iget_file_id() */
+ check_file_id(fid, datatype_id);
/* Create a property list and try to get file ID from it.
* Supposed to fail.
@@ -935,7 +947,32 @@ test_get_file_id(void)
ret = H5Gclose(group_id);
CHECK(ret, FAIL, "H5Gclose");
- ret = H5Fclose(fid1);
+ ret = H5Fclose(fid);
+ CHECK(ret, FAIL, "H5Fclose");
+}
+
+/****************************************************************
+**
+** check_file_id(): Internal function of test_get_file_id()
+**
+*****************************************************************/
+static void
+check_file_id(hid_t fid, hid_t object_id)
+{
+ hid_t new_fid;
+ herr_t ret;
+
+ /* Return a duplicated file ID even not expecting user to do it.
+ * And close this duplicated ID
+ */
+ new_fid = H5Iget_file_id(object_id);
+
+ if(fid >=0)
+ VERIFY(new_fid, fid, "H5Iget_file_id");
+ else
+ CHECK(new_fid, FAIL, "H5Iget_file_id");
+
+ ret = H5Fclose(new_fid);
CHECK(ret, FAIL, "H5Fclose");
}