]> git.proxmox.com Git - mirror_ovs.git/blob - tests/json.at
tests: Update interface-reconfigure tests.
[mirror_ovs.git] / tests / json.at
1 m4_define([JSON_CHECK_POSITIVE_C],
2 [AT_SETUP([$1])
3 AT_KEYWORDS([json positive])
4 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
5 AT_CAPTURE_FILE([input])
6 AT_CHECK([test-json $4 input], [0], [stdout], [])
7 AT_CHECK([cat stdout], [0], [$3
8 ])
9 AT_CLEANUP])
10
11 m4_define([JSON_CHECK_POSITIVE_PY],
12 [AT_SETUP([$1])
13 AT_KEYWORDS([json positive Python])
14 AT_SKIP_IF([test $HAVE_PYTHON = no])
15 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
16 AT_CAPTURE_FILE([input])
17 AT_CHECK([$PYTHON $srcdir/test-json.py $4 input], [0], [stdout], [])
18 AT_CHECK([cat stdout], [0], [$3
19 ])
20 AT_CLEANUP])
21
22 m4_define([JSON_CHECK_POSITIVE],
23 [JSON_CHECK_POSITIVE_C([$1 - C], [$2], [$3], [$4])
24 JSON_CHECK_POSITIVE_PY([$1 - Python], [$2], [$3], [$4])])
25
26 m4_define([JSON_CHECK_NEGATIVE_C],
27 [AT_SETUP([$1])
28 AT_KEYWORDS([json negative])
29 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
30 AT_CAPTURE_FILE([input])
31 AT_CHECK([test-json $4 input], [1], [stdout], [])
32 AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3
33 ])
34 AT_CLEANUP])
35
36 m4_define([JSON_CHECK_NEGATIVE_PY],
37 [AT_SETUP([$1])
38 AT_KEYWORDS([json negative Python])
39 AT_SKIP_IF([test $HAVE_PYTHON = no])
40 AT_CHECK([printf %s "AS_ESCAPE([$2])" > input])
41 AT_CAPTURE_FILE([input])
42 AT_CHECK([$PYTHON $srcdir/test-json.py $4 input], [1], [stdout], [])
43 AT_CHECK([[sed 's/^error: [^:]*:/error:/' < stdout]], [0], [$3
44 ])
45 AT_CLEANUP])
46
47 m4_define([JSON_CHECK_NEGATIVE],
48 [JSON_CHECK_NEGATIVE_C([$1 - C], [$2], [$3], [$4])
49 JSON_CHECK_NEGATIVE_PY([$1 - Python], [$2], [$3], [$4])])
50
51 AT_BANNER([JSON -- arrays])
52
53 JSON_CHECK_POSITIVE([empty array], [[ [ ] ]], [[[]]])
54 JSON_CHECK_POSITIVE([single-element array], [[ [ 1 ] ]], [[[1]]])
55 JSON_CHECK_POSITIVE([2-element array], [[ [ 1, 2 ] ]], [[[1,2]]])
56 JSON_CHECK_POSITIVE([many-element array],
57 [[ [ 1, 2, 3, 4, 5 ] ]],
58 [[[1,2,3,4,5]]])
59 JSON_CHECK_NEGATIVE([missing comma], [[ [ 1, 2, 3 4, 5 ] ]],
60 [error: syntax error expecting '@:>@' or ','])
61 JSON_CHECK_NEGATIVE([trailing comma not allowed],
62 [[[1,2,]]], [error: syntax error expecting value])
63 JSON_CHECK_NEGATIVE([doubled comma not allowed],
64 [[[1,,2]]], [error: syntax error expecting value])
65
66 AT_BANNER([JSON -- strings])
67
68 JSON_CHECK_POSITIVE([empty string], [[[ "" ]]], [[[""]]])
69 JSON_CHECK_POSITIVE([1-character strings],
70 [[[ "a", "b", "c" ]]],
71 [[["a","b","c"]]])
72 JSON_CHECK_POSITIVE([escape sequences],
73 [[[ " \" \\ \/ \b \f \n \r \t" ]]],
74 [[[" \" \\ / \b \f \n \r \t"]]])
75 JSON_CHECK_POSITIVE([Unicode escape sequences],
76 [[[ " \u0022 \u005c \u002F \u0008 \u000c \u000A \u000d \u0009" ]]],
77 [[[" \" \\ / \b \f \n \r \t"]]])
78 JSON_CHECK_POSITIVE([surrogate pairs],
79 [[["\ud834\udd1e"]]],
80 [[["𝄞"]]])
81 JSON_CHECK_NEGATIVE([a string by itself is not valid JSON], ["xxx"],
82 [error: syntax error at beginning of input])
83 JSON_CHECK_NEGATIVE([end of line in quoted string],
84 [[["xxx
85 "]]],
86 [error: U+000A must be escaped in quoted string])
87 JSON_CHECK_NEGATIVE([formfeed in quoted string],
88 [[["xxx\f"]]],
89 [error: U+000C must be escaped in quoted string])
90 JSON_CHECK_NEGATIVE([bad escape in quoted string],
91 [[["\x12"]]],
92 [error: bad escape \x])
93 JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (1)],
94 [[["\u1x"]]],
95 [error: quoted string ends within \u escape])
96 JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (2)],
97 [[["\u1xyz"]]],
98 [error: malformed \u escape])
99 JSON_CHECK_NEGATIVE([isolated leading surrogate not allowed],
100 [[["\ud834xxx"]]],
101 [error: malformed escaped surrogate pair])
102 JSON_CHECK_NEGATIVE([surrogatess must paired properly],
103 [[["\ud834\u1234"]]],
104 [error: second half of escaped surrogate pair is not trailing surrogate])
105 JSON_CHECK_NEGATIVE([null bytes not allowed],
106 [[["\u0000"]]],
107 [error: null bytes not supported in quoted strings])
108
109 AT_SETUP([end of input in quoted string - C])
110 AT_KEYWORDS([json negative])
111 AT_CHECK([printf '"xxx' | test-json -], [1],
112 [error: line 0, column 4, byte 4: unexpected end of input in quoted string
113 ])
114 AT_CLEANUP
115
116 AT_SETUP([end of input in quoted string - Python])
117 AT_KEYWORDS([json negative Python])
118 AT_SKIP_IF([test $HAVE_PYTHON = no])
119 AT_CHECK([printf '"xxx' > input
120 $PYTHON $srcdir/test-json.py input], [1],
121 [error: line 0, column 4, byte 4: unexpected end of input in quoted string
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.
185 JSON_CHECK_POSITIVE(
186 [large integers that overflow to reals],
187 [[[9223372036854775807000, -92233720368547758080000]]],
188 [[[9.22337203685478e+21,-9.22337203685478e+22]]])
189
190 JSON_CHECK_POSITIVE(
191 [negative zero],
192 [[[-0, -0.0, 1e-9999, -1e-9999]]],
193 [[[0,0,0,0]]])
194
195 JSON_CHECK_POSITIVE(
196 [reals],
197 [[[0.0, 1.0, 2.0, 3.0, 3.5, 81.250]]],
198 [[[0,1,2,3,3.5,81.25]]])
199 JSON_CHECK_POSITIVE(
200 [scientific notation],
201 [[[1e3, 1E3, 2.5E2, 1e+3, 125e-3, 3.125e-2, 3125e-05, 1.525878906e-5]]],
202 [[[1000,1000,250,1000,0.125,0.03125,0.03125,1.525878906e-05]]])
203 # It seems likely that the following test will fail on some system that
204 # rounds slightly differently in arithmetic or in printf, but I'd like
205 # to keep it this way until we run into such a system.
206 JSON_CHECK_POSITIVE(
207 [+/- DBL_MAX],
208 [[[1.7976931348623157e+308, -1.7976931348623157e+308]]],
209 [[[1.79769313486232e+308,-1.79769313486232e+308]]])
210
211 JSON_CHECK_POSITIVE(
212 [negative reals],
213 [[[-0, -1.0, -2.0, -3.0, -3.5, -8.1250]]],
214 [[[0,-1,-2,-3,-3.5,-8.125]]])
215 JSON_CHECK_POSITIVE(
216 [negative scientific notation],
217 [[[-1e3, -1E3, -2.5E2, -1e+3, -125e-3, -3.125e-2, -3125e-05, -1.525878906e-5]]],
218 [[[-1000,-1000,-250,-1000,-0.125,-0.03125,-0.03125,-1.525878906e-05]]])
219 JSON_CHECK_POSITIVE(
220 [1e-9999 underflows to 0],
221 [[[1e-9999]]],
222 [[[0]]])
223 JSON_CHECK_NEGATIVE([a number by itself is not valid JSON], [1],
224 [error: syntax error at beginning of input])
225 JSON_CHECK_NEGATIVE(
226 [leading zeros not allowed],
227 [[[0123]]],
228 [error: leading zeros not allowed])
229 JSON_CHECK_NEGATIVE(
230 [1e9999 is too big],
231 [[[1e9999]]],
232 [error: number outside valid range])
233 JSON_CHECK_NEGATIVE(
234 [exponent bigger than INT_MAX],
235 [[[1e9999999999999999999]]],
236 [error: exponent outside valid range])
237 JSON_CHECK_NEGATIVE(
238 [decimal point must be followed by digit],
239 [[[1.]]],
240 [error: decimal point must be followed by digit])
241 JSON_CHECK_NEGATIVE(
242 [exponent must contain at least one digit (1)],
243 [[[1e]]],
244 [error: exponent must contain at least one digit])
245 JSON_CHECK_NEGATIVE(
246 [exponent must contain at least one digit (2)],
247 [[[1e+]]],
248 [error: exponent must contain at least one digit])
249 JSON_CHECK_NEGATIVE(
250 [exponent must contain at least one digit (3)],
251 [[[1e-]]],
252 [error: exponent must contain at least one digit])
253
254 AT_BANNER([JSON -- RFC 4627 examples])
255
256 JSON_CHECK_POSITIVE([RFC 4267 object example],
257 [[{
258 "Image": {
259 "Width": 800,
260 "Height": 600,
261 "Title": "View from 15th Floor",
262 "Thumbnail": {
263 "Url": "http://www.example.com/image/481989943",
264 "Height": 125,
265 "Width": "100"
266 },
267 "IDs": [116, 943, 234, 38793]
268 }
269 }]],
270 [[{"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}}]])
271
272 JSON_CHECK_POSITIVE([RFC 4267 array example],
273 [[[
274 {
275 "precision": "zip",
276 "Latitude": 37.7668,
277 "Longitude": -122.3959,
278 "Address": "",
279 "City": "SAN FRANCISCO",
280 "State": "CA",
281 "Zip": "94107",
282 "Country": "US"
283 },
284 {
285 "precision": "zip",
286 "Latitude": 37.371991,
287 "Longitude": -122.026020,
288 "Address": "",
289 "City": "SUNNYVALE",
290 "State": "CA",
291 "Zip": "94085",
292 "Country": "US"
293 }
294 ]]],
295 [[[{"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"}]]])
296
297 AT_BANNER([JSON -- pathological cases])
298
299 JSON_CHECK_NEGATIVE([trailing garbage], [[[1]null]],
300 [error: trailing garbage at end of input])
301 JSON_CHECK_NEGATIVE([formfeeds are not valid white space],
302 [[[\f]]], [error: invalid character U+000c])
303 JSON_CHECK_NEGATIVE([';' is not a valid token],
304 [;], [error: invalid character ';'])
305 JSON_CHECK_NEGATIVE([arrays nesting too deep],
306 [m4_for([i], [0], [1002], [1], [@<:@])dnl
307 m4_for([i], [0], [1002], [1], [@:>@])],
308 [error: input exceeds maximum nesting depth 1000])
309 JSON_CHECK_NEGATIVE([objects nesting too deep],
310 [m4_for([i], [0], [1002], [1], [{"x":])dnl
311 m4_for([i], [0], [1002], [1], [}])],
312 [error: input exceeds maximum nesting depth 1000])
313
314 AT_SETUP([input may not be empty])
315 AT_KEYWORDS([json negative])
316 AT_CHECK([test-json /dev/null], [1], [error: line 0, column 0, byte 0: empty input stream
317 ])
318 AT_CLEANUP
319
320 AT_BANNER([JSON -- multiple inputs])
321
322 JSON_CHECK_POSITIVE([multiple adjacent objects], [[{}{}{}]], [[{}
323 {}
324 {}]],
325 [--multiple])
326
327 JSON_CHECK_POSITIVE([multiple space-separated objects], [[{} {} {}]], [[{}
328 {}
329 {}]],
330 [--multiple])
331
332 JSON_CHECK_POSITIVE([multiple objects on separate lines], [[{}
333 {}
334 {}]], [[{}
335 {}
336 {}]],
337 [--multiple])
338
339 JSON_CHECK_POSITIVE([multiple objects and arrays], [[{}[]{}[]]], [[{}
340 []
341 {}
342 []]],
343 [--multiple])
344
345 JSON_CHECK_NEGATIVE([garbage between multiple objects], [[{}x{}]], [[{}
346 error: invalid keyword 'x'
347 {}]], [--multiple])
348
349 JSON_CHECK_NEGATIVE([garbage after multiple objects], [[{}{}x]], [[{}
350 {}
351 error: invalid keyword 'x']], [--multiple])