diff options
author | bapt <bapt@FreeBSD.org> | 2014-07-19 23:44:57 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2014-07-19 23:44:57 +0000 |
commit | 6f718e3669e9ecc1b1ca407a465d6ee20571a2b8 (patch) | |
tree | ba71cc26671c93ed9809f7cadb07734c0bddb4c7 /contrib/libucl/tests | |
parent | 6095428430d025abcf6983536297f168bf62b45b (diff) | |
download | FreeBSD-src-6f718e3669e9ecc1b1ca407a465d6ee20571a2b8.zip FreeBSD-src-6f718e3669e9ecc1b1ca407a465d6ee20571a2b8.tar.gz |
MFC: r263648, r264789, r266636
This brings:
- schema validation
- xpath-like interface for ucl objects
Adapt pkg(7) to the new libucl API
Diffstat (limited to 'contrib/libucl/tests')
61 files changed, 2303 insertions, 33 deletions
diff --git a/contrib/libucl/tests/.gitignore b/contrib/libucl/tests/.gitignore new file mode 100644 index 0000000..5a48681 --- /dev/null +++ b/contrib/libucl/tests/.gitignore @@ -0,0 +1,8 @@ +*.log +*.trs +*.plist + +test_basic +test_generate +test_schema +test_speed diff --git a/contrib/libucl/tests/10.in b/contrib/libucl/tests/10.in deleted file mode 100644 index 560150c..0000000 --- a/contrib/libucl/tests/10.in +++ /dev/null @@ -1 +0,0 @@ -a [] diff --git a/contrib/libucl/tests/5.in b/contrib/libucl/tests/5.in deleted file mode 100644 index 83c831f..0000000 --- a/contrib/libucl/tests/5.in +++ /dev/null @@ -1 +0,0 @@ -# test diff --git a/contrib/libucl/tests/5.res b/contrib/libucl/tests/5.res deleted file mode 100644 index 8b13789..0000000 --- a/contrib/libucl/tests/5.res +++ /dev/null @@ -1 +0,0 @@ - diff --git a/contrib/libucl/tests/7.in b/contrib/libucl/tests/7.in deleted file mode 100644 index e69de29..0000000 --- a/contrib/libucl/tests/7.in +++ /dev/null diff --git a/contrib/libucl/tests/7.res b/contrib/libucl/tests/7.res deleted file mode 100644 index 8b13789..0000000 --- a/contrib/libucl/tests/7.res +++ /dev/null @@ -1 +0,0 @@ - diff --git a/contrib/libucl/tests/Makefile.am b/contrib/libucl/tests/Makefile.am new file mode 100644 index 0000000..880036d --- /dev/null +++ b/contrib/libucl/tests/Makefile.am @@ -0,0 +1,33 @@ +EXTRA_DIST = $(TESTS) basic schema generate.res rcl_test.json.xz + +TESTS = basic.test \ + generate.test \ + schema.test \ + speed.test +TESTS_ENVIRONMENT = $(SH) \ + TEST_DIR=$(top_srcdir)/tests \ + TEST_OUT_DIR=$(top_builddir)/tests \ + TEST_BINARY_DIR=$(top_builddir)/tests + +common_test_cflags = -I$(top_srcdir)/include \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/uthash +common_test_ldadd = $(top_builddir)/src/libucl.la + +test_basic_SOURCES = test_basic.c +test_basic_LDADD = $(common_test_ldadd) +test_basic_CFLAGS = $(common_test_cflags) + +test_speed_SOURCES = test_speed.c +test_speed_LDADD = $(common_test_ldadd) +test_speed_CFLAGS = $(common_test_cflags) + +test_generate_SOURCES = test_generate.c +test_generate_LDADD = $(common_test_ldadd) +test_generate_CFLAGS = $(common_test_cflags) + +test_schema_SOURCES = test_schema.c +test_schema_LDADD = $(common_test_ldadd) +test_schema_CFLAGS = $(common_test_cflags) + +check_PROGRAMS = test_basic test_speed test_generate test_schema
\ No newline at end of file diff --git a/contrib/libucl/tests/basic.test b/contrib/libucl/tests/basic.test new file mode 100755 index 0000000..a4a07eb --- /dev/null +++ b/contrib/libucl/tests/basic.test @@ -0,0 +1,26 @@ +#!/bin/sh + +PROG=${TEST_BINARY_DIR}/test_basic + +for _tin in ${TEST_DIR}/basic/*.in ; do + _t=`echo $_tin | sed -e 's/.in$//'` + _out=${TEST_OUT_DIR}/basic.out + $PROG $_t.in $_out + if [ $? -ne 0 ] ; then + echo "Test: $_t failed, output:" + cat $_out + rm $_out + exit 1 + fi + if [ -f $_t.res ] ; then + diff -s $_out $_t.res -u 2>/dev/null + if [ $? -ne 0 ] ; then + rm $_out + echo "Test: $_t output missmatch" + exit 1 + fi + fi + rm $_out +done + + diff --git a/contrib/libucl/tests/1.in b/contrib/libucl/tests/basic/1.in index 9c14df6..9c14df6 100644 --- a/contrib/libucl/tests/1.in +++ b/contrib/libucl/tests/basic/1.in diff --git a/contrib/libucl/tests/1.res b/contrib/libucl/tests/basic/1.res index 660af9f..660af9f 100644 --- a/contrib/libucl/tests/1.res +++ b/contrib/libucl/tests/basic/1.res diff --git a/contrib/libucl/tests/basic/10.in b/contrib/libucl/tests/basic/10.in new file mode 100644 index 0000000..e0910c1 --- /dev/null +++ b/contrib/libucl/tests/basic/10.in @@ -0,0 +1,9 @@ +section foo bar { + key = value +} +section foo baz { + key = value +} +section foo { + bar = lol /* removing this line makes parsing successful */ +} diff --git a/contrib/libucl/tests/2.in b/contrib/libucl/tests/basic/2.in index a4419a4..a4419a4 100644 --- a/contrib/libucl/tests/2.in +++ b/contrib/libucl/tests/basic/2.in diff --git a/contrib/libucl/tests/2.res b/contrib/libucl/tests/basic/2.res index 72e9570..72e9570 100644 --- a/contrib/libucl/tests/2.res +++ b/contrib/libucl/tests/basic/2.res diff --git a/contrib/libucl/tests/3.in b/contrib/libucl/tests/basic/3.in index b3e3696..b3e3696 100644 --- a/contrib/libucl/tests/3.in +++ b/contrib/libucl/tests/basic/3.in diff --git a/contrib/libucl/tests/3.res b/contrib/libucl/tests/basic/3.res index bb18457..bb18457 100644 --- a/contrib/libucl/tests/3.res +++ b/contrib/libucl/tests/basic/3.res diff --git a/contrib/libucl/tests/4.in b/contrib/libucl/tests/basic/4.in index 2b296ef..2b296ef 100644 --- a/contrib/libucl/tests/4.in +++ b/contrib/libucl/tests/basic/4.in diff --git a/contrib/libucl/tests/4.res b/contrib/libucl/tests/basic/4.res index 58c3599..58c3599 100644 --- a/contrib/libucl/tests/4.res +++ b/contrib/libucl/tests/basic/4.res diff --git a/contrib/libucl/tests/6.in b/contrib/libucl/tests/basic/6.in index 5b46088..5b46088 100644 --- a/contrib/libucl/tests/6.in +++ b/contrib/libucl/tests/basic/6.in diff --git a/contrib/libucl/tests/6.res b/contrib/libucl/tests/basic/6.res index 4b17c4b..4b17c4b 100644 --- a/contrib/libucl/tests/6.res +++ b/contrib/libucl/tests/basic/6.res diff --git a/contrib/libucl/tests/8.in b/contrib/libucl/tests/basic/8.in index 605c0c9..605c0c9 100644 --- a/contrib/libucl/tests/8.in +++ b/contrib/libucl/tests/basic/8.in diff --git a/contrib/libucl/tests/8.res b/contrib/libucl/tests/basic/8.res index 54c904e..54c904e 100644 --- a/contrib/libucl/tests/8.res +++ b/contrib/libucl/tests/basic/8.res diff --git a/contrib/libucl/tests/9-comment.inc b/contrib/libucl/tests/basic/9-comment.inc index 8939db1..8939db1 100644 --- a/contrib/libucl/tests/9-comment.inc +++ b/contrib/libucl/tests/basic/9-comment.inc diff --git a/contrib/libucl/tests/9-empty.inc b/contrib/libucl/tests/basic/9-empty.inc index e69de29..e69de29 100644 --- a/contrib/libucl/tests/9-empty.inc +++ b/contrib/libucl/tests/basic/9-empty.inc diff --git a/contrib/libucl/tests/9.in b/contrib/libucl/tests/basic/9.in index da04e40..4c06e39 100644 --- a/contrib/libucl/tests/9.in +++ b/contrib/libucl/tests/basic/9.in @@ -1,5 +1,4 @@ .include "$CURDIR/9.inc" -.include "$CURDIR/9-empty.inc" .include "$CURDIR/9-comment.inc" #.include "$CURDIR/9.inc" .include "$CURDIR/9.inc" diff --git a/contrib/libucl/tests/9.inc b/contrib/libucl/tests/basic/9.inc index c5592b8..c5592b8 100644 --- a/contrib/libucl/tests/9.inc +++ b/contrib/libucl/tests/basic/9.inc diff --git a/contrib/libucl/tests/9.res b/contrib/libucl/tests/basic/9.res index ec3f014..ec3f014 100644 --- a/contrib/libucl/tests/9.res +++ b/contrib/libucl/tests/basic/9.res diff --git a/contrib/libucl/tests/generate.test b/contrib/libucl/tests/generate.test new file mode 100755 index 0000000..ed237a3 --- /dev/null +++ b/contrib/libucl/tests/generate.test @@ -0,0 +1,13 @@ +#!/bin/sh + +PROG=${TEST_BINARY_DIR}/test_generate + +$PROG ${TEST_OUT_DIR}/generate.out +diff -s ${TEST_OUT_DIR}/generate.out ${TEST_DIR}/generate.res -u 2>/dev/null +if [ $? -ne 0 ] ; then + rm ${TEST_OUT_DIR}/generate.out + echo "Test: generate.res output missmatch" + exit 1 +fi +rm ${TEST_OUT_DIR}/generate.out + diff --git a/contrib/libucl/tests/run_tests.sh b/contrib/libucl/tests/run_tests.sh index 6c7751e..bc26160 100755 --- a/contrib/libucl/tests/run_tests.sh +++ b/contrib/libucl/tests/run_tests.sh @@ -37,6 +37,15 @@ if [ $# -gt 2 ] ; then rm ${TEST_DIR}/generate.out fi +if [ $# -gt 3 ] ; then + rm /tmp/_ucl_test_schema.out ||true + for i in ${TEST_DIR}/schema/*.json ; do + _name=`basename $i` + printf "running schema test suite $_name... " + cat $i | $4 >> /tmp/_ucl_test_schema.out && ( echo "OK" ) || ( echo "Fail" ) + done +fi + sh -c "xz -c < /dev/null > /dev/null" if [ $? -eq 0 -a $# -gt 1 ] ; then echo 'Running speed tests' diff --git a/contrib/libucl/tests/schema.test b/contrib/libucl/tests/schema.test new file mode 100755 index 0000000..0f2c252 --- /dev/null +++ b/contrib/libucl/tests/schema.test @@ -0,0 +1,9 @@ +#!/bin/sh + +PROG=${TEST_BINARY_DIR}/test_schema +rm /tmp/_ucl_test_schema.out ||true +for i in ${TEST_DIR}/schema/*.json ; do + _name=`basename $i` + printf "running schema test suite $_name... " + $PROG >> /tmp/_ucl_test_schema.out < $i && ( echo "OK" ) || ( echo "Fail" ) +done diff --git a/contrib/libucl/tests/schema/additionalItems.json b/contrib/libucl/tests/schema/additionalItems.json new file mode 100644 index 0000000..521745c --- /dev/null +++ b/contrib/libucl/tests/schema/additionalItems.json @@ -0,0 +1,82 @@ +[ + { + "description": "additionalItems as schema", + "schema": { + "items": [{}], + "additionalItems": {"type": "integer"} + }, + "tests": [ + { + "description": "additional items match schema", + "data": [ null, 2, 3, 4 ], + "valid": true + }, + { + "description": "additional items do not match schema", + "data": [ null, 2, 3, "foo" ], + "valid": false + } + ] + }, + { + "description": "items is schema, no additionalItems", + "schema": { + "items": {}, + "additionalItems": false + }, + "tests": [ + { + "description": "all items match schema", + "data": [ 1, 2, 3, 4, 5 ], + "valid": true + } + ] + }, + { + "description": "array of items with no additionalItems", + "schema": { + "items": [{}, {}, {}], + "additionalItems": false + }, + "tests": [ + { + "description": "no additional items present", + "data": [ 1, 2, 3 ], + "valid": true + }, + { + "description": "additional items are not permitted", + "data": [ 1, 2, 3, 4 ], + "valid": false + } + ] + }, + { + "description": "additionalItems as false without items", + "schema": {"additionalItems": false}, + "tests": [ + { + "description": + "items defaults to empty schema so everything is valid", + "data": [ 1, 2, 3, 4, 5 ], + "valid": true + }, + { + "description": "ignores non-arrays", + "data": {"foo" : "bar"}, + "valid": true + } + ] + }, + { + "description": "additionalItems are allowed by default", + "schema": {"items": [{"type": "integer"}]}, + "tests": [ + { + "description": "only the first item is validated", + "data": [1, "foo", false], + "valid": true + } + ] + } +] diff --git a/contrib/libucl/tests/schema/additionalProperties.json b/contrib/libucl/tests/schema/additionalProperties.json new file mode 100644 index 0000000..eb334c9 --- /dev/null +++ b/contrib/libucl/tests/schema/additionalProperties.json @@ -0,0 +1,69 @@ +[ + { + "description": + "additionalProperties being false does not allow other properties", + "schema": { + "properties": {"foo": {}, "bar": {}}, + "patternProperties": { "^v": {} }, + "additionalProperties": false + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "an additional property is invalid", + "data": {"foo" : 1, "bar" : 2, "quux" : "boom"}, + "valid": false + }, + { + "description": "ignores non-objects", + "data": [1, 2, 3], + "valid": true + }, + { + "description": "patternProperties are not additional properties", + "data": {"foo":1, "vroom": 2}, + "valid": true + } + ] + }, + { + "description": + "additionalProperties allows a schema which should validate", + "schema": { + "properties": {"foo": {}, "bar": {}}, + "additionalProperties": {"type": "boolean"} + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "an additional valid property is valid", + "data": {"foo" : 1, "bar" : 2, "quux" : true}, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": {"foo" : 1, "bar" : 2, "quux" : 12}, + "valid": false + } + ] + }, + { + "description": "additionalProperties are allowed by default", + "schema": {"properties": {"foo": {}, "bar": {}}}, + "tests": [ + { + "description": "additional properties are allowed", + "data": {"foo": 1, "bar": 2, "quux": true}, + "valid": true + } + ] + } +] diff --git a/contrib/libucl/tests/schema/allOf.json b/contrib/libucl/tests/schema/allOf.json new file mode 100644 index 0000000..bbb5f89 --- /dev/null +++ b/contrib/libucl/tests/schema/allOf.json @@ -0,0 +1,112 @@ +[ + { + "description": "allOf", + "schema": { + "allOf": [ + { + "properties": { + "bar": {"type": "integer"} + }, + "required": ["bar"] + }, + { + "properties": { + "foo": {"type": "string"} + }, + "required": ["foo"] + } + ] + }, + "tests": [ + { + "description": "allOf", + "data": {"foo": "baz", "bar": 2}, + "valid": true + }, + { + "description": "mismatch second", + "data": {"foo": "baz"}, + "valid": false + }, + { + "description": "mismatch first", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "wrong type", + "data": {"foo": "baz", "bar": "quux"}, + "valid": false + } + ] + }, + { + "description": "allOf with base schema", + "schema": { + "properties": {"bar": {"type": "integer"}}, + "required": ["bar"], + "allOf" : [ + { + "properties": { + "foo": {"type": "string"} + }, + "required": ["foo"] + }, + { + "properties": { + "baz": {"type": "null"} + }, + "required": ["baz"] + } + ] + }, + "tests": [ + { + "description": "valid", + "data": {"foo": "quux", "bar": 2, "baz": null}, + "valid": true + }, + { + "description": "mismatch base schema", + "data": {"foo": "quux", "baz": null}, + "valid": false + }, + { + "description": "mismatch first allOf", + "data": {"bar": 2, "baz": null}, + "valid": false + }, + { + "description": "mismatch second allOf", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "mismatch both", + "data": {"bar": 2}, + "valid": false + } + ] + }, + { + "description": "allOf simple types", + "schema": { + "allOf": [ + {"maximum": 30}, + {"minimum": 20} + ] + }, + "tests": [ + { + "description": "valid", + "data": 25, + "valid": true + }, + { + "description": "mismatch one", + "data": 35, + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/anyOf.json b/contrib/libucl/tests/schema/anyOf.json new file mode 100644 index 0000000..a58714a --- /dev/null +++ b/contrib/libucl/tests/schema/anyOf.json @@ -0,0 +1,68 @@ +[ + { + "description": "anyOf", + "schema": { + "anyOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first anyOf valid", + "data": 1, + "valid": true + }, + { + "description": "second anyOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both anyOf valid", + "data": 3, + "valid": true + }, + { + "description": "neither anyOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "anyOf with base schema", + "schema": { + "type": "string", + "anyOf" : [ + { + "maxLength": 2 + }, + { + "minLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one anyOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both anyOf invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/definitions.json b/contrib/libucl/tests/schema/definitions.json new file mode 100644 index 0000000..cf935a3 --- /dev/null +++ b/contrib/libucl/tests/schema/definitions.json @@ -0,0 +1,32 @@ +[ + { + "description": "valid definition", + "schema": {"$ref": "http://json-schema.org/draft-04/schema#"}, + "tests": [ + { + "description": "valid definition schema", + "data": { + "definitions": { + "foo": {"type": "integer"} + } + }, + "valid": true + } + ] + }, + { + "description": "invalid definition", + "schema": {"$ref": "http://json-schema.org/draft-04/schema#"}, + "tests": [ + { + "description": "invalid definition schema", + "data": { + "definitions": { + "foo": {"type": 1} + } + }, + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/dependencies.json b/contrib/libucl/tests/schema/dependencies.json new file mode 100644 index 0000000..7b9b16a --- /dev/null +++ b/contrib/libucl/tests/schema/dependencies.json @@ -0,0 +1,113 @@ +[ + { + "description": "dependencies", + "schema": { + "dependencies": {"bar": ["foo"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "with dependency", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"bar": 2}, + "valid": false + }, + { + "description": "ignores non-objects", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "multiple dependencies", + "schema": { + "dependencies": {"quux": ["foo", "bar"]} + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "with dependencies", + "data": {"foo": 1, "bar": 2, "quux": 3}, + "valid": true + }, + { + "description": "missing dependency", + "data": {"foo": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing other dependency", + "data": {"bar": 1, "quux": 2}, + "valid": false + }, + { + "description": "missing both dependencies", + "data": {"quux": 1}, + "valid": false + } + ] + }, + { + "description": "multiple dependencies subschema", + "schema": { + "dependencies": { + "bar": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "integer"} + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "no dependency", + "data": {"foo": "quux"}, + "valid": true + }, + { + "description": "wrong type", + "data": {"foo": "quux", "bar": 2}, + "valid": false + }, + { + "description": "wrong type other", + "data": {"foo": 2, "bar": "quux"}, + "valid": false + }, + { + "description": "wrong type both", + "data": {"foo": "quux", "bar": "quux"}, + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/enum.json b/contrib/libucl/tests/schema/enum.json new file mode 100644 index 0000000..f124436 --- /dev/null +++ b/contrib/libucl/tests/schema/enum.json @@ -0,0 +1,72 @@ +[ + { + "description": "simple enum validation", + "schema": {"enum": [1, 2, 3]}, + "tests": [ + { + "description": "one of the enum is valid", + "data": 1, + "valid": true + }, + { + "description": "something else is invalid", + "data": 4, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum validation", + "schema": {"enum": [6, "foo", [], true, {"foo": 12}]}, + "tests": [ + { + "description": "one of the enum is valid", + "data": [], + "valid": true + }, + { + "description": "something else is invalid", + "data": null, + "valid": false + }, + { + "description": "objects are deep compared", + "data": {"foo": false}, + "valid": false + } + ] + }, + { + "description": "enums in properties", + "schema": { + "type":"object", + "properties": { + "foo": {"enum":["foo"]}, + "bar": {"enum":["bar"]} + }, + "required": ["bar"] + }, + "tests": [ + { + "description": "both properties are valid", + "data": {"foo":"foo", "bar":"bar"}, + "valid": true + }, + { + "description": "missing optional property is valid", + "data": {"bar":"bar"}, + "valid": true + }, + { + "description": "missing required property is invalid", + "data": {"foo":"foo"}, + "valid": false + }, + { + "description": "missing all properties is invalid", + "data": {}, + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/items.json b/contrib/libucl/tests/schema/items.json new file mode 100644 index 0000000..f5e18a1 --- /dev/null +++ b/contrib/libucl/tests/schema/items.json @@ -0,0 +1,46 @@ +[ + { + "description": "a schema given for items", + "schema": { + "items": {"type": "integer"} + }, + "tests": [ + { + "description": "valid items", + "data": [ 1, 2, 3 ], + "valid": true + }, + { + "description": "wrong type of items", + "data": [1, "x"], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": {"foo" : "bar"}, + "valid": true + } + ] + }, + { + "description": "an array of schemas for items", + "schema": { + "items": [ + {"type": "integer"}, + {"type": "string"} + ] + }, + "tests": [ + { + "description": "correct types", + "data": [ 1, "foo" ], + "valid": true + }, + { + "description": "wrong types", + "data": [ "foo", 1 ], + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/maxItems.json b/contrib/libucl/tests/schema/maxItems.json new file mode 100644 index 0000000..3b53a6b --- /dev/null +++ b/contrib/libucl/tests/schema/maxItems.json @@ -0,0 +1,28 @@ +[ + { + "description": "maxItems validation", + "schema": {"maxItems": 2}, + "tests": [ + { + "description": "shorter is valid", + "data": [1], + "valid": true + }, + { + "description": "exact length is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "too long is invalid", + "data": [1, 2, 3], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "foobar", + "valid": true + } + ] + } +] diff --git a/contrib/libucl/tests/schema/maxLength.json b/contrib/libucl/tests/schema/maxLength.json new file mode 100644 index 0000000..561767b --- /dev/null +++ b/contrib/libucl/tests/schema/maxLength.json @@ -0,0 +1,28 @@ +[ + { + "description": "maxLength validation", + "schema": {"maxLength": 2}, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 10, + "valid": true + } + ] + } +] diff --git a/contrib/libucl/tests/schema/maxProperties.json b/contrib/libucl/tests/schema/maxProperties.json new file mode 100644 index 0000000..d282446 --- /dev/null +++ b/contrib/libucl/tests/schema/maxProperties.json @@ -0,0 +1,28 @@ +[ + { + "description": "maxProperties validation", + "schema": {"maxProperties": 2}, + "tests": [ + { + "description": "shorter is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "exact length is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "too long is invalid", + "data": {"foo": 1, "bar": 2, "baz": 3}, + "valid": false + }, + { + "description": "ignores non-objects", + "data": "foobar", + "valid": true + } + ] + } +] diff --git a/contrib/libucl/tests/schema/maximum.json b/contrib/libucl/tests/schema/maximum.json new file mode 100644 index 0000000..86c7b89 --- /dev/null +++ b/contrib/libucl/tests/schema/maximum.json @@ -0,0 +1,42 @@ +[ + { + "description": "maximum validation", + "schema": {"maximum": 3.0}, + "tests": [ + { + "description": "below the maximum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "exclusiveMaximum validation", + "schema": { + "maximum": 3.0, + "exclusiveMaximum": true + }, + "tests": [ + { + "description": "below the maximum is still valid", + "data": 2.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 3.0, + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/minItems.json b/contrib/libucl/tests/schema/minItems.json new file mode 100644 index 0000000..ed51188 --- /dev/null +++ b/contrib/libucl/tests/schema/minItems.json @@ -0,0 +1,28 @@ +[ + { + "description": "minItems validation", + "schema": {"minItems": 1}, + "tests": [ + { + "description": "longer is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "exact length is valid", + "data": [1], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "", + "valid": true + } + ] + } +] diff --git a/contrib/libucl/tests/schema/minLength.json b/contrib/libucl/tests/schema/minLength.json new file mode 100644 index 0000000..e9c14b1 --- /dev/null +++ b/contrib/libucl/tests/schema/minLength.json @@ -0,0 +1,28 @@ +[ + { + "description": "minLength validation", + "schema": {"minLength": 2}, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 1, + "valid": true + } + ] + } +] diff --git a/contrib/libucl/tests/schema/minProperties.json b/contrib/libucl/tests/schema/minProperties.json new file mode 100644 index 0000000..a72c7d2 --- /dev/null +++ b/contrib/libucl/tests/schema/minProperties.json @@ -0,0 +1,28 @@ +[ + { + "description": "minProperties validation", + "schema": {"minProperties": 1}, + "tests": [ + { + "description": "longer is valid", + "data": {"foo": 1, "bar": 2}, + "valid": true + }, + { + "description": "exact length is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false + }, + { + "description": "ignores non-objects", + "data": "", + "valid": true + } + ] + } +] diff --git a/contrib/libucl/tests/schema/minimum.json b/contrib/libucl/tests/schema/minimum.json new file mode 100644 index 0000000..d5bf000 --- /dev/null +++ b/contrib/libucl/tests/schema/minimum.json @@ -0,0 +1,42 @@ +[ + { + "description": "minimum validation", + "schema": {"minimum": 1.1}, + "tests": [ + { + "description": "above the minimum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "below the minimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "exclusiveMinimum validation", + "schema": { + "minimum": 1.1, + "exclusiveMinimum": true + }, + "tests": [ + { + "description": "above the minimum is still valid", + "data": 1.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 1.1, + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/multipleOf.json b/contrib/libucl/tests/schema/multipleOf.json new file mode 100644 index 0000000..ca3b761 --- /dev/null +++ b/contrib/libucl/tests/schema/multipleOf.json @@ -0,0 +1,60 @@ +[ + { + "description": "by int", + "schema": {"multipleOf": 2}, + "tests": [ + { + "description": "int by int", + "data": 10, + "valid": true + }, + { + "description": "int by int fail", + "data": 7, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "by number", + "schema": {"multipleOf": 1.5}, + "tests": [ + { + "description": "zero is multiple of anything", + "data": 0, + "valid": true + }, + { + "description": "4.5 is multiple of 1.5", + "data": 4.5, + "valid": true + }, + { + "description": "35 is not multiple of 1.5", + "data": 35, + "valid": false + } + ] + }, + { + "description": "by small number", + "schema": {"multipleOf": 0.0001}, + "tests": [ + { + "description": "0.0075 is multiple of 0.0001", + "data": 0.0075, + "valid": true + }, + { + "description": "0.00751 is not multiple of 0.0001", + "data": 0.00751, + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/not.json b/contrib/libucl/tests/schema/not.json new file mode 100644 index 0000000..cbb7f46 --- /dev/null +++ b/contrib/libucl/tests/schema/not.json @@ -0,0 +1,96 @@ +[ + { + "description": "not", + "schema": { + "not": {"type": "integer"} + }, + "tests": [ + { + "description": "allowed", + "data": "foo", + "valid": true + }, + { + "description": "disallowed", + "data": 1, + "valid": false + } + ] + }, + { + "description": "not multiple types", + "schema": { + "not": {"type": ["integer", "boolean"]} + }, + "tests": [ + { + "description": "valid", + "data": "foo", + "valid": true + }, + { + "description": "mismatch", + "data": 1, + "valid": false + }, + { + "description": "other mismatch", + "data": true, + "valid": false + } + ] + }, + { + "description": "not more complex schema", + "schema": { + "not": { + "type": "object", + "properties": { + "foo": { + "type": "string" + } + } + } + }, + "tests": [ + { + "description": "match", + "data": 1, + "valid": true + }, + { + "description": "other match", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "mismatch", + "data": {"foo": "bar"}, + "valid": false + } + ] + }, + { + "description": "forbidden property", + "schema": { + "properties": { + "foo": { + "not": {} + } + } + }, + "tests": [ + { + "description": "property present", + "data": {"foo": 1, "bar": 2}, + "valid": false + }, + { + "description": "property absent", + "data": {"bar": 1, "baz": 2}, + "valid": true + } + ] + } + +] diff --git a/contrib/libucl/tests/schema/oneOf.json b/contrib/libucl/tests/schema/oneOf.json new file mode 100644 index 0000000..1eaa4e4 --- /dev/null +++ b/contrib/libucl/tests/schema/oneOf.json @@ -0,0 +1,68 @@ +[ + { + "description": "oneOf", + "schema": { + "oneOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": 1, + "valid": true + }, + { + "description": "second oneOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both oneOf valid", + "data": 3, + "valid": false + }, + { + "description": "neither oneOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "oneOf with base schema", + "schema": { + "type": "string", + "oneOf" : [ + { + "minLength": 2 + }, + { + "maxLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one oneOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both oneOf valid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/pattern.json b/contrib/libucl/tests/schema/pattern.json new file mode 100644 index 0000000..befc4b5 --- /dev/null +++ b/contrib/libucl/tests/schema/pattern.json @@ -0,0 +1,23 @@ +[ + { + "description": "pattern validation", + "schema": {"pattern": "^a*$"}, + "tests": [ + { + "description": "a matching pattern is valid", + "data": "aaa", + "valid": true + }, + { + "description": "a non-matching pattern is invalid", + "data": "abc", + "valid": false + }, + { + "description": "ignores non-strings", + "data": true, + "valid": true + } + ] + } +] diff --git a/contrib/libucl/tests/schema/patternProperties.json b/contrib/libucl/tests/schema/patternProperties.json new file mode 100644 index 0000000..18586e5 --- /dev/null +++ b/contrib/libucl/tests/schema/patternProperties.json @@ -0,0 +1,110 @@ +[ + { + "description": + "patternProperties validates properties matching a regex", + "schema": { + "patternProperties": { + "f.*o": {"type": "integer"} + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "multiple valid matches is valid", + "data": {"foo": 1, "foooooo" : 2}, + "valid": true + }, + { + "description": "a single invalid match is invalid", + "data": {"foo": "bar", "fooooo": 2}, + "valid": false + }, + { + "description": "multiple invalid matches is invalid", + "data": {"foo": "bar", "foooooo" : "baz"}, + "valid": false + }, + { + "description": "ignores non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "multiple simultaneous patternProperties are validated", + "schema": { + "patternProperties": { + "a*": {"type": "integer"}, + "aaa*": {"maximum": 20} + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": {"a": 21}, + "valid": true + }, + { + "description": "a simultaneous match is valid", + "data": {"aaaa": 18}, + "valid": true + }, + { + "description": "multiple matches is valid", + "data": {"a": 21, "aaaa": 18}, + "valid": true + }, + { + "description": "an invalid due to one is invalid", + "data": {"a": "bar"}, + "valid": false + }, + { + "description": "an invalid due to the other is invalid", + "data": {"aaaa": 31}, + "valid": false + }, + { + "description": "an invalid due to both is invalid", + "data": {"aaa": "foo", "aaaa": 31}, + "valid": false + } + ] + }, + { + "description": "regexes are not anchored by default and are case sensitive", + "schema": { + "patternProperties": { + "[0-9]{2,}": { "type": "boolean" }, + "X_": { "type": "string" } + } + }, + "tests": [ + { + "description": "non recognized members are ignored", + "data": { "answer 1": "42" }, + "valid": true + }, + { + "description": "recognized members are accounted for", + "data": { "a31b": null }, + "valid": false + }, + { + "description": "regexes are case sensitive", + "data": { "a_x_3": 3 }, + "valid": true + }, + { + "description": "regexes are case sensitive, 2", + "data": { "a_X_3": 3 }, + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/properties.json b/contrib/libucl/tests/schema/properties.json new file mode 100644 index 0000000..cd1644d --- /dev/null +++ b/contrib/libucl/tests/schema/properties.json @@ -0,0 +1,92 @@ +[ + { + "description": "object properties validation", + "schema": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"type": "string"} + } + }, + "tests": [ + { + "description": "both properties present and valid is valid", + "data": {"foo": 1, "bar": "baz"}, + "valid": true + }, + { + "description": "one property invalid is invalid", + "data": {"foo": 1, "bar": {}}, + "valid": false + }, + { + "description": "both properties invalid is invalid", + "data": {"foo": [], "bar": {}}, + "valid": false + }, + { + "description": "doesn't invalidate other properties", + "data": {"quux": []}, + "valid": true + }, + { + "description": "ignores non-objects", + "data": [], + "valid": true + } + ] + }, + { + "description": + "properties, patternProperties, additionalProperties interaction", + "schema": { + "properties": { + "foo": {"type": "array", "maxItems": 3}, + "bar": {"type": "array"} + }, + "patternProperties": {"f.o": {"minItems": 2}}, + "additionalProperties": {"type": "integer"} + }, + "tests": [ + { + "description": "property validates property", + "data": {"foo": [1, 2]}, + "valid": true + }, + { + "description": "property invalidates property", + "data": {"foo": [1, 2, 3, 4]}, + "valid": false + }, + { + "description": "patternProperty invalidates property", + "data": {"foo": []}, + "valid": false + }, + { + "description": "patternProperty validates nonproperty", + "data": {"fxo": [1, 2]}, + "valid": true + }, + { + "description": "patternProperty invalidates nonproperty", + "data": {"fxo": []}, + "valid": false + }, + { + "description": "additionalProperty ignores property", + "data": {"bar": []}, + "valid": true + }, + { + "description": "additionalProperty validates others", + "data": {"quux": 3}, + "valid": true + }, + { + "description": "additionalProperty invalidates others", + "data": {"quux": "foo"}, + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/ref.json b/contrib/libucl/tests/schema/ref.json new file mode 100644 index 0000000..1b88b27 --- /dev/null +++ b/contrib/libucl/tests/schema/ref.json @@ -0,0 +1,146 @@ +[ + { + "description": "root pointer ref", + "schema": { + "properties": { + "foo": {"$ref": "#"} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": {"foo": false}, + "valid": true + }, + { + "description": "recursive match", + "data": {"foo": {"foo": false}}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": false}, + "valid": false + }, + { + "description": "recursive mismatch", + "data": {"foo": {"bar": false}}, + "valid": false + } + ] + }, + { + "description": "relative pointer ref to object", + "schema": { + "properties": { + "foo": {"type": "integer"}, + "bar": {"$ref": "#/properties/foo"} + } + }, + "tests": [ + { + "description": "match", + "data": {"bar": 3}, + "valid": true + }, + { + "description": "mismatch", + "data": {"bar": true}, + "valid": false + } + ] + }, + { + "description": "relative pointer ref to array", + "schema": { + "items": [ + {"type": "integer"}, + {"$ref": "#/items/0"} + ] + }, + "tests": [ + { + "description": "match array", + "data": [1, 2], + "valid": true + }, + { + "description": "mismatch array", + "data": [1, "foo"], + "valid": false + } + ] + }, + { + "description": "escaped pointer ref", + "schema": { + "tilda~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"}, + "properties": { + "tilda": {"$ref": "#/tilda~0field"}, + "slash": {"$ref": "#/slash~1field"}, + "percent": {"$ref": "#/percent%25field"} + } + }, + "tests": [ + { + "description": "slash", + "data": {"slash": "aoeu"}, + "valid": false + }, + { + "description": "tilda", + "data": {"tilda": "aoeu"}, + "valid": false + }, + { + "description": "percent", + "data": {"percent": "aoeu"}, + "valid": false + } + ] + }, + { + "description": "nested refs", + "schema": { + "definitions": { + "a": {"type": "integer"}, + "b": {"$ref": "#/definitions/a"}, + "c": {"$ref": "#/definitions/b"} + }, + "$ref": "#/definitions/c" + }, + "tests": [ + { + "description": "nested ref valid", + "data": 5, + "valid": true + }, + { + "description": "nested ref invalid", + "data": "a", + "valid": false + } + ] + }, +/* + { + "description": "remote ref, containing refs itself", + "schema": {"$ref": "http://json-schema.org/draft-04/schema#"}, + "tests": [ + { + "description": "remote ref valid", + "data": {"minLength": 1}, + "valid": true + }, + { + "description": "remote ref invalid", + "data": {"minLength": -1}, + "valid": false + } + ] + } +*/ +] diff --git a/contrib/libucl/tests/schema/refRemote.json b/contrib/libucl/tests/schema/refRemote.json new file mode 100644 index 0000000..4ca8047 --- /dev/null +++ b/contrib/libucl/tests/schema/refRemote.json @@ -0,0 +1,74 @@ +[ + { + "description": "remote ref", + "schema": {"$ref": "http://localhost:1234/integer.json"}, + "tests": [ + { + "description": "remote ref valid", + "data": 1, + "valid": true + }, + { + "description": "remote ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "fragment within remote ref", + "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, + "tests": [ + { + "description": "remote fragment valid", + "data": 1, + "valid": true + }, + { + "description": "remote fragment invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "ref within remote ref", + "schema": { + "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" + }, + "tests": [ + { + "description": "ref within ref valid", + "data": 1, + "valid": true + }, + { + "description": "ref within ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "change resolution scope", + "schema": { + "id": "http://localhost:1234/", + "items": { + "id": "folder/", + "items": {"$ref": "folderInteger.json"} + } + }, + "tests": [ + { + "description": "changed scope ref valid", + "data": [[1]], + "valid": true + }, + { + "description": "changed scope ref invalid", + "data": [["a"]], + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/required.json b/contrib/libucl/tests/schema/required.json new file mode 100644 index 0000000..612f73f --- /dev/null +++ b/contrib/libucl/tests/schema/required.json @@ -0,0 +1,39 @@ +[ + { + "description": "required validation", + "schema": { + "properties": { + "foo": {}, + "bar": {} + }, + "required": ["foo"] + }, + "tests": [ + { + "description": "present required property is valid", + "data": {"foo": 1}, + "valid": true + }, + { + "description": "non-present required property is invalid", + "data": {"bar": 1}, + "valid": false + } + ] + }, + { + "description": "required default validation", + "schema": { + "properties": { + "foo": {} + } + }, + "tests": [ + { + "description": "not required by default", + "data": {}, + "valid": true + } + ] + } +] diff --git a/contrib/libucl/tests/schema/type.json b/contrib/libucl/tests/schema/type.json new file mode 100644 index 0000000..257f051 --- /dev/null +++ b/contrib/libucl/tests/schema/type.json @@ -0,0 +1,330 @@ +[ + { + "description": "integer type matches integers", + "schema": {"type": "integer"}, + "tests": [ + { + "description": "an integer is an integer", + "data": 1, + "valid": true + }, + { + "description": "a float is not an integer", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an integer", + "data": "foo", + "valid": false + }, + { + "description": "an object is not an integer", + "data": {}, + "valid": false + }, + { + "description": "an array is not an integer", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an integer", + "data": true, + "valid": false + }, + { + "description": "null is not an integer", + "data": null, + "valid": false + } + ] + }, + { + "description": "number type matches numbers", + "schema": {"type": "number"}, + "tests": [ + { + "description": "an integer is a number", + "data": 1, + "valid": true + }, + { + "description": "a float is a number", + "data": 1.1, + "valid": true + }, + { + "description": "a string is not a number", + "data": "foo", + "valid": false + }, + { + "description": "an object is not a number", + "data": {}, + "valid": false + }, + { + "description": "an array is not a number", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a number", + "data": true, + "valid": false + }, + { + "description": "null is not a number", + "data": null, + "valid": false + } + ] + }, + { + "description": "string type matches strings", + "schema": {"type": "string"}, + "tests": [ + { + "description": "1 is not a string", + "data": 1, + "valid": false + }, + { + "description": "a float is not a string", + "data": 1.1, + "valid": false + }, + { + "description": "a string is a string", + "data": "foo", + "valid": true + }, + { + "description": "an object is not a string", + "data": {}, + "valid": false + }, + { + "description": "an array is not a string", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a string", + "data": true, + "valid": false + }, + { + "description": "null is not a string", + "data": null, + "valid": false + } + ] + }, + { + "description": "object type matches objects", + "schema": {"type": "object"}, + "tests": [ + { + "description": "an integer is not an object", + "data": 1, + "valid": false + }, + { + "description": "a float is not an object", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an object", + "data": "foo", + "valid": false + }, + { + "description": "an object is an object", + "data": {}, + "valid": true + }, + { + "description": "an array is not an object", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an object", + "data": true, + "valid": false + }, + { + "description": "null is not an object", + "data": null, + "valid": false + } + ] + }, + { + "description": "array type matches arrays", + "schema": {"type": "array"}, + "tests": [ + { + "description": "an integer is not an array", + "data": 1, + "valid": false + }, + { + "description": "a float is not an array", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an array", + "data": "foo", + "valid": false + }, + { + "description": "an object is not an array", + "data": {}, + "valid": false + }, + { + "description": "an array is not an array", + "data": [], + "valid": true + }, + { + "description": "a boolean is not an array", + "data": true, + "valid": false + }, + { + "description": "null is not an array", + "data": null, + "valid": false + } + ] + }, + { + "description": "boolean type matches booleans", + "schema": {"type": "boolean"}, + "tests": [ + { + "description": "an integer is not a boolean", + "data": 1, + "valid": false + }, + { + "description": "a float is not a boolean", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not a boolean", + "data": "foo", + "valid": false + }, + { + "description": "an object is not a boolean", + "data": {}, + "valid": false + }, + { + "description": "an array is not a boolean", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a boolean", + "data": true, + "valid": true + }, + { + "description": "null is not a boolean", + "data": null, + "valid": false + } + ] + }, + { + "description": "null type matches only the null object", + "schema": {"type": "null"}, + "tests": [ + { + "description": "an integer is not null", + "data": 1, + "valid": false + }, + { + "description": "a float is not null", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not null", + "data": "foo", + "valid": false + }, + { + "description": "an object is not null", + "data": {}, + "valid": false + }, + { + "description": "an array is not null", + "data": [], + "valid": false + }, + { + "description": "a boolean is not null", + "data": true, + "valid": false + }, + { + "description": "null is null", + "data": null, + "valid": true + } + ] + }, + { + "description": "multiple types can be specified in an array", + "schema": {"type": ["integer", "string"]}, + "tests": [ + { + "description": "an integer is valid", + "data": 1, + "valid": true + }, + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a float is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "an object is invalid", + "data": {}, + "valid": false + }, + { + "description": "an array is invalid", + "data": [], + "valid": false + }, + { + "description": "a boolean is invalid", + "data": true, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/schema/uniqueItems.json b/contrib/libucl/tests/schema/uniqueItems.json new file mode 100644 index 0000000..c1f4ab9 --- /dev/null +++ b/contrib/libucl/tests/schema/uniqueItems.json @@ -0,0 +1,79 @@ +[ + { + "description": "uniqueItems validation", + "schema": {"uniqueItems": true}, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [1, 2], + "valid": true + }, + { + "description": "non-unique array of integers is invalid", + "data": [1, 1], + "valid": false + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [1.0, 1.00, 1], + "valid": false + }, + { + "description": "unique array of objects is valid", + "data": [{"foo": "bar"}, {"foo": "baz"}], + "valid": true + }, + { + "description": "non-unique array of objects is invalid", + "data": [{"foo": "bar"}, {"foo": "bar"}], + "valid": false + }, + { + "description": "unique array of nested objects is valid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : false}}} + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is invalid", + "data": [ + {"foo": {"bar" : {"baz" : true}}}, + {"foo": {"bar" : {"baz" : true}}} + ], + "valid": false + }, + { + "description": "unique array of arrays is valid", + "data": [["foo"], ["bar"]], + "valid": true + }, + { + "description": "non-unique array of arrays is invalid", + "data": [["foo"], ["foo"]], + "valid": false + }, + { + "description": "1 and true are unique", + "data": [1, true], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [0, false], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [{}, [1], true, null, 1], + "valid": true + }, + { + "description": "non-unique heterogeneous types are invalid", + "data": [{}, [1], true, null, {}, 1], + "valid": false + } + ] + } +] diff --git a/contrib/libucl/tests/speed.test b/contrib/libucl/tests/speed.test new file mode 100755 index 0000000..34db653 --- /dev/null +++ b/contrib/libucl/tests/speed.test @@ -0,0 +1,21 @@ +#!/bin/sh + +PROG=${TEST_BINARY_DIR}/test_speed + +sh -c "xz -c < /dev/null > /dev/null" +echo 'Running speed tests' +for _tin in ${TEST_DIR}/*.xz ; do + echo "Unpacking $_tin..." + xz -cd < $_tin > ${TEST_OUT_DIR}/test_file + # Preread file to cheat benchmark! + cat ${TEST_OUT_DIR}/test_file > /dev/null + echo "Starting benchmarking for $_tin..." + $PROG ${TEST_OUT_DIR}/test_file + if [ $? -ne 0 ] ; then + echo "Test: $_tin failed" + rm ${TEST_OUT_DIR}/test_file + exit 1 + fi + rm ${TEST_OUT_DIR}/test_file +done + diff --git a/contrib/libucl/tests/test_basic.c b/contrib/libucl/tests/test_basic.c index 641679f..5a977aa 100644 --- a/contrib/libucl/tests/test_basic.c +++ b/contrib/libucl/tests/test_basic.c @@ -21,10 +21,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <stdio.h> -#include <errno.h> -#include <unistd.h> #include "ucl.h" +#include "ucl_internal.h" int main (int argc, char **argv) @@ -80,7 +78,9 @@ main (int argc, char **argv) while (!feof (in)) { memset (inbuf, 0, sizeof (inbuf)); - (void)fread (inbuf, sizeof (inbuf) - 1, 1, in); + if (fread (inbuf, 1, sizeof (inbuf) - 1, in) == 0) { + break; + } inlen = strlen (inbuf); test_in = malloc (inlen); memcpy (test_in, inbuf, inlen); @@ -97,7 +97,7 @@ main (int argc, char **argv) else { out = stdout; } - if (ucl_parser_get_error(parser) != NULL) { + if (ucl_parser_get_error (parser) != NULL) { fprintf (out, "Error occurred: %s\n", ucl_parser_get_error(parser)); ret = 1; goto end; @@ -112,7 +112,7 @@ main (int argc, char **argv) ucl_parser_free (parser); ucl_object_unref (obj); parser2 = ucl_parser_new (UCL_PARSER_KEY_LOWERCASE); - ucl_parser_add_chunk (parser2, emitted, strlen (emitted)); + ucl_parser_add_string (parser2, emitted, 0); if (ucl_parser_get_error(parser2) != NULL) { fprintf (out, "Error occurred: %s\n", ucl_parser_get_error(parser2)); diff --git a/contrib/libucl/tests/test_generate.c b/contrib/libucl/tests/test_generate.c index b2081ba..5c130e6 100644 --- a/contrib/libucl/tests/test_generate.c +++ b/contrib/libucl/tests/test_generate.c @@ -29,7 +29,8 @@ int main (int argc, char **argv) { - ucl_object_t *obj, *cur, *ar; + ucl_object_t *obj, *cur, *ar, *ref; + const ucl_object_t *found; FILE *out; unsigned char *emitted; const char *fname_out = NULL; @@ -55,62 +56,81 @@ main (int argc, char **argv) obj = ucl_object_typed_new (UCL_OBJECT); /* Create some strings */ cur = ucl_object_fromstring_common (" test string ", 0, UCL_STRING_TRIM); - obj = ucl_object_insert_key (obj, cur, "key1", 0, false); + ucl_object_insert_key (obj, cur, "key1", 0, false); cur = ucl_object_fromstring_common (" test \nstring\n ", 0, UCL_STRING_TRIM | UCL_STRING_ESCAPE); - obj = ucl_object_insert_key (obj, cur, "key2", 0, false); + ucl_object_insert_key (obj, cur, "key2", 0, false); cur = ucl_object_fromstring_common (" test string \n", 0, 0); - obj = ucl_object_insert_key (obj, cur, "key3", 0, false); + ucl_object_insert_key (obj, cur, "key3", 0, false); /* Array of numbers */ + ar = ucl_object_typed_new (UCL_ARRAY); cur = ucl_object_fromint (10); - ar = ucl_array_append (NULL, cur); + ucl_array_append (ar, cur); cur = ucl_object_fromdouble (10.1); - ar = ucl_array_append (ar, cur); + ucl_array_append (ar, cur); cur = ucl_object_fromdouble (9.999); - ar = ucl_array_prepend (ar, cur); + ucl_array_prepend (ar, cur); /* Removing from an array */ cur = ucl_object_fromdouble (1.0); - ar = ucl_array_append (ar, cur); + ucl_array_append (ar, cur); cur = ucl_array_delete (ar, cur); assert (ucl_object_todouble (cur) == 1.0); ucl_object_unref (cur); cur = ucl_object_fromdouble (2.0); - ar = ucl_array_append (ar, cur); + ucl_array_append (ar, cur); cur = ucl_array_pop_last (ar); assert (ucl_object_todouble (cur) == 2.0); ucl_object_unref (cur); cur = ucl_object_fromdouble (3.0); - ar = ucl_array_prepend (ar, cur); + ucl_array_prepend (ar, cur); cur = ucl_array_pop_first (ar); assert (ucl_object_todouble (cur) == 3.0); ucl_object_unref (cur); - obj = ucl_object_insert_key (obj, ar, "key4", 0, false); + ucl_object_insert_key (obj, ar, "key4", 0, false); cur = ucl_object_frombool (true); - obj = ucl_object_insert_key (obj, cur, "key4", 0, false); + /* Ref object to test refcounts */ + ref = ucl_object_ref (cur); + ucl_object_insert_key (obj, cur, "key4", 0, false); /* Empty strings */ cur = ucl_object_fromstring_common (" ", 0, UCL_STRING_TRIM); - obj = ucl_object_insert_key (obj, cur, "key5", 0, false); + ucl_object_insert_key (obj, cur, "key5", 0, false); cur = ucl_object_fromstring_common ("", 0, UCL_STRING_ESCAPE); - obj = ucl_object_insert_key (obj, cur, "key6", 0, false); + ucl_object_insert_key (obj, cur, "key6", 0, false); cur = ucl_object_fromstring_common (" \n", 0, UCL_STRING_ESCAPE); - obj = ucl_object_insert_key (obj, cur, "key7", 0, false); + ucl_object_insert_key (obj, cur, "key7", 0, false); /* Numbers and booleans */ cur = ucl_object_fromstring_common ("1mb", 0, UCL_STRING_ESCAPE | UCL_STRING_PARSE); - obj = ucl_object_insert_key (obj, cur, "key8", 0, false); + ucl_object_insert_key (obj, cur, "key8", 0, false); cur = ucl_object_fromstring_common ("3.14", 0, UCL_STRING_PARSE); - obj = ucl_object_insert_key (obj, cur, "key9", 0, false); + ucl_object_insert_key (obj, cur, "key9", 0, false); cur = ucl_object_fromstring_common ("true", 0, UCL_STRING_PARSE); - obj = ucl_object_insert_key (obj, cur, "key10", 0, false); + ucl_object_insert_key (obj, cur, "key10", 0, false); cur = ucl_object_fromstring_common (" off ", 0, UCL_STRING_PARSE | UCL_STRING_TRIM); - obj = ucl_object_insert_key (obj, cur, "key11", 0, false); + ucl_object_insert_key (obj, cur, "key11", 0, false); cur = ucl_object_fromstring_common ("gslin@gslin.org", 0, UCL_STRING_PARSE_INT); - obj = ucl_object_insert_key (obj, cur, "key12", 0, false); + ucl_object_insert_key (obj, cur, "key12", 0, false); cur = ucl_object_fromstring_common ("#test", 0, UCL_STRING_PARSE_INT); - obj = ucl_object_insert_key (obj, cur, "key13", 0, false); + ucl_object_insert_key (obj, cur, "key13", 0, false); cur = ucl_object_frombool (true); - obj = ucl_object_insert_key (obj, cur, "k=3", 0, false); + ucl_object_insert_key (obj, cur, "k=3", 0, false); + /* Try to find using path */ + /* Should exist */ + found = ucl_lookup_path (obj, "key4.1"); + assert (found != NULL && ucl_object_toint (found) == 10); + /* . should be ignored */ + found = ucl_lookup_path (obj, ".key4.1"); + assert (found != NULL && ucl_object_toint (found) == 10); + /* moar dots... */ + found = ucl_lookup_path (obj, ".key4........1..."); + assert (found != NULL && ucl_object_toint (found) == 10); + /* No such index */ + found = ucl_lookup_path (obj, ".key4.3"); + assert (found == NULL); + /* No such key */ + found = ucl_lookup_path (obj, "key9..key1"); + assert (found == NULL); emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG); @@ -122,5 +142,9 @@ main (int argc, char **argv) } fclose (out); + /* Ref should still be accessible */ + ref->value.iv = 100500; + ucl_object_unref (ref); + return ret; } diff --git a/contrib/libucl/tests/test_schema.c b/contrib/libucl/tests/test_schema.c new file mode 100644 index 0000000..afce178 --- /dev/null +++ b/contrib/libucl/tests/test_schema.c @@ -0,0 +1,158 @@ +/* Copyright (c) 2014, Vsevolod Stakhov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include "ucl.h" + +static int +read_stdin (char **buf) +{ + int size = BUFSIZ, remain, ret; + char *p; + + *buf = malloc (size); + if (*buf == NULL) { + return -1; + } + + p = *buf; + remain = size; + + while ((ret = read (STDIN_FILENO, p, remain)) > 0) { + remain -= ret; + p += ret; + if (remain == 0) { + *buf = realloc (*buf, size * 2); + if (*buf == NULL) { + return -1; + } + p = *buf + size; + remain = size; + size *= 2; + } + } + + return ret; +} + +static bool +perform_test (const ucl_object_t *schema, const ucl_object_t *obj, + struct ucl_schema_error *err) +{ + const const ucl_object_t *valid, *data, *description; + bool match; + + data = ucl_object_find_key (obj, "data"); + description = ucl_object_find_key (obj, "description"); + valid = ucl_object_find_key (obj, "valid"); + + if (data == NULL || description == NULL || valid == NULL) { + fprintf (stdout, "Bad test case\n"); + return false; + } + + match = ucl_object_validate (schema, data, err); + if (match != ucl_object_toboolean (valid)) { + fprintf (stdout, "Test case '%s' failed (expected %s): '%s'\n", + ucl_object_tostring (description), + ucl_object_toboolean (valid) ? "valid" : "invalid", + err->msg); + return false; + } + + return true; +} + +static int +perform_tests (const ucl_object_t *obj) +{ + struct ucl_schema_error err; + ucl_object_iter_t iter = NULL; + const ucl_object_t *schema, *tests, *description, *test; + + if (obj->type != UCL_OBJECT) { + fprintf (stdout, "Bad test case\n"); + return EXIT_FAILURE; + } + + schema = ucl_object_find_key (obj, "schema"); + tests = ucl_object_find_key (obj, "tests"); + description = ucl_object_find_key (obj, "description"); + + if (schema == NULL || tests == NULL || description == NULL) { + fprintf (stdout, "Bad test case\n"); + return EXIT_FAILURE; + } + + memset (&err, 0, sizeof (err)); + + while ((test = ucl_iterate_object (tests, &iter, true)) != NULL) { + if (!perform_test (schema, test, &err)) { + fprintf (stdout, "Test suite '%s' failed\n", + ucl_object_tostring (description)); + return EXIT_FAILURE; + } + } + + return 0; +} + +int +main (int argc, char **argv) +{ + char *buf = NULL; + struct ucl_parser *parser; + ucl_object_t *obj = NULL; + const ucl_object_t *elt; + ucl_object_iter_t iter = NULL; + int ret = 0; + + if (read_stdin (&buf) == -1) { + exit (EXIT_FAILURE); + } + + parser = ucl_parser_new (0); + + ucl_parser_add_string (parser, buf, 0); + + if (ucl_parser_get_error (parser) != NULL) { + fprintf (stdout, "Error occurred: %s\n", ucl_parser_get_error (parser)); + ret = 1; + return EXIT_FAILURE; + } + obj = ucl_parser_get_object (parser); + ucl_parser_free (parser); + + while ((elt = ucl_iterate_object (obj, &iter, true)) != NULL) { + ret = perform_tests (elt); + if (ret != 0) { + break; + } + } + + ucl_object_unref (obj); + + return ret; +} diff --git a/contrib/libucl/tests/test_speed.c b/contrib/libucl/tests/test_speed.c index cbf290c..56f2e5a 100644 --- a/contrib/libucl/tests/test_speed.c +++ b/contrib/libucl/tests/test_speed.c @@ -32,8 +32,10 @@ #include <time.h> #ifdef __APPLE__ +#ifdef HAVE_MACH_MACH_TIME_H #include <mach/mach_time.h> #endif +#endif #include "ucl.h" |