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