File: macros.c

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 (230 lines) | stat: -rw-r--r-- 7,163 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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "tproto.h"

#define INT16MAX 32767 /* 0x7fff */

#define UINT16MAX 65535 /* 0xffff */

#define INT32MAX 2147483647 /* 0x7fffffff */

#define UINT32MAX 4294967295UL /* 0xffffffff */

extern int Verbocity;

void
test_macros(void)
{

    uint8_t *p;
    uint16   new16u, old16u, str16u;
    int16    new16, old16, str16;
    uint32   new32u, old32u, str32u;
    int32    new32, old32, str32;
    int      errors1, errors2, errors3, errors4;
    int      errors = 0;

    uint16 data1[10] = {0, 1, 2, 3, 4, UINT16MAX - 4, UINT16MAX - 3, UINT16MAX - 2, UINT16MAX - 1, UINT16MAX};

    int16 data2[20] = {-INT16MAX - 1,
                       -INT16MAX,
                       -INT16MAX + 1,
                       -INT16MAX + 2,
                       -INT16MAX + 3,
                       -INT16MAX + 4,
                       -4,
                       -3,
                       -2,
                       -1,
                       0,
                       1,
                       2,
                       3,
                       4,
                       INT16MAX - 4,
                       INT16MAX - 3,
                       INT16MAX - 2,
                       INT16MAX - 1,
                       INT16MAX};

    uint32 data3[10] = {0, 1, 2, 3, 4, UINT32MAX - 4, UINT32MAX - 3, UINT32MAX - 2, UINT32MAX - 1, UINT32MAX};

    int32 data4[20] = {-INT32MAX - 1,
                       -INT32MAX,
                       -INT32MAX + 1,
                       -INT32MAX + 2,
                       -INT32MAX + 3,
                       -INT32MAX + 4,
                       -4,
                       -3,
                       -2,
                       -1,
                       0,
                       1,
                       2,
                       3,
                       4,
                       INT32MAX - 4,
                       INT32MAX - 3,
                       INT32MAX - 2,
                       INT32MAX - 1,
                       INT32MAX};

    if (Verbosity > 5)
        printf("\n");
    errors1 = 0;
    for (size_t j = 0; j < 10; j++) {
        old16u = data1[j];

        p = (uint8_t *)&str16u;
        UINT16ENCODE(p, old16u);
        p = (uint8_t *)&str16u;
        UINT16DECODE(p, new16u);

        if (old16u != new16u) {
            if (Verbosity > 8) {
                printf("old16u = %" PRIu16 ", %" PRIx16 "\n", old16u, old16u);
                printf("str: ");
                p = (uint8_t *)&str16u;
                for (size_t i = 0; i < sizeof(uint16); i++) {
                    printf("%x ", 0xff & *p++);
                }
                printf("\n");
                printf("new16u = %" PRIu16 ", %" PRIx16 "\n", new16u, new16u);
                printf("\n");
            }
            errors1++;
        }
    }
    if (Verbosity > 5) {
        if (errors1 == 0) {
            printf("UNSIGNED INTEGER16: SUCCESSFUL\n");
        }
        else {
            printf("UNSIGNED INTEGER16: %d ERRORS\n", errors1);
        }
    }

    if (Verbosity > 5)
        printf("\n");
    errors2 = 0;
    for (size_t j = 0; j < 20; j++) {
        old16 = data2[j];

        p = (uint8_t *)&str16;
        INT16ENCODE(p, old16);
        p = (uint8_t *)&str16;
        INT16DECODE(p, new16);

        if (old16 != new16) {
            if (Verbosity > 8) {
                printf("old16 = %" PRId16 ", %" PRIx16 "\n", old16, old16);
                printf("str: ");
                p = (uint8_t *)&str16;
                for (size_t i = 0; i < sizeof(int16); i++) {
                    printf("%x ", 0xff & *p++);
                }
                printf("\n");
                printf("new16 = %" PRId16 ", %" PRIx16 "\n", new16, new16);
                printf("\n");
            }
            errors2++;
        }
    }
    if (Verbosity > 5) {
        if (errors2 == 0) {
            printf("SIGNED INTEGER16: SUCCESSFUL\n");
        }
        else {
            printf("SIGNED INTEGER16: %d ERRORS\n", errors2);
        }
    }

    if (Verbosity > 5)
        printf("\n");
    errors3 = 0;
    for (size_t j = 0; j < 10; j++) {
        old32u = data3[j];

        p = (uint8_t *)&str32u;
        UINT32ENCODE(p, old32u);
        p = (uint8_t *)&str32u;
        UINT32DECODE(p, new32u);

        if (old32u != new32u) {
            if (Verbosity > 8) {
                printf("old32u = %" PRIu32 ", %" PRIx32 "\n", old32u, old32u);
                printf("str: ");
                p = (uint8_t *)&str32u;
                for (size_t i = 0; i < sizeof(uint32); i++) {
                    printf("%x ", 0xff & *p++);
                }
                printf("\n");
                printf("new32u = %" PRIu32 ", %" PRIx32 "\n", new32u, new32u);
                printf("\n");
            }
            errors3++;
        }
    }
    if (Verbosity > 5) {
        if (errors3 == 0) {
            printf("UNSIGNED INTEGER32: SUCCESSFUL\n");
        }
        else {
            printf("UNSIGNED INTEGER32: %d ERRORS\n", errors3);
        }
    }

    if (Verbosity > 5)
        printf("\n");
    errors4 = 0;
    for (size_t j = 0; j < 20; j++) {
        old32 = data4[j];

        p = (uint8_t *)&str32;
        INT32ENCODE(p, old32);
        p = (uint8_t *)&str32;
        INT32DECODE(p, new32);

        if (old32 != new32) {
            if (Verbosity > 8) {
                printf("old32 = %" PRId32 ", %" PRIx32 "\n", old32, old32);
                printf("str: ");
                p = (uint8_t *)&str32;
                for (size_t i = 0; i < sizeof(int32); i++) {
                    printf("%x ", 0xff & *p++);
                }
                printf("\n");
                printf("new32 = %" PRId32 ", %" PRIx32 "\n", new32, new32);
                printf("\n");
            }
            errors4++;
        }
    }
    if (Verbosity > 5) {
        if (errors4 == 0) {
            printf("SIGNED INTEGER32: SUCCESSFUL\n");
        }
        else {
            printf("SIGNED INTEGER32: %d ERRORS\n", errors4);
        }
    }

    errors = errors1 + errors2 + errors3 + errors4;
    if (errors > 0) {
        printf("            %d ERRORS were detected during (macros) Testing\n", errors);
        num_errs += errors;
    }

} /* end test_macros() */