summaryrefslogtreecommitdiffstats
path: root/test/API/testhdf5.h
blob: 44ccfe000c3afdb2e729ed2461ecf28880ee5c60 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * This header file contains information required for testing the HDF5 library.
 */

#ifndef TESTHDF5_H
#define TESTHDF5_H

/* Include generic testing header also */
/* #include "h5test.h" */
#include "hdf5.h"
#include "H5private.h"
#include "H5_api_tests_disabled.h"

#define VERBO_NONE 0 /* None    */
#define VERBO_DEF  3 /* Default */
#define VERBO_LO   5 /* Low     */
#define VERBO_MED  7 /* Medium  */
#define VERBO_HI   9 /* High    */

/* Turn off verbose reporting by default */
#define VERBOSE_MED (FALSE)
#define VERBOSE_HI  (FALSE)

/* Use %ld to print the value because long should cover most cases. */
/* Used to make certain a return value _is_not_ a value */
#define CHECK(ret, val, where)                                                                               \
    do {                                                                                                     \
        if (VERBOSE_HI) {                                                                                    \
            print_func("   Call to routine: %15s at line %4d "                                               \
                       "in %s returned %ld \n",                                                              \
                       where, (int)__LINE__, __FILE__, (long)(ret));                                         \
        }                                                                                                    \
        if ((ret) == (val)) {                                                                                \
            TestErrPrintf("*** UNEXPECTED RETURN from %s is %ld at line %4d "                                \
                          "in %s\n",                                                                         \
                          where, (long)(ret), (int)__LINE__, __FILE__);                                      \
            H5Eprint2(H5E_DEFAULT, stdout);                                                                  \
        }                                                                                                    \
    } while (0)

#define CHECK_I(ret, where)                                                                                  \
    {                                                                                                        \
        if (VERBOSE_HI) {                                                                                    \
            print_func("   Call to routine: %15s at line %4d in %s returned %ld\n", (where), (int)__LINE__,  \
                       __FILE__, (long)(ret));                                                               \
        }                                                                                                    \
        if ((ret) < 0) {                                                                                     \
            TestErrPrintf("*** UNEXPECTED RETURN from %s is %ld line %4d in %s\n", (where), (long)(ret),     \
                          (int)__LINE__, __FILE__);                                                          \
            H5Eprint2(H5E_DEFAULT, stdout);                                                                  \
        }                                                                                                    \
    }

/* Check that a pointer is valid (i.e.: not NULL) */
#define CHECK_PTR(ret, where)                                                                                \
    {                                                                                                        \
        if (VERBOSE_HI) {                                                                                    \
            print_func("   Call to routine: %15s at line %4d in %s returned %p\n", (where), (int)__LINE__,   \
                       __FILE__, ((const void *)ret));                                                       \
        }                                                                                                    \
        if (!(ret)) {                                                                                        \
            TestErrPrintf("*** UNEXPECTED RETURN from %s is NULL line %4d in %s\n", (where), (int)__LINE__,  \
                          __FILE__);                                                                         \
            H5Eprint2(H5E_DEFAULT, stdout);                                                                  \
        }                                                                                                    \
    }

/* Check that a pointer is NULL */
#define CHECK_PTR_NULL(ret, where)                                                                           \
    {                                                                                                        \
        if (VERBOSE_HI) {                                                                                    \
            print_func("   Call to routine: %15s at line %4d in %s returned %p\n", (where), (int)__LINE__,   \
                       __FILE__, ((const void *)ret));                                                       \
        }                                                                                                    \
        if (ret) {                                                                                           \
            TestErrPrintf("*** UNEXPECTED RETURN from %s is not NULL line %4d in %s\n", (where),             \
                          (int)__LINE__, __FILE__);                                                          \
            H5Eprint2(H5E_DEFAULT, stdout);                                                                  \
        }                                                                                                    \
    }

/* Check that two pointers are equal */
#define CHECK_PTR_EQ(ret, val, where)                                                                        \
    {                                                                                                        \
        if (VERBOSE_HI) {                                                                                    \
            print_func("   Call to routine: %15s at line %4d in %s returned %p\n", (where), (int)__LINE__,   \
                       __FILE__, (const void *)(ret));                                                       \
        }                                                                                                    \
        if (ret != val) {                                                                                    \
            TestErrPrintf(                                                                                   \
                "*** UNEXPECTED RETURN from %s: returned value of %p is not equal to %p line %4d in %s\n",   \
                (where), (const void *)(ret), (const void *)(val), (int)__LINE__, __FILE__);                 \
            H5Eprint2(H5E_DEFAULT, stdout);                                                                  \
        }                                                                                                    \
    }

