datapath: Catch missed formatting changes.
[sliver-openvswitch.git] / tests / ovsdb-data.at
index e868477..ac0f0b7 100644 (file)
@@ -1,4 +1,77 @@
-AT_BANNER([OVSDB -- atoms])
+AT_BANNER([OVSDB -- default values])
+
+OVSDB_CHECK_POSITIVE([default atoms],
+  [default-atoms],
+  [[integer: OK
+real: OK
+boolean: OK
+string: OK
+uuid: OK]])
+
+OVSDB_CHECK_POSITIVE([default data],
+  [default-data],
+  [[key integer, value void, n_min 0: OK
+key integer, value integer, n_min 0: OK
+key integer, value real, n_min 0: OK
+key integer, value boolean, n_min 0: OK
+key integer, value string, n_min 0: OK
+key integer, value uuid, n_min 0: OK
+key real, value void, n_min 0: OK
+key real, value integer, n_min 0: OK
+key real, value real, n_min 0: OK
+key real, value boolean, n_min 0: OK
+key real, value string, n_min 0: OK
+key real, value uuid, n_min 0: OK
+key boolean, value void, n_min 0: OK
+key boolean, value integer, n_min 0: OK
+key boolean, value real, n_min 0: OK
+key boolean, value boolean, n_min 0: OK
+key boolean, value string, n_min 0: OK
+key boolean, value uuid, n_min 0: OK
+key string, value void, n_min 0: OK
+key string, value integer, n_min 0: OK
+key string, value real, n_min 0: OK
+key string, value boolean, n_min 0: OK
+key string, value string, n_min 0: OK
+key string, value uuid, n_min 0: OK
+key uuid, value void, n_min 0: OK
+key uuid, value integer, n_min 0: OK
+key uuid, value real, n_min 0: OK
+key uuid, value boolean, n_min 0: OK
+key uuid, value string, n_min 0: OK
+key uuid, value uuid, n_min 0: OK
+key integer, value void, n_min 1: OK
+key integer, value integer, n_min 1: OK
+key integer, value real, n_min 1: OK
+key integer, value boolean, n_min 1: OK
+key integer, value string, n_min 1: OK
+key integer, value uuid, n_min 1: OK
+key real, value void, n_min 1: OK
+key real, value integer, n_min 1: OK
+key real, value real, n_min 1: OK
+key real, value boolean, n_min 1: OK
+key real, value string, n_min 1: OK
+key real, value uuid, n_min 1: OK
+key boolean, value void, n_min 1: OK
+key boolean, value integer, n_min 1: OK
+key boolean, value real, n_min 1: OK
+key boolean, value boolean, n_min 1: OK
+key boolean, value string, n_min 1: OK
+key boolean, value uuid, n_min 1: OK
+key string, value void, n_min 1: OK
+key string, value integer, n_min 1: OK
+key string, value real, n_min 1: OK
+key string, value boolean, n_min 1: OK
+key string, value string, n_min 1: OK
+key string, value uuid, n_min 1: OK
+key uuid, value void, n_min 1: OK
+key uuid, value integer, n_min 1: OK
+key uuid, value real, n_min 1: OK
+key uuid, value boolean, n_min 1: OK
+key uuid, value string, n_min 1: OK
+key uuid, value uuid, n_min 1: OK]])
+
+AT_BANNER([OVSDB -- atoms without constraints])
 
 OVSDB_CHECK_POSITIVE([integer atom from JSON], 
   [[parse-atoms '["integer"]' \
@@ -152,29 +225,39 @@ OVSDB_CHECK_POSITIVE([uuid atom sorting],
     ["uuid", "00001000-0000-0000-0000-000000000000"]]']],
   [[[["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"]]]])
 
-OVSDB_CHECK_NEGATIVE([real not acceptable integer JSON atom],
+OVSDB_CHECK_POSITIVE([real not acceptable integer JSON atom],
   [[parse-atoms '["integer"]' '[0.5]' ]],
-  [expected integer])
+  [syntax "0.5": syntax error: expected integer])
+
+dnl <C0> is not allowed anywhere in a UTF-8 string.
+dnl <ED A0 80> is a surrogate and not allowed in UTF-8.
+OVSDB_CHECK_POSITIVE([no invalid UTF-8 sequences in strings],
+  [parse-atoms '[["string"]]' \
+     '@<:@"m4_esyscmd([printf "\300"])"@:>@' \
+     '@<:@"m4_esyscmd([printf "\355\240\200"])"@:>@' \
+],
+  [constraint violation: "m4_esyscmd([printf "\300"])" is not a valid UTF-8 string: invalid UTF-8 sequence 0xc0
+constraint violation: "m4_esyscmd([printf "\355\240\200"])" is not a valid UTF-8 string: invalid UTF-8 sequence 0xed 0xa0])
 
 OVSDB_CHECK_NEGATIVE([real not acceptable integer string atom],
   [[parse-atom-strings '["integer"]' '0.5' ]],
   ["0.5" is not a valid integer])
 
-OVSDB_CHECK_NEGATIVE([string "true" not acceptable boolean JSON atom],
+OVSDB_CHECK_POSITIVE([string "true" not acceptable boolean JSON atom],
   [[parse-atoms '["boolean"]' '["true"]' ]],
-  [expected boolean])
+  [syntax ""true"": syntax error: expected boolean])
 
 OVSDB_CHECK_NEGATIVE([string "true" not acceptable boolean string atom],
   [[parse-atom-strings '["boolean"]' '"true"' ]],
   [""true"" is not a valid boolean (use "true" or "false")])
 
-OVSDB_CHECK_NEGATIVE([integer not acceptable string JSON atom],
+OVSDB_CHECK_POSITIVE([integer not acceptable string JSON atom],
   [[parse-atoms '["string"]' '[1]']],
-  [expected string])
+  [syntax "1": syntax error: expected string])
 
-OVSDB_CHECK_NEGATIVE([uuid atom must be expressed as JSON array],
+OVSDB_CHECK_POSITIVE([uuid atom must be expressed as JSON array],
   [[parse-atoms '["uuid"]' '["550e8400-e29b-41d4-a716-446655440000"]']],
-  [[expected ["uuid", <string>]]])
+  [[syntax ""550e8400-e29b-41d4-a716-446655440000"": syntax error: expected ["uuid", <string>]]])
 
 OVSDB_CHECK_NEGATIVE([empty string atom must be quoted],
   [[parse-atom-strings '["string"]' '']],
@@ -187,11 +270,202 @@ OVSDB_CHECK_NEGATIVE([quotes must be balanced],
 OVSDB_CHECK_NEGATIVE([uuids must be valid],
   [parse-atom-strings '[["uuid"]]' '1234-5678'],
   ["1234-5678" is not a valid UUID])
+\f
+AT_BANNER([OVSDB -- atoms with enum constraints])
+
+OVSDB_CHECK_POSITIVE([integer atom enum], 
+  [[parse-atoms '[{"type": "integer", "enum": ["set", [1, 6, 8, 10]]}]' \
+    '[0]' \
+    '[1]' \
+    '[2]' \
+    '[3]' \
+    '[6]' \
+    '[7]' \
+    '[8]' \
+    '[9]' \
+    '[10]' \
+    '[11]']], 
+  [[constraint violation: 0 is not one of the allowed values ([1, 6, 8, 10])
+1
+constraint violation: 2 is not one of the allowed values ([1, 6, 8, 10])
+constraint violation: 3 is not one of the allowed values ([1, 6, 8, 10])
+6
+constraint violation: 7 is not one of the allowed values ([1, 6, 8, 10])
+8
+constraint violation: 9 is not one of the allowed values ([1, 6, 8, 10])
+10
+constraint violation: 11 is not one of the allowed values ([1, 6, 8, 10])]])
+
+OVSDB_CHECK_POSITIVE([real atom enum], 
+  [[parse-atoms '[{"type": "real", "enum": ["set", [-1.5, 1.5]]}]' \
+    '[-2]' \
+    '[-1]' \
+    '[-1.5]' \
+    '[0]' \
+    '[1]' \
+    '[1.5]' \
+    '[2]']], 
+  [[constraint violation: -2 is not one of the allowed values ([-1.5, 1.5])
+constraint violation: -1 is not one of the allowed values ([-1.5, 1.5])
+-1.5
+constraint violation: 0 is not one of the allowed values ([-1.5, 1.5])
+constraint violation: 1 is not one of the allowed values ([-1.5, 1.5])
+1.5
+constraint violation: 2 is not one of the allowed values ([-1.5, 1.5])]])
+
+OVSDB_CHECK_POSITIVE([boolean atom enum], 
+  [[parse-atoms '[{"type": "boolean", "enum": false}]' \
+    '[false]' \
+    '[true]']], 
+  [[false
+constraint violation: true is not one of the allowed values ([false])]])
+
+OVSDB_CHECK_POSITIVE([string atom enum], 
+  [[parse-atoms '[{"type": "string", "enum": ["set", ["abc", "def"]]}]' \
+    '[""]' \
+    '["ab"]' \
+    '["abc"]' \
+    '["def"]' \
+    '["defg"]' \
+    '["DEF"]']], 
+  [[constraint violation: "" is not one of the allowed values ([abc, def])
+constraint violation: ab is not one of the allowed values ([abc, def])
+"abc"
+"def"
+constraint violation: defg is not one of the allowed values ([abc, def])
+constraint violation: DEF is not one of the allowed values ([abc, def])]])
+
+OVSDB_CHECK_POSITIVE([uuid atom enum], 
+  [[parse-atoms '[{"type": "uuid", "enum": ["set", [["uuid", "6d53a6dd-2da7-4924-9927-97f613812382"], ["uuid", "52cbc842-137a-4db5-804f-9f34106a0ba3"]]]}]' \
+    '["uuid", "6d53a6dd-2da7-4924-9927-97f613812382"]' \
+    '["uuid", "52cbc842-137a-4db5-804f-9f34106a0ba3"]' \
+    '["uuid", "dab2a6b2-6094-4f43-a7ef-4c0f0608f176"]']], 
+  [[["uuid","6d53a6dd-2da7-4924-9927-97f613812382"]
+["uuid","52cbc842-137a-4db5-804f-9f34106a0ba3"]
+constraint violation: dab2a6b2-6094-4f43-a7ef-4c0f0608f176 is not one of the allowed values ([52cbc842-137a-4db5-804f-9f34106a0ba3, 6d53a6dd-2da7-4924-9927-97f613812382])]])
+\f
+AT_BANNER([OVSDB -- atoms with other constraints])
+
+OVSDB_CHECK_POSITIVE([integers >= 5], 
+  [[parse-atoms '[{"type": "integer", "minInteger": 5}]' \
+    '[0]' \
+    '[4]' \
+    '[5]' \
+    '[6]' \
+    '[12345]']], 
+  [constraint violation: 0 is less than minimum allowed value 5
+constraint violation: 4 is less than minimum allowed value 5
+5
+6
+12345])
+
+OVSDB_CHECK_POSITIVE([integers <= -1], 
+  [[parse-atoms '[{"type": "integer", "maxInteger": -1}]' \
+    '[0]' \
+    '[-1]' \
+    '[-2]' \
+    '[-123]']], 
+  [constraint violation: 0 is greater than maximum allowed value -1
+-1
+-2
+-123])
+
+OVSDB_CHECK_POSITIVE([integers in range -10 to 10], 
+  [[parse-atoms '[{"type": "integer", "minInteger": -10, "maxInteger": 10}]' \
+    '[-20]' \
+    '[-11]' \
+    '[-10]' \
+    '[-9]' \
+    '[1]' \
+    '[9]' \
+    '[10]' \
+    '[11]' \
+    '[123576]']], 
+  [constraint violation: -20 is not in the valid range -10 to 10 (inclusive)
+constraint violation: -11 is not in the valid range -10 to 10 (inclusive)
+-10
+-9
+1
+9
+10
+constraint violation: 11 is not in the valid range -10 to 10 (inclusive)
+constraint violation: 123576 is not in the valid range -10 to 10 (inclusive)])
+
+OVSDB_CHECK_POSITIVE([reals >= 5], 
+  [[parse-atoms '[{"type": "real", "minReal": 5}]' \
+    '[0]' \
+    '[4]' \
+    '[5]' \
+    '[6]' \
+    '[12345]']], 
+  [constraint violation: 0 is less than minimum allowed value 5
+constraint violation: 4 is less than minimum allowed value 5
+5
+6
+12345])
+
+OVSDB_CHECK_POSITIVE([reals <= -1], 
+  [[parse-atoms '[{"type": "real", "maxReal": -1}]' \
+    '[0]' \
+    '[-1]' \
+    '[-2]' \
+    '[-123]']], 
+  [constraint violation: 0 is greater than maximum allowed value -1
+-1
+-2
+-123])
+
+OVSDB_CHECK_POSITIVE([reals in range -10 to 10], 
+  [[parse-atoms '[{"type": "real", "minReal": -10, "maxReal": 10}]' \
+    '[-20]' \
+    '[-11]' \
+    '[-10]' \
+    '[-9]' \
+    '[1]' \
+    '[9]' \
+    '[10]' \
+    '[11]' \
+    '[123576]']], 
+  [constraint violation: -20 is not in the valid range -10 to 10 (inclusive)
+constraint violation: -11 is not in the valid range -10 to 10 (inclusive)
+-10
+-9
+1
+9
+10
+constraint violation: 11 is not in the valid range -10 to 10 (inclusive)
+constraint violation: 123576 is not in the valid range -10 to 10 (inclusive)])
+
+OVSDB_CHECK_POSITIVE([strings at least 2 characters long],
+  [[parse-atoms '{"type": "string", "minLength": 2}' \
+    '[""]' \
+    '["a"]' \
+    '["ab"]' \
+    '["abc"]' \
+    '["\ud834\udd1e"]']],
+  [[constraint violation: "" length 0 is less than minimum allowed length 2
+constraint violation: "a" length 1 is less than minimum allowed length 2
+"ab"
+"abc"
+constraint violation: "𝄞" length 1 is less than minimum allowed length 2]])
+
+OVSDB_CHECK_POSITIVE([strings no more than 2 characters long],
+  [[parse-atoms '{"type": "string", "maxLength": 2}' \
+    '[""]' \
+    '["a"]' \
+    '["ab"]' \
+    '["abc"]' \
+    '["\ud834\udd1e"]']],
+  [[""
+"a"
+"ab"
+constraint violation: "abc" length 3 is greater than maximum allowed length 2
+"𝄞"]])
 
 AT_BANNER([OSVDB -- simple data])
 
 OVSDB_CHECK_POSITIVE([integer JSON datum],
-  [[parse-data '["integer"]' '[0]' '[1]' '[-1]']],
+  [[parse-data '["integer"]' '[0]' '["set",[1]]' '[-1]']],
   [0
 1
 -1])
@@ -204,7 +478,7 @@ OVSDB_CHECK_POSITIVE([integer string datum],
 1])
 
 OVSDB_CHECK_POSITIVE([real JSON datum], 
-  [[parse-data '["real"]' '[0]' '[1.0]' '[-1.25]']],
+  [[parse-data '["real"]' '[0]' '["set",[1.0]]' '[-1.25]']],
   [0
 1
 -1.25])
@@ -216,7 +490,7 @@ OVSDB_CHECK_POSITIVE([real string datum],
 -1.25])
 
 OVSDB_CHECK_POSITIVE([boolean JSON datum],
-  [[parse-data '["boolean"]' '[true]' '[false]' ]],
+  [[parse-data '["boolean"]' '["set", [true]]' '[false]' ]],
   [true
 false])
 
@@ -226,7 +500,7 @@ OVSDB_CHECK_POSITIVE([boolean string datum],
 false])
 
 OVSDB_CHECK_POSITIVE([string JSON datum],
-  [[parse-data '["string"]' '[""]' '["true"]' '["\"\\\/\b\f\n\r\t"]']],
+  [[parse-data '["string"]' '["set",[""]]' '["true"]' '["\"\\\/\b\f\n\r\t"]']],
   [""
 "true"
 "\"\\/\b\f\n\r\t"])
@@ -237,16 +511,16 @@ OVSDB_CHECK_POSITIVE([string string datum],
 ""
 "true"
 "\"\\/\b\f\n\r\t"])
