summaryrefslogtreecommitdiffstats
path: root/tools/h5stat
diff options
context:
space:
mode:
Diffstat (limited to 'tools/h5stat')
-rw-r--r--tools/h5stat/CMakeLists.txt6
-rw-r--r--tools/h5stat/h5stat.c39
-rw-r--r--tools/h5stat/testfiles/h5stat_notexist.ddl5
-rw-r--r--tools/h5stat/testh5stat.sh.in3
4 files changed, 21 insertions, 32 deletions
diff --git a/tools/h5stat/CMakeLists.txt b/tools/h5stat/CMakeLists.txt
index 1f19ca0..e8d75e3 100644
--- a/tools/h5stat/CMakeLists.txt
+++ b/tools/h5stat/CMakeLists.txt
@@ -41,6 +41,7 @@ IF (BUILD_TESTING)
SET (HDF5_REFERENCE_FILES
h5stat_help1.ddl
h5stat_help2.ddl
+ h5stat_notexist.ddl
h5stat_filters.ddl
h5stat_filters-file.ddl
h5stat_filters-F.ddl
@@ -136,6 +137,8 @@ IF (BUILD_TESTING)
h5stat_help1.out.err
h5stat_help2.out
h5stat_help2.out.err
+ h5stat_notexist.out
+ h5stat_notexist.out.err
h5stat_filters.out
h5stat_filters.out.err
h5stat_filters-file.out
@@ -171,6 +174,9 @@ IF (BUILD_TESTING)
ADD_H5_TEST (h5stat_help1 0 -h)
ADD_H5_TEST (h5stat_help2 0 --help)
+# Test when h5stat a file that does not exist
+ ADD_H5_TEST (h5stat_notexist 1 notexist.h5)
+
# Test file with groups, compressed datasets, user-applied fileters, etc.
# h5stat_filters.h5 is a copy of ../../testfiles/tfilters.h5 as of release 1.8.0-alpha4
ADD_H5_TEST (h5stat_filters 0 h5stat_filters.h5)
diff --git a/tools/h5stat/h5stat.c b/tools/h5stat/h5stat.c
index 99ea688..a68760d 100644
--- a/tools/h5stat/h5stat.c
+++ b/tools/h5stat/h5stat.c
@@ -937,36 +937,9 @@ error:
/*-------------------------------------------------------------------------
- * Function: init_iter
+ * Function: iter_free
*
- * Purpose: Initialize iter structure
- *
- * Return: Success: 0
- *
- * Failure: Never fails
- *
- * Programmer: Elena Pourmal
- * Saturday, August 12, 2006
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-iter_init(iter_t *iter, hid_t fid)
-{
- /* Clear everything to zeros */
- HDmemset(iter, 0, sizeof(*iter));
-
- /* Set the file ID for later use in callbacks */
- iter->fid = fid;
-
- return 0;
-} /* iter_init() */
-
-
-/*-------------------------------------------------------------------------
- * Function: free_iter
- *
- * Purpose: Freee iter structure
+ * Purpose: Free iter structure
*
* Return: Success: 0
*
@@ -1610,7 +1583,7 @@ main(int argc, const char *argv[])
{
iter_t iter;
const char *fname = NULL;
- hid_t fid;
+ hid_t fid = -1;
hid_t fcpl;
struct handler_t *hand = NULL;
H5F_info2_t finfo;
@@ -1633,6 +1606,8 @@ main(int argc, const char *argv[])
printf("Filename: %s\n", fname);
+ HDmemset(&iter, 0, sizeof(iter));
+
fid = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);
if(fid < 0) {
error_msg("unable to open file \"%s\"\n", fname);
@@ -1641,7 +1616,7 @@ main(int argc, const char *argv[])
} /* end if */
/* Initialize iter structure */
- iter_init(&iter, fid);
+ iter.fid = fid;
if(H5Fget_filesize(fid, &iter.filesize) < 0)
warn_msg("Unable to retrieve file size\n");
@@ -1708,7 +1683,7 @@ done:
/* Free iter structure */
iter_free(&iter);
- if(H5Fclose(fid) < 0) {
+ if(fid >= 0 && H5Fclose(fid) < 0) {
error_msg("unable to close file \"%s\"\n", fname);
h5tools_setstatus(EXIT_FAILURE);
}
diff --git a/tools/h5stat/testfiles/h5stat_notexist.ddl b/tools/h5stat/testfiles/h5stat_notexist.ddl
new file mode 100644
index 0000000..ac0fce4
--- /dev/null
+++ b/tools/h5stat/testfiles/h5stat_notexist.ddl
@@ -0,0 +1,5 @@
+#############################
+Expected output for 'h5stat notexist.h5'
+#############################
+Filename: notexist.h5
+h5stat error: unable to open file "notexist.h5"
diff --git a/tools/h5stat/testh5stat.sh.in b/tools/h5stat/testh5stat.sh.in
index 74155e9..c605295 100644
--- a/tools/h5stat/testh5stat.sh.in
+++ b/tools/h5stat/testh5stat.sh.in
@@ -78,6 +78,7 @@ $SRC_H5STAT_TESTFILES/h5stat_idx.h5
LIST_OTHER_TEST_FILES="
$SRC_H5STAT_TESTFILES/h5stat_help1.ddl
$SRC_H5STAT_TESTFILES/h5stat_help2.ddl
+$SRC_H5STAT_TESTFILES/h5stat_notexist.ddl
$SRC_H5STAT_TESTFILES/h5stat_filters.ddl
$SRC_H5STAT_TESTFILES/h5stat_filters-file.ddl
$SRC_H5STAT_TESTFILES/h5stat_filters-F.ddl
@@ -191,6 +192,8 @@ COPY_TESTFILES_TO_TESTDIR
# Test for help flag
TOOLTEST h5stat_help1.ddl -h
TOOLTEST h5stat_help2.ddl --help
+# Test when h5stat a file that does not exist
+TOOLTEST h5stat_notexist.ddl notexist.h5
# Test file with groups, compressed datasets, user-applied fileters, etc.
# h5stat_filters.h5 is a copy of ../../testfiles/tfilters.h5 as of release 1.8.0-alpha4