1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 /*
15 * Serial tests for encoding/decoding plists
16 */
17
18 #include "h5test.h"
19 #include "H5srcdir.h"
20
21 #define CONFIG_LE 0x01
22 #define CONFIG_64 0x02
23 #define NCONFIG 0x04
24
25 static int test_plists(const char *filename_prefix);
26
27 int
main(void)28 main(void)
29 {
30 if(VERBOSE_MED)
31 HDprintf("Encode/Decode property list endianess\n");
32
33 /******* ENCODE/DECODE DCPLS *****/
34 TESTING("Default DCPL Encoding/Decoding");
35 if(test_plists("testfiles/plist_files/def_dcpl_") < 0)
36 FAIL_STACK_ERROR
37 PASSED();
38 TESTING("DCPL Encoding/Decoding");
39 if(test_plists("testfiles/plist_files/dcpl_") < 0)
40 FAIL_STACK_ERROR
41 PASSED();
42
43 /******* ENCODE/DECODE DAPLS *****/
44 TESTING("Default DAPL Encoding/Decoding");
45 if(test_plists("testfiles/plist_files/def_dapl_") < 0)
46 FAIL_STACK_ERROR
47 PASSED();
48 TESTING("DAPL Encoding/Decoding");
49 if(test_plists("testfiles/plist_files/dapl_") < 0)
50 FAIL_STACK_ERROR
51 PASSED();
52
53 /******* ENCODE/DECODE DXPLS *****/
54 TESTING("Default DXPL Encoding/Decoding");
55 if(test_plists("testfiles/plist_files/def_dxpl_") < 0)
56 FAIL_STACK_ERROR
57 PASSED();
58 TESTING("DXPL Encoding/Decoding");
59 if(test_plists("testfiles/plist_files/dxpl_") < 0)
60 FAIL_STACK_ERROR
61 PASSED();
62
63 /******* ENCODE/DECODE GCPLS *****/
64 TESTING("Default GCPL Encoding/Decoding");
65 if(test_plists("testfiles/plist_files/def_gcpl_") < 0)
66 FAIL_STACK_ERROR
67 PASSED();
68 TESTING("GCPL Encoding/Decoding");
69 if(test_plists("testfiles/plist_files/gcpl_") < 0)
70 FAIL_STACK_ERROR
71 PASSED();
72
73 /******* ENCODE/DECODE LCPLS *****/
74 TESTING("Default LCPL Encoding/Decoding");
75 if(test_plists("testfiles/plist_files/def_lcpl_") < 0)
76 FAIL_STACK_ERROR
77 PASSED();
78 TESTING("LCPL Encoding/Decoding");
79 if(test_plists("testfiles/plist_files/lcpl_") < 0)
80 FAIL_STACK_ERROR
81 PASSED();
82
83 /******* ENCODE/DECODE LAPLS *****/
84 TESTING("Default LAPL Encoding/Decoding");
85 if(test_plists("testfiles/plist_files/def_lapl_") < 0)
86 FAIL_STACK_ERROR
87 PASSED();
88 TESTING("LAPL Encoding/Decoding");
89 if(test_plists("testfiles/plist_files/lapl_") < 0)
90 FAIL_STACK_ERROR
91 PASSED();
92
93 /******* ENCODE/DECODE OCPLS *****/
94 TESTING("Default OCPL Encoding/Decoding");
95 if(test_plists("testfiles/plist_files/def_ocpl_") < 0)
96 FAIL_STACK_ERROR
97 PASSED();
98 TESTING("OCPL Encoding/Decoding");
99 if(test_plists("testfiles/plist_files/ocpl_") < 0)
100 FAIL_STACK_ERROR
101 PASSED();
102
103 /******* ENCODE/DECODE OCPYPLS *****/
104 TESTING("Default OCPYPL Encoding/Decoding");
105 if(test_plists("testfiles/plist_files/def_ocpypl_") < 0)
106 FAIL_STACK_ERROR
107 PASSED();
108 TESTING("OCPYPL Encoding/Decoding");
109 if(test_plists("testfiles/plist_files/ocpypl_") < 0)
110 FAIL_STACK_ERROR
111 PASSED();
112
113 /******* ENCODE/DECODE FCPLS *****/
114 TESTING("Default FCPL Encoding/Decoding");
115 if(test_plists("testfiles/plist_files/def_fcpl_") < 0)
116 FAIL_STACK_ERROR
117 PASSED();
118 TESTING("FCPL Encoding/Decoding");
119 if(test_plists("testfiles/plist_files/fcpl_") < 0)
120 FAIL_STACK_ERROR
121 PASSED();
122
123 /******* ENCODE/DECODE FAPLS *****/
124 TESTING("Default FAPL Encoding/Decoding");
125 if(test_plists("testfiles/plist_files/def_fapl_") < 0)
126 FAIL_STACK_ERROR
127 PASSED();
128 TESTING("FAPL Encoding/Decoding");
129 if(test_plists("testfiles/plist_files/fapl_") < 0)
130 FAIL_STACK_ERROR
131 PASSED();
132
133 /******* ENCODE/DECODE STRCPLS *****/
134 TESTING("Default STRCPL Encoding/Decoding");
135 if(test_plists("testfiles/plist_files/def_strcpl_") < 0)
136 FAIL_STACK_ERROR
137 PASSED();
138 TESTING("STRCPL Encoding/Decoding");
139 if(test_plists("testfiles/plist_files/strcpl_") < 0)
140 FAIL_STACK_ERROR
141 PASSED();
142
143 /******* ENCODE/DECODE ACPLS *****/
144 TESTING("Default ACPL Encoding/Decoding");
145 if(test_plists("testfiles/plist_files/def_acpl_") < 0)
146 FAIL_STACK_ERROR
147 PASSED();
148 TESTING("ACPL Encoding/Decoding");
149 if(test_plists("testfiles/plist_files/acpl_") < 0)
150 FAIL_STACK_ERROR
151 PASSED();
152
153 return 0;
154
155 error:
156 return 1;
157 }
158
159 static int
test_plists(const char * filename_prefix)160 test_plists(const char *filename_prefix)
161 {
162 unsigned config_1, config_2;
163 int fd_1, fd_2;
164 size_t size_1 = 0, size_2 = 0;
165 void *buf_1 = NULL, *buf_2 = NULL;
166 hid_t plist_1, plist_2;
167 char filename[1024];
168 const char *testfile;
169
170 /* Iterate over all combinations of configurations */
171 for(config_1 = 0; config_1 < (NCONFIG - 1); config_1++)
172 for(config_2 = config_1 + 1; config_2 < NCONFIG; config_2++) {
173 /* Generate filename for file 1 */
174 if(HDsnprintf(filename, sizeof(filename), "%s%s%s", filename_prefix,
175 config_1 & CONFIG_64 ? "64" : "32",
176 config_1 & CONFIG_LE ? "le" : "be") < 0)
177 TEST_ERROR
178
179 /* Read file 1 */
180 testfile = H5_get_srcdir_filename(filename);
181 if((fd_1 = HDopen(testfile, O_RDONLY)) < 0)
182 TEST_ERROR
183 size_1 = (size_t)HDlseek(fd_1, (HDoff_t)0, SEEK_END);
184 HDlseek(fd_1, (HDoff_t)0, SEEK_SET);
185 buf_1 = (void *)HDmalloc(size_1);
186 if(HDread(fd_1, buf_1, size_1) < 0)
187 TEST_ERROR
188 HDclose(fd_1);
189
190 /* Generate filename for file 2 */
191 if(HDsnprintf(filename, sizeof(filename), "%s%s%s", filename_prefix,
192 config_2 & CONFIG_64 ? "64" : "32",
193 config_2 & CONFIG_LE ? "le" : "be") < 0)
194 TEST_ERROR
195
196 /* Read file 1 */
197 testfile = H5_get_srcdir_filename(filename);
198 if((fd_2 = HDopen(testfile, O_RDONLY)) < 0)
199 TEST_ERROR
200 size_2 = (size_t)HDlseek(fd_2, (HDoff_t)0, SEEK_END);
201 HDlseek(fd_2, (HDoff_t)0, SEEK_SET);
202 buf_2 = (void *)HDmalloc(size_2);
203 if(HDread(fd_2, buf_2, size_2) < 0)
204 TEST_ERROR
205 HDclose(fd_2);
206
207 /* Decode property lists */
208 if((plist_1 = H5Pdecode(buf_1)) < 0)
209 FAIL_STACK_ERROR
210 if((plist_2 = H5Pdecode(buf_2)) < 0)
211 FAIL_STACK_ERROR
212
213 /* Compare decoded property lists */
214 if(!H5Pequal(plist_1, plist_2))
215 FAIL_PUTS_ERROR("PLIST encoding/decoding comparison failed\n")
216
217 /* Close */
218 if((H5Pclose(plist_1)) < 0)
219 FAIL_STACK_ERROR
220 if((H5Pclose(plist_2)) < 0)
221 FAIL_STACK_ERROR
222
223 HDfree(buf_1);
224 HDfree(buf_2);
225 } /* end for */
226
227 return 1;
228
229 error:
230 HDprintf("***** Plist Encode/Decode tests FAILED! *****\n");
231 return -1;
232 }
233
234