summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2004-06-30 13:45:07 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2004-06-30 13:45:07 (GMT)
commit358b8545dd9e3baa4b63c88a0d28aa8d7afb065b (patch)
tree50e0eac8be56d523b056778f4d3cac14dd777c28 /test
parent62f6531f2d3910a53c333047fdd941539eb6908f (diff)
downloadhdf5-358b8545dd9e3baa4b63c88a0d28aa8d7afb065b.zip
hdf5-358b8545dd9e3baa4b63c88a0d28aa8d7afb065b.tar.gz
hdf5-358b8545dd9e3baa4b63c88a0d28aa8d7afb065b.tar.bz2
[svn-r8765] Purpose: New feature and its test.
Description: Added new API H5Fget_name and new test program called filename.c. This function returns the name of the file by object ID(file, group, dataset, named datatype, and attribute) which belongs to the file. Platforms tested: h5committest and fuss. Misc. update: MANIFEST and RELEASE.txt
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.in9
-rw-r--r--test/filename.c157
2 files changed, 163 insertions, 3 deletions
diff --git a/test/Makefile.in b/test/Makefile.in
index 78e25d1..7121290 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -31,7 +31,7 @@ TEST_PROGS=testhdf5 lheap ohdr stab gheap hyperslab istore bittests dtypes
dsets cmpd_dset extend external links unlink big mtime fillval mount \
flush1 flush2 enum gass_write gass_read gass_append set_extent \
srb_write srb_append srb_read ttsafe stream_test getname file_handle \
- ntypes dangle dtransform
+ ntypes dangle dtransform filename
## Test programs for Error API. Only compile them but let testerror.sh run
## them to compare the output error messages with standard ones. 'make check'
@@ -68,7 +68,7 @@ MOSTLYCLEAN=cmpd_dset.h5 compact_dataset.h5 dataset.h5 extend.h5 istore.h5 \
getname.h5 getname[1-3].h5 sec2_file.h5 \
family_file000[0-3][0-9].h5 multi_file-[rs].h5 core_file \
new_move_[ab].h5 ntypes.h5 dangle.h5 error_test.h5 err_compat.h5 \
- dtransform.h5 test_filters.h5
+ dtransform.h5 test_filters.h5 get_file_name.h5
CLEAN=$(TIMINGS)
@@ -87,7 +87,7 @@ TEST_SRC=big.c bittests.c cmpd_dset.c dsets.c dtypes.c extend.c \
ttsafe_cancel.c ttsafe_acreate.c gass_write.c gass_read.c \
gass_append.c srb_read.c srb_write.c srb_append.c stream_test.c \
set_extent.c getname.c file_handle.c ntypes.c dangle.c error_test.c \
- err_compat.c dtransform.c
+ err_compat.c dtransform.c filename.c
TEST_OBJ=$(TEST_SRC:.c=.lo)
@@ -238,4 +238,7 @@ err_compat: err_compat.lo
dtransform: dtransform.lo
@$(LT_LINK_EXE) $(CFLAGS) -o $@ dtransform.lo $(LIB) $(LIBHDF5) $(LDFLAGS) $(LIBS)
+filename: filename.lo
+ @$(LT_LINK_EXE) $(CFLAGS) -o $@ filename.lo $(LIB) $(LIBHDF5) $(LDFLAGS) $(LIBS)
+
@CONCLUDE@
diff --git a/test/filename.c b/test/filename.c
new file mode 100644
index 0000000..992ae0d
--- /dev/null
+++ b/test/filename.c
@@ -0,0 +1,157 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Programmer: Raymond Lu <slu@ncsa.uiuc.edu>
+ * June 29, 2004
+ *
+ * Purpose: Tests the "H5Fget_name" functionality
+ */
+
+#include "hdf5.h"
+#include "h5test.h"
+#include "testhdf5.h"
+
+#define FILENAME "get_file_name"
+#define GROUPNAME "group"
+#define DSETNAME "dataset"
+#define ATTRNAME "attribute"
+#define DTYPENAME "compound"
+#define NAME_BUF_SIZE 64
+
+#define RANK 2
+#define NX 4
+#define NY 5
+
+/* Compound datatype */
+typedef struct s1_t {
+ unsigned int a;
+ float b;
+} s1_t;
+
+/* Used to make certain a return name _is_ the file name */
+#define VERIFY_NAME(x, val, where) do { \
+ if (GetTestVerbosity()>=VERBO_HI) { \
+ print_func(" Call to routine: %15s at line %4d in %s had value " \
+ "%ld \n", (where), (int)__LINE__, __FILE__, (long)(x)); \
+ } \
+ if (strcmp(x, val)) { \
+ TestErrPrintf("*** UNEXPECTED VALUE from %s should be %s, but is %s at line %4d " \
+ "in %s\n", where, val, x, (int)__LINE__, __FILE__); \
+ H5Eprint (H5E_DEFAULT, stdout); \
+ } \
+ strcmp(x, ""); \
+} while(0)
+
+int main( void )
+{
+ char filename[NAME_BUF_SIZE];
+ hid_t fapl;
+ hid_t file_id;
+ hid_t group_id;
+ hid_t dataset_id;
+ hid_t space_id;
+ hid_t type_id;
+ hid_t attr_id;
+ hsize_t dims[RANK] = {NX, NY};
+ char name[NAME_BUF_SIZE];
+ ssize_t name_len;
+ herr_t ret;
+
+ TESTING("H5Fget_name");
+
+ /* Reset the library and get the file access property list */
+ h5_reset();
+ fapl = h5_fileaccess();
+
+ /* Initialize the file names */
+ h5_fixname(FILENAME, fapl, filename, sizeof filename);
+
+ /* Create a new file_id using default properties. */
+ file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl );
+ CHECK(file_id, FAIL, "H5Fcreate");
+
+ /* Get and verify file name */
+ name_len = H5Fget_name(file_id, name, NAME_BUF_SIZE);
+ CHECK(name_len, FAIL, "H5Fget_name");
+ VERIFY_NAME(name, filename, "H5Fget_name");
+
+ /* Create a group in the root group */
+ group_id = H5Gcreate(file_id, GROUPNAME, 0);
+ CHECK(group_id, FAIL, "H5Gcreate");
+
+ /* Get and verify file name */
+ name_len = H5Fget_name(group_id, name, NAME_BUF_SIZE);
+ CHECK(name_len, FAIL, "H5Fget_name");
+ VERIFY_NAME(name, filename, "H5Fget_name");
+
+ /* Create the data space */
+ space_id = H5Screate_simple(RANK, dims, NULL);
+ CHECK(space_id, FAIL, "H5Screate_simple");
+
+ /* Try get file name from data space. Supposed to fail because
+ * it's illegal operation. */
+ H5E_BEGIN_TRY {
+ name_len = H5Fget_name(space_id, name, NAME_BUF_SIZE);
+ } H5E_END_TRY;
+ VERIFY(name_len, FAIL, "H5Fget_name");
+
+ /* Create a new dataset */
+ dataset_id = H5Dcreate(file_id, DSETNAME, H5T_NATIVE_INT, space_id, H5P_DEFAULT);
+ CHECK(dataset_id, FAIL, "H5Dcreate");
+
+ /* Get and verify file name */
+ name_len = H5Fget_name(dataset_id, name, NAME_BUF_SIZE);
+ CHECK(name_len, FAIL, "H5Fget_name");
+ VERIFY_NAME(name, filename, "H5Fget_name");
+
+ /* Create an attribute for the dataset */
+ attr_id = H5Acreate(dataset_id,ATTRNAME,H5T_NATIVE_INT,space_id,H5P_DEFAULT);
+ CHECK(attr_id, FAIL, "H5Acreate");
+
+ /* Get and verify file name */
+ name_len = H5Fget_name(attr_id, name, NAME_BUF_SIZE);
+ CHECK(name_len, FAIL, "H5Fget_name");
+ VERIFY_NAME(name, filename, "H5Fget_name");
+
+ /* Create a compound datatype */
+ type_id = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
+ CHECK(type_id, FAIL, "H5Tcreate");
+
+ /* Insert fields */
+ ret = H5Tinsert (type_id, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT);
+ CHECK(ret, FAIL, "H5Tinsert");
+
+ ret = H5Tinsert (type_id, "b", HOFFSET(s1_t,b), H5T_NATIVE_FLOAT);
+ CHECK(ret, FAIL, "H5Tinsert");
+
+ /* Save it on file */
+ ret = H5Tcommit(file_id, DTYPENAME, type_id);
+ CHECK(ret, FAIL, "H5Tcommit");
+
+ /* Get and verify file name */
+ name_len = H5Fget_name(type_id, name, NAME_BUF_SIZE);
+ CHECK(name_len, FAIL, "H5Fget_name");
+ VERIFY_NAME(name, filename, "H5Fget_name");
+
+ H5Tclose(type_id);
+ H5Aclose(attr_id);
+ H5Dclose(dataset_id);
+ H5Sclose(space_id);
+ H5Gclose(group_id);
+ H5Fclose(file_id);
+
+ PASSED();
+ return 0;
+}