2003-07-11 04:15:46 +08:00
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
|
* 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
|
2005-08-14 04:53:35 +08:00
|
|
|
|
* October 14, 2001
|
2003-07-11 04:15:46 +08:00
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests the H5Tget_native_type function.
|
|
|
|
|
*/
|
|
|
|
|
#include "h5test.h"
|
|
|
|
|
|
2003-09-25 03:26:50 +08:00
|
|
|
|
#ifdef H5_WANT_H5_V1_6_COMPAT
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
2005-08-14 04:53:35 +08:00
|
|
|
|
printf("Test skipped because backward compatbility with v1.6 is configured in\n");
|
2003-09-25 03:26:50 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
|
2003-07-11 04:15:46 +08:00
|
|
|
|
const char *FILENAME[] = {
|
|
|
|
|
"errors",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define DIM0 100
|
|
|
|
|
#define DIM1 200
|
|
|
|
|
|
|
|
|
|
int ipoints2[DIM0][DIM1], icheck2[DIM0][DIM1];
|
|
|
|
|
|
|
|
|
|
hid_t ERR_CLS;
|
2003-07-18 09:46:40 +08:00
|
|
|
|
hid_t ERR_STACK;
|
2003-07-16 06:17:09 +08:00
|
|
|
|
|
2003-07-11 04:15:46 +08:00
|
|
|
|
hid_t ERR_MAJ_TEST;
|
2003-07-16 06:17:09 +08:00
|
|
|
|
hid_t ERR_MAJ_IO;
|
2003-07-18 09:46:40 +08:00
|
|
|
|
hid_t ERR_MAJ_API;
|
2003-07-16 06:17:09 +08:00
|
|
|
|
|
2003-07-11 04:15:46 +08:00
|
|
|
|
hid_t ERR_MIN_SUBROUTINE;
|
2003-07-18 09:46:40 +08:00
|
|
|
|
hid_t ERR_MIN_ERRSTACK;
|
2003-07-16 06:17:09 +08:00
|
|
|
|
hid_t ERR_MIN_CREATE;
|
2003-07-22 09:32:27 +08:00
|
|
|
|
hid_t ERR_MIN_WRITE;
|
2003-07-18 09:46:40 +08:00
|
|
|
|
hid_t ERR_MIN_GETNUM;
|
2003-07-11 04:15:46 +08:00
|
|
|
|
|
2003-07-12 05:04:38 +08:00
|
|
|
|
#define DSET_NAME "a_dataset"
|
2003-07-22 09:32:27 +08:00
|
|
|
|
#define FAKE_ID 0
|
2003-07-11 04:15:46 +08:00
|
|
|
|
|
|
|
|
|
#define ERR_CLS_NAME "Error Test"
|
|
|
|
|
#define PROG_NAME "Error Program"
|
|
|
|
|
#define PROG_VERS "1.0"
|
2003-07-18 09:46:40 +08:00
|
|
|
|
|
2003-07-16 06:17:09 +08:00
|
|
|
|
#define ERR_MAJ_TEST_MSG "Error in test"
|
|
|
|
|
#define ERR_MAJ_IO_MSG "Error in IO"
|
2003-07-18 09:46:40 +08:00
|
|
|
|
#define ERR_MAJ_API_MSG "Error in API"
|
2003-07-16 06:17:09 +08:00
|
|
|
|
#define ERR_MIN_SUBROUTINE_MSG "Error in subroutine"
|
2003-07-18 09:46:40 +08:00
|
|
|
|
#define ERR_MIN_ERRSTACK_MSG "Error in error stack"
|
2003-07-16 06:17:09 +08:00
|
|
|
|
#define ERR_MIN_CREATE_MSG "Error in H5Dcreate"
|
2003-07-22 09:32:27 +08:00
|
|
|
|
#define ERR_MIN_WRITE_MSG "Error in H5Dwrite"
|
2003-07-18 09:46:40 +08:00
|
|
|
|
#define ERR_MIN_GETNUM_MSG "Error in H5Eget_num"
|
2003-07-11 04:15:46 +08:00
|
|
|
|
|
2003-07-18 09:46:40 +08:00
|
|
|
|
#define MSG_SIZE 64
|
2003-07-11 04:15:46 +08:00
|
|
|
|
#define SPACE1_DIM1 4
|
|
|
|
|
#define SPACE1_RANK 1
|
|
|
|
|
#define SPACE2_RANK 2
|
|
|
|
|
#define SPACE2_DIM1 10
|
|
|
|
|
#define SPACE2_DIM2 10
|
|
|
|
|
|
2005-01-15 03:36:01 +08:00
|
|
|
|
#define LONG_DESC_SIZE 8192
|
|
|
|
|
|
2006-05-13 02:29:49 +08:00
|
|
|
|
herr_t custom_print_cb(unsigned n, const H5E_error_stack_t *err_desc, void* client_data);
|
2003-07-18 09:46:40 +08:00
|
|
|
|
|
2003-07-11 04:15:46 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_error
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test error API functions
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* July 10, 2003
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
test_error(hid_t file)
|
|
|
|
|
{
|
|
|
|
|
hid_t dataset, space;
|
2003-07-22 09:32:27 +08:00
|
|
|
|
hid_t estack_id;
|
2003-07-11 04:15:46 +08:00
|
|
|
|
hsize_t dims[2];
|
2003-07-18 09:46:40 +08:00
|
|
|
|
const char *FUNC_test_error="test_error";
|
2004-09-09 10:37:02 +08:00
|
|
|
|
H5E_auto_stack_t old_func;
|
2003-07-22 09:32:27 +08:00
|
|
|
|
void *old_data;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
TESTING("error API based on data I/O");
|
2003-07-11 04:15:46 +08:00
|
|
|
|
|
|
|
|
|
/* Create the data space */
|
|
|
|
|
dims[0] = DIM0;
|
|
|
|
|
dims[1] = DIM1;
|
|
|
|
|
if ((space = H5Screate_simple(2, dims, NULL))<0) TEST_ERROR;
|
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
/* Test H5E_BEGIN_TRY */
|
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
dataset = H5Dcreate(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT);
|
|
|
|
|
} H5E_END_TRY;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-11 04:15:46 +08:00
|
|
|
|
/* Create the dataset */
|
2003-07-12 05:04:38 +08:00
|
|
|
|
if ((dataset = H5Dcreate(file, DSET_NAME, H5T_STD_I32BE, space,
|
2003-07-16 06:17:09 +08:00
|
|
|
|
H5P_DEFAULT))<0) {
|
2005-08-14 04:53:35 +08:00
|
|
|
|
H5Epush_stack(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_CREATE,
|
2003-07-16 06:17:09 +08:00
|
|
|
|
"H5Dcreate failed");
|
2003-07-18 09:46:40 +08:00
|
|
|
|
goto error;
|
2003-07-16 06:17:09 +08:00
|
|
|
|
}
|
2003-07-11 04:15:46 +08:00
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
/* Test enabling and disabling default printing */
|
2004-09-02 01:43:30 +08:00
|
|
|
|
if (H5Eget_auto_stack(H5E_DEFAULT, &old_func, &old_data)<0)
|
2003-07-22 09:32:27 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
if (old_data != NULL)
|
2003-07-22 09:32:27 +08:00
|
|
|
|
TEST_ERROR;
|
2004-09-09 10:37:02 +08:00
|
|
|
|
if (old_func != (H5E_auto_stack_t)H5Eprint_stack)
|
2003-07-11 04:15:46 +08:00
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
2004-09-02 01:43:30 +08:00
|
|
|
|
if(H5Eset_auto_stack(H5E_DEFAULT, NULL, NULL)<0)
|
2003-07-11 04:15:46 +08:00
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
/* Make H5Dwrite fail, verify default print is disabled */
|
2003-08-09 03:02:26 +08:00
|
|
|
|
if (H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2)>=0) {
|
2005-08-14 04:53:35 +08:00
|
|
|
|
H5Epush_stack(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE,
|
2003-07-22 09:32:27 +08:00
|
|
|
|
"H5Dwrite shouldn't succeed");
|
|
|
|
|
goto error;
|
2003-08-09 03:02:26 +08:00
|
|
|
|
}
|
2003-07-11 04:15:46 +08:00
|
|
|
|
|
2004-09-02 01:43:30 +08:00
|
|
|
|
if(H5Eset_auto_stack(H5E_DEFAULT, old_func, old_data)<0)
|
2003-07-11 04:15:46 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-22 09:32:27 +08:00
|
|
|
|
|
|
|
|
|
/* Test saving and restoring the current error stack */
|
|
|
|
|
if (H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2)<0) {
|
2005-08-14 04:53:35 +08:00
|
|
|
|
H5Epush_stack(H5E_DEFAULT, __FILE__, FUNC_test_error, __LINE__, ERR_CLS, ERR_MAJ_IO, ERR_MIN_WRITE,
|
2003-07-22 09:32:27 +08:00
|
|
|
|
"H5Dwrite failed as supposed to");
|
|
|
|
|
estack_id = H5Eget_current_stack();
|
|
|
|
|
H5Dclose(dataset);
|
|
|
|
|
H5Sclose(space);
|
|
|
|
|
H5Eset_current_stack(estack_id);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
goto error;
|
2003-07-11 04:15:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
/* In case program comes to this point, close dataset */
|
2003-07-11 04:15:46 +08:00
|
|
|
|
if(H5Dclose(dataset)<0) TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
|
|
TEST_ERROR;
|
2003-07-11 04:15:46 +08:00
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: init_error
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Initialize error information.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* July 10, 2003
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
static herr_t
|
2003-07-11 04:15:46 +08:00
|
|
|
|
init_error(void)
|
|
|
|
|
{
|
2004-04-18 12:10:09 +08:00
|
|
|
|
ssize_t cls_size = (ssize_t)HDstrlen(ERR_CLS_NAME)+1;
|
|
|
|
|
char *cls_name = HDmalloc(strlen(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));
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-11 04:15:46 +08:00
|
|
|
|
if((ERR_CLS = H5Eregister_class(ERR_CLS_NAME, PROG_NAME, PROG_VERS))<0)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
if(cls_size != H5Eget_class_name(ERR_CLS, cls_name, (size_t)cls_size) + 1)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
if(strcmp(ERR_CLS_NAME, cls_name))
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-26 10:55:47 +08:00
|
|
|
|
if((ERR_MAJ_TEST = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_TEST_MSG))<0)
|
2003-07-16 06:17:09 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-26 10:55:47 +08:00
|
|
|
|
if((ERR_MAJ_IO = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_IO_MSG))<0)
|
2003-07-16 06:17:09 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-26 10:55:47 +08:00
|
|
|
|
if((ERR_MAJ_API = H5Ecreate_msg(ERR_CLS, H5E_MAJOR, ERR_MAJ_API_MSG))<0)
|
2003-07-18 09:46:40 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-16 06:17:09 +08:00
|
|
|
|
|
2003-07-26 10:55:47 +08:00
|
|
|
|
if((ERR_MIN_SUBROUTINE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_SUBROUTINE_MSG))<0)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-26 10:55:47 +08:00
|
|
|
|
if((ERR_MIN_ERRSTACK = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_ERRSTACK_MSG))<0)
|
2003-07-18 09:46:40 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-26 10:55:47 +08:00
|
|
|
|
if((ERR_MIN_CREATE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_CREATE_MSG))<0)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-26 10:55:47 +08:00
|
|
|
|
if((ERR_MIN_WRITE = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_WRITE_MSG))<0)
|
2003-07-22 09:32:27 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-26 10:55:47 +08:00
|
|
|
|
if((ERR_MIN_GETNUM = H5Ecreate_msg(ERR_CLS, H5E_MINOR, ERR_MIN_GETNUM_MSG))<0)
|
2003-07-18 09:46:40 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-15 23:49:36 +08:00
|
|
|
|
|
2003-07-18 09:46:40 +08:00
|
|
|
|
if(msg_size != H5Eget_msg(ERR_MIN_SUBROUTINE, msg_type, msg, (size_t)msg_size) + 1)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-26 10:55:47 +08:00
|
|
|
|
if(*msg_type != H5E_MINOR)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-16 06:17:09 +08:00
|
|
|
|
if(strcmp(msg, ERR_MIN_SUBROUTINE_MSG))
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
free(cls_name);
|
|
|
|
|
free(msg);
|
|
|
|
|
free(msg_type);
|
2003-07-12 05:04:38 +08:00
|
|
|
|
|
2003-07-15 04:08:27 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: error_stack
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Manipulates current error stack.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* July 14, 2003
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
static herr_t
|
2003-07-15 04:08:27 +08:00
|
|
|
|
error_stack(void)
|
|
|
|
|
{
|
2003-07-16 06:17:09 +08:00
|
|
|
|
int err_num;
|
2003-07-18 09:46:40 +08:00
|
|
|
|
const char *FUNC_error_stack="error_stack";
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-16 06:17:09 +08:00
|
|
|
|
if((err_num = H5Eget_num(H5E_DEFAULT))<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
if(err_num)
|
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-18 09:46:40 +08:00
|
|
|
|
if((ERR_STACK = H5Eget_current_stack())<0)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-15 04:08:27 +08:00
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
/* Make it push error, force this function to fail */
|
|
|
|
|
if((err_num = H5Eget_num(ERR_STACK))==0) {
|
2005-08-14 04:53:35 +08:00
|
|
|
|
H5Epush_stack(ERR_STACK, __FILE__, FUNC_error_stack, __LINE__, ERR_CLS, ERR_MAJ_API, ERR_MIN_GETNUM,
|
2003-07-18 09:46:40 +08:00
|
|
|
|
"Get number test failed, returned %d", err_num);
|
|
|
|
|
goto error;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* In case program falls through here, close the stack and let it fail. */
|
2003-07-18 09:46:40 +08:00
|
|
|
|
if(H5Eclose_stack(ERR_STACK)<0)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
return -1;
|
2003-07-15 04:08:27 +08:00
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-20 04:15:26 +08:00
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: long_desc_cb
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Callback function to help test long description handling
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* January 19, 2005
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2006-01-24 04:46:34 +08:00
|
|
|
|
static herr_t
|
2006-05-13 02:29:49 +08:00
|
|
|
|
long_desc_cb(unsigned UNUSED n, const H5E_error_stack_t *err_desc, void* client_data)
|
2005-01-20 04:15:26 +08:00
|
|
|
|
{
|
|
|
|
|
char *real_desc = (char *)client_data;
|
|
|
|
|
|
|
|
|
|
if(err_desc->desc!=NULL && HDstrcmp(err_desc->desc,real_desc)==0)
|
|
|
|
|
return(0);
|
|
|
|
|
else
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_long_desc
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test long error description handling
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* January 19, 2005
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
static herr_t
|
2005-01-20 04:15:26 +08:00
|
|
|
|
test_long_desc(void)
|
|
|
|
|
{
|
2006-01-24 04:46:34 +08:00
|
|
|
|
const char *format="Testing very long description string, %s";
|
2005-01-20 04:15:26 +08:00
|
|
|
|
char *long_desc;
|
|
|
|
|
char *full_desc;
|
|
|
|
|
size_t u;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/* 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';
|
|
|
|
|
|
|
|
|
|
/* Clear the default error stack */
|
|
|
|
|
if(H5Eclear_stack(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;
|
|
|
|
|
|
|
|
|
|
/* Create the string that should be in the description */
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/* Clear the default error stack again */
|
|
|
|
|
if(H5Eclear_stack(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);
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-18 09:46:40 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2005-08-14 04:53:35 +08:00
|
|
|
|
* Function: dump_error
|
2003-07-18 09:46:40 +08:00
|
|
|
|
*
|
|
|
|
|
* Purpose: Prints error stack in default and customized ways.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* July 17, 2003
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
static herr_t
|
2003-07-18 09:46:40 +08:00
|
|
|
|
dump_error(hid_t estack)
|
|
|
|
|
{
|
|
|
|
|
/* Print errors in library default way */
|
|
|
|
|
fprintf(stderr, "********* Print error stack in HDF5 default way *********\n");
|
2004-09-02 01:43:30 +08:00
|
|
|
|
if(H5Eprint_stack(estack, stderr)<0)
|
2003-07-22 09:32:27 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-18 09:46:40 +08:00
|
|
|
|
/* Customized way to print errors */
|
|
|
|
|
fprintf(stderr, "\n********* Print error stack in customized way *********\n");
|
2004-09-02 01:43:30 +08:00
|
|
|
|
if(H5Ewalk_stack(estack, H5E_WALK_UPWARD, custom_print_cb, stderr)<0)
|
2003-07-22 09:32:27 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-18 09:46:40 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: custom_print_cb
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Callback function to print error stack in customized way.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* July 17, 2003
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
herr_t
|
2006-05-13 02:29:49 +08:00
|
|
|
|
custom_print_cb(unsigned n, const H5E_error_stack_t *err_desc, void* client_data)
|
2003-07-18 09:46:40 +08:00
|
|
|
|
{
|
|
|
|
|
FILE *stream = (FILE *)client_data;
|
|
|
|
|
char maj[MSG_SIZE];
|
|
|
|
|
char min[MSG_SIZE];
|
|
|
|
|
char cls[MSG_SIZE];
|
|
|
|
|
const int indent = 4;
|
|
|
|
|
|
|
|
|
|
/* Get descriptions for the major and minor error numbers */
|
2003-07-22 09:32:27 +08:00
|
|
|
|
if(H5Eget_class_name(err_desc->cls_id, cls, MSG_SIZE)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
2003-09-25 03:26:50 +08:00
|
|
|
|
if(H5Eget_msg(err_desc->maj_num, NULL, maj, MSG_SIZE)<0)
|
2003-07-22 09:32:27 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-09-25 03:26:50 +08:00
|
|
|
|
if(H5Eget_msg(err_desc->min_num, NULL, min, MSG_SIZE)<0)
|
2003-07-22 09:32:27 +08:00
|
|
|
|
TEST_ERROR;
|
2003-07-18 09:46:40 +08:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2003-07-15 04:08:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: close_error
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Closes error information.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: -1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* July 10, 2003
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
static herr_t
|
2003-07-15 04:08:27 +08:00
|
|
|
|
close_error(void)
|
|
|
|
|
{
|
2003-07-22 09:32:27 +08:00
|
|
|
|
/* Close major errors, let H5Eunregister_class close minor errors */
|
2003-07-15 04:08:27 +08:00
|
|
|
|
if(H5Eclose_msg(ERR_MAJ_TEST)<0)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR ;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
if(H5Eclose_msg(ERR_MAJ_IO)<0)
|
|
|
|
|
TEST_ERROR ;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
if(H5Eclose_msg(ERR_MAJ_API)<0)
|
|
|
|
|
TEST_ERROR ;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-15 04:08:27 +08:00
|
|
|
|
if(H5Eunregister_class(ERR_CLS)<0)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR ;
|
2003-07-15 04:08:27 +08:00
|
|
|
|
|
2003-07-11 04:15:46 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-11 04:15:46 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: main
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test error API.
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* July 10, 2003
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
main(void)
|
|
|
|
|
{
|
|
|
|
|
hid_t file, fapl;
|
2003-07-22 09:32:27 +08:00
|
|
|
|
hid_t estack_id;
|
2003-07-11 04:15:46 +08:00
|
|
|
|
char filename[1024];
|
2003-07-18 09:46:40 +08:00
|
|
|
|
const char *FUNC_main="main";
|
2003-07-16 06:17:09 +08:00
|
|
|
|
|
2003-07-26 10:55:47 +08:00
|
|
|
|
fprintf(stderr, " This program tests the Error API. There're supposed to be some error messages\n");
|
2003-07-22 09:32:27 +08:00
|
|
|
|
|
|
|
|
|
/* Initialize errors */
|
2003-07-11 04:15:46 +08:00
|
|
|
|
if(init_error()<0)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR ;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-11 04:15:46 +08:00
|
|
|
|
fapl = h5_fileaccess();
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-11 04:15:46 +08:00
|
|
|
|
h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
|
|
|
|
|
if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR ;
|
2003-07-26 10:55:47 +08:00
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
/* Test error stack */
|
2003-07-18 09:46:40 +08:00
|
|
|
|
if(error_stack()<0) {
|
2003-07-22 09:32:27 +08:00
|
|
|
|
/* Push an error onto error stack */
|
2005-08-14 04:53:35 +08:00
|
|
|
|
if(H5Epush_stack(ERR_STACK, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_ERRSTACK,
|
2005-01-15 03:36:01 +08:00
|
|
|
|
"Error stack test failed")<0) TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
/* Delete an error from the top of error stack */
|
2003-07-18 09:46:40 +08:00
|
|
|
|
H5Epop(ERR_STACK, 1);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
/* Print out the errors on stack */
|
2003-07-18 09:46:40 +08:00
|
|
|
|
dump_error(ERR_STACK);
|
2003-07-22 09:32:27 +08:00
|
|
|
|
|
|
|
|
|
/* Empty error stack */
|
2004-09-02 01:43:30 +08:00
|
|
|
|
H5Eclear_stack(ERR_STACK);
|
2003-07-22 09:32:27 +08:00
|
|
|
|
|
|
|
|
|
/* Close error stack */
|
2003-07-18 09:46:40 +08:00
|
|
|
|
H5Eclose_stack(ERR_STACK);
|
|
|
|
|
}
|
2003-07-11 04:15:46 +08:00
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
/* Test error API */
|
2003-07-16 06:17:09 +08:00
|
|
|
|
if(test_error(file)<0) {
|
2005-08-14 04:53:35 +08:00
|
|
|
|
H5Epush_stack(H5E_DEFAULT, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE,
|
2003-07-18 09:46:40 +08:00
|
|
|
|
"Error test failed, %s", "it's wrong");
|
2003-07-22 09:32:27 +08:00
|
|
|
|
estack_id = H5Eget_current_stack();
|
2004-09-02 01:43:30 +08:00
|
|
|
|
H5Eprint_stack(estack_id, stderr);
|
2003-07-22 09:32:27 +08:00
|
|
|
|
H5Eclose_stack(estack_id);
|
2003-07-16 06:17:09 +08:00
|
|
|
|
}
|
2005-01-15 03:36:01 +08:00
|
|
|
|
|
|
|
|
|
/* Test pushing a very long error description */
|
2005-01-20 04:15:26 +08:00
|
|
|
|
if(test_long_desc()<0) TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2003-07-15 23:49:36 +08:00
|
|
|
|
if (H5Fclose(file)<0) TEST_ERROR ;
|
2003-07-11 04:15:46 +08:00
|
|
|
|
h5_cleanup(FILENAME, fapl);
|
2003-07-12 05:04:38 +08:00
|
|
|
|
|
2003-07-22 09:32:27 +08:00
|
|
|
|
/* Close error information */
|
2003-07-15 04:08:27 +08:00
|
|
|
|
if(close_error()<0)
|
2003-07-15 23:49:36 +08:00
|
|
|
|
TEST_ERROR ;
|
2003-07-22 09:32:27 +08:00
|
|
|
|
|
2003-08-09 03:02:26 +08:00
|
|
|
|
printf("All error API tests passed.\n");
|
2003-07-11 04:15:46 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
printf("***** ERROR TEST FAILED! *****\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2004-09-02 01:43:30 +08:00
|
|
|
|
#endif /*H5_WANT_H5_V1_6_COMPAT*/
|