/* Used to make certain a return value _is_ a value */
#define VERIFY(_x, _val, where)                                                                              \
    do {                                                                                                     \
        long __x = (long)_x, __val = (long)_val;                                                             \
        if (VERBOSE_HI) {                                                                                    \
            print_func("   Call to routine: %15s at line %4d in %s had value "                               \
                       "%ld \n",                                                                             \
                       (where), (int)__LINE__, __FILE__, __x);                                               \
        }                                                                                                    \
        if ((__x) != (__val)) {                                                                              \
            TestErrPrintf("*** UNEXPECTED VALUE from %s should be %ld, but is %ld at line %4d "              \
                          "in %s\n",                                                                         \
                          (where), __val, __x, (int)__LINE__, __FILE__);                                     \
            H5Eprint2(H5E_DEFAULT, stdout);                                                                  \
        }                                                                                                    \
    } while (0)

/* Used to make certain a (non-'long' type's) return value _is_ a value */
#define VERIFY_TYPE(_x, _val, _type, _format, where)                                                         \
    do {                                                                                                     \
        _type __x = (_type)_x, __val = (_type)_val;                                                          \
        if (VERBOSE_HI) {                                                                                    \
            print_func("   Call to routine: %15s at line %4d in %s had value " _format " \n", (where),       \
                       (int)__LINE__, __FILE__, __x);                                                        \
        }                                                                                                    \
        if ((__x) != (__val)) {                                                                              \
            TestErrPrintf("*** UNEXPECTED VALUE from %s should be " _format ", but is " _format              \
                          " at line %4d "                                                                    \
                          "in %s\n",                                                                         \
                          (where), __val, __x, (int)__LINE__, __FILE__);                                     \
            H5Eprint2(H5E_DEFAULT, stdout);                                                                  \
        }                                                                                                    \
    } while (0)

/* Used to make certain a string return value _is_ a value */
#define VERIFY_STR(x, val, where)                                                                            \
    do {                                                                                                     \
        if (VERBOSE_HI) {                                                                                    \
            print_func("   Call to routine: %15s at line %4d in %s had value "                               \
                       "%s \n",                                                                              \
                       (where), (int)__LINE__, __FILE__, x);                                                 \
        }                                                                                                    \
        if (HDstrcmp(x, val) != 0) {                                                                         \
            TestErrPrintf("*** UNEXPECTED VALUE from %s should be %s, but is %s at line %4d "                \
                          "in %s\n",                                                                         \
                          where, val, x, (int)__LINE__, __FILE__);                                           \
            H5Eprint2(H5E_DEFAULT, stdout);                                                                  \
        }                                                                                                    \
    } while (0)

/* Used to document process through a test and to check for errors */
#define RESULT(ret, func)                                                                                    \
    do {                                                                                                     \
        if (VERBOSE_MED) {                                                                                   \
            print_func("   Call to routine: %15s at line %4d in %s returned "                                \
                       "%ld\n",                                                                              \
                       func, (int)__LINE__, __FILE__, (long)(ret));                                          \
        }                                                                                                    \
        if (VERBOSE_HI)                                                                                      \
            H5Eprint2(H5E_DEFAULT, stdout);                                                                  \
        if ((ret) == FAIL) {                                                                                 \
            TestErrPrintf("*** UNEXPECTED RETURN from %s is %ld at line %4d "                                \
                          "in %s\n",                                                                         \
                          func, (long)(ret), (int)__LINE__, __FILE__);                                       \
            H5Eprint2(H5E_DEFAULT, stdout);                                                                  \
        }                                                                                                    \
    } while (0)

/* Used to document process through a test */
#if defined(H5_HAVE_PARALLEL) && defined(H5_PARALLEL_TEST)
#define MESSAGE(V, A)                                                                                        \
    {                                                                                                        \
        int mpi_rank;                                                                                        \
                                                                                                             \
        MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);                                                            \
        if (mpi_rank == 0 && VERBO_LO /* HDGetTestVerbosity() */ >= (V))                                     \
            print_func A;                                                                                    \
    }
#else /* H5_HAVE_PARALLEL */
#define MESSAGE(V, A)                                                                                        \
    {                                                                                                        \
        if (VERBO_LO /* HDGetTestVerbosity() */ >= (V))                                                      \
            print_func A;                                                                                    \
    }
#endif /* H5_HAVE_PARALLEL */

/* Used to indicate an error that is complex to check for */
#define ERROR(where)                                                                                         \
    do {                                                                                                     \
        if (VERBOSE_HI)                                                                                      \
            print_func("   Call to routine: %15s at line %4d in %s returned "                                \
                       "invalid result\n",                                                                   \
                       where, (int)__LINE__, __FILE__);                                                      \
        TestErrPrintf("*** UNEXPECTED RESULT from %s at line %4d in %s\n", where, (int)__LINE__, __FILE__);  \
    } while (0)

