]>
Commit | Line | Data |
---|---|---|
622749d8 | 1 | m4_define([JSON_CHECK_POSITIVE_C], |
f38b84ea BP |
2 | [AT_SETUP([$1]) |
3 | AT_KEYWORDS([json positive]) | |
4 | AT_CHECK([printf %s "AS_ESCAPE([$2])" > input]) | |
0bdf342a | 5 | AT_CAPTURE_FILE([input]) |
eadd1644 | 6 | AT_CHECK([ovstest test-json $4 input], [0], [stdout], []) |
0bdf342a BP |
7 | AT_CHECK([cat stdout], [0], [$3 |
8 | ]) | |
f38b84ea BP |
9 | AT_CLEANUP]) |
10 | ||
1ca0323e | 11 | # JSON_CHECK_POSITIVE_PY(TITLE, INPUT, OUTPUT, TEST-JSON-ARGS) |
f7255f06 | 12 | # |
622749d8 | 13 | m4_define([JSON_CHECK_POSITIVE_PY], |
99155935 BP |
14 | [AT_SETUP([$1]) |
15 | AT_KEYWORDS([json positive Python]) | |
99155935 BP |
16 | AT_CHECK([printf %s "AS_ESCAPE([$2])" > input]) |
17 | AT_CAPTURE_FILE([input]) | |
1ca0323e | 18 | AT_CHECK([$PYTHON3 $srcdir/test-json.py $4 input], [0], [stdout], []) |
65683353 EJ |
19 | AT_CHECK([cat stdout], [0], [$3 |
20 | ]) | |
21 | AT_CLEANUP]) | |
22 | ||
99155935 BP |
23 | m4_define([JSON_CHECK_POSITIVE], |
24 | [JSON_CHECK_POSITIVE_C([$1 - C], [$2], [$3], [$4]) | |
1ca0323e | 25 | JSON_CHECK_POSITIVE_PY([$1 - Python3], [$2], [$3], [$4])]) |
622749d8 | 26 | |
99155935 | 27 | m4_define([JSON_CHECK_NEGATIVE_C], |
f38b84ea BP |
28 | [AT_SETUP([$1]) |
29 | AT_KEYWORDS([json negative]) | |
30 | AT_CHECK([printf %s "AS_ESCAPE([$2])" > input]) | |
0bdf342a | 31 | AT_CAPTURE_FILE([input]) |
eadd1644 | 32 | AT_CHECK([ovstest test-json $4 input], [1], [stdout], []) |
0bdf342a | 33 | AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3 |
f38b84ea BP |
34 | ]) |
35 | AT_CLEANUP]) | |
36 | ||
1ca0323e | 37 | # JSON_CHECK_NEGATIVE_PY(TITLE, INPUT, OUTPUT, TEST-JSON-ARGS) |
f7255f06 | 38 | # |
99155935 BP |
39 | m4_define([JSON_CHECK_NEGATIVE_PY], |
40 | [AT_SETUP([$1]) | |
41 | AT_KEYWORDS([json negative Python]) | |
99155935 BP |
42 | AT_CHECK([printf %s "AS_ESCAPE([$2])" > input]) |
43 | AT_CAPTURE_FILE([input]) | |
1ca0323e | 44 | AT_CHECK([$PYTHON3 $srcdir/test-json.py $4 input], [1], [stdout], []) |
99155935 BP |
45 | AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3 |
46 | ]) | |
47 | AT_CLEANUP]) | |
48 | ||
49 | m4_define([JSON_CHECK_NEGATIVE], | |
50 | [JSON_CHECK_NEGATIVE_C([$1 - C], [$2], [$3], [$4]) | |
1ca0323e | 51 | JSON_CHECK_NEGATIVE_PY([$1 - Python3], [$2], [$3], [$4])]) |
99155935 | 52 | |
f38b84ea BP |
53 | AT_BANNER([JSON -- arrays]) |
54 | ||
55 | JSON_CHECK_POSITIVE([empty array], [[ [ ] ]], [[[]]]) | |
56 | JSON_CHECK_POSITIVE([single-element array], [[ [ 1 ] ]], [[[1]]]) | |
57 | JSON_CHECK_POSITIVE([2-element array], [[ [ 1, 2 ] ]], [[[1,2]]]) | |
58 | JSON_CHECK_POSITIVE([many-element array], | |
59 | [[ [ 1, 2, 3, 4, 5 ] ]], | |
60 | [[[1,2,3,4,5]]]) | |
61 | JSON_CHECK_NEGATIVE([missing comma], [[ [ 1, 2, 3 4, 5 ] ]], | |
62 | [error: syntax error expecting '@:>@' or ',']) | |
63 | JSON_CHECK_NEGATIVE([trailing comma not allowed], | |
64 | [[[1,2,]]], [error: syntax error expecting value]) | |
65 | JSON_CHECK_NEGATIVE([doubled comma not allowed], | |
66 | [[[1,,2]]], [error: syntax error expecting value]) | |
67 | ||
68 | AT_BANNER([JSON -- strings]) | |
69 | ||
70 | JSON_CHECK_POSITIVE([empty string], [[[ "" ]]], [[[""]]]) | |
71 | JSON_CHECK_POSITIVE([1-character strings], | |
72 | [[[ "a", "b", "c" ]]], | |
73 | [[["a","b","c"]]]) | |
74 | JSON_CHECK_POSITIVE([escape sequences], | |
75 | [[[ " \" \\ \/ \b \f \n \r \t" ]]], | |
76 | [[[" \" \\ / \b \f \n \r \t"]]]) | |
77 | JSON_CHECK_POSITIVE([Unicode escape sequences], | |
78 | [[[ " \u0022 \u005c \u002F \u0008 \u000c \u000A \u000d \u0009" ]]], | |
79 | [[[" \" \\ / \b \f \n \r \t"]]]) | |
65683353 EJ |
80 | JSON_CHECK_POSITIVE_C([surrogate pairs - C], |
81 | [[["\ud834\udd1e"]]], | |
82 | [[["𝄞"]]]) | |
f38b84ea BP |
83 | JSON_CHECK_NEGATIVE([a string by itself is not valid JSON], ["xxx"], |
84 | [error: syntax error at beginning of input]) | |
85 | JSON_CHECK_NEGATIVE([end of line in quoted string], | |
86 | [[["xxx | |
87 | "]]], | |
88 | [error: U+000A must be escaped in quoted string]) | |
89 | JSON_CHECK_NEGATIVE([formfeed in quoted string], | |
90 | [[["xxx\f"]]], | |
91 | [error: U+000C must be escaped in quoted string]) | |
92 | JSON_CHECK_NEGATIVE([bad escape in quoted string], | |
93 | [[["\x12"]]], | |
94 | [error: bad escape \x]) | |
7d23a63a | 95 | JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (1)], |
f38b84ea | 96 | [[["\u1x"]]], |
7d23a63a BP |
97 | [error: quoted string ends within \u escape]) |
98 | JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (2)], | |
99 | [[["\u1xyz"]]], | |
f38b84ea BP |
100 | [error: malformed \u escape]) |
101 | JSON_CHECK_NEGATIVE([isolated leading surrogate not allowed], | |
102 | [[["\ud834xxx"]]], | |
103 | [error: malformed escaped surrogate pair]) | |
104 | JSON_CHECK_NEGATIVE([surrogatess must paired properly], | |
105 | [[["\ud834\u1234"]]], | |
106 | [error: second half of escaped surrogate pair is not trailing surrogate]) | |
107 | JSON_CHECK_NEGATIVE([null bytes not allowed], | |
108 | [[["\u0000"]]], | |
109 | [error: null bytes not supported in quoted strings]) | |
7b7c2a46 BP |
110 | dnl Check for regression against a prior bug. |
111 | JSON_CHECK_POSITIVE([properly quoted backslash at end of string], | |
112 | [[["\\"]]], | |
113 | [[["\\"]]]) | |
114 | JSON_CHECK_NEGATIVE([stray backslash at end of string], | |
115 | [[["abcd\"]]], | |
116 | [error: unexpected end of input in quoted string]) | |
f38b84ea | 117 | |
99155935 | 118 | AT_SETUP([end of input in quoted string - C]) |
f38b84ea | 119 | AT_KEYWORDS([json negative]) |
eadd1644 | 120 | AT_CHECK([printf '"xxx' | ovstest test-json -], [1], |
0bdf342a | 121 | [error: line 0, column 4, byte 4: unexpected end of input in quoted string |
f38b84ea BP |
122 | ]) |
123 | AT_CLEANUP | |
124 | ||
125 | AT_BANNER([JSON -- objects]) | |
126 | ||
127 | JSON_CHECK_POSITIVE([empty object], [[{ }]], [[{}]]) | |
128 | JSON_CHECK_POSITIVE([simple object], | |
129 | [[{"b": 2, "a": 1, "c": 3}]], | |
130 | [[{"a":1,"b":2,"c":3}]]) | |
131 | JSON_CHECK_NEGATIVE([bad value], [[{"a": }, "b": 2]], | |
132 | [error: syntax error expecting value]) | |
133 | JSON_CHECK_NEGATIVE([missing colon], [[{"b": 2, "a" 1, "c": 3}]], | |
134 | [error: syntax error parsing object expecting ':']) | |
135 | JSON_CHECK_NEGATIVE([missing comma], [[{"b": 2 "a" 1, "c": 3}]], | |
136 | [error: syntax error expecting '}' or ',']) | |
137 | JSON_CHECK_NEGATIVE([trailing comma not allowed], | |
138 | [[{"b": 2, "a": 1, "c": 3, }]], | |
139 | [[error: syntax error parsing object expecting string]]) | |
140 | JSON_CHECK_NEGATIVE([doubled comma not allowed], | |
141 | [[{"b": 2, "a": 1,, "c": 3}]], | |
142 | [[error: syntax error parsing object expecting string]]) | |
143 | JSON_CHECK_NEGATIVE([names must be strings], | |
144 | [[{1: 2}]], | |
145 | [[error: syntax error parsing object expecting string]]) | |
146 | ||
147 | AT_BANNER([JSON -- literal names]) | |
148 | ||
149 | JSON_CHECK_POSITIVE([null], [[[ null ]]], [[[null]]]) | |
150 | JSON_CHECK_POSITIVE([false], [[[ false ]]], [[[false]]]) | |
151 | JSON_CHECK_POSITIVE([true], [[[ true ]]], [[[true]]]) | |
152 | JSON_CHECK_NEGATIVE([a literal by itself is not valid JSON], [null], | |
153 | [error: syntax error at beginning of input]) | |
154 | JSON_CHECK_NEGATIVE([nullify is invalid], [[[ nullify ]]], | |
155 | [error: invalid keyword 'nullify']) | |
156 | JSON_CHECK_NEGATIVE([nubs is invalid], [[[ nubs ]]], | |
157 | [error: invalid keyword 'nubs']) | |
158 | JSON_CHECK_NEGATIVE([xxx is invalid], [[[ xxx ]]], | |
159 | [error: invalid keyword 'xxx']) | |
160 | ||
161 | AT_BANNER([JSON -- numbers]) | |
162 | ||
163 | JSON_CHECK_POSITIVE( | |
164 | [integers expressed as reals], | |
165 | [[[1.0000000000, | |
166 | 2.00000000000000000000000000000000000, | |
167 | 2e5, | |
168 | 2.1234e4, | |
169 | 2.1230e3, | |
170 | 0e-10000, | |
171 | 0e10000]]], | |
172 | [[[1,2,200000,21234,2123,0,0]]]) | |
173 | JSON_CHECK_POSITIVE( | |
174 | [large integers], | |
175 | [[[9223372036854775807, -9223372036854775808]]], | |
176 | [[[9223372036854775807,-9223372036854775808]]]) | |
177 | JSON_CHECK_POSITIVE( | |
178 | [large integers expressed as reals], | |
179 | [[[9223372036854775807.0, -9223372036854775808.0, | |
180 | 92233720.36854775807e11, -9.223372036854775808e18]]], | |
181 | [[[9223372036854775807,-9223372036854775808,9223372036854775807,-9223372036854775808]]]) | |
182 | # It seems likely that the following test will fail on some system that | |
183 | # rounds slightly differently in arithmetic or in printf, but I'd like | |
184 | # to keep it this way until we run into such a system. | |
622749d8 TW |
185 | JSON_CHECK_POSITIVE_C( |
186 | [C - large integers that overflow to reals], | |
f38b84ea BP |
187 | [[[9223372036854775807000, -92233720368547758080000]]], |
188 | [[[9.22337203685478e+21,-9.22337203685478e+22]]]) | |
1ca0323e | 189 | JSON_CHECK_POSITIVE_PY( |
622749d8 TW |
190 | [large integers that overflow to reals], |
191 | [[[9223372036854775807000, -92233720368547758080000]]], | |
192 | [[[9.223372036854776e+21,-9.223372036854776e+22]]]) | |
f38b84ea BP |
193 | |
194 | JSON_CHECK_POSITIVE( | |
195 | [negative zero], | |
196 | [[[-0, -0.0, 1e-9999, -1e-9999]]], | |
197 | [[[0,0,0,0]]]) | |
198 | ||
199 | JSON_CHECK_POSITIVE( | |
200 | [reals], | |
201 | [[[0.0, 1.0, 2.0, 3.0, 3.5, 81.250]]], | |
202 | [[[0,1,2,3,3.5,81.25]]]) | |
203 | JSON_CHECK_POSITIVE( | |
204 | [scientific notation], | |
205 | [[[1e3, 1E3, 2.5E2, 1e+3, 125e-3, 3.125e-2, 3125e-05, 1.525878906e-5]]], | |
206 | [[[1000,1000,250,1000,0.125,0.03125,0.03125,1.525878906e-05]]]) | |
a105c27b BP |
207 | # It seems likely that the following test will fail on some system that |
208 | # rounds slightly differently in arithmetic or in printf, but I'd like | |
209 | # to keep it this way until we run into such a system. | |
622749d8 TW |
210 | JSON_CHECK_POSITIVE_C( |
211 | [C - +/- DBL_MAX], | |
a105c27b BP |
212 | [[[1.7976931348623157e+308, -1.7976931348623157e+308]]], |
213 | [[[1.79769313486232e+308,-1.79769313486232e+308]]]) | |
1ca0323e | 214 | JSON_CHECK_POSITIVE_PY( |
622749d8 TW |
215 | [+/- DBL_MAX], |
216 | [[[1.7976931348623157e+308, -1.7976931348623157e+308]]], | |
217 | [[[1.7976931348623157e+308,-1.7976931348623157e+308]]]) | |
a105c27b | 218 | |
f38b84ea BP |
219 | JSON_CHECK_POSITIVE( |
220 | [negative reals], | |
221 | [[[-0, -1.0, -2.0, -3.0, -3.5, -8.1250]]], | |
222 | [[[0,-1,-2,-3,-3.5,-8.125]]]) | |
223 | JSON_CHECK_POSITIVE( | |
224 | [negative scientific notation], | |
225 | [[[-1e3, -1E3, -2.5E2, -1e+3, -125e-3, -3.125e-2, -3125e-05, -1.525878906e-5]]], | |
226 | [[[-1000,-1000,-250,-1000,-0.125,-0.03125,-0.03125,-1.525878906e-05]]]) | |
227 | JSON_CHECK_POSITIVE( | |
228 | [1e-9999 underflows to 0], | |
229 | [[[1e-9999]]], | |
230 | [[[0]]]) | |
231 | JSON_CHECK_NEGATIVE([a number by itself is not valid JSON], [1], | |
232 | [error: syntax error at beginning of input]) | |
233 | JSON_CHECK_NEGATIVE( | |
234 | [leading zeros not allowed], | |
235 | [[[0123]]], | |
236 | [error: leading zeros not allowed]) | |
237 | JSON_CHECK_NEGATIVE( | |
238 | [1e9999 is too big], | |
239 | [[[1e9999]]], | |
240 | [error: number outside valid range]) | |
f1a57715 | 241 | JSON_CHECK_NEGATIVE_C( |
f38b84ea BP |
242 | [exponent bigger than INT_MAX], |
243 | [[[1e9999999999999999999]]], | |
244 | [error: exponent outside valid range]) | |
f1a57715 BP |
245 | JSON_CHECK_NEGATIVE_C( |
246 | [exponent smaller than INT_MIN], | |
247 | [[[1e-9999999999999999999]]], | |
248 | [error: exponent outside valid range]) | |
249 | JSON_CHECK_NEGATIVE_C( | |
250 | [accumulated exponent bigger than INT_MAX], | |
251 | [[[340282366920938463461761716499e2147483647]]], | |
252 | [error: exponent outside valid range]) | |
253 | JSON_CHECK_NEGATIVE_C( | |
254 | [accumulated exponent smaller than INT_MIN], | |
255 | [[[0.340282366920938463461761716499e-2147483648]]], | |
256 | [error: exponent outside valid range]) | |
f38b84ea BP |
257 | JSON_CHECK_NEGATIVE( |
258 | [decimal point must be followed by digit], | |
259 | [[[1.]]], | |
260 | [error: decimal point must be followed by digit]) | |
261 | JSON_CHECK_NEGATIVE( | |
262 | [exponent must contain at least one digit (1)], | |
263 | [[[1e]]], | |
264 | [error: exponent must contain at least one digit]) | |
265 | JSON_CHECK_NEGATIVE( | |
266 | [exponent must contain at least one digit (2)], | |
267 | [[[1e+]]], | |
268 | [error: exponent must contain at least one digit]) | |
269 | JSON_CHECK_NEGATIVE( | |
270 | [exponent must contain at least one digit (3)], | |
271 | [[[1e-]]], | |
272 | [error: exponent must contain at least one digit]) | |
273 | ||
274 | AT_BANNER([JSON -- RFC 4627 examples]) | |
275 | ||
276 | JSON_CHECK_POSITIVE([RFC 4267 object example], | |
277 | [[{ | |
278 | "Image": { | |
279 | "Width": 800, | |
280 | "Height": 600, | |
281 | "Title": "View from 15th Floor", | |
282 | "Thumbnail": { | |
283 | "Url": "http://www.example.com/image/481989943", | |
284 | "Height": 125, | |
285 | "Width": "100" | |
286 | }, | |
287 | "IDs": [116, 943, 234, 38793] | |
288 | } | |
289 | }]], | |
290 | [[{"Image":{"Height":600,"IDs":[116,943,234,38793],"Thumbnail":{"Height":125,"Url":"http://www.example.com/image/481989943","Width":"100"},"Title":"View from 15th Floor","Width":800}}]]) | |
291 | ||
292 | JSON_CHECK_POSITIVE([RFC 4267 array example], | |
293 | [[[ | |
294 | { | |
295 | "precision": "zip", | |
296 | "Latitude": 37.7668, | |
297 | "Longitude": -122.3959, | |
298 | "Address": "", | |
299 | "City": "SAN FRANCISCO", | |
300 | "State": "CA", | |
301 | "Zip": "94107", | |
302 | "Country": "US" | |
303 | }, | |
304 | { | |
305 | "precision": "zip", | |
306 | "Latitude": 37.371991, | |
307 | "Longitude": -122.026020, | |
308 | "Address": "", | |
309 | "City": "SUNNYVALE", | |
310 | "State": "CA", | |
311 | "Zip": "94085", | |
312 | "Country": "US" | |
313 | } | |
314 | ]]], | |
315 | [[[{"Address":"","City":"SAN FRANCISCO","Country":"US","Latitude":37.7668,"Longitude":-122.3959,"State":"CA","Zip":"94107","precision":"zip"},{"Address":"","City":"SUNNYVALE","Country":"US","Latitude":37.371991,"Longitude":-122.02602,"State":"CA","Zip":"94085","precision":"zip"}]]]) | |
316 | ||
317 | AT_BANNER([JSON -- pathological cases]) | |
318 | ||
319 | JSON_CHECK_NEGATIVE([trailing garbage], [[[1]null]], | |
320 | [error: trailing garbage at end of input]) | |
321 | JSON_CHECK_NEGATIVE([formfeeds are not valid white space], | |
322 | [[[\f]]], [error: invalid character U+000c]) | |
323 | JSON_CHECK_NEGATIVE([';' is not a valid token], | |
324 | [;], [error: invalid character ';']) | |
325 | JSON_CHECK_NEGATIVE([arrays nesting too deep], | |
326 | [m4_for([i], [0], [1002], [1], [@<:@])dnl | |
327 | m4_for([i], [0], [1002], [1], [@:>@])], | |
328 | [error: input exceeds maximum nesting depth 1000]) | |
329 | JSON_CHECK_NEGATIVE([objects nesting too deep], | |
330 | [m4_for([i], [0], [1002], [1], [{"x":])dnl | |
331 | m4_for([i], [0], [1002], [1], [}])], | |
332 | [error: input exceeds maximum nesting depth 1000]) | |
333 | ||
334 | AT_SETUP([input may not be empty]) | |
335 | AT_KEYWORDS([json negative]) | |
eadd1644 | 336 | AT_CHECK([ovstest test-json /dev/null], [1], [error: line 0, column 0, byte 0: empty input stream |
f38b84ea BP |
337 | ]) |
338 | AT_CLEANUP | |
339 | ||
340 | AT_BANNER([JSON -- multiple inputs]) | |
341 | ||
342 | JSON_CHECK_POSITIVE([multiple adjacent objects], [[{}{}{}]], [[{} | |
343 | {} | |
344 | {}]], | |
345 | [--multiple]) | |
346 | ||
347 | JSON_CHECK_POSITIVE([multiple space-separated objects], [[{} {} {}]], [[{} | |
348 | {} | |
349 | {}]], | |
350 | [--multiple]) | |
351 | ||
352 | JSON_CHECK_POSITIVE([multiple objects on separate lines], [[{} | |
353 | {} | |
354 | {}]], [[{} | |
355 | {} | |
356 | {}]], | |
357 | [--multiple]) | |
358 | ||
359 | JSON_CHECK_POSITIVE([multiple objects and arrays], [[{}[]{}[]]], [[{} | |
360 | [] | |
361 | {} | |
362 | []]], | |
363 | [--multiple]) | |
364 | ||
365 | JSON_CHECK_NEGATIVE([garbage between multiple objects], [[{}x{}]], [[{} | |
366 | error: invalid keyword 'x' | |
367 | {}]], [--multiple]) | |
368 | ||
369 | JSON_CHECK_NEGATIVE([garbage after multiple objects], [[{}{}x]], [[{} | |
370 | {} | |
371 | error: invalid keyword 'x']], [--multiple]) |