diff options
author | Ben Pfaff <blp@nicira.com> | 2010-02-08 14:09:36 -0800 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2010-02-08 14:16:19 -0800 |
commit | bd76d25d8b3b7d11c5a326e91d784ad2cdeecd45 (patch) | |
tree | 688e7370f9794e3c4189c38ff38a59937c9016e1 /tests | |
parent | 629cd2f17fedf8d922f61ffd13365d1f4f9b34fe (diff) |
ovsdb: Add simple constraints.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/automake.mk | 2 | ||||
-rw-r--r-- | tests/ovs-vsctl.at | 78 | ||||
-rw-r--r-- | tests/ovsdb-data.at | 169 | ||||
-rw-r--r-- | tests/ovsdb-execution.at | 26 | ||||
-rw-r--r-- | tests/ovsdb-mutation.at | 86 | ||||
-rw-r--r-- | tests/ovsdb-types.at | 62 | ||||
-rw-r--r-- | tests/test-ovsdb.c | 62 |
7 files changed, 406 insertions, 79 deletions
diff --git a/tests/automake.mk b/tests/automake.mk index f862c33b..8fa6c158 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -214,7 +214,7 @@ tests_test_ovsdb_SOURCES = \ tests/idltest.c \ tests/idltest.h EXTRA_DIST += tests/uuidfilt.pl -tests_test_ovsdb_LDADD = ovsdb/libovsdb.a lib/libopenvswitch.a $(SSL_LIBS) +tests_test_ovsdb_LDADD = ovsdb/libovsdb.a lib/libopenvswitch.a $(SSL_LIBS) $(PCRE_LIBS) # idltest schema and IDL OVSIDL_BUILT += tests/idltest.c tests/idltest.h tests/idltest.ovsidl diff --git a/tests/ovs-vsctl.at b/tests/ovs-vsctl.at index 0d35d17c..06bff53b 100644 --- a/tests/ovs-vsctl.at +++ b/tests/ovs-vsctl.at @@ -459,17 +459,18 @@ AT_CHECK([RUN_OVS_VSCTL([list b])], cp stdout out2 AT_CHECK([perl $srcdir/uuidfilt.pl out1 out2], [0], [[<0> -_uuid (RO): <0> -controller (RO): [] -datapath_id (RO): [] -datapath_type (RO): "" -external_ids (RW): {} -flood_vlans (RW): [] -mirrors (RO): [] -name (RO): "br0" -netflow (RO): [] -other_config (RW): {} -ports (RO): [] +_uuid : <0> +controller : [] +datapath_id : [] +datapath_type : "" +external_ids : {} +flood_vlans : [] +mirrors : [] +name : "br0" +netflow : [] +other_config : {} +ports : [] +sflow : [] ]], [ignore], [test ! -e pid || kill `cat pid`]) AT_CHECK( [RUN_OVS_VSCTL( @@ -518,12 +519,12 @@ AT_CHECK([RUN_OVS_VSCTL([list n `cat netflow-uuid`])], [0], [stdout], [], [OVS_VSCTL_CLEANUP]) AT_CHECK([perl $srcdir/uuidfilt.pl netflow-uuid stdout], [0], [[<0> -_uuid (RO): <0> -active_timeout (RW): 0 -add_id_to_interface (RW): false -engine_id (RW): [] -engine_type (RW): [] -targets (RW): ["1.2.3.4:567"] +_uuid : <0> +active_timeout : 0 +add_id_to_interface : false +engine_id : [] +engine_type : [] +targets : ["1.2.3.4:567"] ]], [ignore], [test ! -e pid || kill `cat pid`]) AT_CHECK([RUN_OVS_VSCTL([list interx x])], [1], [], [ovs-vsctl: unknown table "interx" @@ -556,35 +557,23 @@ AT_CHECK([RUN_OVS_VSCTL([get b br0 external_ids:x])], [1], [], [ovs-vsctl: no key "x" in Bridge record "br0" column external_ids ], [OVS_VSCTL_CLEANUP]) AT_CHECK([RUN_OVS_VSCTL([set b br0 flood_vlans=-1])], - [1], [], [ovs-vsctl: -1 is outside the valid range 1 to 4095 (inclusive) + [1], [], [ovs-vsctl: constraint violation: -1 is not in the valid range 0 to 4095 (inclusive) ], [OVS_VSCTL_CLEANUP]) AT_CHECK([RUN_OVS_VSCTL([set b br0 flood_vlans=4096])], - [1], [], [ovs-vsctl: 4096 is outside the valid range 1 to 4095 (inclusive) -], [OVS_VSCTL_CLEANUP]) -AT_CHECK([RUN_OVS_VSCTL([set b br0 datapath_id=4096])], - [1], [], [ovs-vsctl: datapath_id=4096: cannot modify read-only column datapath_id in table Bridge + [1], [], [ovs-vsctl: constraint violation: 4096 is not in the valid range 0 to 4095 (inclusive) ], [OVS_VSCTL_CLEANUP]) AT_CHECK([RUN_OVS_VSCTL([set c br1 'connection-mode=xyz'])], - [1], [], [ovs-vsctl: xyz is not valid (it does not match ^in-band|out-of-band$) + [1], [], [ovs-vsctl: constraint violation: "xyz" is not a either "in-band" or "out-of-band" ], [OVS_VSCTL_CLEANUP]) AT_CHECK([RUN_OVS_VSCTL([set c br1 connection-mode:x=y])], [1], [], [ovs-vsctl: cannot specify key to set for non-map column connection_mode ], [OVS_VSCTL_CLEANUP]) -AT_CHECK([RUN_OVS_VSCTL([add b br1 datapath_id x=y])], - [1], [], [ovs-vsctl: cannot modify read-only column datapath_id in table Bridge -], [OVS_VSCTL_CLEANUP]) -AT_CHECK([RUN_OVS_VSCTL([--force add b br1 datapath_id x y])], +AT_CHECK([RUN_OVS_VSCTL([add b br1 datapath_id x y])], [1], [], [ovs-vsctl: "add" operation would put 2 values in column datapath_id of table Bridge but the maximum number is 1 ], [OVS_VSCTL_CLEANUP]) -AT_CHECK([RUN_OVS_VSCTL([remove b br1 datapath_id x=y])], - [1], [], [ovs-vsctl: cannot modify read-only column datapath_id in table Bridge -], [OVS_VSCTL_CLEANUP]) AT_CHECK([RUN_OVS_VSCTL([remove n `cat netflow-uuid` targets '"1.2.3.4:567"'])], [1], [], [ovs-vsctl: "remove" operation would put 0 values in column targets of table NetFlow but the minimun number is 1 ], [OVS_VSCTL_CLEANUP]) -AT_CHECK([RUN_OVS_VSCTL([clear bri br0 netflow])], - [1], [], [ovs-vsctl: cannot modify read-only column netflow in table Bridge -], [OVS_VSCTL_CLEANUP]) AT_CHECK([RUN_OVS_VSCTL([clear n `cat netflow-uuid` targets])], [1], [], [ovs-vsctl: "clear" operation cannot be applied to column targets of table NetFlow, which is not allowed to be empty ], [OVS_VSCTL_CLEANUP]) @@ -610,17 +599,18 @@ AT_CHECK([RUN_OVS_VSCTL([--force create Bridge name=br0 -- list b])], [0], [stdout], [], [OVS_VSCTL_CLEANUP]) AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [[<0> -_uuid (RO): <1> -controller (RO): [] -datapath_id (RO): [] -datapath_type (RO): "" -external_ids (RW): {} -flood_vlans (RW): [] -mirrors (RO): [] -name (RO): "br0" -netflow (RO): [] -other_config (RW): {} -ports (RO): [] +_uuid : <1> +controller : [] +datapath_id : [] +datapath_type : "" +external_ids : {} +flood_vlans : [] +mirrors : [] +name : "br0" +netflow : [] +other_config : {} +ports : [] +sflow : [] ]], [ignore], [test ! -e pid || kill `cat pid`]) OVS_VSCTL_CLEANUP AT_CLEANUP diff --git a/tests/ovsdb-data.at b/tests/ovsdb-data.at index e868477d..03ec3b33 100644 --- a/tests/ovsdb-data.at +++ b/tests/ovsdb-data.at @@ -1,4 +1,4 @@ -AT_BANNER([OVSDB -- atoms]) +AT_BANNER([OVSDB -- atoms without constraints]) OVSDB_CHECK_POSITIVE([integer atom from JSON], [[parse-atoms '["integer"]' \ @@ -152,29 +152,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 "\xc0"])"@:>@' \ + '@<:@"m4_esyscmd([printf "\xed\xa0\x80"])"@:>@' \ +], + [constraint violation: "m4_esyscmd([printf "\xc0"])" is not a valid UTF-8 string: invalid UTF-8 sequence 0xc0 +constraint violation: "m4_esyscmd([printf "\xed\xa0\x80"])" 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,6 +197,143 @@ 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]) + +AT_BANNER([OVSDB -- atoms with 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 matching /(a(b)?)c?/], + [[parse-atoms '{"type": "string", "reMatch": "(a(b)?)?c?"}' \ + '[""]' \ + '["a"]' \ + '["ab"]' \ + '["abc"]' \ + '["ac"]' \ + '["b"]' \ + '["bc"]' \ + '["c"]']], + [["" +"a" +"ab" +"abc" +"ac" +constraint violation: "b" does not match regular expression /(a(b)?)?c?/ +constraint violation: "bc" does not match regular expression /(a(b)?)?c?/ +"c"]]) + +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]) @@ -237,7 +384,7 @@ OVSDB_CHECK_POSITIVE([string string datum], "" "true" "\"\\/\b\f\n\r\t"]) - + AT_BANNER([OVSDB -- set data]) OVSDB_CHECK_POSITIVE([JSON optional boolean], @@ -375,7 +522,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]) - + AT_BANNER([OVSDB -- map data]) OVSDB_CHECK_POSITIVE([JSON map of 1 integer to boolean], diff --git a/tests/ovsdb-execution.at b/tests/ovsdb-execution.at index 1113f948..bb9d6cf4 100644 --- a/tests/ovsdb-execution.at +++ b/tests/ovsdb-execution.at @@ -8,6 +8,14 @@ m4_define([ORDINAL_SCHEMA], "number": {"type": "integer"}, "name": {"type": "string"}}}}}]]) +m4_define([CONSTRAINT_SCHEMA], + [[{"name": "constraints", + "tables": { + "constrained": { + "columns": { + "positive": {"type": {"key": {"type": "integer", + "minInteger": 1}}}}}}}]]) + # OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS]) # # Runs "test-ovsdb execute" with the given SCHEMA and each of the @@ -352,6 +360,22 @@ OVSDB_CHECK_EXECUTION([inequality wait with missing row], "rows": [{"name": "one", "number": 1}]}]]]], [[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{}] ]]) -]) + +OVSDB_CHECK_EXECUTION([insert and update constraints], + [CONSTRAINT_SCHEMA], + [[[[{"op": "insert", + "table": "constrained", + "row": {}}]]], + [[[{"op": "insert", + "table": "constrained", + "row": {"positive": -1}}]]], + [[[{"op": "update", + "table": "constrained", + "where": [], + "row": {"positive": -2}}]]]], + [[[{"details":"0 is less than minimum allowed value 1","error":"constraint violation"}] +[{"details":"-1 is less than minimum allowed value 1","error":"constraint violation"}] +[{"details":"-2 is less than minimum allowed value 1","error":"constraint violation"}] +]])]) EXECUTION_EXAMPLES diff --git a/tests/ovsdb-mutation.at b/tests/ovsdb-mutation.at index b10aff16..cf4ca011 100644 --- a/tests/ovsdb-mutation.at +++ b/tests/ovsdb-mutation.at @@ -282,6 +282,45 @@ row 5: domain error: Division by zero. row 6: domain error: Division by zero. ], [mutation]) +OVSDB_CHECK_POSITIVE([executing mutations on integers with constraints], + [[execute-mutations \ + '{"columns": {"i": {"type": {"key": {"type": "integer", + "minInteger": 0, + "maxInteger": 2}}}}}' \ + '[[["i", "+=", 1]], + [["i", "-=", 2]], + [["i", "*=", 3]], + [["i", "/=", 4]], + [["i", "%=", 2]]]' \ + '[{"i": 0}, + {"i": 1}, + {"i": 2}']]], + [mutation 0: +row 0: {"i":1} +row 1: {"i":2} +row 2: constraint violation: 3 is not in the valid range 0 to 2 (inclusive) + +mutation 1: +row 0: constraint violation: -2 is not in the valid range 0 to 2 (inclusive) +row 1: constraint violation: -1 is not in the valid range 0 to 2 (inclusive) +row 2: {"i":0} + +mutation 2: +row 0: no change +row 1: constraint violation: 3 is not in the valid range 0 to 2 (inclusive) +row 2: constraint violation: 6 is not in the valid range 0 to 2 (inclusive) + +mutation 3: +row 0: no change +row 1: {"i":0} +row 2: {"i":0} + +mutation 4: +row 0: no change +row 1: no change +row 2: {"i":0} +], [mutation]) + OVSDB_CHECK_POSITIVE([executing mutations on reals], [[execute-mutations \ '{"columns": {"r": {"type": "real"}}}' \ @@ -356,9 +395,45 @@ row 1: domain error: Division by zero. row 2: domain error: Division by zero. ], [mutation]) +OVSDB_CHECK_POSITIVE([executing mutations on reals with constraints], + [[execute-mutations \ + '{"columns": {"r": {"type": {"key": {"type": "real", + "minReal": -2.5, + "maxReal": 1.75}}}}}' \ + '[[["r", "+=", 0.5]], + [["r", "-=", 1.5]], + [["r", "*=", 2.5]], + [["r", "/=", 4]]]' \ + '[{"r": 0}, + {"r": -2.5}, + {"r": 1.25}']]], + [mutation 0: +row 0: {"r":0.5} +row 1: {"r":-2} +row 2: {"r":1.75} + +mutation 1: +row 0: {"r":-1.5} +row 1: constraint violation: -4 is not in the valid range -2.5 to 1.75 (inclusive) +row 2: {"r":-0.25} + +mutation 2: +row 0: no change +row 1: constraint violation: -6.25 is not in the valid range -2.5 to 1.75 (inclusive) +row 2: constraint violation: 3.125 is not in the valid range -2.5 to 1.75 (inclusive) + +mutation 3: +row 0: no change +row 1: {"r":-0.625} +row 2: {"r":0.3125} +], [mutation]) + OVSDB_CHECK_POSITIVE([executing mutations on integer sets], [[execute-mutations \ - '{"columns": {"i": {"type": {"key": "integer", "min": 0, "max": "unlimited"}}}}' \ + '{"columns": {"i": {"type": {"key": {"type": "integer", + "maxInteger": 5}, + "min": 0, + "max": "unlimited"}}}}' \ '[[["i", "+=", 1]], [["i", "-=", 2]], [["i", "*=", 3]], @@ -388,7 +463,7 @@ mutation 2: row 0: no change row 1: no change row 2: {"i":["set",[0,3]]} -row 3: {"i":["set",[0,3,6]]} +row 3: constraint violation: 6 is greater than maximum allowed value 5 mutation 3: row 0: no change @@ -429,7 +504,9 @@ row 3: {"i":["set",[0,1]]} OVSDB_CHECK_POSITIVE([executing mutations on real sets], [[execute-mutations \ - '{"columns": {"r": {"type": {"key": "real", "min": 0, "max": "unlimited"}}}}' \ + '{"columns": {"r": {"type": {"key": {"type": "real", + "maxReal": 6}, + "min": 0, "max": "unlimited"}}}}' \ '[[["r", "+=", 0.5]], [["r", "-=", 1.5]], [["r", "*=", 2.5]], @@ -459,7 +536,7 @@ mutation 2: row 0: no change row 1: {"r":["set",[1.25]]} row 2: {"r":["set",[1.25,3.75]]} -row 3: {"r":["set",[1.25,3.75,6.25]]} +row 3: constraint violation: 6.25 is greater than maximum allowed value 6 mutation 3: row 0: no change @@ -648,7 +725,6 @@ row 2: no change row 3: {"u":["set",[]]} ]], [mutation]) - OVSDB_CHECK_POSITIVE([executing mutations on integer maps], [[execute-mutations \ '{"columns": {"i": {"type": {"key": "integer", "value": "integer", "min": 0, "max": "unlimited"}}}}' \ diff --git a/tests/ovsdb-types.at b/tests/ovsdb-types.at index ebaffff7..b7fddc7e 100644 --- a/tests/ovsdb-types.at +++ b/tests/ovsdb-types.at @@ -13,6 +13,68 @@ OVSDB_CHECK_POSITIVE([uuid], OVSDB_CHECK_NEGATIVE([void is not a valid atomic-type], [[parse-atomic-type '["void"]' ]], ["void" is not an atomic-type]) +AT_BANNER([OVSDB -- base types]) + +OVSDB_CHECK_POSITIVE([integer >= 5], + [[parse-base-type '{"type": "integer", "minInteger": 5}' ]], + [{"minInteger":5,"type":"integer"}]) +OVSDB_CHECK_POSITIVE([integer <= 7], + [[parse-base-type '{"type": "integer", "maxInteger": 7}' ]], + [{"maxInteger":7,"type":"integer"}]) +OVSDB_CHECK_POSITIVE([integer between -5 and 10], + [[parse-base-type '{"type": "integer", "minInteger": -5, "maxInteger": 10}']], + [{"maxInteger":10,"minInteger":-5,"type":"integer"}]) +OVSDB_CHECK_NEGATIVE([integer max may not be less than min], + [[parse-base-type '{"type": "integer", "minInteger": 5, "maxInteger": 3}']], + [minInteger exceeds maxInteger]) + +OVSDB_CHECK_POSITIVE([real >= -1.5], + [[parse-base-type '{"type": "real", "minReal": -1.5}']], + [{"minReal":-1.5,"type":"real"}]) +OVSDB_CHECK_POSITIVE([real <= 1e5], + [[parse-base-type '{"type": "real", "maxReal": 1e5}']], + [{"maxReal":100000,"type":"real"}]) +OVSDB_CHECK_POSITIVE([real between -2.5 and 3.75], + [[parse-base-type '{"type": "real", "minReal": -2.5, "maxReal": 3.75}']], + [{"maxReal":3.75,"minReal":-2.5,"type":"real"}]) +OVSDB_CHECK_NEGATIVE([real max may not be less than min], + [[parse-base-type '{"type": "real", "minReal": 555, "maxReal": 444}']], + [minReal exceeds maxReal]) + +OVSDB_CHECK_POSITIVE([boolean], + [[parse-base-type '[{"type": "boolean"}]' ]], ["boolean"]) + +OVSDB_CHECK_POSITIVE([string reMatch], + [[parse-base-type '{"type": "string", "reMatch": "\\d{3}-\\d{3}-\\d{4}"}']], + [{"reMatch":"\\d{3}-\\d{3}-\\d{4}","type":"string"}]) +OVSDB_CHECK_POSITIVE([string reMatch + reComment], + [[parse-base-type '{"type": "string", "reMatch": "\\d{3}-\\d{3}-\\d{4}", "reComment": "US-style telephone number"}']], + [{"reComment":"US-style telephone number","reMatch":"\\d{3}-\\d{3}-\\d{4}","type":"string"}]) +OVSDB_CHECK_NEGATIVE([reMatch must be a valid JavaScript regexp], + [[parse-base-type '{"type": "string", "reMatch": "ab@:>@cd"}']], + [[test-ovsdb: invalid regular expression: "ab@:>@cd" is not a valid regular expression: @:>@ is an invalid data character in JavaScript compatibility mode]]) + +OVSDB_CHECK_POSITIVE([string minLength], + [[parse-base-type '{"type": "string", "minLength": 1}']], + [{"minLength":1,"type":"string"}]) +OVSDB_CHECK_POSITIVE([string maxLength], + [[parse-base-type '{"type": "string", "maxLength": 5}']], + [{"maxLength":5,"type":"string"}]) +OVSDB_CHECK_POSITIVE([string minLength and maxLength], + [[parse-base-type '{"type": "string", "minLength": 1, "maxLength": 5}']], + [{"maxLength":5,"minLength":1,"type":"string"}]) +OVSDB_CHECK_NEGATIVE([maxLength must not be less than minLength], + [[parse-base-type '{"type": "string", "minLength": 5, "maxLength": 3}']], + [minLength exceeds maxLength]) +OVSDB_CHECK_NEGATIVE([maxLength must not be negative], + [[parse-base-type '{"type": "string", "maxLength": -1}']], + [maxLength out of valid range 0 to 4294967295]) + +OVSDB_CHECK_NEGATIVE([void is not a valid base-type], + [[parse-base-type '["void"]' ]], ["void" is not an atomic-type]) +OVSDB_CHECK_NEGATIVE(["type" member must be present], + [[parse-base-type '{}']], [Parsing ovsdb type failed: Required 'type' member is missing.]) + AT_BANNER([OVSDB -- simple types]) OVSDB_CHECK_POSITIVE([simple integer], diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index a40b780f..4b38ecb5 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -123,6 +123,8 @@ usage(void) " open FILE with FLAGS, run COMMANDs\n" " parse-atomic-type TYPE\n" " parse TYPE as OVSDB atomic type, and re-serialize\n" + " parse-base-type TYPE\n" + " parse TYPE as OVSDB base type, and re-serialize\n" " parse-type JSON\n" " parse JSON as OVSDB type, and re-serialize\n" " parse-atoms TYPE ATOM...\n" @@ -333,6 +335,19 @@ do_parse_atomic_type(int argc UNUSED, char *argv[]) } static void +do_parse_base_type(int argc UNUSED, char *argv[]) +{ + struct ovsdb_base_type base; + struct json *json; + + json = unbox_json(parse_json(argv[1])); + check_ovsdb_error(ovsdb_base_type_from_json(&base, json)); + json_destroy(json); + print_and_free_json(ovsdb_base_type_to_json(&base)); + ovsdb_base_type_destroy(&base); +} + +static void do_parse_type(int argc UNUSED, char *argv[]) { struct ovsdb_type type; @@ -342,56 +357,63 @@ do_parse_type(int argc UNUSED, char *argv[]) check_ovsdb_error(ovsdb_type_from_json(&type, json)); json_destroy(json); print_and_free_json(ovsdb_type_to_json(&type)); + ovsdb_type_destroy(&type); } static void do_parse_atoms(int argc, char *argv[]) { - enum ovsdb_atomic_type type; + struct ovsdb_base_type base; struct json *json; int i; json = unbox_json(parse_json(argv[1])); - check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json)); + check_ovsdb_error(ovsdb_base_type_from_json(&base, json)); json_destroy(json); for (i = 2; i < argc; i++) { + struct ovsdb_error *error; union ovsdb_atom atom; json = unbox_json(parse_json(argv[i])); - check_ovsdb_error(ovsdb_atom_from_json(&atom, type, json, NULL)); + error = ovsdb_atom_from_json(&atom, &base, json, NULL); json_destroy(json); - print_and_free_json(ovsdb_atom_to_json(&atom, type)); - - ovsdb_atom_destroy(&atom, type); + if (error) { + print_and_free_ovsdb_error(error); + } else { + print_and_free_json(ovsdb_atom_to_json(&atom, base.type)); + ovsdb_atom_destroy(&atom, base.type); + } } + ovsdb_base_type_destroy(&base); } static void do_parse_atom_strings(int argc, char *argv[]) { - enum ovsdb_atomic_type type; + struct ovsdb_base_type base; struct json *json; int i; json = unbox_json(parse_json(argv[1])); - check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json)); + check_ovsdb_error(ovsdb_base_type_from_json(&base, json)); json_destroy(json); for (i = 2; i < argc; i++) { union ovsdb_atom atom; struct ds out; - die_if_error(ovsdb_atom_from_string(&atom, type, argv[i])); + die_if_error(ovsdb_atom_from_string(&atom, &base, argv[i])); ds_init(&out); - ovsdb_atom_to_string(&atom, type, &out); + ovsdb_atom_to_string(&atom, base.type, &out); puts(ds_cstr(&out)); ds_destroy(&out); - ovsdb_atom_destroy(&atom, type); + ovsdb_atom_destroy(&atom, base.type); } + ovsdb_base_type_destroy(&base); } static void @@ -416,6 +438,7 @@ do_parse_data(int argc, char *argv[]) ovsdb_datum_destroy(&datum, &type); } + ovsdb_type_destroy(&type); } static void @@ -442,6 +465,7 @@ do_parse_data_strings(int argc, char *argv[]) ovsdb_datum_destroy(&datum, &type); } + ovsdb_type_destroy(&type); } static enum ovsdb_atomic_type compare_atoms_atomic_type; @@ -458,14 +482,14 @@ compare_atoms(const void *a_, const void *b_) static void do_sort_atoms(int argc UNUSED, char *argv[]) { - enum ovsdb_atomic_type type; + struct ovsdb_base_type base; union ovsdb_atom *atoms; struct json *json, **json_atoms; size_t n_atoms; int i; json = unbox_json(parse_json(argv[1])); - check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json)); + check_ovsdb_error(ovsdb_base_type_from_json(&base, json)); json_destroy(json); json = unbox_json(parse_json(argv[2])); @@ -477,23 +501,24 @@ do_sort_atoms(int argc UNUSED, char *argv[]) n_atoms = json->u.array.n; atoms = xmalloc(n_atoms * sizeof *atoms); for (i = 0; i < n_atoms; i++) { - check_ovsdb_error(ovsdb_atom_from_json(&atoms[i], type, + check_ovsdb_error(ovsdb_atom_from_json(&atoms[i], &base, json->u.array.elems[i], NULL)); } json_destroy(json); /* Sort atoms. */ - compare_atoms_atomic_type = type; + compare_atoms_atomic_type = base.type; qsort(atoms, n_atoms, sizeof *atoms, compare_atoms); /* Convert internal representation back to JSON. */ json_atoms = xmalloc(n_atoms * sizeof *json_atoms); for (i = 0; i < n_atoms; i++) { - json_atoms[i] = ovsdb_atom_to_json(&atoms[i], type); - ovsdb_atom_destroy(&atoms[i], type); + json_atoms[i] = ovsdb_atom_to_json(&atoms[i], base.type); + ovsdb_atom_destroy(&atoms[i], base.type); } print_and_free_json(json_array_create(json_atoms, n_atoms)); free(atoms); + ovsdb_base_type_destroy(&base); } static void @@ -1733,6 +1758,8 @@ do_idl(int argc, char *argv[]) int error; int i; + idltest_init(); + idl = ovsdb_idl_create(argv[1], &idltest_idl_class); if (argc > 2) { struct stream *stream; @@ -1788,6 +1815,7 @@ do_idl(int argc, char *argv[]) static struct command all_commands[] = { { "log-io", 2, INT_MAX, do_log_io }, { "parse-atomic-type", 1, 1, do_parse_atomic_type }, + { "parse-base-type", 1, 1, do_parse_base_type }, { "parse-type", 1, 1, do_parse_type }, { "parse-atoms", 2, INT_MAX, do_parse_atoms }, { "parse-atom-strings", 2, INT_MAX, do_parse_atom_strings }, |