/* definitions for command strings */
#define VERBOSITY_STR "Verbosity"
#define SKIP_STR      "Skip"
#define TEST_STR      "Test"
#define CLEAN_STR     "Cleanup"

#define AT() HDprintf("   at %s:%d in %s()...\n", __FILE__, __LINE__, __func__);
#define TESTING(WHAT)                                                                                        \
    {                                                                                                        \
        HDprintf("Testing %-62s", WHAT);                                                                     \
        HDfflush(stdout);                                                                                    \
    }
#define TESTING_2(WHAT)                                                                                      \
    {                                                                                                        \
        HDprintf("  Testing %-60s", WHAT);                                                                   \
        HDfflush(stdout);                                                                                    \
    }
#define PASSED()                                                                                             \
    {                                                                                                        \
        HDputs(" PASSED");                                                                                   \
        HDfflush(stdout);                                                                                    \
    }
#define H5_FAILED()                                                                                          \
    {                                                                                                        \
        HDputs("*FAILED*");                                                                                  \
        HDfflush(stdout);                                                                                    \
    }
#define H5_WARNING()                                                                                         \
    {                                                                                                        \
        HDputs("*WARNING*");                                                                                 \
        HDfflush(stdout);                                                                                    \
    }
#define SKIPPED()                                                                                            \
    {                                                                                                        \
        HDputs(" -SKIP-");                                                                                   \
        HDfflush(stdout);                                                                                    \
    }
#define PUTS_ERROR(s)                                                                                        \
    {                                                                                                        \
        HDputs(s);                                                                                           \
        AT();                                                                                                \
        goto error;                                                                                          \
    }
#define TEST_ERROR                                                                                           \
    {                                                                                                        \
        H5_FAILED();                                                                                         \
        AT();                                                                                                \
        goto error;                                                                                          \
    }
#define STACK_ERROR                                                                                          \
    {                                                                                                        \
        H5Eprint2(H5E_DEFAULT, stdout);                                                                      \
        goto error;                                                                                          \
    }
#define FAIL_STACK_ERROR                                                                                     \
    {                                                                                                        \
        H5_FAILED();                                                                                         \
        AT();                                                                                                \
        H5Eprint2(H5E_DEFAULT, stdout);                                                                      \
        goto error;                                                                                          \
    }
#define FAIL_PUTS_ERROR(s)                                                                                   \
    {                                                                                                        \
        H5_FAILED();                                                                                         \
        AT();                                                                                                \
        HDputs(s);                                                                                           \
        goto error;                                                                                          \
    }

#ifdef __cplusplus
extern "C" {
#endif

extern int nerrors;

int   print_func(const char *format, ...);
int   TestErrPrintf(const char *format, ...);
hid_t h5_fileaccess(void);
/* Functions that will replace components of a FAPL */
herr_t  h5_get_vfd_fapl(hid_t fapl_id);
herr_t  h5_get_libver_fapl(hid_t fapl_id);
char   *h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size);
char   *h5_fixname_superblock(const char *base_name, hid_t fapl, char *fullname, size_t size);
hbool_t h5_using_default_driver(const char *drv_name);
herr_t  h5_driver_is_default_vfd_compatible(hid_t fapl_id, hbool_t *default_vfd_compatible);

#ifdef H5_HAVE_PARALLEL
char *getenv_all(MPI_Comm comm, int root, const char *name);
#endif

/* Prototypes for the test routines */
void test_metadata(void);
void test_checksum(void);
void test_refstr(void);
void test_file(void);
void test_h5o(void);
void test_h5t(void);
void test_h5s(void);
void test_coords(void);
void test_h5d(void);
void test_attr(void);
void test_select(void);
void test_time(void);
void test_reference(void);
void test_reference_deprec(void);
void test_vltypes(void);
void test_vlstrings(void);
void test_iterate(void);
void test_array(void);
void test_genprop(void);
void test_configure(void);
void test_h5_system(void);
void test_misc(void);
void test_ids(void);
void test_skiplist(void);
void test_sohm(void);
void test_unicode(void);

/* Prototypes for the cleanup routines */
void cleanup_metadata(void);
void cleanup_checksum(void);
void cleanup_file(void);
void cleanup_h5o(void);
void cleanup_h5s(void);
void cleanup_coords(void);
void cleanup_attr(void);
void cleanup_select(void);
void cleanup_time(void);
void cleanup_reference(void);
void cleanup_reference_deprec(void);
void cleanup_vltypes(void);
void cleanup_vlstrings(void);
void cleanup_iterate(void);
void cleanup_array(void);
void cleanup_genprop(void);
void cleanup_configure(void);
void cleanup_h5_system(void);
void cleanup_sohm(void);
void cleanup_misc(void);
void cleanup_unicode(void);

#ifdef __cplusplus
}
#endif
#endif /* TESTHDF5_H */