-
+\f
 AT_BANNER([OVSDB -- set data])
 
 OVSDB_CHECK_POSITIVE([JSON optional boolean],
   [[parse-data '{"key": "boolean", "min": 0}' \
-    '["set", [true]]' \
+    '[true]' \
     '["set", [false]]' \
     '["set", []]']], 
-  [[["set",[true]]
-["set",[false]]
+  [[true
+false
 ["set",[]]]],
   [set])
 
@@ -263,12 +537,14 @@ false
 OVSDB_CHECK_POSITIVE([JSON set of 0 or more integers],
   [[parse-data '{"key": "integer", "min": 0, "max": "unlimited"}' \
     '["set", [0]]' \
+    '[1]' \
     '["set", [0, 1]]' \
     '["set", [0, 1, 2]]' \
     '["set", [0, 1, 2, 3, 4, 5]]' \
     '["set", [0, 1, 2, 3, 4, 5, 6, 7, 8]]' \
     '["set", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]']],
-  [[["set",[0]]
+  [[0
+1
 ["set",[0,1]]
 ["set",[0,1,2]]
 ["set",[0,1,2,3,4,5]]
@@ -293,10 +569,12 @@ OVSDB_CHECK_POSITIVE([string set of 0 or more integers],
 OVSDB_CHECK_POSITIVE([JSON set of 1 to 3 uuids],
   [[parse-data '{"key": "uuid", "min": 1, "max": 3}' \
     '["set", [["uuid", "550e8400-e29b-41d4-a716-446655440000"]]]' \
+    '["uuid", "b5078be0-7664-4299-b836-8bcc03ef941f"]' \
     '["set", [["uuid", "c5051240-30ff-43ed-b4b9-93cf3f050813"],
               ["uuid", "90558331-09af-4d2f-a572-509cad2e9088"],
               ["uuid", "550e8400-e29b-41d4-a716-446655440000"]]]']],
-  [[["set",[["uuid","550e8400-e29b-41d4-a716-446655440000"]]]
+  [[["uuid","550e8400-e29b-41d4-a716-446655440000"]
+["uuid","b5078be0-7664-4299-b836-8bcc03ef941f"]
 ["set",[["uuid","550e8400-e29b-41d4-a716-446655440000"],["uuid","90558331-09af-4d2f-a572-509cad2e9088"],["uuid","c5051240-30ff-43ed-b4b9-93cf3f050813"]]]]])
 
 OVSDB_CHECK_POSITIVE([string set of 1 to 3 uuids],
@@ -311,11 +589,13 @@ OVSDB_CHECK_POSITIVE([string set of 1 to 3 uuids],
 OVSDB_CHECK_POSITIVE([JSON set of 0 to 3 strings],
   [[parse-data '{"key": "string", "min": 0, "max": 3}' \
     '["set", []]' \
+    '["a longer string"]' \
     '["set", ["a relatively long string"]]' \
     '["set", ["short string", "a relatively long string"]]' \
     '["set", ["zzz", "short string", "a relatively long string"]]']],
   [[["set",[]]
-["set",["a relatively long string"]]
+"a longer string"
+"a relatively long string"
 ["set",["a relatively long string","short string"]]
 ["set",["a relatively long string","short string","zzz"]]]])
 
@@ -375,7 +655,7 @@ OVSDB_CHECK_NEGATIVE([duplicate uuid not allowed in string set],
      355ad037-f1da-40aa-b47c-ff9c7e8c6a38,
      7ef21525-0088-4a28-a418-5518413e43ea']],
   [set contains duplicate value])
-
+\f
 AT_BANNER([OVSDB -- map data])
 
 OVSDB_CHECK_POSITIVE([JSON map of 1 integer to boolean],