summaryrefslogtreecommitdiffstats
path: root/test/enc_dec_plist_cross_platform.c
blob: b151df706147deaefbef20868a99a3ce9f5d97d7 (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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * Serial tests for encoding/decoding plists
 */

#include "h5test.h"
#include "H5srcdir.h"

#define CONFIG_LE 0x01
#define CONFIG_64 0x02
#define NCONFIG   0x04

static int test_plists(const char *filename_prefix);

int
main(void)
{
    if (VERBOSE_MED)
        HDprintf("Encode/Decode property list endianness\n");

    /******* ENCODE/DECODE DCPLS *****/
    TESTING("Default DCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_dcpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("DCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/dcpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    /******* ENCODE/DECODE DAPLS *****/
    TESTING("Default DAPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_dapl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("DAPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/dapl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    /******* ENCODE/DECODE DXPLS *****/
    TESTING("Default DXPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_dxpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("DXPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/dxpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    /******* ENCODE/DECODE GCPLS *****/
    TESTING("Default GCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_gcpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("GCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/gcpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    /******* ENCODE/DECODE LCPLS *****/
    TESTING("Default LCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_lcpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("LCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/lcpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    /******* ENCODE/DECODE LAPLS *****/
    TESTING("Default LAPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_lapl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("LAPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/lapl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    /******* ENCODE/DECODE OCPLS *****/
    TESTING("Default OCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_ocpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("OCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/ocpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    /******* ENCODE/DECODE OCPYPLS *****/
    TESTING("Default OCPYPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_ocpypl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("OCPYPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/ocpypl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    /******* ENCODE/DECODE FCPLS *****/
    TESTING("Default FCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_fcpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("FCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/fcpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    /******* ENCODE/DECODE FAPLS *****/
    TESTING("Default FAPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_fapl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("FAPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/fapl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    /******* ENCODE/DECODE STRCPLS *****/
    TESTING("Default STRCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_strcpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("STRCPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/strcpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    /******* ENCODE/DECODE ACPLS *****/
    TESTING("Default ACPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/def_acpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();
    TESTING("ACPL Encoding/Decoding");
    if (test_plists("testfiles/plist_files/acpl_") < 0)
        FAIL_STACK_ERROR
    PASSED();

    return 0;

error:
    return 1;
}

static int
test_plists(const char *filename_prefix)
{
    unsigned    config_1, config_2;
    int         fd_1, fd_2;
    size_t      size_1 = 0, size_2 = 0;
    void       *buf_1 = NULL, *buf_2 = NULL;
    hid_t       plist_1, plist_2;
    char        filename[1024];
    const char *testfile;

    /* Iterate over all combinations of configurations */
    for (config_1 = 0; config_1 < (NCONFIG - 1); config_1++)
        for (config_2 = config_1 + 1; config_2 < NCONFIG; config_2++) {
            /* Generate filename for file 1 */
            if (HDsnprintf(filename, sizeof(filename), "%s%s%s", filename_prefix,
                           config_1 & CONFIG_64 ? "64" : "32", config_1 & CONFIG_LE ? "le" : "be") < 0)
                TEST_ERROR

            /* Read file 1 */
            testfile = H5_get_srcdir_filename(filename);
            if ((fd_1 = HDopen(testfile, O_RDONLY)) < 0)
                TEST_ERROR
            size_1 = (size_t)HDlseek(fd_1, (HDoff_t)0, SEEK_END);
            HDlseek(fd_1, (HDoff_t)0, SEEK_SET);
            buf_1 = (void *)HDmalloc(size_1);
            if (HDread(fd_1, buf_1, size_1) < 0)
                TEST_ERROR
            HDclose(fd_1);

            /* Generate filename for file 2 */
            if (HDsnprintf(filename, sizeof(filename), "%s%s%s", filename_prefix,
                           config_2 & CONFIG_64 ? "64" : "32", config_2 & CONFIG_LE ? "le" : "be") < 0)
                TEST_ERROR

            /* Read file 1 */
            testfile = H5_get_srcdir_filename(filename);
            if ((fd_2 = HDopen(testfile, O_RDONLY)) < 0)
                TEST_ERROR
            size_2 = (size_t)HDlseek(fd_2, (HDoff_t)0, SEEK_END);
            HDlseek(fd_2, (HDoff_t)0, SEEK_SET);
            buf_2 = (void *)HDmalloc(size_2);
            if (HDread(fd_2, buf_2, size_2) < 0)
                TEST_ERROR
            HDclose(fd_2);

            /* Decode property lists */
            if ((plist_1 = H5Pdecode(buf_1)) < 0)
                FAIL_STACK_ERROR
            if ((plist_2 = H5Pdecode(buf_2)) < 0)
                FAIL_STACK_ERROR

            /* Compare decoded property lists */
            if (!H5Pequal(plist_1, plist_2))
                FAIL_PUTS_ERROR("PLIST encoding/decoding comparison failed\n")

            /* Close */
            if ((H5Pclose(plist_1)) < 0)
                FAIL_STACK_ERROR
            if ((H5Pclose(plist_2)) < 0)
                FAIL_STACK_ERROR

            HDfree(buf_1);
            HDfree(buf_2);
        } /* end for */

    return 1;

error:
    HDprintf("***** Plist Encode/Decode tests FAILED! *****\n");
    return -1;
}