summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ovsdb-types.c3
-rw-r--r--ovsdb/SPECS6
-rw-r--r--tests/ovsdb-data.at6
-rw-r--r--tests/ovsdb-types.at27
4 files changed, 23 insertions, 19 deletions
diff --git a/lib/ovsdb-types.c b/lib/ovsdb-types.c
index 07982e343..659b50db3 100644
--- a/lib/ovsdb-types.c
+++ b/lib/ovsdb-types.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -75,6 +75,7 @@ ovsdb_type_is_valid(const struct ovsdb_type *type)
return (type->key_type != OVSDB_TYPE_VOID
&& ovsdb_atomic_type_is_valid(type->key_type)
&& ovsdb_atomic_type_is_valid(type->value_type)
+ && type->n_min <= 1
&& type->n_min <= type->n_max
&& (type->value_type == OVSDB_TYPE_VOID
|| ovsdb_atomic_type_is_valid_key(type->key_type)));
diff --git a/ovsdb/SPECS b/ovsdb/SPECS
index 1635c771a..7963a2adf 100644
--- a/ovsdb/SPECS
+++ b/ovsdb/SPECS
@@ -113,9 +113,9 @@ is represented by <database-schema>, as described below.
If "min" or "max" is not specified, each defaults to 1. If "max"
is specified as "unlimited", then there is no specified maximum
number of elements, although the implementation will enforce some
- limit. After considering defaults, "min" must be at least 0,
- "max" must be at least 1, and "max" must be greater than or equal
- to "min".
+ limit. After considering defaults, "min" must be exactly 0 or
+ exactly 1, "max" must be at least 1, and "max" must be greater
+ than or equal to "min".
If "min" and "max" are both 1 and "value" is not specified, the
type is the scalar type specified by "key".
diff --git a/tests/ovsdb-data.at b/tests/ovsdb-data.at
index bedaf7003..e7125fea4 100644
--- a/tests/ovsdb-data.at
+++ b/tests/ovsdb-data.at
@@ -230,8 +230,8 @@ OVSDB_CHECK_POSITIVE([map of 1 boolean to integer],
'["map", [[true, 1]]]']],
[[["map",[[true,1]]]]])
-OVSDB_CHECK_POSITIVE([map of 5 uuid to real],
- [[parse-data '{"key": "uuid", "value": "real", "min": 5, "max": 5}' \
+OVSDB_CHECK_POSITIVE([map of 1 uuid to real],
+ [[parse-data '{"key": "uuid", "value": "real", "min": 1, "max": 5}' \
'["map", [[["uuid", "cad8542b-6ee1-486b-971b-7dcbf6e14979"], 1.0],
[["uuid", "6b94b968-2702-4f64-9457-314a34d69b8c"], 2.0],
[["uuid", "d2c4a168-24de-47eb-a8a3-c1abfc814979"], 3.0],
@@ -240,7 +240,7 @@ OVSDB_CHECK_POSITIVE([map of 5 uuid to real],
[[["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]]]]])
OVSDB_CHECK_POSITIVE([map of 10 string to string],
- [[parse-data '{"key": "string", "value": "string", "min": 10, "max": 10}' \
+ [[parse-data '{"key": "string", "value": "string", "min": 1, "max": 10}' \
'["map", [["2 gills", "1 chopin"],
["2 chopins", "1 pint"],
["2 pints", "1 quart"],
diff --git a/tests/ovsdb-types.at b/tests/ovsdb-types.at
index 9a92a5ca6..ebaffff77 100644
--- a/tests/ovsdb-types.at
+++ b/tests/ovsdb-types.at
@@ -50,9 +50,9 @@ OVSDB_CHECK_POSITIVE([set of 0 to 3 strings],
OVSDB_CHECK_POSITIVE([set of 0 or more integers],
[[parse-type '{"key": "integer", "min": 0, "max": "unlimited"}']],
[[{"key":"integer","max":"unlimited","min":0}]])
-OVSDB_CHECK_POSITIVE([set of 10 or more reals],
- [[parse-type '{"key": "real", "min": 10, "max": "unlimited"}']],
- [[{"key":"real","max":"unlimited","min":10}]])
+OVSDB_CHECK_POSITIVE([set of 1 or more reals],
+ [[parse-type '{"key": "real", "min": 1, "max": "unlimited"}']],
+ [[{"key":"real","max":"unlimited"}]])
OVSDB_CHECK_NEGATIVE([set max cannot be less than min],
[[parse-type '{"key": "real", "min": 5, "max": 3}' ]],
@@ -63,6 +63,9 @@ OVSDB_CHECK_NEGATIVE([set max cannot be negative],
OVSDB_CHECK_NEGATIVE([set min cannot be negative],
[[parse-type '{"key": "real", "min": -1}' ]],
[bad min or max value])
+OVSDB_CHECK_NEGATIVE([set min cannot be greater than one],
+ [[parse-type '{"key": "real", "min": 10, "max": "unlimited"}']],
+ [ovsdb type fails constraint checks])
AT_BANNER([OVSDB -- map types])
@@ -72,18 +75,18 @@ OVSDB_CHECK_POSITIVE([map of 1 integer to boolean],
OVSDB_CHECK_POSITIVE([map of 1 boolean to integer, explicit min and max],
[[parse-type '{"key": "boolean", "value": "integer", "min": 1, "max": 1}' ]],
[[{"key":"boolean","value":"integer"}]])
-OVSDB_CHECK_POSITIVE([map of 2 to 5 uuid to real],
- [[parse-type '{"key": "uuid", "value": "real", "min": 2, "max": 5}' ]],
- [[{"key":"uuid","max":5,"min":2,"value":"real"}]])
+OVSDB_CHECK_POSITIVE([map of 1 to 5 uuid to real],
+ [[parse-type '{"key": "uuid", "value": "real", "min": 1, "max": 5}' ]],
+ [[{"key":"uuid","max":5,"value":"real"}]])
OVSDB_CHECK_POSITIVE([map of 0 to 10 string to uuid],
[[parse-type '{"key": "string", "value": "uuid", "min": 0, "max": 10}' ]],
[[{"key":"string","max":10,"min":0,"value":"uuid"}]])
-OVSDB_CHECK_POSITIVE([map of 10 to 20 real to string],
- [[parse-type '{"key": "real", "value": "string", "min": 10, "max": 20}' ]],
- [[{"key":"real","max":20,"min":10,"value":"string"}]])
-OVSDB_CHECK_POSITIVE([map of 20 or more string to real],
- [[parse-type '{"key": "string", "value": "real", "min": 20, "max": "unlimited"}' ]],
- [[{"key":"string","max":"unlimited","min":20,"value":"real"}]])
+OVSDB_CHECK_POSITIVE([map of 1 to 20 real to string],
+ [[parse-type '{"key": "real", "value": "string", "min": 1, "max": 20}' ]],
+ [[{"key":"real","max":20,"value":"string"}]])
+OVSDB_CHECK_POSITIVE([map of 0 or more string to real],
+ [[parse-type '{"key": "string", "value": "real", "min": 0, "max": "unlimited"}' ]],
+ [[{"key":"string","max":"unlimited","min":0,"value":"real"}]])
OVSDB_CHECK_NEGATIVE([map key type is required],
[[parse-type '{"value": "integer"}' ]],