File: tutils.h

package info (click to toggle)
libhdf4 4.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,384 kB
  • sloc: ansic: 128,700; sh: 15,015; fortran: 12,444; java: 5,863; xml: 1,205; makefile: 794; yacc: 678; pascal: 418; perl: 360; javascript: 203; lex: 163; csh: 41
file content (249 lines) | stat: -rw-r--r-- 17,859 bytes parent folder | download | duplicates (2)
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF.  The full HDF 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://support.hdfgroup.org/ftp/HDF/releases/.  *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef H4_TUTILS_H
#define H4_TUTILS_H

#include <float.h>
#include <math.h>

#include "hdf_priv.h"

/* Define these for use in all the tests */
#ifndef TESTMASTER
extern
#endif
    int num_errs
#ifdef TESTMASTER
    = 0
#endif
    ,
    Verbosity
#ifdef TESTMASTER
    = 0
#endif
    ;

/* Use %ld to print the value because long could cover most cases. */
/* Used to make certain a return value _is_not_ a value.  If not true, */
/* print error messages, increment num_err and return. */
#define CHECK(ret, val, where)                                                                               \
    do {                                                                                                     \
        if (Verbosity > 9)                                                                                   \
            printf("   Call to HDF routine: %15s at line %4d in %s returned %ld \n", where, (int)__LINE__,   \
                   __FILE__, (long)ret);                                                                     \
        if (ret == val) {                                                                                    \
            printf("*** UNEXPECTED RETURN from %s is %ld at line %4d in %s\n", where, (long)ret,             \
                   (int)__LINE__, __FILE__);                                                                 \
            num_errs++;                                                                                      \
            return num_errs;                                                                                 \
        }                                                                                                    \
    } while (0)

#define CHECK_VOID(ret, val, where)                                                                          \
    do {                                                                                                     \
        if (Verbosity > 9)                                                                                   \
            printf("   Call to HDF routine: %15s at line %4d in %s returned %ld \n", where, (int)__LINE__,   \
                   __FILE__, (long)ret);                                                                     \
        if (ret == val) {                                                                                    \
            printf("*** UNEXPECTED RETURN from %s is %ld at line %4d in %s\n", where, (long)ret,             \
                   (int)__LINE__, __FILE__);                                                                 \
            num_errs++;                                                                                      \
            return;                                                                                          \
        }                                                                                                    \
    } while (0)

/* Same as CHECK except no return but continue. */
#define CHECK_CONT(ret, val, where)                                                                          \
    do {                                                                                                     \
        if (Verbosity > 9)                                                                                   \
            printf("   Call to HDF routine: %15s at line %4d in %s returned %ld \n", where, (int)__LINE__,   \
                   __FILE__, (long)ret);                                                                     \
        if (ret == val) {                                                                                    \
            printf("*** UNEXPECTED RETURN from %s is %ld at line %4d in %s\n", where, (long)ret,             \
                   (int)__LINE__, __FILE__);                                                                 \
            num_errs++;                                                                                      \
        }                                                                                                    \
    } while (0)

/* If values match, display message supplied by caller. */
#define CHECK_STATUS(status, val, msg)                                                                       \
    do {                                                                                                     \
        if (status == val)                                                                                   \
            printf("   %s failed at line %4d in %s\n", msg, (int)__LINE__, __FILE__);                        \
    } while (0)

/* Used to validate that 'buffer' has been successfully allocated */
#define CHECK_ALLOC(buffer, buf_name, func_name)                                                             \
    {                                                                                                        \
        if (buffer == NULL) {                                                                                \
            fprintf(stderr, "in %s: space allocation for %s failed.  Terminated!\n", func_name, buf_name);   \
            exit(1);                                                                                         \
        }                                                                                                    \
    }

/* Used to make certain a return value _is_ a value */
#define VERIFY(x, val, where)                                                                                \
    do {                                                                                                     \
        if (Verbosity > 9)                                                                                   \
            printf("   Call to HDF routine: %15s at line %4d in %s had value %ld \n", where, (int)__LINE__,  \
                   __FILE__, (long)x);                                                                       \
        if (x != val) {                                                                                      \
            printf("*** UNEXPECTED VALUE from %s is %ld at line %4d in %s\n", where, (long)x, (int)__LINE__, \
                   __FILE__);                                                                                \
            num_errs++;                                                                                      \
            return (num_errs);                                                                               \
        }                                                                                                    \
    } while (0)

/* Same as VERIFY except return without a value. */
#define VERIFY_VOID(x, val, where)                                                                           \
    do {                                                                                                     \
        if (Verbosity > 9)                                                                                   \
            printf("   Call to HDF routine: %15s at line %4d in %s had value %ld \n", where, (int)__LINE__,  \
                   __FILE__, (long)x);                                                                       \
        if (x != val) {                                                                                      \
            printf("*** UNEXPECTED VALUE from %s is %ld at line %4d in %s\n", where, (long)x, (int)__LINE__, \
                   __FILE__);                                                                                \
            num_errs++;                                                                                      \
            return;                                                                                          \
        }                                                                                                    \
    } while (0)

