ac0f0b7be0b6fa2651d337263d601313f6d89a80
[sliver-openvswitch.git] / tests / ovsdb-data.at
1 AT_BANNER([OVSDB -- default values])
2
3 OVSDB_CHECK_POSITIVE([default atoms],
4   [default-atoms],
5   [[integer: OK
6 real: OK
7 boolean: OK
8 string: OK
9 uuid: OK]])
10
11 OVSDB_CHECK_POSITIVE([default data],
12   [default-data],
13   [[key integer, value void, n_min 0: OK
14 key integer, value integer, n_min 0: OK
15 key integer, value real, n_min 0: OK
16 key integer, value boolean, n_min 0: OK
17 key integer, value string, n_min 0: OK
18 key integer, value uuid, n_min 0: OK
19 key real, value void, n_min 0: OK
20 key real, value integer, n_min 0: OK
21 key real, value real, n_min 0: OK
22 key real, value boolean, n_min 0: OK
23 key real, value string, n_min 0: OK
24 key real, value uuid, n_min 0: OK
25 key boolean, value void, n_min 0: OK
26 key boolean, value integer, n_min 0: OK
27 key boolean, value real, n_min 0: OK
28 key boolean, value boolean, n_min 0: OK
29 key boolean, value string, n_min 0: OK
30 key boolean, value uuid, n_min 0: OK
31 key string, value void, n_min 0: OK
32 key string, value integer, n_min 0: OK
33 key string, value real, n_min 0: OK
34 key string, value boolean, n_min 0: OK
35 key string, value string, n_min 0: OK
36 key string, value uuid, n_min 0: OK
37 key uuid, value void, n_min 0: OK
38 key uuid, value integer, n_min 0: OK
39 key uuid, value real, n_min 0: OK
40 key uuid, value boolean, n_min 0: OK
41 key uuid, value string, n_min 0: OK
42 key uuid, value uuid, n_min 0: OK
43 key integer, value void, n_min 1: OK
44 key integer, value integer, n_min 1: OK
45 key integer, value real, n_min 1: OK
46 key integer, value boolean, n_min 1: OK
47 key integer, value string, n_min 1: OK
48 key integer, value uuid, n_min 1: OK
49 key real, value void, n_min 1: OK
50 key real, value integer, n_min 1: OK
51 key real, value real, n_min 1: OK
52 key real, value boolean, n_min 1: OK
53 key real, value string, n_min 1: OK
54 key real, value uuid, n_min 1: OK
55 key boolean, value void, n_min 1: OK
56 key boolean, value integer, n_min 1: OK
57 key boolean, value real, n_min 1: OK
58 key boolean, value boolean, n_min 1: OK
59 key boolean, value string, n_min 1: OK
60 key boolean, value uuid, n_min 1: OK
61 key string, value void, n_min 1: OK
62 key string, value integer, n_min 1: OK
63 key string, value real, n_min 1: OK
64 key string, value boolean, n_min 1: OK
65 key string, value string, n_min 1: OK
66 key string, value uuid, n_min 1: OK
67 key uuid, value void, n_min 1: OK
68 key uuid, value integer, n_min 1: OK
69 key uuid, value real, n_min 1: OK
70 key uuid, value boolean, n_min 1: OK
71 key uuid, value string, n_min 1: OK
72 key uuid, value uuid, n_min 1: OK]])
73
74 AT_BANNER([OVSDB -- atoms without constraints])
75
76 OVSDB_CHECK_POSITIVE([integer atom from JSON], 
77   [[parse-atoms '["integer"]' \
78     '[0]' \
79     '[-1]' \
80     '[1e3]' \
81     '[9223372036854775807]' \
82     '[-9223372036854775808]' ]], 
83   [0
84 -1
85 1000
86 9223372036854775807
87 -9223372036854775808])
88
89 OVSDB_CHECK_POSITIVE([integer atom from string], 
90   [[parse-atom-strings -- '["integer"]' \
91     '0' \
92     '-1' \
93     '+1000' \
94     '9223372036854775807' \
95     '-9223372036854775808' ]], 
96   [0
97 -1
98 1000
99 9223372036854775807
100 -9223372036854775808])
101
102 OVSDB_CHECK_POSITIVE([real atom from JSON], 
103   [[parse-atoms '["real"]' \
104     '[0]' \
105     '[0.0]' \
106     '[-0.0]' \
107     '[-1.25]' \
108     '[1e3]' \
109     '[1e37]' \
110     '[0.00390625]' ]], 
111   [0
112 0
113 0
114 -1.25
115 1000
116 1e+37
117 0.00390625])
118
119 OVSDB_CHECK_POSITIVE([real atom from string], 
120   [[parse-atom-strings -- '["real"]' \
121     '0' \
122     '0.0' \
123     '-0.0' \
124     '-1.25' \
125     '1e3' \
126     '1e37' \
127     '0.00390625' ]], 
128   [0
129 0
130 0
131 -1.25
132 1000
133 1e+37
134 0.00390625])
135
136 OVSDB_CHECK_POSITIVE([boolean atom from JSON],
137   [[parse-atoms '["boolean"]' '[true]' '[false]' ]],
138   [true
139 false])
140
141 OVSDB_CHECK_POSITIVE([boolean atom from string],
142   [[parse-atom-strings '["boolean"]' 'true' 'false' ]],
143   [true
144 false])
145
146 OVSDB_CHECK_POSITIVE([string atom from JSON],
147   [[parse-atoms '["string"]' '[""]' '["true"]' '["\"\\\/\b\f\n\r\t"]']],
148   [""
149 "true"
150 "\"\\/\b\f\n\r\t"])
151
152 OVSDB_CHECK_POSITIVE([string atom from string],
153   [[parse-atom-strings '["string"]' \
154     'unquoted' \
155     '"quoted-string"' \
156     '"needs quotes"' \
157     '""' \
158     '"true"' \
159     '"\"\\\/\b\f\n\r\t"']],
160   [unquoted
161 quoted-string
162 "needs quotes"
163 ""
164 "true"
165 "\"\\/\b\f\n\r\t"])
166
167 OVSDB_CHECK_POSITIVE([uuid atom from JSON],
168   [[parse-atoms '["uuid"]' '["uuid", "550e8400-e29b-41d4-a716-446655440000"]']],
169   [[["uuid","550e8400-e29b-41d4-a716-446655440000"]]])
170
171 OVSDB_CHECK_POSITIVE([uuid atom from string],
172   [[parse-atom-strings '["uuid"]' '550e8400-e29b-41d4-a716-446655440000']],
173   [550e8400-e29b-41d4-a716-446655440000])
174
175 OVSDB_CHECK_POSITIVE([integer atom sorting],
176   [[sort-atoms '["integer"]' '[55,0,-1,2,1]']],
177   [[[-1,0,1,2,55]]])
178
179 OVSDB_CHECK_POSITIVE([real atom sorting],
180   [[sort-atoms '["real"]' '[1.25,1.23,0.0,-0.0,-1e99]']],
181   [[[-1e+99,0,0,1.23,1.25]]])
182
183 OVSDB_CHECK_POSITIVE([boolean atom sorting],
184   [[sort-atoms '["boolean"]' '[true,false,true,false,false]']],
185   [[[false,false,false,true,true]]])
186
187 OVSDB_CHECK_POSITIVE([string atom sorting],
188   [[sort-atoms '["string"]' '["abd","abc","\b","xxx"]']],
189   [[["\b","abc","abd","xxx"]]])
190
191 OVSDB_CHECK_POSITIVE([uuid atom sorting],
192   [[sort-atoms '["uuid"]' '[
193     ["uuid", "00000000-0000-0000-0000-000000000001"],
194     ["uuid", "00000000-1000-0000-0000-000000000000"],
195     ["uuid", "00000000-0000-1000-0000-000000000000"],
196     ["uuid", "00010000-0000-0000-0000-000000000000"],
197     ["uuid", "00000000-0000-0000-0000-000000000100"],
198     ["uuid", "00000000-0000-0000-0000-000100000000"],
199     ["uuid", "00000000-0000-0010-0000-000000000000"],
200     ["uuid", "00000100-0000-0000-0000-000000000000"],
201     ["uuid", "00000000-0000-0001-0000-000000000000"],
202     ["uuid", "00000000-0000-0000-0000-000001000000"],
203     ["uuid", "01000000-0000-0000-0000-000000000000"],
204     ["uuid", "00000000-0000-0000-0000-000000001000"],
205     ["uuid", "00000000-0000-0000-0000-000010000000"],
206     ["uuid", "00000000-0000-0000-0000-010000000000"],
207     ["uuid", "00000000-0000-0100-0000-000000000000"],
208     ["uuid", "10000000-0000-0000-0000-000000000000"],
209     ["uuid", "00000000-0000-0000-0000-000000000010"],
210     ["uuid", "00000000-0100-0000-0000-000000000000"],
211     ["uuid", "00000000-0000-0000-0100-000000000000"],
212     ["uuid", "00000000-0000-0000-0001-000000000000"],
213     ["uuid", "00000010-0000-0000-0000-000000000000"],
214     ["uuid", "00000000-0000-0000-0010-000000000000"],
215     ["uuid", "00000000-0000-0000-0000-000000010000"],
216     ["uuid", "00000000-0000-0000-1000-000000000000"],
217     ["uuid", "00000000-0000-0000-0000-100000000000"],
218     ["uuid", "00000000-0000-0000-0000-001000000000"],
219     ["uuid", "00000000-0000-0000-0000-000000100000"],
220     ["uuid", "00000000-0000-0000-0000-000000000000"],
221     ["uuid", "00000000-0010-0000-0000-000000000000"],
222     ["uuid", "00100000-0000-0000-0000-000000000000"],
223     ["uuid", "00000000-0001-0000-0000-000000000000"],
224     ["uuid", "00000001-0000-0000-0000-000000000000"],
225     ["uuid", "00001000-0000-0000-0000-000000000000"]]']],
226   [[[["uuid","00000000-0000-0000-0000-000000000000"],["uuid","00000000-0000-0000-0000-000000000001"],["uuid","00000000-0000-0000-0000-000000000010"],["uuid","00000000-0000-0000-0000-000000000100"],["uuid","00000000-0000-0000-0000-000000001000"],["uuid","00000000-0000-0000-0000-000000010000"],["uuid","00000000-0000-0000-0000-000000100000"],["uuid","00000000-0000-0000-0000-000001000000"],["uuid","00000000-0000-0000-0000-000010000000"],["uuid","00000000-0000-0000-0000-000100000000"],["uuid","00000000-0000-0000-0000-001000000000"],["uuid","00000000-0000-0000-0000-010000000000"],["uuid","00000000-0000-0000-0000-100000000000"],["uuid","00000000-0000-0000-0001-000000000000"],["uuid","00000000-0000-0000-0010-000000000000"],["uuid","00000000-0000-0000-0100-000000000000"],["uuid","00000000-0000-0000-1000-000000000000"],["uuid","00000000-0000-0001-0000-000000000000"],["uuid","00000000-0000-0010-0000-000000000000"],["uuid","00000000-0000-0100-0000-000000000000"],["uuid","00000000-0000-1000-0000-000000000000"],["uuid","00000000-0001-0000-0000-000000000000"],["uuid","00000000-0010-0000-0000-000000000000"],["uuid","00000000-0100-0000-0000-000000000000"],["uuid","00000000-1000-0000-0000-000000000000"],["uuid","00000001-0000-0000-0000-000000000000"],["uuid","00000010-0000-0000-0000-000000000000"],["uuid","00000100-0000-0000-0000-000000000000"],["uuid","00001000-0000-0000-0000-000000000000"],["uuid","00010000-0000-0000-0000-000000000000"],["uuid","00100000-0000-0000-0000-000000000000"],["uuid","01000000-0000-0000-0000-000000000000"],["uuid","10000000-0000-0000-0000-000000000000"]]]])
227
228 OVSDB_CHECK_POSITIVE([real not acceptable integer JSON atom],
229   [[parse-atoms '["integer"]' '[0.5]' ]],
230   [syntax "0.5": syntax error: expected integer])
231
232 dnl <C0> is not allowed anywhere in a UTF-8 string.
233 dnl <ED A0 80> is a surrogate and not allowed in UTF-8.
234 OVSDB_CHECK_POSITIVE([no invalid UTF-8 sequences in strings],
235   [parse-atoms '[["string"]]' \
236      '@<:@"m4_esyscmd([printf "\300"])"@:>@' \
237      '@<:@"m4_esyscmd([printf "\355\240\200"])"@:>@' \
238 ],
239   [constraint violation: "m4_esyscmd([printf "\300"])" is not a valid UTF-8 string: invalid UTF-8 sequence 0xc0
240 constraint violation: "m4_esyscmd([printf "\355\240\200"])" is not a valid UTF-8 string: invalid UTF-8 sequence 0xed 0xa0])
241
242 OVSDB_CHECK_NEGATIVE([real not acceptable integer string atom],
243   [[parse-atom-strings '["integer"]' '0.5' ]],
244   ["0.5" is not a valid integer])
245
246 OVSDB_CHECK_POSITIVE([string "true" not acceptable boolean JSON atom],
247   [[parse-atoms '["boolean"]' '["true"]' ]],
248   [syntax ""true"": syntax error: expected boolean])
249
250 OVSDB_CHECK_NEGATIVE([string "true" not acceptable boolean string atom],
251   [[parse-atom-strings '["boolean"]' '"true"' ]],
252   [""true"" is not a valid boolean (use "true" or "false")])
253
254 OVSDB_CHECK_POSITIVE([integer not acceptable string JSON atom],
255   [[parse-atoms '["string"]' '[1]']],
256   [syntax "1": syntax error: expected string])
257
258 OVSDB_CHECK_POSITIVE([uuid atom must be expressed as JSON array],
259   [[parse-atoms '["uuid"]' '["550e8400-e29b-41d4-a716-446655440000"]']],
260   [[syntax ""550e8400-e29b-41d4-a716-446655440000"": syntax error: expected ["uuid", <string>]]])
261
262 OVSDB_CHECK_NEGATIVE([empty string atom must be quoted],
263   [[parse-atom-strings '["string"]' '']],
264   [An empty string is not valid as input; use "" to represent the empty string])
265
266 OVSDB_CHECK_NEGATIVE([quotes must be balanced],
267   [parse-atom-strings '[["string"]]' '"asdf'],
268   ["asdf: missing quote at end of quoted string])
269
270 OVSDB_CHECK_NEGATIVE([uuids must be valid],
271   [parse-atom-strings '[["uuid"]]' '1234-5678'],
272   ["1234-5678" is not a valid UUID])
273 \f
274 AT_BANNER([OVSDB -- atoms with enum constraints])
275
276 OVSDB_CHECK_POSITIVE([integer atom enum], 
277   [[parse-atoms '[{"type": "integer", "enum": ["set", [1, 6, 8, 10]]}]' \
278     '[0]' \
279     '[1]' \
280     '[2]' \
281     '[3]' \
282     '[6]' \
283     '[7]' \
284     '[8]' \
285     '[9]' \
286     '[10]' \
287     '[11]']], 
288   [[constraint violation: 0 is not one of the allowed values ([1, 6, 8, 10])
289 1
290 constraint violation: 2 is not one of the allowed values ([1, 6, 8, 10])
291 constraint violation: 3 is not one of the allowed values ([1, 6, 8, 10])
292 6
293 constraint violation: 7 is not one of the allowed values ([1, 6, 8, 10])
294 8
295 constraint violation: 9 is not one of the allowed values ([1, 6, 8, 10])
296 10
297 constraint violation: 11 is not one of the allowed values ([1, 6, 8, 10])]])
298
299 OVSDB_CHECK_POSITIVE([real atom enum], 
300   [[parse-atoms '[{"type": "real", "enum": ["set", [-1.5, 1.5]]}]' \
301     '[-2]' \
302     '[-1]' \
303     '[-1.5]' \
304     '[0]' \
305     '[1]' \
306     '[1.5]' \
307     '[2]']], 
308   [[constraint violation: -2 is not one of the allowed values ([-1.5, 1.5])
309 constraint violation: -1 is not one of the allowed values ([-1.5, 1.5])
310 -1.5
311 constraint violation: 0 is not one of the allowed values ([-1.5, 1.5])
312 constraint violation: 1 is not one of the allowed values ([-1.5, 1.5])
313 1.5
314 constraint violation: 2 is not one of the allowed values ([-1.5, 1.5])]])
315
316 OVSDB_CHECK_POSITIVE([boolean atom enum], 
317   [[parse-atoms '[{"type": "boolean", "enum": false}]' \
318     '[false]' \
319     '[true]']], 
320   [[false
321 constraint violation: true is not one of the allowed values ([false])]])
322
323 OVSDB_CHECK_POSITIVE([string atom enum], 
324   [[parse-atoms '[{"type": "string", "enum": ["set", ["abc", "def"]]}]' \
325     '[""]' \
326     '["ab"]' \
327     '["abc"]' \
328     '["def"]' \
329     '["defg"]' \
330     '["DEF"]']], 
331   [[constraint violation: "" is not one of the allowed values ([abc, def])
332 constraint violation: ab is not one of the allowed values ([abc, def])
333 "abc"
334 "def"
335 constraint violation: defg is not one of the allowed values ([abc, def])
336 constraint violation: DEF is not one of the allowed values ([abc, def])]])
337
338 OVSDB_CHECK_POSITIVE([uuid atom enum], 
339   [[parse-atoms '[{"type": "uuid", "enum": ["set", [["uuid", "6d53a6dd-2da7-4924-9927-97f613812382"], ["uuid", "52cbc842-137a-4db5-804f-9f34106a0ba3"]]]}]' \
340     '["uuid", "6d53a6dd-2da7-4924-9927-97f613812382"]' \
341     '["uuid", "52cbc842-137a-4db5-804f-9f34106a0ba3"]' \
342     '["uuid", "dab2a6b2-6094-4f43-a7ef-4c0f0608f176"]']], 
343   [[["uuid","6d53a6dd-2da7-4924-9927-97f613812382"]
344 ["uuid","52cbc842-137a-4db5-804f-9f34106a0ba3"]
345 constraint violation: dab2a6b2-6094-4f43-a7ef-4c0f0608f176 is not one of the allowed values ([52cbc842-137a-4db5-804f-9f34106a0ba3, 6d53a6dd-2da7-4924-9927-97f613812382])]])
346 \f
347 AT_BANNER([OVSDB -- atoms with other constraints])
348
349 OVSDB_CHECK_POSITIVE([integers >= 5], 
350   [[parse-atoms '[{"type": "integer", "minInteger": 5}]' \
351     '[0]' \
352     '[4]' \
353     '[5]' \
354     '[6]' \
355     '[12345]']], 
356   [constraint violation: 0 is less than minimum allowed value 5
357 constraint violation: 4 is less than minimum allowed value 5
358 5
359 6
360 12345])
361
362 OVSDB_CHECK_POSITIVE([integers <= -1], 
363   [[parse-atoms '[{"type": "integer", "maxInteger": -1}]' \
364     '[0]' \
365     '[-1]' \
366     '[-2]' \
367     '[-123]']], 
368   [constraint violation: 0 is greater than maximum allowed value -1
369 -1
370 -2
371 -123])
372
373 OVSDB_CHECK_POSITIVE([integers in range -10 to 10], 
374   [[parse-atoms '[{"type": "integer", "minInteger": -10, "maxInteger": 10}]' \
375     '[-20]' \
376     '[-11]' \
377     '[-10]' \
378     '[-9]' \
379     '[1]' \
380     '[9]' \
381     '[10]' \
382     '[11]' \
383     '[123576]']], 
384   [constraint violation: -20 is not in the valid range -10 to 10 (inclusive)
385 constraint violation: -11 is not in the valid range -10 to 10 (inclusive)
386 -10
387 -9
388 1
389 9
390 10
391 constraint violation: 11 is not in the valid range -10 to 10 (inclusive)
392 constraint violation: 123576 is not in the valid range -10 to 10 (inclusive)])
393
394 OVSDB_CHECK_POSITIVE([reals >= 5], 
395   [[parse-atoms '[{"type": "real", "minReal": 5}]' \
396     '[0]' \
397     '[4]' \
398     '[5]' \
399     '[6]' \
400     '[12345]']], 
401   [constraint violation: 0 is less than minimum allowed value 5
402 constraint violation: 4 is less than minimum allowed value 5
403 5
404 6
405 12345])
406
407 OVSDB_CHECK_POSITIVE([reals <= -1], 
408   [[parse-atoms '[{"type": "real", "maxReal": -1}]' \
409     '[0]' \
410     '[-1]' \
411     '[-2]' \
412     '[-123]']], 
413   [constraint violation: 0 is greater than maximum allowed value -1
414 -1
415 -2
416 -123])
417
418 OVSDB_CHECK_POSITIVE([reals in range -10 to 10], 
419   [[parse-atoms '[{"type": "real", "minReal": -10, "maxReal": 10}]' \
420     '[-20]' \
421     '[-11]' \
422     '[-10]' \
423     '[-9]' \
424     '[1]' \
425     '[9]' \
426     '[10]' \
427     '[11]' \
428     '[123576]']], 
429   [constraint violation: -20 is not in the valid range -10 to 10 (inclusive)
430 constraint violation: -11 is not in the valid range -10 to 10 (inclusive)
431 -10
432 -9
433 1
434 9
435 10
436 constraint violation: 11 is not in the valid range -10 to 10 (inclusive)
437 constraint violation: 123576 is not in the valid range -10 to 10 (inclusive)])
438
439 OVSDB_CHECK_POSITIVE([strings at least 2 characters long],
440   [[parse-atoms '{"type": "string", "minLength": 2}' \
441     '[""]' \
442     '["a"]' \
443     '["ab"]' \
444     '["abc"]' \
445     '["\ud834\udd1e"]']],
446   [[constraint violation: "" length 0 is less than minimum allowed length 2
447 constraint violation: "a" length 1 is less than minimum allowed length 2
448 "ab"
449 "abc"
450 constraint violation: "𝄞" length 1 is less than minimum allowed length 2]])
451
452 OVSDB_CHECK_POSITIVE([strings no more than 2 characters long],
453   [[parse-atoms '{"type": "string", "maxLength": 2}' \
454     '[""]' \
455     '["a"]' \
456     '["ab"]' \
457     '["abc"]' \
458     '["\ud834\udd1e"]']],
459   [[""
460 "a"
461 "ab"
462 constraint violation: "abc" length 3 is greater than maximum allowed length 2
463 "𝄞"]])
464
465 AT_BANNER([OSVDB -- simple data])
466
467 OVSDB_CHECK_POSITIVE([integer JSON datum],
468   [[parse-data '["integer"]' '[0]' '["set",[1]]' '[-1]']],
469   [0
470 1
471 -1])
472
473 OVSDB_CHECK_POSITIVE([integer string datum],
474   [[parse-data-strings -- '["integer"]' '0' '1' '-1' '+1']],
475   [0
476 1
477 -1
478 1])
479
480 OVSDB_CHECK_POSITIVE([real JSON datum], 
481   [[parse-data '["real"]' '[0]' '["set",[1.0]]' '[-1.25]']],
482   [0
483 1
484 -1.25])
485
486 OVSDB_CHECK_POSITIVE([real string datum], 
487   [[parse-data-strings -- '["real"]' '0' '1.0' '-1.25']],
488   [0
489 1
490 -1.25])
491
492 OVSDB_CHECK_POSITIVE([boolean JSON datum],
493   [[parse-data '["boolean"]' '["set", [true]]' '[false]' ]],
494   [true
495 false])
496
497 OVSDB_CHECK_POSITIVE([boolean string datum],
498   [[parse-data-strings '["boolean"]' 'true' 'false' ]],
499   [true
500 false])
501
502 OVSDB_CHECK_POSITIVE([string JSON datum],
503   [[parse-data '["string"]' '["set",[""]]' '["true"]' '["\"\\\/\b\f\n\r\t"]']],
504   [""
505 "true"
506 "\"\\/\b\f\n\r\t"])
507
508 OVSDB_CHECK_POSITIVE([string string datum],
509   [[parse-data-strings '["string"]' '"x"' '""' '"true"' '"\"\\\/\b\f\n\r\t"']],
510   [x
511 ""
512 "true"
513 "\"\\/\b\f\n\r\t"])
514 \f
515 AT_BANNER([OVSDB -- set data])
516
517 OVSDB_CHECK_POSITIVE([JSON optional boolean],
518   [[parse-data '{"key": "boolean", "min": 0}' \
519     '[true]' \
520     '["set", [false]]' \
521     '["set", []]']], 
522   [[true
523 false
524 ["set",[]]]],
525   [set])
526
527 OVSDB_CHECK_POSITIVE([string optional boolean],
528   [[parse-data-strings '{"key": "boolean", "min": 0}' \
529     'true' \
530     'false' \
531     '[]']], 
532   [[true
533 false
534 []]],
535   [set])
536
537 OVSDB_CHECK_POSITIVE([JSON set of 0 or more integers],
538   [[parse-data '{"key": "integer", "min": 0, "max": "unlimited"}' \
539     '["set", [0]]' \
540     '[1]' \
541     '["set", [0, 1]]' \
542     '["set", [0, 1, 2]]' \
543     '["set", [0, 1, 2, 3, 4, 5]]' \
544     '["set", [0, 1, 2, 3, 4, 5, 6, 7, 8]]' \
545     '["set", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]']],
546   [[0
547 1
548 ["set",[0,1]]
549 ["set",[0,1,2]]
550 ["set",[0,1,2,3,4,5]]
551 ["set",[0,1,2,3,4,5,6,7,8]]
552 ["set",[0,1,2,3,4,5,6,7,8,9,10]]]])
553
554 OVSDB_CHECK_POSITIVE([string set of 0 or more integers],
555   [[parse-data-strings '{"key": "integer", "min": 0, "max": "unlimited"}' \
556     '0' \
557     '0,1' \
558     '0, 1, 2' \
559     '[0, 1,2, 3, 4, 5]' \
560     '0, 1,2, 3,4, 5, 6, 7, 8' \
561     '[0, 1, 2, 3, 4,5, 6,7, 8, 9, 10]']],
562   [[[0]
563 [0, 1]
564 [0, 1, 2]
565 [0, 1, 2, 3, 4, 5]
566 [0, 1, 2, 3, 4, 5, 6, 7, 8]
567 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]])
568
569 OVSDB_CHECK_POSITIVE([JSON set of 1 to 3 uuids],
570   [[parse-data '{"key": "uuid", "min": 1, "max": 3}' \
571     '["set", [["uuid", "550e8400-e29b-41d4-a716-446655440000"]]]' \
572     '["uuid", "b5078be0-7664-4299-b836-8bcc03ef941f"]' \
573     '["set", [["uuid", "c5051240-30ff-43ed-b4b9-93cf3f050813"],
574               ["uuid", "90558331-09af-4d2f-a572-509cad2e9088"],
575               ["uuid", "550e8400-e29b-41d4-a716-446655440000"]]]']],
576   [[["uuid","550e8400-e29b-41d4-a716-446655440000"]
577 ["uuid","b5078be0-7664-4299-b836-8bcc03ef941f"]
578 ["set",[["uuid","550e8400-e29b-41d4-a716-446655440000"],["uuid","90558331-09af-4d2f-a572-509cad2e9088"],["uuid","c5051240-30ff-43ed-b4b9-93cf3f050813"]]]]])
579
580 OVSDB_CHECK_POSITIVE([string set of 1 to 3 uuids],
581   [[parse-data-strings '{"key": "uuid", "min": 1, "max": 3}' \
582     '[550e8400-e29b-41d4-a716-446655440000]' \
583     '[c5051240-30ff-43ed-b4b9-93cf3f050813,
584       90558331-09af-4d2f-a572-509cad2e9088,
585       550e8400-e29b-41d4-a716-446655440000]']],
586   [[[550e8400-e29b-41d4-a716-446655440000]
587 [550e8400-e29b-41d4-a716-446655440000, 90558331-09af-4d2f-a572-509cad2e9088, c5051240-30ff-43ed-b4b9-93cf3f050813]]])
588
589 OVSDB_CHECK_POSITIVE([JSON set of 0 to 3 strings],
590   [[parse-data '{"key": "string", "min": 0, "max": 3}' \
591     '["set", []]' \
592     '["a longer string"]' \
593     '["set", ["a relatively long string"]]' \
594     '["set", ["short string", "a relatively long string"]]' \
595     '["set", ["zzz", "short string", "a relatively long string"]]']],
596   [[["set",[]]
597 "a longer string"
598 "a relatively long string"
599 ["set",["a relatively long string","short string"]]
600 ["set",["a relatively long string","short string","zzz"]]]])
601
602 OVSDB_CHECK_POSITIVE([string set of 0 to 3 strings],
603   [[parse-data-strings '{"key": "string", "min": 0, "max": 3}' \
604     '[]' \
605     '"a relatively long string"' \
606     '["short string", "a relatively long string"]' \
607     '"zzz","short string","a relatively long string"']],
608   [[[]
609 ["a relatively long string"]
610 ["a relatively long string", "short string"]
611 ["a relatively long string", "short string", zzz]]])
612
613 OVSDB_CHECK_NEGATIVE([duplicate boolean not allowed in JSON set],
614   [[parse-data '{"key": "boolean", "max": 5}' '["set", [true, true]]']],
615   [ovsdb error: set contains duplicate])
616
617 OVSDB_CHECK_NEGATIVE([duplicate boolean not allowed in string set],
618   [[parse-data-strings '{"key": "boolean", "max": 5}' 'true, true']],
619   [set contains duplicate value])
620
621 OVSDB_CHECK_NEGATIVE([duplicate integer not allowed in JSON set],
622   [[parse-data '{"key": "integer", "max": 5}' '["set", [1, 2, 3, 1]]']],
623   [ovsdb error: set contains duplicate])
624
625 OVSDB_CHECK_NEGATIVE([duplicate integer not allowed in string set],
626   [[parse-data-strings '{"key": "integer", "max": 5}' '[1, 2, 3, 1]']],
627   [set contains duplicate value])
628
629 OVSDB_CHECK_NEGATIVE([duplicate real not allowed in JSON set],
630   [[parse-data '{"key": "real", "max": 5}' '["set", [0.0, -0.0]]']],
631   [ovsdb error: set contains duplicate])
632
633 OVSDB_CHECK_NEGATIVE([duplicate real not allowed in string set],
634   [[parse-data-strings '{"key": "real", "max": 5}' '0.0, -0.0']],
635   [set contains duplicate value])
636
637 OVSDB_CHECK_NEGATIVE([duplicate string not allowed in JSON set],
638   [[parse-data '{"key": "string", "max": 5}' '["set", ["asdf", "ASDF", "asdf"]]']],
639   [ovsdb error: set contains duplicate])
640
641 OVSDB_CHECK_NEGATIVE([duplicate string not allowed in string set],
642   [[parse-data-strings '{"key": "string", "max": 5}' 'asdf, ASDF, "asdf"']],
643   [set contains duplicate value])
644
645 OVSDB_CHECK_NEGATIVE([duplicate uuid not allowed in JSON set],
646   [[parse-data '{"key": "uuid", "max": 5}' \
647     '["set", [["uuid", "7ef21525-0088-4a28-a418-5518413e43ea"],
648               ["uuid", "355ad037-f1da-40aa-b47c-ff9c7e8c6a38"],
649               ["uuid", "7ef21525-0088-4a28-a418-5518413e43ea"]]]']],
650   [ovsdb error: set contains duplicate])
651
652 OVSDB_CHECK_NEGATIVE([duplicate uuid not allowed in string set],
653   [[parse-data-strings '{"key": "uuid", "max": 5}' \
654     '7ef21525-0088-4a28-a418-5518413e43ea,
655      355ad037-f1da-40aa-b47c-ff9c7e8c6a38,
656      7ef21525-0088-4a28-a418-5518413e43ea']],
657   [set contains duplicate value])
658 \f
659 AT_BANNER([OVSDB -- map data])
660
661 OVSDB_CHECK_POSITIVE([JSON map of 1 integer to boolean],
662   [[parse-data '{"key": "integer", "value": "boolean"}' \
663     '["map", [[1, true]]]']],
664   [[["map",[[1,true]]]]])
665
666 OVSDB_CHECK_POSITIVE([string map of 1 integer to boolean],
667   [[parse-data-strings '{"key": "integer", "value": "boolean"}' \
668     '1=true']],
669   [[1=true]])
670
671 OVSDB_CHECK_POSITIVE([JSON map of at least 1 integer to boolean],
672   [[parse-data '{"key": "integer", "value": "boolean", "max": "unlimited"}' \
673     '["map", [[1, true]]]' \
674     '["map", [[0, true], [1, false], [2, true], [3, true], [4, true]]]' \
675     '["map", [[3, false], [0, true], [4, false]]]']],
676   [[["map",[[1,true]]]
677 ["map",[[0,true],[1,false],[2,true],[3,true],[4,true]]]
678 ["map",[[0,true],[3,false],[4,false]]]]])
679
680 OVSDB_CHECK_POSITIVE([string map of at least 1 integer to boolean],
681   [[parse-data-strings '{"key": "integer", "value": "boolean", "max": "unlimited"}' \
682     '1=true' \
683     '0=true 1=false 2=true, 3=true 4=true,' \
684     '3=false,0=true ,4=false']],
685   [[{1=true}
686 {0=true, 1=false, 2=true, 3=true, 4=true}
687 {0=true, 3=false, 4=false}]])
688
689 OVSDB_CHECK_POSITIVE([JSON map of 1 boolean to integer],
690  [[parse-data '{"key": "boolean", "value": "integer"}' \
691    '["map", [[true, 1]]]']],
692  [[["map",[[true,1]]]]])
693
694 OVSDB_CHECK_POSITIVE([string map of 1 boolean to integer],
695  [[parse-data-strings '{"key": "boolean", "value": "integer"}' \
696    'true=1']],
697  [[true=1]])
698
699 OVSDB_CHECK_POSITIVE([JSON map of 1 uuid to real],
700   [[parse-data '{"key": "uuid", "value": "real", "min": 1, "max": 5}' \
701     '["map", [[["uuid", "cad8542b-6ee1-486b-971b-7dcbf6e14979"], 1.0],
702               [["uuid", "6b94b968-2702-4f64-9457-314a34d69b8c"], 2.0],
703               [["uuid", "d2c4a168-24de-47eb-a8a3-c1abfc814979"], 3.0],
704               [["uuid", "25bfa475-d072-4f60-8be1-00f48643e9cb"], 4.0],
705               [["uuid", "1c92b8ca-d5e4-4628-a85d-1dc2d099a99a"], 5.0]]]']],
706   [[["map",[[["uuid","1c92b8ca-d5e4-4628-a85d-1dc2d099a99a"],5],[["uuid","25bfa475-d072-4f60-8be1-00f48643e9cb"],4],[["uuid","6b94b968-2702-4f64-9457-314a34d69b8c"],2],[["uuid","cad8542b-6ee1-486b-971b-7dcbf6e14979"],1],[["uuid","d2c4a168-24de-47eb-a8a3-c1abfc814979"],3]]]]])
707
708 OVSDB_CHECK_POSITIVE([string map of 1 uuid to real],
709   [[parse-data-strings '{"key": "uuid", "value": "real", "min": 1, "max": 5}' \
710     'cad8542b-6ee1-486b-971b-7dcbf6e14979=1.0,
711      6b94b968-2702-4f64-9457-314a34d69b8c=2.0,
712      d2c4a168-24de-47eb-a8a3-c1abfc814979=3.0,
713      25bfa475-d072-4f60-8be1-00f48643e9cb=4.0,
714      1c92b8ca-d5e4-4628-a85d-1dc2d099a99a=5.0']],
715   [[{1c92b8ca-d5e4-4628-a85d-1dc2d099a99a=5, 25bfa475-d072-4f60-8be1-00f48643e9cb=4, 6b94b968-2702-4f64-9457-314a34d69b8c=2, cad8542b-6ee1-486b-971b-7dcbf6e14979=1, d2c4a168-24de-47eb-a8a3-c1abfc814979=3}]])
716
717 OVSDB_CHECK_POSITIVE([JSON map of 10 string to string],
718   [[parse-data '{"key": "string", "value": "string", "min": 1, "max": 10}' \
719     '["map", [["2 gills", "1 chopin"],
720               ["2 chopins", "1 pint"],
721               ["2 pints", "1 quart"],
722               ["2 quarts", "1 pottle"],
723               ["2 pottles", "1 gallon"],
724               ["2 gallons", "1 peck"],
725               ["2 pecks", "1 demibushel"],
726               ["2 demibushel", "1 firkin"],
727               ["2 firkins", "1 kilderkin"],
728               ["2 kilderkins", "1 barrel"]]]']],
729    [[["map",[["2 chopins","1 pint"],["2 demibushel","1 firkin"],["2 firkins","1 kilderkin"],["2 gallons","1 peck"],["2 gills","1 chopin"],["2 kilderkins","1 barrel"],["2 pecks","1 demibushel"],["2 pints","1 quart"],["2 pottles","1 gallon"],["2 quarts","1 pottle"]]]]])
730
731 OVSDB_CHECK_POSITIVE([string map of 10 string to string],
732   [[parse-data-strings '{"key": "string", "value": "string", "min": 1, "max": 10}' \
733     '{"2 gills"="1 chopin",
734       "2 chopins"= "1 pint",
735       "2 pints"= "1 quart",
736       "2 quarts"= "1 pottle",
737       "2 pottles"= "1 gallon",
738       "2 gallons"= "1 peck",
739       "2 pecks"= "1 demibushel",
740       "2 demibushel"= "1 firkin",
741       "2 firkins"= "1 kilderkin",
742       "2 kilderkins"= "1 barrel"}']],
743    [[{"2 chopins"="1 pint", "2 demibushel"="1 firkin", "2 firkins"="1 kilderkin", "2 gallons"="1 peck", "2 gills"="1 chopin", "2 kilderkins"="1 barrel", "2 pecks"="1 demibushel", "2 pints"="1 quart", "2 pottles"="1 gallon", "2 quarts"="1 pottle"}]])
744
745 OVSDB_CHECK_NEGATIVE([duplicate integer key not allowed in JSON map],
746   [[parse-data '{"key": "integer", "value": "boolean", "max": 5}' \
747     '["map", [[1, true], [2, false], [1, false]]]']],
748   [ovsdb error: map contains duplicate key])
749
750 OVSDB_CHECK_NEGATIVE([duplicate integer key not allowed in string map],
751   [[parse-data-strings '{"key": "integer", "value": "boolean", "max": 5}' \
752     '1=true 2=false 1=false']],
753   [map contains duplicate key])