summaryrefslogtreecommitdiffstats
path: root/test/error_test.c
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-06-06 22:15:24 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-06-06 22:15:24 (GMT)
commit99030cf45c9f6a804e4a22b1af38b872f06396cb (patch)
tree04c920f3196566d1ec82dd0a0fbd9528f497d59e /test/error_test.c
parentbecc4769b65311e5f837e7c2d2e195a4389692c7 (diff)
downloadhdf5-99030cf45c9f6a804e4a22b1af38b872f06396cb.zip
hdf5-99030cf45c9f6a804e4a22b1af38b872f06396cb.tar.gz
hdf5-99030cf45c9f6a804e4a22b1af38b872f06396cb.tar.bz2
[svn-r20936] Issue 4278 - When reading data fails, the error message should say which filter isn't registered. The fix is simple. Most of the effort is on the test. The file with filter enabled is created in gen_filter.c. The verification of the error message is in test_error.c. The output is compared against the standard output.
Tested on jam, koala, and heiwa.
Diffstat (limited to 'test/error_test.c')
-rw-r--r--test/error_test.c77
1 files changed, 69 insertions, 8 deletions
diff --git a/test/error_test.c b/test/error_test.c
index 52dcc0c..760351d 100644
--- a/test/error_test.c
+++ b/test/error_test.c
@@ -20,17 +20,19 @@
* Purpose: Tests the error API routines.
*/
#include "h5test.h"
+#include "H5srcdir.h"
#ifdef H5_USE_16_API
int main(void)
{
- printf("Test skipped because backward compatbility with v1.6 is configured in\n");
+ fprintf(stderr, "Test skipped because backward compatbility with v1.6 is configured in\n");
return 0;
}
#else /* H5_USE_16_API */
const char *FILENAME[] = {
"errors",
+ "filter_error",
NULL
};
@@ -74,6 +76,8 @@ hid_t ERR_MIN_GETNUM;
#define MSG_SIZE 64
#define LONG_DESC_SIZE 8192
+#define DSET_FILTER_NAME "dataset_with_filter"
+
static herr_t custom_print_cb(unsigned n, const H5E_error2_t *err_desc,
void *client_data);
@@ -102,8 +106,7 @@ test_error(hid_t file)
H5E_auto2_t old_func;
void *old_data;
- TESTING("error API based on data I/O");
- printf("\n");
+ fprintf(stderr, "\nTesting error API based on data I/O\n");
/* Create the data space */
dims[0] = DIM0;
@@ -360,7 +363,7 @@ test_long_desc(void)
if(H5Epush(H5E_DEFAULT, __FILE__, test_FUNC, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, format, long_desc) < 0) TEST_ERROR;
/* Create the string that should be in the description */
- HDsnprintf(full_desc, LONG_DESC_SIZE + 128, format, long_desc);
+ snprintf(full_desc, (size_t)(LONG_DESC_SIZE + 128), format, long_desc);
/* Make certain that the description is correct */
if(H5Ewalk2(H5E_DEFAULT, H5E_WALK_UPWARD, long_desc_cb, full_desc) < 0) TEST_ERROR;
@@ -534,7 +537,6 @@ test_copy(void)
const char *err_func = "test_copy"; /* Function name for pushing error */
const char *err_msg = "Error message"; /* Error message for pushing error */
int err_num; /* Number of errors on stack */
- int err_num_copy; /* Number of errors on stack copy */
hid_t estack_id; /* Error stack ID */
herr_t ret; /* Generic return value */
@@ -618,6 +620,57 @@ error:
/*-------------------------------------------------------------------------
+ * Function: test_filter_error
+ *
+ * Purpose: Make sure the error message prints out the filter name
+ * when the existent file is opened but the filter isn't
+ * registered. The existent file was created with
+ * gen_filters.c.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * 2 June 2011
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_filter_error(const char *fname)
+{
+ const char *pathname = H5_get_srcdir_filename(fname); /* Corrected test file name */
+ hid_t file, dataset; /* handles */
+ int buf[20];
+
+ fprintf(stderr, "\nTesting error message during data reading when filter isn't registered\n");
+
+ /* Open the file */
+ if((file = H5Fopen(pathname, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
+
+ /* Open the regular dataset */
+ if((dataset = H5Dopen2(file, DSET_FILTER_NAME, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
+
+ if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) >= 0)
+ TEST_ERROR;
+
+ /* Close/release resources */
+ if(H5Dclose(dataset) < 0)
+ TEST_ERROR
+
+ if(H5Fclose(file) < 0)
+ TEST_ERROR
+
+ return 0;
+
+error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
* Function: main
*
* Purpose: Test error API.
@@ -689,17 +742,25 @@ main(void)
if(test_copy() < 0) TEST_ERROR;
if(H5Fclose(file) < 0) TEST_ERROR;
- h5_cleanup(FILENAME, fapl);
/* Close error information */
if(close_error() < 0)
TEST_ERROR;
- printf("All error API tests passed.\n");
+ /* Test error message during data reading when filter isn't registered
+ * Use default FAPL to avoid some VFD drivers by the check-vfd test because
+ * the test file was pre-generated. */
+ h5_fixname(FILENAME[1], H5P_DEFAULT, filename, sizeof filename);
+ if(test_filter_error(filename) < 0)
+ TEST_ERROR;
+
+ h5_cleanup(FILENAME, fapl);
+
+ fprintf(stderr, "\nAll error API tests passed.\n");
return 0;
error:
- printf("***** ERROR TEST FAILED! *****\n");
+ fprintf(stderr, "\n***** ERROR TEST FAILED (real problem)! *****\n");
return 1;
}
#endif /* H5_USE_16_API */