summaryrefslogtreecommitdiffstats
path: root/test/error_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/error_test.c')
-rw-r--r--test/error_test.c249
1 files changed, 115 insertions, 134 deletions
diff --git a/test/error_test.c b/test/error_test.c
index e8ccacf..7850ff1 100644
--- a/test/error_test.c
+++ b/test/error_test.c
@@ -77,7 +77,8 @@ hid_t ERR_MIN_GETNUM;
#define LONG_DESC_SIZE 8192
-herr_t custom_print_cb(unsigned n, const H5E_error_stack_t *err_desc, void* client_data);
+herr_t custom_print_cb(unsigned n, const H5E_error2_t *err_desc,
+ void *client_data);
/*-------------------------------------------------------------------------
@@ -92,9 +93,6 @@ herr_t custom_print_cb(unsigned n, const H5E_error_stack_t *err_desc, void* clie
* Programmer: Raymond Lu
* July 10, 2003
*
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -103,8 +101,8 @@ test_error(hid_t file)
hid_t dataset, space;
hid_t estack_id;
hsize_t dims[2];
- const char *FUNC_test_error="test_error";
- H5E_auto_stack_t old_func;
+ const char *FUNC_test_error = "test_error";
+ H5E_auto2_t old_func;
void *old_data;
TESTING("error API based on data I/O");
@@ -120,53 +118,52 @@ test_error(hid_t file)
} H5E_END_TRY;
/* Create the dataset */
- if ((dataset = H5Dcreate(file, DSET_NAME, H5T_STD_I32BE, space,
- H5P_DEFAULT))<0) {
- H5Epush_stack(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_CREATE,
+ if((dataset = H5Dcreate(file, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT)) < 0) {
+ H5Epush2(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_CREATE,
"H5Dcreate failed");
goto error;
- }
+ } /* end if */
/* Test enabling and disabling default printing */
- if (H5Eget_auto_stack(H5E_DEFAULT, &old_func, &old_data)<0)
+ if(H5Eget_auto2(H5E_DEFAULT, &old_func, &old_data) < 0)
TEST_ERROR;
- if (old_data != NULL)
+ if(old_data != NULL)
TEST_ERROR;
- if (old_func != (H5E_auto_stack_t)H5Eprint_stack)
+ if(old_func != (H5E_auto2_t)H5Eprint2)
TEST_ERROR;
- if(H5Eset_auto_stack(H5E_DEFAULT, NULL, NULL)<0)
+ if(H5Eset_auto2(H5E_DEFAULT, NULL, NULL) < 0)
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) {
- H5Epush_stack(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE,
+ if(H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) >= 0) {
+ H5Epush2(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE,
"H5Dwrite shouldn't succeed");
goto error;
- }
+ } /* end if */
- if(H5Eset_auto_stack(H5E_DEFAULT, old_func, old_data)<0)
+ if(H5Eset_auto2(H5E_DEFAULT, old_func, old_data) < 0)
TEST_ERROR;
/* Test saving and restoring the current error stack */
- if (H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2)<0) {
- H5Epush_stack(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE,
+ if(H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) < 0) {
+ H5Epush2(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE,
"H5Dwrite failed as supposed to");
estack_id = H5Eget_current_stack();
H5Dclose(dataset);
H5Sclose(space);
H5Eset_current_stack(estack_id);
goto error;
- }
+ } /* end if */
/* In case program comes to this point, close dataset */
- if(H5Dclose(dataset)<0) TEST_ERROR;
+ if(H5Dclose(dataset) < 0) TEST_ERROR;
TEST_ERROR;
error:
return -1;
-}
+} /* end test_error() */
/*-------------------------------------------------------------------------
@@ -181,62 +178,59 @@ test_error(hid_t file)
* Programmer: Raymond Lu
* July 10, 2003
*
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
init_error(void)
{
ssize_t cls_size = (ssize_t)HDstrlen(ERR_CLS_NAME)+1;
- char *cls_name = HDmalloc(strlen(ERR_CLS_NAME)+1);
+ char *cls_name = HDmalloc(HDstrlen(ERR_CLS_NAME)+1);
ssize_t msg_size = (ssize_t)HDstrlen(ERR_MIN_SUBROUTINE_MSG) + 1;
char *msg = HDmalloc(HDstrlen(ERR_MIN_SUBROUTINE_MSG)+1);
H5E_type_t *msg_type= HDmalloc(sizeof(H5E_type_t));
- if((ERR_CLS = H5Eregister_class(ERR_CLS_NAME, PROG_NAME, PROG_VERS))<0)
+ if((ERR_CLS = H5Eregister_class(ERR_CLS_NAME, PROG_NAME, PROG_VERS)) < 0)
TEST_ERROR;
if(cls_size != H5Eget_class_name(ERR_CLS, cls_name, (size_t)cls_size) + 1)
TEST_ERROR;
- if(strcmp(ERR_CLS_NAME, cls_name))
+ if(HDstrcmp(ERR_CLS_NAME, cls_name))
TEST_ERROR;
- if((ERR_MAJ_TEST = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_TEST_MSG))<0)
+ if((ERR_MAJ_TEST = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_TEST_MSG)) < 0)
TEST_ERROR;
- if((ERR_MAJ_IO = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_IO_MSG))<0)
+ if((ERR_MAJ_IO = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_IO_MSG)) < 0)
TEST_ERROR;
- if((ERR_MAJ_API = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_API_MSG))<0)
+ if((ERR_MAJ_API = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_API_MSG)) < 0)
TEST_ERROR;
- if((ERR_MIN_SUBROUTINE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_SUBROUTINE_MSG))<0)
+ if((ERR_MIN_SUBROUTINE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_SUBROUTINE_MSG)) < 0)
TEST_ERROR;
- if((ERR_MIN_ERRSTACK = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_ERRSTACK_MSG))<0)
+ if((ERR_MIN_ERRSTACK = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_ERRSTACK_MSG)) < 0)
TEST_ERROR;
- if((ERR_MIN_CREATE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_CREATE_MSG))<0)
+ if((ERR_MIN_CREATE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_CREATE_MSG)) < 0)
TEST_ERROR;
- if((ERR_MIN_WRITE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_WRITE_MSG))<0)
+ if((ERR_MIN_WRITE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_WRITE_MSG)) < 0)
TEST_ERROR;
- if((ERR_MIN_GETNUM = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_GETNUM_MSG))<0)
+ if((ERR_MIN_GETNUM = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_GETNUM_MSG)) < 0)
TEST_ERROR;
if(msg_size != H5Eget_msg(ERR_MIN_SUBROUTINE, msg_type, msg, (size_t)msg_size) + 1)
TEST_ERROR;
if(*msg_type != H5E_MINOR)
TEST_ERROR;
- if(strcmp(msg, ERR_MIN_SUBROUTINE_MSG))
+ if(HDstrcmp(msg, ERR_MIN_SUBROUTINE_MSG))
TEST_ERROR;
- free(cls_name);
- free(msg);
- free(msg_type);
+ HDfree(cls_name);
+ HDfree(msg);
+ HDfree(msg_type);
return 0;
- error:
+error:
return -1;
-}
+} /* end init_error() */
/*-------------------------------------------------------------------------
@@ -251,42 +245,40 @@ init_error(void)
* Programmer: Raymond Lu
* July 14, 2003
*
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
error_stack(void)
{
int err_num;
- const char *FUNC_error_stack="error_stack";
+ const char *FUNC_error_stack = "error_stack";
- if((err_num = H5Eget_num(H5E_DEFAULT))<0)
+ if((err_num = H5Eget_num(H5E_DEFAULT)) < 0)
TEST_ERROR;
if(err_num)
TEST_ERROR;
- if((ERR_STACK = H5Eget_current_stack())<0)
+ if((ERR_STACK = H5Eget_current_stack()) < 0)
TEST_ERROR;
/* Make it push error, force this function to fail */
- if((err_num = H5Eget_num(ERR_STACK))==0) {
- H5Epush_stack(ERR_STACK, __FILE__, FUNC_error_stack, __LINE__, ERR_CLS, ERR_MAJ_API, ERR_MIN_GETNUM,
+ if((err_num = H5Eget_num(ERR_STACK)) == 0) {
+ H5Epush2(ERR_STACK, __FILE__, FUNC_error_stack, __LINE__, ERR_CLS, ERR_MAJ_API, ERR_MIN_GETNUM,
"Get number test failed, returned %d", err_num);
goto error;
- }
+ } /* end if */
/* In case program falls through here, close the stack and let it fail. */
- if(H5Eclose_stack(ERR_STACK)<0)
+ if(H5Eclose_stack(ERR_STACK) < 0)
TEST_ERROR;
return -1;
- error:
+error:
return -1;
-}
+} /* end error_stack() */
+
/*-------------------------------------------------------------------------
* Function: long_desc_cb
*
@@ -299,21 +291,18 @@ error_stack(void)
* Programmer: Quincey Koziol
* January 19, 2005
*
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
-long_desc_cb(unsigned UNUSED n, const H5E_error_stack_t *err_desc, void* client_data)
+long_desc_cb(unsigned UNUSED n, const H5E_error2_t *err_desc, void *client_data)
{
- char *real_desc = (char *)client_data;
+ char *real_desc = (char *)client_data;
- if(err_desc->desc!=NULL && HDstrcmp(err_desc->desc,real_desc)==0)
+ if(err_desc->desc != NULL && HDstrcmp(err_desc->desc, real_desc) == 0)
return(0);
else
return(-1);
-}
+} /* end long_desc_cb() */
/*-------------------------------------------------------------------------
@@ -328,53 +317,54 @@ long_desc_cb(unsigned UNUSED n, const H5E_error_stack_t *err_desc, void* client_
* Programmer: Quincey Koziol
* January 19, 2005
*
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
test_long_desc(void)
{
- const char *format="Testing very long description string, %s";
+ const char *format = "Testing very long description string, %s";
char *long_desc = NULL;
char *full_desc = NULL;
size_t u;
- const char *test_FUNC="test_long_desc";
+ const char *test_FUNC = "test_long_desc";
/* Allocate space for the error description info */
- if((long_desc=HDmalloc(LONG_DESC_SIZE))==NULL) TEST_ERROR;
- if((full_desc=HDmalloc(LONG_DESC_SIZE+128))==NULL) TEST_ERROR;
+ if(NULL == (long_desc = HDmalloc(LONG_DESC_SIZE))) TEST_ERROR;
+ if(NULL == (full_desc = HDmalloc(LONG_DESC_SIZE + 128))) TEST_ERROR;
/* Create the long part of the error description */
- for(u=0; u<LONG_DESC_SIZE; u++)
- long_desc[u]='A'+(u%26);
- long_desc[LONG_DESC_SIZE-1]='\0';
+ for(u = 0; u < LONG_DESC_SIZE; u++)
+ long_desc[u] = 'A' + (u % 26);
+ long_desc[LONG_DESC_SIZE - 1] = '\0';
/* Clear the default error stack */
- if(H5Eclear_stack(H5E_DEFAULT)<0) TEST_ERROR;
+ if(H5Eclear2(H5E_DEFAULT) < 0) TEST_ERROR;
/* Push an error with a long description */
- if(H5Epush_stack(H5E_DEFAULT, __FILE__, test_FUNC, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, format, long_desc)<0) TEST_ERROR;
+ if(H5Epush2(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);
+ HDsnprintf(full_desc, LONG_DESC_SIZE + 128, format, long_desc);
/* Make certain that the description is correct */
- if(H5Ewalk_stack(H5E_DEFAULT, H5E_WALK_UPWARD, long_desc_cb, full_desc)<0) TEST_ERROR;
+ if(H5Ewalk2(H5E_DEFAULT, H5E_WALK_UPWARD, long_desc_cb, full_desc) < 0) TEST_ERROR;
/* Clear the default error stack again */
- if(H5Eclear_stack(H5E_DEFAULT)<0) TEST_ERROR;
+ if(H5Eclear2(H5E_DEFAULT) < 0) TEST_ERROR;
HDfree(long_desc);
HDfree(full_desc);
+
return(0);
error:
- if(long_desc) HDfree(long_desc);
- if(full_desc) HDfree(full_desc);
+ if(long_desc)
+ HDfree(long_desc);
+ if(full_desc)
+ HDfree(full_desc);
+
return(-1);
-}
+} /* end test_long_desc() */
/*-------------------------------------------------------------------------
@@ -389,9 +379,6 @@ error:
* Programmer: Raymond Lu
* July 17, 2003
*
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -399,20 +386,21 @@ dump_error(hid_t estack)
{
/* Print errors in library default way */
fprintf(stderr, "********* Print error stack in HDF5 default way *********\n");
- if(H5Eprint_stack(estack, stderr)<0)
+ if(H5Eprint2(estack, stderr) < 0)
TEST_ERROR;
/* Customized way to print errors */
fprintf(stderr, "\n********* Print error stack in customized way *********\n");
- if(H5Ewalk_stack(estack, H5E_WALK_UPWARD, custom_print_cb, stderr)<0)
+ if(H5Ewalk2(estack, H5E_WALK_UPWARD, custom_print_cb, stderr) < 0)
TEST_ERROR;
return 0;
- error:
+error:
return -1;
-}
+} /* end dump_error() */
+
/*-------------------------------------------------------------------------
* Function: custom_print_cb
*
@@ -425,13 +413,10 @@ dump_error(hid_t estack)
* Programmer: Raymond Lu
* July 17, 2003
*
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
herr_t
-custom_print_cb(unsigned n, const H5E_error_stack_t *err_desc, void* client_data)
+custom_print_cb(unsigned n, const H5E_error2_t *err_desc, void* client_data)
{
FILE *stream = (FILE *)client_data;
char maj[MSG_SIZE];
@@ -440,27 +425,27 @@ custom_print_cb(unsigned n, const H5E_error_stack_t *err_desc, void* client_data
const int indent = 4;
/* Get descriptions for the major and minor error numbers */
- if(H5Eget_class_name(err_desc->cls_id, cls, MSG_SIZE)<0)
+ if(H5Eget_class_name(err_desc->cls_id, cls, MSG_SIZE) < 0)
TEST_ERROR;
- if(H5Eget_msg(err_desc->maj_num, NULL, maj, MSG_SIZE)<0)
+ if(H5Eget_msg(err_desc->maj_num, NULL, maj, MSG_SIZE) < 0)
TEST_ERROR;
- if(H5Eget_msg(err_desc->min_num, NULL, min, MSG_SIZE)<0)
+ if(H5Eget_msg(err_desc->min_num, NULL, min, MSG_SIZE) < 0)
TEST_ERROR;
- fprintf (stream, "%*serror #%03d: %s in %s(): line %u\n",
+ fprintf(stream, "%*serror #%03d: %s in %s(): line %u\n",
indent, "", n, err_desc->file_name,
err_desc->func_name, err_desc->line);
- fprintf (stream, "%*sclass: %s\n", indent*2, "", cls);
- fprintf (stream, "%*smajor: %s\n", indent*2, "", maj);
- fprintf (stream, "%*sminor: %s\n", indent*2, "", min);
+ fprintf(stream, "%*sclass: %s\n", indent * 2, "", cls);
+ fprintf(stream, "%*smajor: %s\n", indent * 2, "", maj);
+ fprintf(stream, "%*sminor: %s\n", indent * 2, "", min);
return 0;
- error:
+error:
return -1;
-}
+} /* end custom_print_cb() */
/*-------------------------------------------------------------------------
@@ -475,32 +460,29 @@ custom_print_cb(unsigned n, const H5E_error_stack_t *err_desc, void* client_data
* Programmer: Raymond Lu
* July 10, 2003
*
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
close_error(void)
{
/* Close major errors, let H5Eunregister_class close minor errors */
- if(H5Eclose_msg(ERR_MAJ_TEST)<0)
- TEST_ERROR ;
+ if(H5Eclose_msg(ERR_MAJ_TEST) < 0)
+ TEST_ERROR;
- if(H5Eclose_msg(ERR_MAJ_IO)<0)
- TEST_ERROR ;
+ if(H5Eclose_msg(ERR_MAJ_IO) < 0)
+ TEST_ERROR;
- if(H5Eclose_msg(ERR_MAJ_API)<0)
- TEST_ERROR ;
+ if(H5Eclose_msg(ERR_MAJ_API) < 0)
+ TEST_ERROR;
- if(H5Eunregister_class(ERR_CLS)<0)
- TEST_ERROR ;
+ if(H5Eunregister_class(ERR_CLS) < 0)
+ TEST_ERROR;
return 0;
- error:
+error:
return -1;
-}
+} /* end close_error() */
/*-------------------------------------------------------------------------
@@ -511,8 +493,6 @@ close_error(void)
* Programmer: Raymond Lu
* July 10, 2003
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
int
@@ -521,25 +501,25 @@ main(void)
hid_t file, fapl;
hid_t estack_id;
char filename[1024];
- const char *FUNC_main="main";
+ const char *FUNC_main = "main";
fprintf(stderr, " This program tests the Error API. There're supposed to be some error messages\n");
/* Initialize errors */
- if(init_error()<0)
- TEST_ERROR ;
+ if(init_error() < 0)
+ TEST_ERROR;
fapl = h5_fileaccess();
h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
- if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
- TEST_ERROR ;
+ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
+ TEST_ERROR;
/* Test error stack */
- if(error_stack()<0) {
+ if(error_stack() < 0) {
/* Push an error onto error stack */
- if(H5Epush_stack(ERR_STACK, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_ERRSTACK,
- "Error stack test failed")<0) TEST_ERROR;
+ if(H5Epush2(ERR_STACK, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_ERRSTACK,
+ "Error stack test failed") < 0) TEST_ERROR;
/* Delete an error from the top of error stack */
H5Epop(ERR_STACK, 1);
@@ -548,36 +528,37 @@ main(void)
dump_error(ERR_STACK);
/* Empty error stack */
- H5Eclear_stack(ERR_STACK);
+ H5Eclear2(ERR_STACK);
/* Close error stack */
H5Eclose_stack(ERR_STACK);
- }
+ } /* end if */
/* Test error API */
- if(test_error(file)<0) {
- H5Epush_stack(H5E_DEFAULT, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE,
+ if(test_error(file) < 0) {
+ H5Epush2(H5E_DEFAULT, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE,
"Error test failed, %s", "it's wrong");
estack_id = H5Eget_current_stack();
- H5Eprint_stack(estack_id, stderr);
+ H5Eprint2(estack_id, stderr);
H5Eclose_stack(estack_id);
- }
+ } /* end if */
/* Test pushing a very long error description */
- if(test_long_desc()<0) TEST_ERROR;
+ if(test_long_desc() < 0) TEST_ERROR;
- if (H5Fclose(file)<0) TEST_ERROR ;
+ if(H5Fclose(file) < 0) TEST_ERROR;
h5_cleanup(FILENAME, fapl);
/* Close error information */
- if(close_error()<0)
- TEST_ERROR ;
+ if(close_error() < 0)
+ TEST_ERROR;
printf("All error API tests passed.\n");
return 0;
- error:
+error:
printf("***** ERROR TEST FAILED! *****\n");
return 1;
}
#endif /*H5_WANT_H5_V1_6_COMPAT*/
+