1 m4_define([JSON_CHECK_POSITIVE_C],
3 AT_KEYWORDS([json positive])
4 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
5 AT_CAPTURE_FILE([input])
6 AT_CHECK([ovstest test-json $4 input], [0], [stdout], [])
7 AT_CHECK([cat stdout], [0], [$3
11 # JSON_CHECK_POSITIVE_PY(TITLE, INPUT, OUTPUT, TEST-JSON-ARGS)
13 m4_define([JSON_CHECK_POSITIVE_PY],
15 AT_KEYWORDS([json positive Python])
16 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
17 AT_CAPTURE_FILE([input])
18 AT_CHECK([$PYTHON3 $srcdir/test-json.py $4 input], [0], [stdout], [])
19 AT_CHECK([cat stdout], [0], [$3
23 m4_define([JSON_CHECK_POSITIVE],
24 [JSON_CHECK_POSITIVE_C([$1 - C], [$2], [$3], [$4])
25 JSON_CHECK_POSITIVE_PY([$1 - Python3], [$2], [$3], [$4])])
27 m4_define([JSON_CHECK_NEGATIVE_C],
29 AT_KEYWORDS([json negative])
30 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
31 AT_CAPTURE_FILE([input])
32 AT_CHECK([ovstest test-json $4 input], [1], [stdout], [])
33 AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3
37 # JSON_CHECK_NEGATIVE_PY(TITLE, INPUT, OUTPUT, TEST-JSON-ARGS)
39 m4_define([JSON_CHECK_NEGATIVE_PY],
41 AT_KEYWORDS([json negative Python])
42 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
43 AT_CAPTURE_FILE([input])
44 AT_CHECK([$PYTHON3 $srcdir/test-json.py $4 input], [1], [stdout], [])
45 AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3
49 m4_define([JSON_CHECK_NEGATIVE],
50 [JSON_CHECK_NEGATIVE_C([$1 - C], [$2], [$3], [$4])
51 JSON_CHECK_NEGATIVE_PY([$1 - Python3], [$2], [$3], [$4])])
53 AT_BANNER([JSON -- arrays])
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 ] ]],
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])
68 AT_BANNER([JSON -- strings])
70 JSON_CHECK_POSITIVE([empty string], [[[ "" ]]], [[[""]]])
71 JSON_CHECK_POSITIVE([1-character strings],
72 [[[ "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"]]])
80 JSON_CHECK_POSITIVE_C([surrogate pairs - C],
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],
88 [error: U+000A must be escaped in quoted string])
89 JSON_CHECK_NEGATIVE([formfeed in quoted string],
91 [error: U+000C must be escaped in quoted string])
92 JSON_CHECK_NEGATIVE([bad escape in quoted string],
94 [error: bad escape \x])
95 JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (1)],
97 [error: quoted string ends within \u escape])
98 JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (2)],
100 [error: malformed \u escape])
101 JSON_CHECK_NEGATIVE([isolated leading surrogate not allowed],
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],
109 [error: null bytes not supported in quoted strings])
110 dnl Check for regression against a prior bug.
111 JSON_CHECK_POSITIVE([properly quoted backslash at end of string],
114 JSON_CHECK_NEGATIVE([stray backslash at end of string],
116 [error: unexpected end of input in quoted string])
118 AT_SETUP([end of input in quoted string - C])
119 AT_KEYWORDS([json negative])
120 AT_CHECK([printf '"xxx' | ovstest test-json -], [1],
121 [error: line 0, column 4, byte 4: unexpected end of input in quoted string
125 AT_BANNER([JSON -- objects])
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],
145 [[error: syntax error parsing object expecting string]])
147 AT_BANNER([JSON -- literal names])
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'])
161 AT_BANNER([JSON -- numbers])
164 [integers expressed as reals],
166 2.00000000000000000000000000000000000,
172 [[[1,2,200000,21234,2123,0,0]]])
175 [[[9223372036854775807, -9223372036854775808]]],
176 [[[9223372036854775807,-9223372036854775808]]])
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.
185 JSON_CHECK_POSITIVE_C(
186 [C - large integers that overflow to reals],
187 [[[9223372036854775807000, -92233720368547758080000]]],
188 [[[9.22337203685478e+21,-9.22337203685478e+22]]])
189 JSON_CHECK_POSITIVE_PY(
190 [large integers that overflow to reals],
191 [[[9223372036854775807000, -92233720368547758080000]]],
192 [[[9.223372036854776e+21,-9.223372036854776e+22]]])
196 [[[-0, -0.0, 1e-9999, -1e-9999]]],
201 [[[0.0, 1.0, 2.0, 3.0, 3.5, 81.250]]],
202 [[[0,1,2,3,3.5,81.25]]])
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]]])
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.
210 JSON_CHECK_POSITIVE_C(
212 [[[1.7976931348623157e+308, -1.7976931348623157e+308]]],
213 [[[1.79769313486232e+308,-1.79769313486232e+308]]])
214 JSON_CHECK_POSITIVE_PY(
216 [[[1.7976931348623157e+308, -1.7976931348623157e+308]]],
217 [[[1.7976931348623157e+308,-1.7976931348623157e+308]]])
221 [[[-0, -1.0, -2.0, -3.0, -3.5, -8.1250]]],
222 [[[0,-1,-2,-3,-3.5,-8.125]]])
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]]])
228 [1e-9999 underflows to 0],
231 JSON_CHECK_NEGATIVE([a number by itself is not valid JSON], [1],
232 [error: syntax error at beginning of input])
234 [leading zeros not allowed],
236 [error: leading zeros not allowed])
240 [error: number outside valid range])
241 JSON_CHECK_NEGATIVE_C(
242 [exponent bigger than INT_MAX],
243 [[[1e9999999999999999999]]],
244 [error: exponent outside valid range])
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])
258 [decimal point must be followed by digit],
260 [error: decimal point must be followed by digit])
262 [exponent must contain at least one digit (1)],
264 [error: exponent must contain at least one digit])
266 [exponent must contain at least one digit (2)],
268 [error: exponent must contain at least one digit])
270 [exponent must contain at least one digit (3)],
272 [error: exponent must contain at least one digit])
274 AT_BANNER([JSON -- RFC 4627 examples])
276 JSON_CHECK_POSITIVE([RFC 4267 object example],
281 "Title": "View from 15th Floor",
283 "Url": "http://www.example.com/image/481989943",
287 "IDs": [116, 943, 234, 38793]
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}}]])
292 JSON_CHECK_POSITIVE([RFC 4267 array example],
297 "Longitude": -122.3959,
299 "City": "SAN FRANCISCO",
306 "Latitude": 37.371991,
307 "Longitude": -122.026020,
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"}]]])
317 AT_BANNER([JSON -- pathological cases])
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])
334 AT_SETUP([input may not be empty])
335 AT_KEYWORDS([json negative])
336 AT_CHECK([ovstest test-json /dev/null], [1], [error: line 0, column 0, byte 0: empty input stream
340 AT_BANNER([JSON -- multiple inputs])
342 JSON_CHECK_POSITIVE([multiple adjacent objects], [[{}{}{}]], [[{}
347 JSON_CHECK_POSITIVE([multiple space-separated objects], [[{} {} {}]], [[{}
352 JSON_CHECK_POSITIVE([multiple objects on separate lines], [[{}
359 JSON_CHECK_POSITIVE([multiple objects and arrays], [[{}[]{}[]]], [[{}
365 JSON_CHECK_NEGATIVE([garbage between multiple objects], [[{}x{}]], [[{}
366 error: invalid keyword 'x'
369 JSON_CHECK_NEGATIVE([garbage after multiple objects], [[{}{}x]], [[{}
371 error: invalid keyword 'x']], [--multiple])