summaryrefslogtreecommitdiffstats
path: root/test/err_vers.c
blob: 680554503004074b19e38fd0d7cf2a0e5ad1a75e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * 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://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * Programmer:  Neil Fortner <nfortne2@hdfgroup.org>
 *              Saturday, October 11, 2008
 *
 * Purpose:	Tests H5E version compatibility macros.
 */
#include "h5test.h"
#include "H5Gprivate.h"		/* Groups				*/

#define ERR_VERS_NAME   "err_vers"
#define LINK_BUF_SIZE   1024
#define NAME_BUF_SIZE   1024
#define MAX_NAME_LEN    ((64*1024)+1024)


/*-------------------------------------------------------------------------
 *
 * Function:    error_version_macros_cb
 *
 * Purpose:     Callback function for H5Ewalk in error_version_macros.
 *
 * Return:      0
 *
 * Programmer:  Neil Fortner
 *              Saturday, October 11, 2008
 *
 *-------------------------------------------------------------------------
 */
herr_t
error_version_macros_cb(int n, H5E_error1_t *err_desc, void *client_data)
{
    return 0;
}


/*-------------------------------------------------------------------------
 *
 * Function:    error_version_macros
 *
 * Purpose:     Test H5E version compatibility macros.
 *
 * Return:      Success:        0
 *              Failure:        -1
 *
 * Programmer:  Neil Fortner
 *              Saturday, October 11, 2008
 *
 *-------------------------------------------------------------------------
 */
static int
error_version_macros(void)
{
    H5E_walk1_t     walk_cb = &error_version_macros_cb; /* H5Ewalk callback function (test H5E_walk1_t) */
    H5E_auto1_t     auto_func;                      /* Automatic error handler (test H5E_auto1_t) */
    void            *client_data;                   /* Automatic error handler data */
    FILE            *file;                          /* File to redirect output to */
    char            filename[NAME_BUF_SIZE]; 

    /* Output message about test being performed */
    TESTING("H5E version compatibility macros");

    /* Create the test file (used to prevent output of H5Eprint to the terminal) */
    h5_fixname(ERR_VERS_NAME, H5P_DEFAULT, filename, sizeof filename);
    if (NULL == (file = HDfopen(filename, "w"))) TEST_ERROR;

    /* Print error stack (check H5Eprint1) */
    if (H5Eprint1(file) < 0) TEST_ERROR;

    /* Get automatic error traversal function (check H5Eget_auto1) */
    if (H5Eget_auto1(&auto_func, &client_data) < 0) TEST_ERROR;

    /* Set automatic error traversal function (check H5Eset_auto1) */
    if (H5Eset_auto1(auto_func, client_data) < 0) TEST_ERROR;

    /* Push an error message (check H5Epush1) */
    if (H5Epush1("somefile", "somefunc", 13241, H5E_STORAGE, H5E_BADATOM,
        "Hi!  I'm an error message!") < 0) TEST_ERROR;

    /* Clear error stack (check H5Eclear1) */
    if (H5Eclear1() < 0) TEST_ERROR;

    /* Walk the error stack (check H5Ewalk1) */
    if (H5Ewalk1(H5E_WALK_DOWNWARD, walk_cb, NULL) < 0) TEST_ERROR;

    /* Close the file */
    HDfclose(file);
    HDremove(filename);

    PASSED();
    return 0;

error:
    HDfclose(file);
    HDremove(filename);
    return -1;
} /* end error_version_macros() */


/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	Test H5E version compatibility macros.
 *
 * Return:	Success:	exit(0)
 *
 *		Failure:	exit(non-zero)
 *
 * Programmer:	Neil Fortner
 *              Saturday, October 11, 2008
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    int		nerrors = 0;

    h5_reset();

    /* The test... */
    nerrors += error_version_macros() < 0 ? 1 : 0;

    /* Results */
    if (nerrors) {
	printf("***** %d ERROR COMPATIBILITY TEST%s FAILED! *****\n",
	       nerrors, 1 == nerrors ? "" : "S");
	exit(1);
    }
    printf("All error compatibility tests passed.\n");
    return 0;
}