]> git.proxmox.com Git - ovs.git/blame - tests/json.at
Fix ovs-dpctl-top by removing 3 wrong hunks in py3-compat.patch.
[ovs.git] / tests / json.at
CommitLineData
622749d8 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])
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 13m4_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
23m4_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 27m4_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
39m4_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
49m4_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
53AT_BANNER([JSON -- arrays])
54
55JSON_CHECK_POSITIVE([empty array], [[ [ ] ]], [[[]]])
56JSON_CHECK_POSITIVE([single-element array], [[ [ 1 ] ]], [[[1]]])
57JSON_CHECK_POSITIVE([2-element array], [[ [ 1, 2 ] ]], [[[1,2]]])
58JSON_CHECK_POSITIVE([many-element array],
59 [[ [ 1, 2, 3, 4, 5 ] ]],
60 [[[1,2,3,4,5]]])
61JSON_CHECK_NEGATIVE([missing comma], [[ [ 1, 2, 3 4, 5 ] ]],
62 [error: syntax error expecting '@:>@' or ','])
63JSON_CHECK_NEGATIVE([trailing comma not allowed],
64 [[[1,2,]]], [error: syntax error expecting value])
65JSON_CHECK_NEGATIVE([doubled comma not allowed],
66 [[[1,,2]]], [error: syntax error expecting value])
67
68AT_BANNER([JSON -- strings])
69
70JSON_CHECK_POSITIVE([empty string], [[[ "" ]]], [[[""]]])
71JSON_CHECK_POSITIVE([1-character strings],
72 [[[ "a", "b", "c" ]]],
73 [[["a","b","c"]]])
74JSON_CHECK_POSITIVE([escape sequences],
75 [[[ " \" \\ \/ \b \f \n \r \t" ]]],
76 [[[" \" \\ / \b \f \n \r \t"]]])
77JSON_CHECK_POSITIVE([Unicode escape sequences],
78 [[[ " \u0022 \u005c \u002F \u0008 \u000c \u000A \u000d \u0009" ]]],
79 [[[" \" \\ / \b \f \n \r \t"]]])
65683353
EJ
80JSON_CHECK_POSITIVE_C([surrogate pairs - C],
81 [[["\ud834\udd1e"]]],
82 [[["𝄞"]]])
f38b84ea
BP
83JSON_CHECK_NEGATIVE([a string by itself is not valid JSON], ["xxx"],
84 [error: syntax error at beginning of input])
85JSON_CHECK_NEGATIVE([end of line in quoted string],
86 [[["xxx
87"]]],
88 [error: U+000A must be escaped in quoted string])
89JSON_CHECK_NEGATIVE([formfeed in quoted string],
90 [[["xxx\f"]]],
91 [error: U+000C must be escaped in quoted string])
92JSON_CHECK_NEGATIVE([bad escape in quoted string],
93 [[["\x12"]]],
94 [error: bad escape \x])
7d23a63a 95JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (1)],
f38b84ea 96 [[["\u1x"]]],
7d23a63a
BP
97 [error: quoted string ends within \u escape])
98JSON_CHECK_NEGATIVE([\u must be followed by 4 hex digits (2)],
99 [[["\u1xyz"]]],
f38b84ea
BP
100 [error: malformed \u escape])
101JSON_CHECK_NEGATIVE([isolated leading surrogate not allowed],
102 [[["\ud834xxx"]]],
103 [error: malformed escaped surrogate pair])
104JSON_CHECK_NEGATIVE([surrogatess must paired properly],
105 [[["\ud834\u1234"]]],
106 [error: second half of escaped surrogate pair is not trailing surrogate])
107JSON_CHECK_NEGATIVE([null bytes not allowed],
108 [[["\u0000"]]],
109 [error: null bytes not supported in quoted strings])
7b7c2a46
BP
110dnl Check for regression against a prior bug.
111JSON_CHECK_POSITIVE([properly quoted backslash at end of string],
112 [[["\\"]]],
113 [[["\\"]]])
114JSON_CHECK_NEGATIVE([stray backslash at end of string],
115 [[["abcd\"]]],
116 [error: unexpected end of input in quoted string])
f38b84ea 117
99155935 118AT_SETUP([end of input in quoted string - C])
f38b84ea 119AT_KEYWORDS([json negative])
eadd1644 120AT_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])
123AT_CLEANUP
124
125AT_BANNER([JSON -- objects])
126
127JSON_CHECK_POSITIVE([empty object], [[{ }]], [[{}]])
128JSON_CHECK_POSITIVE([simple object],
129 [[{"b": 2, "a": 1, "c": 3}]],
130 [[{"a":1,"b":2,"c":3}]])
131JSON_CHECK_NEGATIVE([bad value], [[{"a": }, "b": 2]],
132 [error: syntax error expecting value])
133JSON_CHECK_NEGATIVE([missing colon], [[{"b": 2, "a" 1, "c": 3}]],
134 [error: syntax error parsing object expecting ':'])
135JSON_CHECK_NEGATIVE([missing comma], [[{"b": 2 "a" 1, "c": 3}]],
136 [error: syntax error expecting '}' or ','])
137JSON_CHECK_NEGATIVE([trailing comma not allowed],
138 [[{"b": 2, "a": 1, "c": 3, }]],
139 [[error: syntax error parsing object expecting string]])
140JSON_CHECK_NEGATIVE([doubled comma not allowed],
141 [[{"b": 2, "a": 1,, "c": 3}]],
142 [[error: syntax error parsing object expecting string]])
143JSON_CHECK_NEGATIVE([names must be strings],
144 [[{1: 2}]],
145 [[error: syntax error parsing object expecting string]])
146
147AT_BANNER([JSON -- literal names])
148
149JSON_CHECK_POSITIVE([null], [[[ null ]]], [[[null]]])
150JSON_CHECK_POSITIVE([false], [[[ false ]]], [[[false]]])
151JSON_CHECK_POSITIVE([true], [[[ true ]]], [[[true]]])
152JSON_CHECK_NEGATIVE([a literal by itself is not valid JSON], [null],
153 [error: syntax error at beginning of input])
154JSON_CHECK_NEGATIVE([nullify is invalid], [[[ nullify ]]],
155 [error: invalid keyword 'nullify'])
156JSON_CHECK_NEGATIVE([nubs is invalid], [[[ nubs ]]],
157 [error: invalid keyword 'nubs'])
158JSON_CHECK_NEGATIVE([xxx is invalid], [[[ xxx ]]],
159 [error: invalid keyword 'xxx'])
160
161AT_BANNER([JSON -- numbers])
162
163JSON_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]]])
173JSON_CHECK_POSITIVE(
174 [large integers],
175 [[[9223372036854775807, -9223372036854775808]]],
176 [[[9223372036854775807,-9223372036854775808]]])
177JSON_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
185JSON_CHECK_POSITIVE_C(
186 [C - large integers that overflow to reals],
f38b84ea
BP
187 [[[9223372036854775807000, -92233720368547758080000]]],
188 [[[9.22337203685478e+21,-9.22337203685478e+22]]])
1ca0323e 189JSON_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
194JSON_CHECK_POSITIVE(
195 [negative zero],
196 [[[-0, -0.0, 1e-9999, -1e-9999]]],
197 [[[0,0,0,0]]])
198
199JSON_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]]])
203JSON_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
210JSON_CHECK_POSITIVE_C(
211 [C - +/- DBL_MAX],
a105c27b
BP
212 [[[1.7976931348623157e+308, -1.7976931348623157e+308]]],
213 [[[1.79769313486232e+308,-1.79769313486232e+308]]])
1ca0323e 214JSON_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
219JSON_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]]])
223JSON_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]]])
227JSON_CHECK_POSITIVE(
228 [1e-9999 underflows to 0],
229 [[[1e-9999]]],
230 [[[0]]])
231JSON_CHECK_NEGATIVE([a number by itself is not valid JSON], [1],
232 [error: syntax error at beginning of input])
233JSON_CHECK_NEGATIVE(
234 [leading zeros not allowed],
235 [[[0123]]],
236 [error: leading zeros not allowed])
237JSON_CHECK_NEGATIVE(
238 [1e9999 is too big],
239 [[[1e9999]]],
240 [error: number outside valid range])
f1a57715 241JSON_CHECK_NEGATIVE_C(
f38b84ea
BP
242 [exponent bigger than INT_MAX],
243 [[[1e9999999999999999999]]],
244 [error: exponent outside valid range])
f1a57715
BP
245JSON_CHECK_NEGATIVE_C(
246 [exponent smaller than INT_MIN],
247 [[[1e-9999999999999999999]]],
248 [error: exponent outside valid range])
249JSON_CHECK_NEGATIVE_C(
250 [accumulated exponent bigger than INT_MAX],
251 [[[340282366920938463461761716499e2147483647]]],
252 [error: exponent outside valid range])
253JSON_CHECK_NEGATIVE_C(
254 [accumulated exponent smaller than INT_MIN],
255 [[[0.340282366920938463461761716499e-2147483648]]],
256 [error: exponent outside valid range])
f38b84ea
BP
257JSON_CHECK_NEGATIVE(
258 [decimal point must be followed by digit],
259 [[[1.]]],
260 [error: decimal point must be followed by digit])
261JSON_CHECK_NEGATIVE(
262 [exponent must contain at least one digit (1)],
263 [[[1e]]],
264 [error: exponent must contain at least one digit])
265JSON_CHECK_NEGATIVE(
266 [exponent must contain at least one digit (2)],
267 [[[1e+]]],
268 [error: exponent must contain at least one digit])
269JSON_CHECK_NEGATIVE(
270 [exponent must contain at least one digit (3)],
271 [[[1e-]]],
272 [error: exponent must contain at least one digit])
273
274AT_BANNER([JSON -- RFC 4627 examples])
275
276JSON_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
292JSON_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
317AT_BANNER([JSON -- pathological cases])
318
319JSON_CHECK_NEGATIVE([trailing garbage], [[[1]null]],
320 [error: trailing garbage at end of input])
321JSON_CHECK_NEGATIVE([formfeeds are not valid white space],
322 [[[\f]]], [error: invalid character U+000c])
323JSON_CHECK_NEGATIVE([';' is not a valid token],
324 [;], [error: invalid character ';'])
325JSON_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])
329JSON_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
334AT_SETUP([input may not be empty])
335AT_KEYWORDS([json negative])
eadd1644 336AT_CHECK([ovstest test-json /dev/null], [1], [error: line 0, column 0, byte 0: empty input stream
f38b84ea
BP
337])
338AT_CLEANUP
339
340AT_BANNER([JSON -- multiple inputs])
341
342JSON_CHECK_POSITIVE([multiple adjacent objects], [[{}{}{}]], [[{}
343{}
344{}]],
345 [--multiple])
346
347JSON_CHECK_POSITIVE([multiple space-separated objects], [[{} {} {}]], [[{}
348{}
349{}]],
350 [--multiple])
351
352JSON_CHECK_POSITIVE([multiple objects on separate lines], [[{}
353{}
354{}]], [[{}
355{}
356{}]],
357 [--multiple])
358
359JSON_CHECK_POSITIVE([multiple objects and arrays], [[{}[]{}[]]], [[{}
360[]
361{}
362[]]],
363 [--multiple])
364
365JSON_CHECK_NEGATIVE([garbage between multiple objects], [[{}x{}]], [[{}
366error: invalid keyword 'x'
367{}]], [--multiple])
368
369JSON_CHECK_NEGATIVE([garbage after multiple objects], [[{}{}x]], [[{}
370{}
371error: invalid keyword 'x']], [--multiple])