summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/CMakeTests.cmake2
-rw-r--r--test/Makefile.am2
-rw-r--r--test/ShellTests.cmake2
-rw-r--r--test/cmpd_dtransform.c136
-rw-r--r--test/dtransform.c24
-rw-r--r--test/err_compat.c273
-rw-r--r--test/error_test.c2
-rw-r--r--test/testfiles/err_compat_112
9 files changed, 318 insertions, 136 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 09ee97b..ecfef57 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -285,6 +285,7 @@ set (H5_TESTS
swmr
thread_id # special link
timer
+ cmpd_dtransform
version_bounds_1_10
)
diff --git a/test/CMakeTests.cmake b/test/CMakeTests.cmake
index 1461648..4cf11f5 100644
--- a/test/CMakeTests.cmake
+++ b/test/CMakeTests.cmake
@@ -919,7 +919,7 @@ if (BUILD_SHARED_LIBS)
##############################################################################
endif ()
-option (TEST_SHELL_SCRIPTS "Enable shell script tests" OFF)
+option (TEST_SHELL_SCRIPTS "Enable shell script tests" ON)
if (TEST_SHELL_SCRIPTS)
include (ShellTests.cmake)
endif()
diff --git a/test/Makefile.am b/test/Makefile.am
index d78cbe3..b677927 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -60,7 +60,7 @@ TEST_PROG= testhdf5 \
cache cache_api cache_image cache_tagging lheap ohdr \
stab gheap evict_on_close farray earray btree2 fheap \
pool accum hyperslab istore bittests dt_arith page_buffer \
- dtypes dsets chunk_info cmpd_dset filter_fail extend direct_chunk \
+ dtypes dsets chunk_info cmpd_dset cmpd_dtransform filter_fail extend direct_chunk \
external efc objcopy links unlink twriteorder big mtime fillval mount \
flush1 flush2 app_ref enum set_extent ttsafe enc_dec_plist \
enc_dec_plist_cross_platform getname vfd ros3 s3comms hdfs ntypes \
diff --git a/test/ShellTests.cmake b/test/ShellTests.cmake
index b28bbd6..812121e 100644
--- a/test/ShellTests.cmake
+++ b/test/ShellTests.cmake
@@ -17,7 +17,7 @@
if (UNIX)
- find_program (SH_PROGRAM sh)
+ find_program (SH_PROGRAM bash)
if (SH_PROGRAM)
##############################################################################
diff --git a/test/cmpd_dtransform.c b/test/cmpd_dtransform.c
new file mode 100644
index 0000000..ef5ad75
--- /dev/null
+++ b/test/cmpd_dtransform.c
@@ -0,0 +1,136 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * 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 COPYING file, which can be found at the root of the source code *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Programmer: Jan-Willem Blokland
+ * December 1, 2020
+ *
+ * Purpose: Test writing compounded attribute followed by
+ * writing data with a data transform function.
+ */
+
+#include "h5test.h"
+
+#define FILENAME "cmpd_dtransform.h5"
+#define LENGTH 11
+
+typedef struct {
+ char name[64];
+ char unit[64];
+} att_t;
+
+int
+main(void)
+{
+ hsize_t dima[] = {1};
+ hsize_t dims[] = {LENGTH};
+ hid_t str_dtyp_id, att_dtyp_id, file_id, fspace_id, dset_id, att_dspc_id, att_attr_id, dxpl_id;
+
+ /* Compound datatype */
+ att_t *atts = HDmalloc(sizeof(att_t));
+ HDstrcpy(atts[0].name, "Name");
+ HDstrcpy(atts[0].unit, "Unit");
+
+ /* String type */
+ if ((str_dtyp_id = H5Tcopy(H5T_C_S1)) < 0)
+ TEST_ERROR;
+ H5Tset_size(str_dtyp_id, 64);
+
+ /* Attribute type */
+ if ((att_dtyp_id = H5Tcreate(H5T_COMPOUND, sizeof(att_t))) < 0)
+ TEST_ERROR;
+ H5Tinsert(att_dtyp_id, "NAME", HOFFSET(att_t, name), str_dtyp_id);
+ H5Tinsert(att_dtyp_id, "UNIT", HOFFSET(att_t, unit), str_dtyp_id);
+
+ /* Create file. */
+ if ((file_id = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
+
+ /* Create file dataspace. */
+ if ((fspace_id = H5Screate_simple(1, dims, NULL)) < 0)
+ TEST_ERROR;
+
+ /* Create dataset. */
+ if ((dset_id = H5Dcreate2(file_id, "test_dset", H5T_NATIVE_INT, fspace_id, H5P_DEFAULT, H5P_DEFAULT,
+ H5P_DEFAULT)) < 0)
+ TEST_ERROR;
+
+ /* Write the attribute (compound) to the dataset */
+ if ((att_dspc_id = H5Screate_simple(1, dima, NULL)) < 0)
+ TEST_ERROR;
+ if ((att_attr_id =
+ H5Acreate2(dset_id, "ATTRIBUTES", att_dtyp_id, att_dspc_id, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
+ if (H5Awrite(att_attr_id, att_dtyp_id, atts) < 0)
+ TEST_ERROR;
+
+ /* Create dataset transfer property list */
+ const char *expr = "2*x";
+ if ((dxpl_id = H5Pcreate(H5P_DATASET_XFER)) < 0)
+ TEST_ERROR;
+ if (H5Pset_data_transform(dxpl_id, expr) < 0) {
+ HDprintf("**** ERROR: H5Pset_data_transform (expression: %s) ****\n", expr);
+ TEST_ERROR;
+ }
+
+ int *data = HDmalloc(LENGTH * sizeof(int));
+ int *data_res = HDmalloc(LENGTH * sizeof(int));
+ for (unsigned i = 0; i < LENGTH; i++) {
+ data[i] = 10;
+ data_res[i] = 2 * data[i];
+ }
+
+ /* Write the data */
+ if (H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl_id, data) < 0)
+ TEST_ERROR;
+
+ /* Read attribute */
+ att_t *atts_res = HDmalloc(sizeof(att_t));
+ if (H5Aread(att_attr_id, att_dtyp_id, atts_res) < 0)
+ TEST_ERROR;
+
+ /* Verify attribute */
+ if (HDstrcmp(atts_res[0].name, atts[0].name) != 0)
+ TEST_ERROR;
+ if (HDstrcmp(atts_res[0].unit, atts[0].unit) != 0)
+ TEST_ERROR;
+
+ /* Read the data */
+ if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0)
+ TEST_ERROR;
+
+ /* Verify data */
+ for (unsigned idx = 0; idx < LENGTH; idx++) {
+ if (data[idx] != data_res[idx])
+ TEST_ERROR;
+ }
+
+ HDfree(atts);
+ HDfree(atts_res);
+ HDfree(data);
+ HDfree(data_res);
+
+ /* Close all identifiers. */
+ H5Pclose(dxpl_id);
+ H5Aclose(att_attr_id);
+ H5Sclose(att_dspc_id);
+ H5Dclose(dset_id);
+ H5Sclose(fspace_id);
+ H5Fclose(file_id);
+ H5Tclose(att_dtyp_id);
+ H5Tclose(str_dtyp_id);
+
+ return 0;
+
+error:
+ return 1;
+}
diff --git a/test/dtransform.c b/test/dtransform.c
index c679d30..9445d83 100644
--- a/test/dtransform.c
+++ b/test/dtransform.c
@@ -581,6 +581,7 @@ test_specials(hid_t file)
const char *special3 = "1000/x";
const char *special4 = "-x";
const char *special5 = "+x";
+ const char *special6 = "2e+1*x";
TESTING("data transform of some special cases")
@@ -705,6 +706,29 @@ test_specials(hid_t file)
if (H5Dclose(dset_id) < 0)
TEST_ERROR
+ /*-----------------------------
+ * Operation 6: 2e+1*x
+ *----------------------------*/
+ if (H5Pset_data_transform(dxpl_id, special6) < 0)
+ TEST_ERROR;
+
+ for (row = 0; row < ROWS; row++)
+ for (col = 0; col < COLS; col++)
+ data_res[row][col] = transformData[row][col] * 20;
+
+ if ((dset_id = H5Dcreate2(file, "/special6", H5T_NATIVE_INT, dataspace, H5P_DEFAULT, H5P_DEFAULT,
+ H5P_DEFAULT)) < 0)
+ TEST_ERROR
+ if (H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl_id, transformData) < 0)
+ TEST_ERROR
+ if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf) < 0)
+ TEST_ERROR
+
+ COMPARE_INT(read_buf, data_res)
+
+ if (H5Dclose(dset_id) < 0)
+ TEST_ERROR
+
if (H5Pclose(dxpl_id) < 0)
TEST_ERROR
if (H5Sclose(dataspace) < 0)
diff --git a/test/err_compat.c b/test/err_compat.c
index 53c8667..6ad69d8 100644
--- a/test/err_compat.c
+++ b/test/err_compat.c
@@ -39,7 +39,6 @@ int * ipoints2_data = NULL;
int * icheck2_data = NULL;
#define DSET_NAME "a_dataset"
-#define FAKE_ID (hid_t) - 1
herr_t custom_print_cb1(int n, H5E_error1_t *err_desc, void *client_data);
herr_t custom_print_cb2(int n, H5E_error2_t *err_desc, void *client_data);
@@ -47,13 +46,13 @@ herr_t custom_print_cb2(int n, H5E_error2_t *err_desc, void *client_data);
/*-------------------------------------------------------------------------
* Function: user_print1
*
- * Purpose: This function is a user-defined old-style printing function.
+ * Purpose: This function is a user-defined old-style printing function.
* This is just a convenience function for H5Ewalk1() with a
* function that prints error messages.
*
- * Return: Non-negative on success/Negative on failure
+ * Return: SUCCEED/FAIL
*
- * Programmer: Raymond Lu
+ * Programmer: Raymond Lu
* 4 October 2010
*
*-------------------------------------------------------------------------
@@ -66,22 +65,22 @@ user_print1(FILE *stream)
if (H5Ewalk1(H5E_WALK_UPWARD, (H5E_walk1_t)custom_print_cb1, stream) < 0)
TEST_ERROR;
- return 0;
+ return SUCCEED;
error:
- return -1;
+ return FAIL;
}
/*-------------------------------------------------------------------------
* Function: user_print2
*
- * Purpose: This function is a user-defined new-style printing function.
+ * Purpose: This function is a user-defined new-style printing function.
* This is just a convenience function for H5Ewalk2() with a
* function that prints error messages.
*
- * Return: Non-negative on success/Negative on failure
+ * Return: SUCCEED/FAIL
*
- * Programmer: Raymond Lu
+ * Programmer: Raymond Lu
* 4 October 2010
*
*-------------------------------------------------------------------------
@@ -94,27 +93,23 @@ user_print2(hid_t err_stack, FILE *stream)
if (H5Ewalk2(err_stack, H5E_WALK_UPWARD, (H5E_walk2_t)custom_print_cb2, stream) < 0)
TEST_ERROR;
- return 0;
+ return SUCCEED;
error:
- return -1;
+ return FAIL;
}
/*-------------------------------------------------------------------------
* Function: custom_print_cb1
*
- * Purpose: Callback function to print error stack in customized way
- * for H5Ewalk1.
+ * Purpose: Callback function to print error stack in customized way
+ * for H5Ewalk1
*
- * Return: Success: 0
+ * Return: SUCCEED/FAIL
*
- * Failure: -1
- *
- * Programmer: Raymond Lu
+ * Programmer: Raymond Lu
* 4 October 2010
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
herr_t
@@ -140,7 +135,7 @@ custom_print_cb1(int n, H5E_error1_t *err_desc, void *client_data)
H5free_memory(maj);
H5free_memory(min);
- return 0;
+ return SUCCEED;
error:
if (maj)
@@ -148,24 +143,20 @@ error:
if (min)
H5free_memory(min);
- return -1;
+ return FAIL;
}
/*-------------------------------------------------------------------------
* Function: custom_print_cb2
*
- * Purpose: Callback function to print error stack in customized way
- * for H5Ewalk1.
- *
- * Return: Success: 0
+ * Purpose: Callback function to print error stack in customized way
+ * for H5Ewalk1
*
- * Failure: -1
+ * Return: SUCCEED/FAIL
*
- * Programmer: Raymond Lu
+ * Programmer: Raymond Lu
* 4 October 2010
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
herr_t
@@ -191,7 +182,7 @@ custom_print_cb2(int n, H5E_error2_t *err_desc, void *client_data)
H5free_memory(maj);
H5free_memory(min);
- return 0;
+ return SUCCEED;
error:
if (maj)
@@ -199,62 +190,59 @@ error:
if (min)
H5free_memory(min);
- return -1;
+ return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: test_error1
- *
- * Purpose: Test the backward compatibility of H5Eset/get_auto.
- *
- * Return: Success: 0
+ * Function: test_error_compat
*
- * Failure: -1
- *
- * Programmer: Raymond Lu
- * 17 September 2010
+ * Purpose: Test the backward compatibility of H5Eset/get_auto
*
+ * Return: SUCCEED/FAIL
*
- * Modifications:
+ * Programmer: Raymond Lu
+ * 17 September 2010
*
*-------------------------------------------------------------------------
*/
static herr_t
-test_error1(void)
+test_error_compat(void)
{
- hid_t dataset, space;
+ hid_t did = H5I_INVALID_HID;
+ hid_t sid = H5I_INVALID_HID;
hsize_t dims[2];
H5E_auto1_t old_func1;
H5E_auto2_t old_func2;
- void * old_data;
+ void * old_data = NULL;
herr_t ret;
TESTING("error API H5Eset/get_auto");
- HDfprintf(stderr, "\n");
- /* Create the data space */
+ /* Add a newline and flush so the output file looks nicer */
+ HDprintf("\n");
+ HDfflush(stdout);
+
+ /* Create the dataspace */
dims[0] = DIM0;
dims[1] = DIM1;
- if ((space = H5Screate_simple(2, dims, NULL)) < 0)
+ if ((sid = H5Screate_simple(2, dims, NULL)) < 0)
TEST_ERROR;
- /* Use H5Eget_auto2 to query the default printing function. The library
- *should indicate H5Eprint2 as the default. */
+ /* Use H5Eget_auto2 to query the default printing function. */
if (H5Eget_auto2(H5E_DEFAULT, &old_func2, &old_data) < 0)
TEST_ERROR;
if (old_data != NULL)
TEST_ERROR;
- if (!old_func2 || (H5E_auto2_t)H5Eprint2 != old_func2)
+ if (old_func2 == NULL)
TEST_ERROR;
- /* This function sets the default printing function to be H5Eprint2. */
if (H5Eset_auto2(H5E_DEFAULT, old_func2, old_data) < 0)
TEST_ERROR;
/* Try the printing function. Dataset creation should fail because the file
* doesn't exist. */
- dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- if (dataset >= 0)
+ did = H5Dcreate2(H5I_INVALID_HID, DSET_NAME, H5T_STD_I32BE, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ if (did >= 0)
TEST_ERROR;
/* This call should work. It simply returns H5Eprint1. */
@@ -271,8 +259,8 @@ test_error1(void)
/* Try the printing function. Dataset creation should fail because the file
* doesn't exist. */
- dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- if (dataset >= 0)
+ did = H5Dcreate2(H5I_INVALID_HID, DSET_NAME, H5T_STD_I32BE, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ if (did >= 0)
TEST_ERROR;
/* This call should fail because the test mixes H5Eget_auto2 with H5Eset_auto1.
@@ -288,16 +276,16 @@ test_error1(void)
/* Try the printing function. Dataset creation should fail because the file
* doesn't exist. */
- dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- if (dataset >= 0)
+ did = H5Dcreate2(H5I_INVALID_HID, DSET_NAME, H5T_STD_I32BE, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ if (did >= 0)
TEST_ERROR;
- /* This function changes the new-style printing function back to the default H5Eprint2. */
- if (H5Eset_auto2(H5E_DEFAULT, (H5E_auto2_t)H5Eprint2, NULL) < 0)
+ /* This function changes the new-style printing function to the original. */
+ if (H5Eset_auto2(H5E_DEFAULT, old_func2, NULL) < 0)
TEST_ERROR;
- /* This call should work because the H5Eset_auto2 above restored the default printing
- * function H5Eprint2. It simply returns user_print1. */
+ /* This call should work because the H5Eset_auto2 above set the default printing
+ * function to H5Eprint2. It simply returns user_print1. */
if ((ret = H5Eget_auto1(&old_func1, &old_data)) < 0)
TEST_ERROR;
if (old_data != NULL)
@@ -315,69 +303,77 @@ test_error1(void)
TEST_ERROR;
if (old_data != NULL)
TEST_ERROR;
- if (!old_func2 || (H5E_auto2_t)H5Eprint2 != old_func2)
+ if (old_func2 == NULL)
TEST_ERROR;
/* Try the printing function. Dataset creation should fail because the file
* doesn't exist. */
- dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- if (dataset >= 0)
+ did = H5Dcreate2(H5I_INVALID_HID, DSET_NAME, H5T_STD_I32BE, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ if (did >= 0)
TEST_ERROR;
- return 0;
+ if (H5Sclose(sid) < 0)
+ TEST_ERROR;
+
+ return SUCCEED;
error:
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Sclose(sid);
+ }
+ H5E_END_TRY
+
+ return FAIL;
}
/*-------------------------------------------------------------------------
- * Function: test_error2
- *
- * Purpose: Test error API functions, mainly on H5Epush1.
+ * Function: test_h5epush1
*
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Raymond Lu
- * July 10, 2003
+ * Purpose: Test error API functions, mainly H5Epush1
*
+ * Return: SUCCEED/FAIL
*
- * Modifications:
+ * Programmer: Raymond Lu
+ * July 10, 2003
*
*-------------------------------------------------------------------------
*/
static herr_t
-test_error2(hid_t file)
+test_h5epush1(hid_t file)
{
- hid_t dataset, space;
+ hid_t did = H5I_INVALID_HID;
+ hid_t sid = H5I_INVALID_HID;
+ hid_t estack_id = H5I_INVALID_HID;
hsize_t dims[2];
- const char *FUNC_test_error = "test_error2";
+ const char *FUNC_test_error = "test_h5epush1";
TESTING("error API based on data I/O");
- HDfprintf(stderr, "\n");
- /* Create the data space */
+ /* Add a newline and flush so the output file looks nicer */
+ HDprintf("\n");
+ HDfflush(stdout);
+
+ /* Create the dataspace */
dims[0] = DIM0;
dims[1] = DIM1;
- if ((space = H5Screate_simple(2, dims, NULL)) < 0)
+ if ((sid = H5Screate_simple(2, dims, NULL)) < 0)
TEST_ERROR;
/* Test H5E_BEGIN_TRY */
H5E_BEGIN_TRY
{
- dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ did =
+ H5Dcreate2(H5I_INVALID_HID, DSET_NAME, H5T_STD_I32BE, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
}
H5E_END_TRY;
/* Create the dataset */
- if ((dataset = H5Dcreate2(file, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) <
- 0) {
- H5Epush1(__FILE__, FUNC_test_error, __LINE__, H5E_ERROR, H5E_CANTCREATE, "H5Dcreate2 failed");
- goto error;
- }
+ if ((did = H5Dcreate2(file, DSET_NAME, H5T_STD_I32BE, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
- /* Disable the library's default printing function */
+ /* Disable the library's default printing function */
#ifdef H5_USE_16_API_DEFAULT
if (H5Eset_auto(NULL, NULL) < 0)
#else
@@ -386,36 +382,48 @@ test_error2(hid_t file)
TEST_ERROR;
/* Make H5Dwrite fail, verify default print is disabled */
- if (H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) < 0) {
- H5Epush1(__FILE__, FUNC_test_error, __LINE__, H5E_ERROR, H5E_WRITEERROR,
- "H5Dwrite shouldn't succeed");
- goto error;
- }
+ if (H5Dwrite(H5I_INVALID_HID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) < 0)
+ H5Epush1(__FILE__, FUNC_test_error, __LINE__, H5E_ERROR, H5E_WRITEERROR, "expected H5Dwrite error");
+ else
+ TEST_ERROR;
+
+ /* Save the error stack so the close calls don't interfere with it */
+ if ((estack_id = H5Eget_current_stack()) < 0)
+ TEST_ERROR;
- /* In case program comes to this point, close dataset */
- if (H5Dclose(dataset) < 0)
+ /* Close open identifiers */
+ if (H5Dclose(did) < 0)
+ TEST_ERROR;
+ if (H5Sclose(sid) < 0)
+ TEST_ERROR;
+
+ /* Restore the stack containing errors */
+ if (H5Eset_current_stack(estack_id) < 0)
TEST_ERROR;
- TEST_ERROR;
+ return SUCCEED;
error:
- return -1;
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(did);
+ H5Sclose(sid);
+ H5Eclose_stack(estack_id);
+ }
+ H5E_END_TRY
+
+ return FAIL;
}
/*-------------------------------------------------------------------------
* Function: dump_error
*
- * Purpose: Prints error stack in default and customized ways.
+ * Purpose: Prints error stack in default and customized ways
*
- * Return: Success: 0
+ * Return: SUCCEED/FAIL
*
- * Failure: -1
- *
- * Programmer: Raymond Lu
- * July 17, 2003
- *
- *
- * Modifications:
+ * Programmer: Raymond Lu
+ * July 17, 2003
*
*-------------------------------------------------------------------------
*/
@@ -432,35 +440,34 @@ dump_error(void)
if (H5Ewalk1(H5E_WALK_UPWARD, custom_print_cb1, stderr) < 0)
TEST_ERROR;
- return 0;
+ return SUCCEED;
error:
- return -1;
+ return FAIL;
}
/*-------------------------------------------------------------------------
* Function: main
*
- * Purpose: Test error API.
- *
- * Programmer: Raymond Lu
- * July 10, 2003
+ * Purpose: Test error API
*
- * Modifications:
+ * Programmer: Raymond Lu
+ * July 10, 2003
*
*-------------------------------------------------------------------------
*/
int
main(void)
{
- hid_t file, fapl;
+ hid_t fid = H5I_INVALID_HID;
+ hid_t fapl_id = H5I_INVALID_HID;
char filename[1024];
const char *FUNC_main = "main";
int i;
HDfprintf(stderr, " This program tests the Error API compatible with HDF5 v1.6. There are supposed to "
"be some error messages\n");
- fapl = h5_fileaccess();
+ fapl_id = h5_fileaccess();
/* Set up data arrays */
if (NULL == (ipoints2_data = (int *)HDcalloc(DIM0 * DIM1, sizeof(int))))
@@ -477,14 +484,14 @@ main(void)
for (i = 0; i < DIM0; i++)
icheck2[i] = icheck2_data + (i * DIM1);
- h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
- if ((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
+ h5_fixname(FILENAME[0], fapl_id, filename, sizeof(filename));
+ if ((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0)
TEST_ERROR;
/* Test error stack */
/* Push an error onto error stack */
- H5Epush1(__FILE__, FUNC_main, __LINE__, H5E_ERROR, H5E_BADVALUE, "Error test failed");
+ H5Epush1(__FILE__, FUNC_main, __LINE__, H5E_ERROR, H5E_BADVALUE, "fake error message 1");
/* Print out the errors on stack */
dump_error();
@@ -493,17 +500,24 @@ main(void)
H5Eclear1();
/* Test error API */
- if (test_error1() < 0)
+ if (test_error_compat() < 0)
TEST_ERROR;
- if (test_error2(file) < 0) {
- H5Epush1(__FILE__, FUNC_main, __LINE__, H5E_ERROR, H5E_BADMESG, "Error test failed");
+ /* Test H5Epush1
+ *
+ * On success, there will be errors on the stack to print.
+ */
+ if (test_h5epush1(fid) < 0) {
+ TEST_ERROR;
+ }
+ else {
+ H5Epush1(__FILE__, FUNC_main, __LINE__, H5E_ERROR, H5E_BADMESG, "fake error message 2");
H5Eprint1(stderr);
}
- if (H5Fclose(file) < 0)
+ if (H5Fclose(fid) < 0)
TEST_ERROR;
- h5_clean_files(FILENAME, fapl);
+ h5_clean_files(FILENAME, fapl_id);
HDfree(ipoints2);
HDfree(ipoints2_data);
@@ -511,7 +525,7 @@ main(void)
HDfree(icheck2_data);
HDprintf("All error API tests passed.\n");
- return 0;
+ return EXIT_SUCCESS;
error:
HDfree(ipoints2);
@@ -519,7 +533,14 @@ error:
HDfree(icheck2);
HDfree(icheck2_data);
+ H5E_BEGIN_TRY
+ {
+ H5Fclose(fid);
+ H5Pclose(fapl_id);
+ }
+ H5E_END_TRY
+
HDprintf("***** ERROR TEST FAILED! *****\n");
- return 1;
+ return EXIT_FAILURE;
}
#endif /* H5_NO_DEPRECATED_SYMBOLS */
diff --git a/test/error_test.c b/test/error_test.c
index c8205ff8..f470318 100644
--- a/test/error_test.c
+++ b/test/error_test.c
@@ -129,7 +129,7 @@ test_error(hid_t file)
TEST_ERROR;
if (old_data != NULL)
TEST_ERROR;
- if (old_func != (H5E_auto2_t)H5Eprint2)
+ if (old_func == NULL)
TEST_ERROR;
if (H5Eset_auto2(H5E_DEFAULT, NULL, NULL) < 0)
diff --git a/test/testfiles/err_compat_1 b/test/testfiles/err_compat_1
index d81dba1..4c32d43 100644
--- a/test/testfiles/err_compat_1
+++ b/test/testfiles/err_compat_1
@@ -1,8 +1,10 @@
-Testing error API H5Eset/get_auto Testing error API based on data I/O All error API tests passed.
+Testing error API H5Eset/get_auto
+Testing error API based on data I/O
+All error API tests passed.
This program tests the Error API compatible with HDF5 version (number). There are supposed to be some error messages
********* Print error stack in HDF5 default way *********
HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs):
- #000: (file name) line (number) in main(): Error test failed
+ #000: (file name) line (number) in main(): fake error message 1
major: Error API
minor: Bad value
@@ -10,7 +12,6 @@ HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs):
error #000: (file name) in main(): line (number)
major: Error API
minor: Bad value
-
HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs):
#000: (file name) line (number) in H5Dcreate2(): not a location ID
major: Invalid arguments to routine
@@ -46,12 +47,11 @@ HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs):
#001: (file name) line (number) in H5G_loc(): invalid location ID
major: Invalid arguments to routine
minor: Bad value
-
HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs):
- #000: (file name) line (number) in main(): Error test failed
+ #000: (file name) line (number) in main(): fake error message 2
major: Error API
minor: Unrecognized message
- #001: (file name) line (number) in test_error2(): H5Dwrite shouldn't succeed
+ #001: (file name) line (number) in test_h5epush1(): expected H5Dwrite error
major: Error API
minor: Write failed
#002: (file name) line (number) in H5Dwrite(): dset_id is not a dataset ID