/* Same as VERIFY except no return but continue. */
#define VERIFY_CONT(x, val, where)                                                                           \
    do {                                                                                                     \
        if (Verbosity > 9)                                                                                   \
            printf("   Call to HDF routine: %15s at line %4d in %s had value %ld \n", where, (int)__LINE__,  \
                   __FILE__, (long)x);                                                                       \
        if (x != val) {                                                                                      \
            printf("*** UNEXPECTED VALUE from %s is %ld at line %4d in %s\n", where, (long)x, (int)__LINE__, \
                   __FILE__);                                                                                \
            num_errs++;                                                                                      \
        }                                                                                                    \
    } while (0)

/* Same as VERIFY except that the value has type char* */
#define VERIFY_CHAR(x, val, where)                                                                           \
    do {                                                                                                     \
        if (Verbosity > 9)                                                                                   \
            printf("   Call to HDF routine: %15s at line %4d in %s had value %s \n", where, (int)__LINE__,   \
                   __FILE__, x);                                                                             \
        if (strcmp(x, val) != 0) {                                                                           \
            printf("*** UNEXPECTED VALUE from %s is %s at line %4d in %s\n", where, x, (int)__LINE__,        \
                   __FILE__);                                                                                \
            num_errs++;                                                                                      \
            return (num_errs);                                                                               \
        }                                                                                                    \
    } while (0)

/* Same as VERIFY_CHAR except return without a value. */
#define VERIFY_CHAR_VOID(x, val, where)                                                                      \
    do {                                                                                                     \
        if (Verbosity > 9)                                                                                   \
            printf("   Call to HDF routine: %15s at line %4d in %s had value %s \n", where, (int)__LINE__,   \
                   __FILE__, x);                                                                             \
        if (strncmp(x, val, strlen(val)) != 0) {                                                             \
            printf("*** UNEXPECTED VALUE from %s is %s at line %4d in %s\n", where, x, (int)__LINE__,        \
                   __FILE__);                                                                                \
            num_errs++;                                                                                      \
            return;                                                                                          \
        }                                                                                                    \
    } while (0)

#define RESULT(a)                                                                                            \
    do {                                                                                                     \
        if (Verbosity > 8)                                                                                   \
            printf("   Call to HDF routine: %15s at line %4d in %s returned %ld \n", a, (int)__LINE__,       \
                   __FILE__, (long)ret);                                                                     \
        if (Verbosity > 9)                                                                                   \
            HEprint(stdout, 0);                                                                              \
        if (ret == FAIL) {                                                                                   \
            printf("*** UNEXPECTED RETURN from %s is %ld at line %4d in %s\n", a, (long)ret, (int)__LINE__,  \
                   __FILE__);                                                                                \
            num_errs++;                                                                                      \
        }                                                                                                    \
    } while (0)

#define MESSAGE(v, a)                                                                                        \
    {                                                                                                        \
        if (Verbosity >= v) {                                                                                \
            a                                                                                                \
        }                                                                                                    \
    }

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

/* Output notices */
#define H4_PASSED()                                                                                          \
    {                                                                                                        \
        puts(" PASSED");                                                                                     \
        fflush(stdout);                                                                                      \
    }
#define H4_FAILED()                                                                                          \
    {                                                                                                        \
        puts("*FAILED*");                                                                                    \
        fflush(stdout);                                                                                      \
    }
#define H4_WARNING()                                                                                         \
    {                                                                                                        \
        puts("*WARNING*");                                                                                   \
        fflush(stdout);                                                                                      \
    }
#define H4_SKIPPED()                                                                                         \
    {                                                                                                        \
        puts(" -SKIP-");                                                                                     \
        fflush(stdout);                                                                                      \
    }

/*
 * Methods to compare the equality of floating-point values:
 *
 *    1. H4_XXX_ABS_EQUAL - check if the difference is smaller than the
 *       Epsilon value.  The Epsilon values, FLT_EPSILON, DBL_EPSILON,
 *       and LDBL_EPSILON, are defined by compiler in float.h.
 *
 *  HDF5 (from whence these macros came) also includes macros that
 *  use relative error. Those will be brought over only if needed.
 */
#define H4_FLT_ABS_EQUAL(X, Y)  (fabsf((X) - (Y)) < FLT_EPSILON)
#define H4_DBL_ABS_EQUAL(X, Y)  (fabs((X) - (Y)) < DBL_EPSILON)
#define H4_LDBL_ABS_EQUAL(X, Y) (fabsl((X) - (Y)) < LDBL_EPSILON)

/* Definition for JPEG tests */
#define JPEG_FUZZ 1

#define ABS(x) ((int)(x) < 0 ? (-x) : x)

/* Just return the srcdir path */
const char *get_srcdir(void);

/* Append the test file name to the srcdir path and return the whole string */
const char *get_srcdir_filename(const char *filename);

intn fuzzy_memcmp(const void *s1, const void *s2, int32 len, intn fuzz_factor);
void print_mismatched(const void *s1, const void *s2, int32 size2cmp);

/* System command to use for Cleanup */
#if defined _WIN32
#define CLEAN_CMD "del *.hdf"
#else
/* default is Unix */
#define CLEAN_CMD "rm -f *.hdf"
#endif /* _WIN32  */

#endif /* H4_TUTILS_H */