rj_schema 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +18 -0
- data/ext/rj_schema/extconf.rb +7 -0
- data/ext/rj_schema/rapidjson/CHANGELOG.md +158 -0
- data/ext/rj_schema/rapidjson/CMakeLists.txt +221 -0
- data/ext/rj_schema/rapidjson/CMakeModules/FindGTestSrc.cmake +30 -0
- data/ext/rj_schema/rapidjson/RapidJSON.pc.in +7 -0
- data/ext/rj_schema/rapidjson/RapidJSONConfig.cmake.in +15 -0
- data/ext/rj_schema/rapidjson/RapidJSONConfigVersion.cmake.in +10 -0
- data/ext/rj_schema/rapidjson/appveyor.yml +41 -0
- data/ext/rj_schema/rapidjson/bin/data/glossary.json +22 -0
- data/ext/rj_schema/rapidjson/bin/data/menu.json +27 -0
- data/ext/rj_schema/rapidjson/bin/data/readme.txt +1 -0
- data/ext/rj_schema/rapidjson/bin/data/sample.json +3315 -0
- data/ext/rj_schema/rapidjson/bin/data/webapp.json +88 -0
- data/ext/rj_schema/rapidjson/bin/data/widget.json +26 -0
- data/ext/rj_schema/rapidjson/bin/draft-04/schema +150 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf16be.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf16bebom.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf16le.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf16lebom.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf32be.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf32bebom.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf32le.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf32lebom.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf8.json +7 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf8bom.json +7 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail1.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail10.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail11.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail12.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail13.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail14.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail15.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail16.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail17.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail18.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail19.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail2.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail20.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail21.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail22.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail23.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail24.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail25.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail26.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail27.json +2 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail28.json +2 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail29.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail3.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail30.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail31.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail32.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail33.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail4.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail5.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail6.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail7.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail8.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail9.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/pass1.json +58 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/pass2.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/pass3.json +6 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/readme.txt +3 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/LICENSE +19 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/README.md +148 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/bin/jsonschema_suite +283 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/folder/folderInteger.json +3 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/integer.json +3 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/subSchemas.json +8 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/additionalItems.json +82 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/additionalProperties.json +88 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/default.json +49 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/dependencies.json +108 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/disallow.json +80 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/divisibleBy.json +60 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/enum.json +71 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/extends.json +94 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/items.json +46 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maxItems.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maxLength.json +33 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maximum.json +42 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minItems.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minLength.json +33 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minimum.json +42 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/bignum.json +107 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/format.json +222 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/jsregex.json +18 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/zeroTerminatedFloats.json +15 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/pattern.json +34 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/patternProperties.json +110 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/properties.json +92 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/ref.json +159 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/refRemote.json +74 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/required.json +53 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/type.json +474 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/uniqueItems.json +79 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/additionalItems.json +82 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/additionalProperties.json +88 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/allOf.json +112 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/anyOf.json +68 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/default.json +49 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/definitions.json +32 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/dependencies.json +113 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/enum.json +72 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/items.json +46 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxItems.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxLength.json +33 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxProperties.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maximum.json +42 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minItems.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minLength.json +33 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minProperties.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minimum.json +42 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/multipleOf.json +60 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/not.json +96 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/oneOf.json +68 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/bignum.json +107 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/format.json +148 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/zeroTerminatedFloats.json +15 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/pattern.json +34 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/patternProperties.json +110 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/properties.json +92 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/ref.json +159 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/refRemote.json +74 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/required.json +39 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/type.json +330 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/uniqueItems.json +79 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tox.ini +8 -0
- data/ext/rj_schema/rapidjson/bin/types/booleans.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/floats.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/guids.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/integers.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/mixed.json +592 -0
- data/ext/rj_schema/rapidjson/bin/types/nulls.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/paragraphs.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/readme.txt +1 -0
- data/ext/rj_schema/rapidjson/contrib/natvis/LICENSE +45 -0
- data/ext/rj_schema/rapidjson/contrib/natvis/README.md +7 -0
- data/ext/rj_schema/rapidjson/contrib/natvis/rapidjson.natvis +38 -0
- data/ext/rj_schema/rapidjson/doc/CMakeLists.txt +27 -0
- data/ext/rj_schema/rapidjson/doc/Doxyfile.in +2369 -0
- data/ext/rj_schema/rapidjson/doc/Doxyfile.zh-cn.in +2369 -0
- data/ext/rj_schema/rapidjson/doc/diagram/architecture.dot +50 -0
- data/ext/rj_schema/rapidjson/doc/diagram/architecture.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/insituparsing.dot +65 -0
- data/ext/rj_schema/rapidjson/doc/diagram/insituparsing.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/iterative-parser-states-diagram.dot +62 -0
- data/ext/rj_schema/rapidjson/doc/diagram/iterative-parser-states-diagram.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/makefile +8 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move1.dot +47 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move1.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move2.dot +62 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move2.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move3.dot +60 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move3.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/normalparsing.dot +56 -0
- data/ext/rj_schema/rapidjson/doc/diagram/normalparsing.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/simpledom.dot +54 -0
- data/ext/rj_schema/rapidjson/doc/diagram/simpledom.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/tutorial.dot +58 -0
- data/ext/rj_schema/rapidjson/doc/diagram/tutorial.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/utilityclass.dot +73 -0
- data/ext/rj_schema/rapidjson/doc/diagram/utilityclass.png +0 -0
- data/ext/rj_schema/rapidjson/doc/dom.md +280 -0
- data/ext/rj_schema/rapidjson/doc/dom.zh-cn.md +284 -0
- data/ext/rj_schema/rapidjson/doc/encoding.md +146 -0
- data/ext/rj_schema/rapidjson/doc/encoding.zh-cn.md +152 -0
- data/ext/rj_schema/rapidjson/doc/faq.md +289 -0
- data/ext/rj_schema/rapidjson/doc/faq.zh-cn.md +290 -0
- data/ext/rj_schema/rapidjson/doc/features.md +104 -0
- data/ext/rj_schema/rapidjson/doc/features.zh-cn.md +103 -0
- data/ext/rj_schema/rapidjson/doc/internals.md +368 -0
- data/ext/rj_schema/rapidjson/doc/internals.zh-cn.md +363 -0
- data/ext/rj_schema/rapidjson/doc/logo/rapidjson.png +0 -0
- data/ext/rj_schema/rapidjson/doc/logo/rapidjson.svg +119 -0
- data/ext/rj_schema/rapidjson/doc/misc/DoxygenLayout.xml +194 -0
- data/ext/rj_schema/rapidjson/doc/misc/doxygenextra.css +274 -0
- data/ext/rj_schema/rapidjson/doc/misc/footer.html +11 -0
- data/ext/rj_schema/rapidjson/doc/misc/header.html +24 -0
- data/ext/rj_schema/rapidjson/doc/npm.md +31 -0
- data/ext/rj_schema/rapidjson/doc/performance.md +26 -0
- data/ext/rj_schema/rapidjson/doc/performance.zh-cn.md +26 -0
- data/ext/rj_schema/rapidjson/doc/pointer.md +234 -0
- data/ext/rj_schema/rapidjson/doc/pointer.zh-cn.md +234 -0
- data/ext/rj_schema/rapidjson/doc/sax.md +509 -0
- data/ext/rj_schema/rapidjson/doc/sax.zh-cn.md +487 -0
- data/ext/rj_schema/rapidjson/doc/schema.md +505 -0
- data/ext/rj_schema/rapidjson/doc/schema.zh-cn.md +237 -0
- data/ext/rj_schema/rapidjson/doc/stream.md +426 -0
- data/ext/rj_schema/rapidjson/doc/stream.zh-cn.md +426 -0
- data/ext/rj_schema/rapidjson/doc/tutorial.md +536 -0
- data/ext/rj_schema/rapidjson/doc/tutorial.zh-cn.md +534 -0
- data/ext/rj_schema/rapidjson/docker/debian/Dockerfile +8 -0
- data/ext/rj_schema/rapidjson/example/CMakeLists.txt +45 -0
- data/ext/rj_schema/rapidjson/example/archiver/archiver.cpp +292 -0
- data/ext/rj_schema/rapidjson/example/archiver/archiver.h +145 -0
- data/ext/rj_schema/rapidjson/example/archiver/archivertest.cpp +287 -0
- data/ext/rj_schema/rapidjson/example/capitalize/capitalize.cpp +67 -0
- data/ext/rj_schema/rapidjson/example/condense/condense.cpp +32 -0
- data/ext/rj_schema/rapidjson/example/filterkey/filterkey.cpp +135 -0
- data/ext/rj_schema/rapidjson/example/filterkeydom/filterkeydom.cpp +170 -0
- data/ext/rj_schema/rapidjson/example/jsonx/jsonx.cpp +207 -0
- data/ext/rj_schema/rapidjson/example/lookaheadparser/lookaheadparser.cpp +350 -0
- data/ext/rj_schema/rapidjson/example/messagereader/messagereader.cpp +105 -0
- data/ext/rj_schema/rapidjson/example/parsebyparts/parsebyparts.cpp +176 -0
- data/ext/rj_schema/rapidjson/example/pretty/pretty.cpp +30 -0
- data/ext/rj_schema/rapidjson/example/prettyauto/prettyauto.cpp +56 -0
- data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +78 -0
- data/ext/rj_schema/rapidjson/example/serialize/serialize.cpp +173 -0
- data/ext/rj_schema/rapidjson/example/simpledom/simpledom.cpp +29 -0
- data/ext/rj_schema/rapidjson/example/simplepullreader/simplepullreader.cpp +53 -0
- data/ext/rj_schema/rapidjson/example/simplereader/simplereader.cpp +42 -0
- data/ext/rj_schema/rapidjson/example/simplewriter/simplewriter.cpp +36 -0
- data/ext/rj_schema/rapidjson/example/tutorial/tutorial.cpp +151 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +271 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +78 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/document.h +2630 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/encodedstream.h +299 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +716 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/error/en.h +74 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/error/error.h +161 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/filereadstream.h +99 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/filewritestream.h +104 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/fwd.h +151 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +290 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +258 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/dtoa.h +245 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/ieee754.h +78 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +304 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +181 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/pow10.h +55 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +734 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/stack.h +231 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/strfunc.h +69 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +269 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/swap.h +46 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +115 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/memorybuffer.h +70 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/memorystream.h +71 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/msinttypes/inttypes.h +316 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/msinttypes/stdint.h +300 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/ostreamwrapper.h +81 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +1363 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +277 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +628 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +2222 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +2479 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/stream.h +223 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/stringbuffer.h +121 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +716 -0
- data/ext/rj_schema/rapidjson/include_dirs.js +2 -0
- data/ext/rj_schema/rapidjson/library.json +15 -0
- data/ext/rj_schema/rapidjson/license.txt +57 -0
- data/ext/rj_schema/rapidjson/package.json +24 -0
- data/ext/rj_schema/rapidjson/rapidjson.autopkg +77 -0
- data/ext/rj_schema/rapidjson/readme.md +160 -0
- data/ext/rj_schema/rapidjson/readme.zh-cn.md +152 -0
- data/ext/rj_schema/rapidjson/test/CMakeLists.txt +20 -0
- data/ext/rj_schema/rapidjson/test/perftest/CMakeLists.txt +28 -0
- data/ext/rj_schema/rapidjson/test/perftest/misctest.cpp +974 -0
- data/ext/rj_schema/rapidjson/test/perftest/perftest.cpp +24 -0
- data/ext/rj_schema/rapidjson/test/perftest/perftest.h +185 -0
- data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +166 -0
- data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +472 -0
- data/ext/rj_schema/rapidjson/test/perftest/schematest.cpp +216 -0
- data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +92 -0
- data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +102 -0
- data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +133 -0
- data/ext/rj_schema/rapidjson/test/unittest/cursorstreamwrappertest.cpp +115 -0
- data/ext/rj_schema/rapidjson/test/unittest/documenttest.cpp +672 -0
- data/ext/rj_schema/rapidjson/test/unittest/dtoatest.cpp +98 -0
- data/ext/rj_schema/rapidjson/test/unittest/encodedstreamtest.cpp +313 -0
- data/ext/rj_schema/rapidjson/test/unittest/encodingstest.cpp +451 -0
- data/ext/rj_schema/rapidjson/test/unittest/filestreamtest.cpp +112 -0
- data/ext/rj_schema/rapidjson/test/unittest/fwdtest.cpp +230 -0
- data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +181 -0
- data/ext/rj_schema/rapidjson/test/unittest/itoatest.cpp +160 -0
- data/ext/rj_schema/rapidjson/test/unittest/jsoncheckertest.cpp +143 -0
- data/ext/rj_schema/rapidjson/test/unittest/namespacetest.cpp +70 -0
- data/ext/rj_schema/rapidjson/test/unittest/ostreamwrappertest.cpp +92 -0
- data/ext/rj_schema/rapidjson/test/unittest/pointertest.cpp +1529 -0
- data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +344 -0
- data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +1895 -0
- data/ext/rj_schema/rapidjson/test/unittest/regextest.cpp +638 -0
- data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +2009 -0
- data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +219 -0
- data/ext/rj_schema/rapidjson/test/unittest/strfunctest.cpp +30 -0
- data/ext/rj_schema/rapidjson/test/unittest/stringbuffertest.cpp +192 -0
- data/ext/rj_schema/rapidjson/test/unittest/strtodtest.cpp +132 -0
- data/ext/rj_schema/rapidjson/test/unittest/unittest.cpp +51 -0
- data/ext/rj_schema/rapidjson/test/unittest/unittest.h +140 -0
- data/ext/rj_schema/rapidjson/test/unittest/valuetest.cpp +1829 -0
- data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +598 -0
- data/ext/rj_schema/rapidjson/test/valgrind.supp +17 -0
- data/ext/rj_schema/rapidjson/travis-doxygen.sh +121 -0
- data/ext/rj_schema/rj_schema.cpp +136 -0
- data/lib/rj_schema.rb +7 -0
- metadata +371 -0
@@ -0,0 +1,2009 @@
|
|
1
|
+
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
|
+
//
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
|
4
|
+
//
|
5
|
+
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
|
+
// in compliance with the License. You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://opensource.org/licenses/MIT
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software distributed
|
11
|
+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
12
|
+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
13
|
+
// specific language governing permissions and limitations under the License.
|
14
|
+
|
15
|
+
#include "unittest.h"
|
16
|
+
#include "rapidjson/schema.h"
|
17
|
+
#include "rapidjson/stringbuffer.h"
|
18
|
+
#include "rapidjson/writer.h"
|
19
|
+
|
20
|
+
#ifdef __clang__
|
21
|
+
RAPIDJSON_DIAG_PUSH
|
22
|
+
RAPIDJSON_DIAG_OFF(variadic-macros)
|
23
|
+
#endif
|
24
|
+
|
25
|
+
using namespace rapidjson;
|
26
|
+
|
27
|
+
#define TEST_HASHER(json1, json2, expected) \
|
28
|
+
{\
|
29
|
+
Document d1, d2;\
|
30
|
+
d1.Parse(json1);\
|
31
|
+
ASSERT_FALSE(d1.HasParseError());\
|
32
|
+
d2.Parse(json2);\
|
33
|
+
ASSERT_FALSE(d2.HasParseError());\
|
34
|
+
internal::Hasher<Value, CrtAllocator> h1, h2;\
|
35
|
+
d1.Accept(h1);\
|
36
|
+
d2.Accept(h2);\
|
37
|
+
ASSERT_TRUE(h1.IsValid());\
|
38
|
+
ASSERT_TRUE(h2.IsValid());\
|
39
|
+
/*printf("%s: 0x%016llx\n%s: 0x%016llx\n\n", json1, h1.GetHashCode(), json2, h2.GetHashCode());*/\
|
40
|
+
EXPECT_TRUE(expected == (h1.GetHashCode() == h2.GetHashCode()));\
|
41
|
+
}
|
42
|
+
|
43
|
+
TEST(SchemaValidator, Hasher) {
|
44
|
+
TEST_HASHER("null", "null", true);
|
45
|
+
|
46
|
+
TEST_HASHER("true", "true", true);
|
47
|
+
TEST_HASHER("false", "false", true);
|
48
|
+
TEST_HASHER("true", "false", false);
|
49
|
+
TEST_HASHER("false", "true", false);
|
50
|
+
TEST_HASHER("true", "null", false);
|
51
|
+
TEST_HASHER("false", "null", false);
|
52
|
+
|
53
|
+
TEST_HASHER("1", "1", true);
|
54
|
+
TEST_HASHER("2147483648", "2147483648", true); // 2^31 can only be fit in unsigned
|
55
|
+
TEST_HASHER("-2147483649", "-2147483649", true); // -2^31 - 1 can only be fit in int64_t
|
56
|
+
TEST_HASHER("2147483648", "2147483648", true); // 2^31 can only be fit in unsigned
|
57
|
+
TEST_HASHER("4294967296", "4294967296", true); // 2^32 can only be fit in int64_t
|
58
|
+
TEST_HASHER("9223372036854775808", "9223372036854775808", true); // 2^63 can only be fit in uint64_t
|
59
|
+
TEST_HASHER("1.5", "1.5", true);
|
60
|
+
TEST_HASHER("1", "1.0", true);
|
61
|
+
TEST_HASHER("1", "-1", false);
|
62
|
+
TEST_HASHER("0.0", "-0.0", false);
|
63
|
+
TEST_HASHER("1", "true", false);
|
64
|
+
TEST_HASHER("0", "false", false);
|
65
|
+
TEST_HASHER("0", "null", false);
|
66
|
+
|
67
|
+
TEST_HASHER("\"\"", "\"\"", true);
|
68
|
+
TEST_HASHER("\"\"", "\"\\u0000\"", false);
|
69
|
+
TEST_HASHER("\"Hello\"", "\"Hello\"", true);
|
70
|
+
TEST_HASHER("\"Hello\"", "\"World\"", false);
|
71
|
+
TEST_HASHER("\"Hello\"", "null", false);
|
72
|
+
TEST_HASHER("\"Hello\\u0000\"", "\"Hello\"", false);
|
73
|
+
TEST_HASHER("\"\"", "null", false);
|
74
|
+
TEST_HASHER("\"\"", "true", false);
|
75
|
+
TEST_HASHER("\"\"", "false", false);
|
76
|
+
|
77
|
+
TEST_HASHER("[]", "[ ]", true);
|
78
|
+
TEST_HASHER("[1, true, false]", "[1, true, false]", true);
|
79
|
+
TEST_HASHER("[1, true, false]", "[1, true]", false);
|
80
|
+
TEST_HASHER("[1, 2]", "[2, 1]", false);
|
81
|
+
TEST_HASHER("[[1], 2]", "[[1, 2]]", false);
|
82
|
+
TEST_HASHER("[1, 2]", "[1, [2]]", false);
|
83
|
+
TEST_HASHER("[]", "null", false);
|
84
|
+
TEST_HASHER("[]", "true", false);
|
85
|
+
TEST_HASHER("[]", "false", false);
|
86
|
+
TEST_HASHER("[]", "0", false);
|
87
|
+
TEST_HASHER("[]", "0.0", false);
|
88
|
+
TEST_HASHER("[]", "\"\"", false);
|
89
|
+
|
90
|
+
TEST_HASHER("{}", "{ }", true);
|
91
|
+
TEST_HASHER("{\"a\":1}", "{\"a\":1}", true);
|
92
|
+
TEST_HASHER("{\"a\":1}", "{\"b\":1}", false);
|
93
|
+
TEST_HASHER("{\"a\":1}", "{\"a\":2}", false);
|
94
|
+
TEST_HASHER("{\"a\":1, \"b\":2}", "{\"b\":2, \"a\":1}", true); // Member order insensitive
|
95
|
+
TEST_HASHER("{}", "null", false);
|
96
|
+
TEST_HASHER("{}", "false", false);
|
97
|
+
TEST_HASHER("{}", "true", false);
|
98
|
+
TEST_HASHER("{}", "0", false);
|
99
|
+
TEST_HASHER("{}", "0.0", false);
|
100
|
+
TEST_HASHER("{}", "\"\"", false);
|
101
|
+
}
|
102
|
+
|
103
|
+
// Test cases following http://spacetelescope.github.io/understanding-json-schema
|
104
|
+
|
105
|
+
#define VALIDATE(schema, json, expected) \
|
106
|
+
{\
|
107
|
+
SchemaValidator validator(schema);\
|
108
|
+
Document d;\
|
109
|
+
/*printf("\n%s\n", json);*/\
|
110
|
+
d.Parse(json);\
|
111
|
+
EXPECT_FALSE(d.HasParseError());\
|
112
|
+
EXPECT_TRUE(expected == d.Accept(validator));\
|
113
|
+
EXPECT_TRUE(expected == validator.IsValid());\
|
114
|
+
if ((expected) && !validator.IsValid()) {\
|
115
|
+
StringBuffer sb;\
|
116
|
+
validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);\
|
117
|
+
printf("Invalid schema: %s\n", sb.GetString());\
|
118
|
+
printf("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());\
|
119
|
+
sb.Clear();\
|
120
|
+
validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);\
|
121
|
+
printf("Invalid document: %s\n", sb.GetString());\
|
122
|
+
sb.Clear();\
|
123
|
+
Writer<StringBuffer> w(sb);\
|
124
|
+
validator.GetError().Accept(w);\
|
125
|
+
printf("Validation error: %s\n", sb.GetString());\
|
126
|
+
}\
|
127
|
+
}
|
128
|
+
|
129
|
+
#define INVALIDATE(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error) \
|
130
|
+
{\
|
131
|
+
INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, SchemaValidator, Pointer) \
|
132
|
+
}
|
133
|
+
|
134
|
+
#define INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, \
|
135
|
+
SchemaValidatorType, PointerType) \
|
136
|
+
{\
|
137
|
+
SchemaValidatorType validator(schema);\
|
138
|
+
Document d;\
|
139
|
+
/*printf("\n%s\n", json);*/\
|
140
|
+
d.Parse(json);\
|
141
|
+
EXPECT_FALSE(d.HasParseError());\
|
142
|
+
EXPECT_FALSE(d.Accept(validator));\
|
143
|
+
EXPECT_FALSE(validator.IsValid());\
|
144
|
+
if (validator.GetInvalidSchemaPointer() != PointerType(invalidSchemaPointer)) {\
|
145
|
+
StringBuffer sb;\
|
146
|
+
validator.GetInvalidSchemaPointer().Stringify(sb);\
|
147
|
+
printf("GetInvalidSchemaPointer() Expected: %s Actual: %s\n", invalidSchemaPointer, sb.GetString());\
|
148
|
+
ADD_FAILURE();\
|
149
|
+
}\
|
150
|
+
ASSERT_TRUE(validator.GetInvalidSchemaKeyword() != 0);\
|
151
|
+
if (strcmp(validator.GetInvalidSchemaKeyword(), invalidSchemaKeyword) != 0) {\
|
152
|
+
printf("GetInvalidSchemaKeyword() Expected: %s Actual %s\n", invalidSchemaKeyword, validator.GetInvalidSchemaKeyword());\
|
153
|
+
ADD_FAILURE();\
|
154
|
+
}\
|
155
|
+
if (validator.GetInvalidDocumentPointer() != PointerType(invalidDocumentPointer)) {\
|
156
|
+
StringBuffer sb;\
|
157
|
+
validator.GetInvalidDocumentPointer().Stringify(sb);\
|
158
|
+
printf("GetInvalidDocumentPointer() Expected: %s Actual: %s\n", invalidDocumentPointer, sb.GetString());\
|
159
|
+
ADD_FAILURE();\
|
160
|
+
}\
|
161
|
+
Document e;\
|
162
|
+
e.Parse(error);\
|
163
|
+
if (validator.GetError() != e) {\
|
164
|
+
StringBuffer sb;\
|
165
|
+
Writer<StringBuffer> w(sb);\
|
166
|
+
validator.GetError().Accept(w);\
|
167
|
+
printf("GetError() Expected: %s Actual: %s\n", error, sb.GetString());\
|
168
|
+
ADD_FAILURE();\
|
169
|
+
}\
|
170
|
+
}
|
171
|
+
|
172
|
+
TEST(SchemaValidator, Typeless) {
|
173
|
+
Document sd;
|
174
|
+
sd.Parse("{}");
|
175
|
+
SchemaDocument s(sd);
|
176
|
+
|
177
|
+
VALIDATE(s, "42", true);
|
178
|
+
VALIDATE(s, "\"I'm a string\"", true);
|
179
|
+
VALIDATE(s, "{ \"an\": [ \"arbitrarily\", \"nested\" ], \"data\": \"structure\" }", true);
|
180
|
+
}
|
181
|
+
|
182
|
+
TEST(SchemaValidator, MultiType) {
|
183
|
+
Document sd;
|
184
|
+
sd.Parse("{ \"type\": [\"number\", \"string\"] }");
|
185
|
+
SchemaDocument s(sd);
|
186
|
+
|
187
|
+
VALIDATE(s, "42", true);
|
188
|
+
VALIDATE(s, "\"Life, the universe, and everything\"", true);
|
189
|
+
INVALIDATE(s, "[\"Life\", \"the universe\", \"and everything\"]", "", "type", "",
|
190
|
+
"{ \"type\": {"
|
191
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
192
|
+
" \"expected\": [\"string\", \"number\"], \"actual\": \"array\""
|
193
|
+
"}}");
|
194
|
+
}
|
195
|
+
|
196
|
+
TEST(SchemaValidator, Enum_Typed) {
|
197
|
+
Document sd;
|
198
|
+
sd.Parse("{ \"type\": \"string\", \"enum\" : [\"red\", \"amber\", \"green\"] }");
|
199
|
+
SchemaDocument s(sd);
|
200
|
+
|
201
|
+
VALIDATE(s, "\"red\"", true);
|
202
|
+
INVALIDATE(s, "\"blue\"", "", "enum", "",
|
203
|
+
"{ \"enum\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
|
204
|
+
}
|
205
|
+
|
206
|
+
TEST(SchemaValidator, Enum_Typless) {
|
207
|
+
Document sd;
|
208
|
+
sd.Parse("{ \"enum\": [\"red\", \"amber\", \"green\", null, 42] }");
|
209
|
+
SchemaDocument s(sd);
|
210
|
+
|
211
|
+
VALIDATE(s, "\"red\"", true);
|
212
|
+
VALIDATE(s, "null", true);
|
213
|
+
VALIDATE(s, "42", true);
|
214
|
+
INVALIDATE(s, "0", "", "enum", "",
|
215
|
+
"{ \"enum\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
|
216
|
+
}
|
217
|
+
|
218
|
+
TEST(SchemaValidator, Enum_InvalidType) {
|
219
|
+
Document sd;
|
220
|
+
sd.Parse("{ \"type\": \"string\", \"enum\": [\"red\", \"amber\", \"green\", null] }");
|
221
|
+
SchemaDocument s(sd);
|
222
|
+
|
223
|
+
VALIDATE(s, "\"red\"", true);
|
224
|
+
INVALIDATE(s, "null", "", "type", "",
|
225
|
+
"{ \"type\": {"
|
226
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
227
|
+
" \"expected\": [\"string\"], \"actual\": \"null\""
|
228
|
+
"}}");
|
229
|
+
}
|
230
|
+
|
231
|
+
TEST(SchemaValidator, AllOf) {
|
232
|
+
{
|
233
|
+
Document sd;
|
234
|
+
sd.Parse("{\"allOf\": [{ \"type\": \"string\" }, { \"type\": \"string\", \"maxLength\": 5 }]}");
|
235
|
+
SchemaDocument s(sd);
|
236
|
+
|
237
|
+
VALIDATE(s, "\"ok\"", true);
|
238
|
+
INVALIDATE(s, "\"too long\"", "", "allOf", "",
|
239
|
+
"{ \"maxLength\": { "
|
240
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\", "
|
241
|
+
" \"expected\": 5, \"actual\": \"too long\""
|
242
|
+
"}}");
|
243
|
+
}
|
244
|
+
{
|
245
|
+
Document sd;
|
246
|
+
sd.Parse("{\"allOf\": [{ \"type\": \"string\" }, { \"type\": \"number\" } ] }");
|
247
|
+
SchemaDocument s(sd);
|
248
|
+
|
249
|
+
VALIDATE(s, "\"No way\"", false);
|
250
|
+
INVALIDATE(s, "-1", "", "allOf", "",
|
251
|
+
"{ \"type\": { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
|
252
|
+
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
253
|
+
"}}");
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
TEST(SchemaValidator, AnyOf) {
|
258
|
+
Document sd;
|
259
|
+
sd.Parse("{\"anyOf\": [{ \"type\": \"string\" }, { \"type\": \"number\" } ] }");
|
260
|
+
SchemaDocument s(sd);
|
261
|
+
|
262
|
+
VALIDATE(s, "\"Yes\"", true);
|
263
|
+
VALIDATE(s, "42", true);
|
264
|
+
INVALIDATE(s, "{ \"Not a\": \"string or number\" }", "", "anyOf", "",
|
265
|
+
"{ \"anyOf\": {"
|
266
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\", "
|
267
|
+
" \"errors\": ["
|
268
|
+
" { \"type\": {"
|
269
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/anyOf/0\","
|
270
|
+
" \"expected\": [\"string\"], \"actual\": \"object\""
|
271
|
+
" }},"
|
272
|
+
" { \"type\": {"
|
273
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/anyOf/1\","
|
274
|
+
" \"expected\": [\"number\"], \"actual\": \"object\""
|
275
|
+
" }}"
|
276
|
+
" ]"
|
277
|
+
"}}");
|
278
|
+
}
|
279
|
+
|
280
|
+
TEST(SchemaValidator, OneOf) {
|
281
|
+
Document sd;
|
282
|
+
sd.Parse("{\"oneOf\": [{ \"type\": \"number\", \"multipleOf\": 5 }, { \"type\": \"number\", \"multipleOf\": 3 } ] }");
|
283
|
+
SchemaDocument s(sd);
|
284
|
+
|
285
|
+
VALIDATE(s, "10", true);
|
286
|
+
VALIDATE(s, "9", true);
|
287
|
+
INVALIDATE(s, "2", "", "oneOf", "",
|
288
|
+
"{ \"oneOf\": {"
|
289
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
290
|
+
" \"errors\": ["
|
291
|
+
" { \"multipleOf\": {"
|
292
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/oneOf/0\","
|
293
|
+
" \"expected\": 5, \"actual\": 2"
|
294
|
+
" }},"
|
295
|
+
" { \"multipleOf\": {"
|
296
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/oneOf/1\","
|
297
|
+
" \"expected\": 3, \"actual\": 2"
|
298
|
+
" }}"
|
299
|
+
" ]"
|
300
|
+
"}}");
|
301
|
+
INVALIDATE(s, "15", "", "oneOf", "",
|
302
|
+
"{ \"oneOf\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\", \"errors\": [{}, {}]}}");
|
303
|
+
}
|
304
|
+
|
305
|
+
TEST(SchemaValidator, Not) {
|
306
|
+
Document sd;
|
307
|
+
sd.Parse("{\"not\":{ \"type\": \"string\"}}");
|
308
|
+
SchemaDocument s(sd);
|
309
|
+
|
310
|
+
VALIDATE(s, "42", true);
|
311
|
+
VALIDATE(s, "{ \"key\": \"value\" }", true);
|
312
|
+
INVALIDATE(s, "\"I am a string\"", "", "not", "",
|
313
|
+
"{ \"not\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
|
314
|
+
}
|
315
|
+
|
316
|
+
TEST(SchemaValidator, Ref) {
|
317
|
+
Document sd;
|
318
|
+
sd.Parse(
|
319
|
+
"{"
|
320
|
+
" \"$schema\": \"http://json-schema.org/draft-04/schema#\","
|
321
|
+
""
|
322
|
+
" \"definitions\": {"
|
323
|
+
" \"address\": {"
|
324
|
+
" \"type\": \"object\","
|
325
|
+
" \"properties\": {"
|
326
|
+
" \"street_address\": { \"type\": \"string\" },"
|
327
|
+
" \"city\": { \"type\": \"string\" },"
|
328
|
+
" \"state\": { \"type\": \"string\" }"
|
329
|
+
" },"
|
330
|
+
" \"required\": [\"street_address\", \"city\", \"state\"]"
|
331
|
+
" }"
|
332
|
+
" },"
|
333
|
+
" \"type\": \"object\","
|
334
|
+
" \"properties\": {"
|
335
|
+
" \"billing_address\": { \"$ref\": \"#/definitions/address\" },"
|
336
|
+
" \"shipping_address\": { \"$ref\": \"#/definitions/address\" }"
|
337
|
+
" }"
|
338
|
+
"}");
|
339
|
+
SchemaDocument s(sd);
|
340
|
+
|
341
|
+
VALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\"}, \"billing_address\": {\"street_address\": \"1st Street SE\", \"city\": \"Washington\", \"state\": \"DC\"} }", true);
|
342
|
+
}
|
343
|
+
|
344
|
+
TEST(SchemaValidator, Ref_AllOf) {
|
345
|
+
Document sd;
|
346
|
+
sd.Parse(
|
347
|
+
"{"
|
348
|
+
" \"$schema\": \"http://json-schema.org/draft-04/schema#\","
|
349
|
+
""
|
350
|
+
" \"definitions\": {"
|
351
|
+
" \"address\": {"
|
352
|
+
" \"type\": \"object\","
|
353
|
+
" \"properties\": {"
|
354
|
+
" \"street_address\": { \"type\": \"string\" },"
|
355
|
+
" \"city\": { \"type\": \"string\" },"
|
356
|
+
" \"state\": { \"type\": \"string\" }"
|
357
|
+
" },"
|
358
|
+
" \"required\": [\"street_address\", \"city\", \"state\"]"
|
359
|
+
" }"
|
360
|
+
" },"
|
361
|
+
" \"type\": \"object\","
|
362
|
+
" \"properties\": {"
|
363
|
+
" \"billing_address\": { \"$ref\": \"#/definitions/address\" },"
|
364
|
+
" \"shipping_address\": {"
|
365
|
+
" \"allOf\": ["
|
366
|
+
" { \"$ref\": \"#/definitions/address\" },"
|
367
|
+
" { \"properties\":"
|
368
|
+
" { \"type\": { \"enum\": [ \"residential\", \"business\" ] } },"
|
369
|
+
" \"required\": [\"type\"]"
|
370
|
+
" }"
|
371
|
+
" ]"
|
372
|
+
" }"
|
373
|
+
" }"
|
374
|
+
"}");
|
375
|
+
SchemaDocument s(sd);
|
376
|
+
|
377
|
+
INVALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\"} }", "/properties/shipping_address", "allOf", "/shipping_address",
|
378
|
+
"{ \"required\": {"
|
379
|
+
" \"instanceRef\": \"#/shipping_address\","
|
380
|
+
" \"schemaRef\": \"#/properties/shipping_address/allOf/1\","
|
381
|
+
" \"missing\": [\"type\"]"
|
382
|
+
"}}");
|
383
|
+
VALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\", \"type\": \"business\"} }", true);
|
384
|
+
}
|
385
|
+
|
386
|
+
TEST(SchemaValidator, String) {
|
387
|
+
Document sd;
|
388
|
+
sd.Parse("{\"type\":\"string\"}");
|
389
|
+
SchemaDocument s(sd);
|
390
|
+
|
391
|
+
VALIDATE(s, "\"I'm a string\"", true);
|
392
|
+
INVALIDATE(s, "42", "", "type", "",
|
393
|
+
"{ \"type\": {"
|
394
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
395
|
+
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
396
|
+
"}}");
|
397
|
+
INVALIDATE(s, "2147483648", "", "type", "",
|
398
|
+
"{ \"type\": {"
|
399
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
400
|
+
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
401
|
+
"}}"); // 2^31 can only be fit in unsigned
|
402
|
+
INVALIDATE(s, "-2147483649", "", "type", "",
|
403
|
+
"{ \"type\": {"
|
404
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
405
|
+
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
406
|
+
"}}"); // -2^31 - 1 can only be fit in int64_t
|
407
|
+
INVALIDATE(s, "4294967296", "", "type", "",
|
408
|
+
"{ \"type\": {"
|
409
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
410
|
+
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
411
|
+
"}}"); // 2^32 can only be fit in int64_t
|
412
|
+
INVALIDATE(s, "3.1415926", "", "type", "",
|
413
|
+
"{ \"type\": {"
|
414
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
415
|
+
" \"expected\": [\"string\"], \"actual\": \"number\""
|
416
|
+
"}}");
|
417
|
+
}
|
418
|
+
|
419
|
+
TEST(SchemaValidator, String_LengthRange) {
|
420
|
+
Document sd;
|
421
|
+
sd.Parse("{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}");
|
422
|
+
SchemaDocument s(sd);
|
423
|
+
|
424
|
+
INVALIDATE(s, "\"A\"", "", "minLength", "",
|
425
|
+
"{ \"minLength\": {"
|
426
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
427
|
+
" \"expected\": 2, \"actual\": \"A\""
|
428
|
+
"}}");
|
429
|
+
VALIDATE(s, "\"AB\"", true);
|
430
|
+
VALIDATE(s, "\"ABC\"", true);
|
431
|
+
INVALIDATE(s, "\"ABCD\"", "", "maxLength", "",
|
432
|
+
"{ \"maxLength\": {"
|
433
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
434
|
+
" \"expected\": 3, \"actual\": \"ABCD\""
|
435
|
+
"}}");
|
436
|
+
}
|
437
|
+
|
438
|
+
#if RAPIDJSON_SCHEMA_HAS_REGEX
|
439
|
+
TEST(SchemaValidator, String_Pattern) {
|
440
|
+
Document sd;
|
441
|
+
sd.Parse("{\"type\":\"string\",\"pattern\":\"^(\\\\([0-9]{3}\\\\))?[0-9]{3}-[0-9]{4}$\"}");
|
442
|
+
SchemaDocument s(sd);
|
443
|
+
|
444
|
+
VALIDATE(s, "\"555-1212\"", true);
|
445
|
+
VALIDATE(s, "\"(888)555-1212\"", true);
|
446
|
+
INVALIDATE(s, "\"(888)555-1212 ext. 532\"", "", "pattern", "",
|
447
|
+
"{ \"pattern\": {"
|
448
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
449
|
+
" \"actual\": \"(888)555-1212 ext. 532\""
|
450
|
+
"}}");
|
451
|
+
INVALIDATE(s, "\"(800)FLOWERS\"", "", "pattern", "",
|
452
|
+
"{ \"pattern\": {"
|
453
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
454
|
+
" \"actual\": \"(800)FLOWERS\""
|
455
|
+
"}}");
|
456
|
+
}
|
457
|
+
|
458
|
+
TEST(SchemaValidator, String_Pattern_Invalid) {
|
459
|
+
Document sd;
|
460
|
+
sd.Parse("{\"type\":\"string\",\"pattern\":\"a{0}\"}"); // TODO: report regex is invalid somehow
|
461
|
+
SchemaDocument s(sd);
|
462
|
+
|
463
|
+
VALIDATE(s, "\"\"", true);
|
464
|
+
VALIDATE(s, "\"a\"", true);
|
465
|
+
VALIDATE(s, "\"aa\"", true);
|
466
|
+
}
|
467
|
+
#endif
|
468
|
+
|
469
|
+
TEST(SchemaValidator, Integer) {
|
470
|
+
Document sd;
|
471
|
+
sd.Parse("{\"type\":\"integer\"}");
|
472
|
+
SchemaDocument s(sd);
|
473
|
+
|
474
|
+
VALIDATE(s, "42", true);
|
475
|
+
VALIDATE(s, "-1", true);
|
476
|
+
VALIDATE(s, "2147483648", true); // 2^31 can only be fit in unsigned
|
477
|
+
VALIDATE(s, "-2147483649", true); // -2^31 - 1 can only be fit in int64_t
|
478
|
+
VALIDATE(s, "2147483648", true); // 2^31 can only be fit in unsigned
|
479
|
+
VALIDATE(s, "4294967296", true); // 2^32 can only be fit in int64_t
|
480
|
+
INVALIDATE(s, "3.1415926", "", "type", "",
|
481
|
+
"{ \"type\": {"
|
482
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
483
|
+
" \"expected\": [\"integer\"], \"actual\": \"number\""
|
484
|
+
"}}");
|
485
|
+
INVALIDATE(s, "\"42\"", "", "type", "",
|
486
|
+
"{ \"type\": {"
|
487
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
488
|
+
" \"expected\": [\"integer\"], \"actual\": \"string\""
|
489
|
+
"}}");
|
490
|
+
}
|
491
|
+
|
492
|
+
TEST(SchemaValidator, Integer_Range) {
|
493
|
+
Document sd;
|
494
|
+
sd.Parse("{\"type\":\"integer\",\"minimum\":0,\"maximum\":100,\"exclusiveMaximum\":true}");
|
495
|
+
SchemaDocument s(sd);
|
496
|
+
|
497
|
+
INVALIDATE(s, "-1", "", "minimum", "",
|
498
|
+
"{ \"minimum\": {"
|
499
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
500
|
+
" \"expected\": 0, \"actual\": -1"
|
501
|
+
"}}");
|
502
|
+
VALIDATE(s, "0", true);
|
503
|
+
VALIDATE(s, "10", true);
|
504
|
+
VALIDATE(s, "99", true);
|
505
|
+
INVALIDATE(s, "100", "", "maximum", "",
|
506
|
+
"{ \"maximum\": {"
|
507
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
508
|
+
" \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100"
|
509
|
+
"}}");
|
510
|
+
INVALIDATE(s, "101", "", "maximum", "",
|
511
|
+
"{ \"maximum\": {"
|
512
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
513
|
+
" \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 101"
|
514
|
+
"}}");
|
515
|
+
}
|
516
|
+
|
517
|
+
TEST(SchemaValidator, Integer_Range64Boundary) {
|
518
|
+
Document sd;
|
519
|
+
sd.Parse("{\"type\":\"integer\",\"minimum\":-9223372036854775807,\"maximum\":9223372036854775806}");
|
520
|
+
SchemaDocument s(sd);
|
521
|
+
|
522
|
+
INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
|
523
|
+
"{ \"minimum\": {"
|
524
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
525
|
+
" \"expected\": -9223372036854775807, \"actual\": -9223372036854775808"
|
526
|
+
"}}");
|
527
|
+
VALIDATE(s, "-9223372036854775807", true);
|
528
|
+
VALIDATE(s, "-2147483648", true); // int min
|
529
|
+
VALIDATE(s, "0", true);
|
530
|
+
VALIDATE(s, "2147483647", true); // int max
|
531
|
+
VALIDATE(s, "2147483648", true); // unsigned first
|
532
|
+
VALIDATE(s, "4294967295", true); // unsigned max
|
533
|
+
VALIDATE(s, "9223372036854775806", true);
|
534
|
+
INVALIDATE(s, "9223372036854775807", "", "maximum", "",
|
535
|
+
"{ \"maximum\": {"
|
536
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
537
|
+
" \"expected\": 9223372036854775806, \"actual\": 9223372036854775807"
|
538
|
+
"}}");
|
539
|
+
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
540
|
+
"{ \"maximum\": {"
|
541
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
542
|
+
" \"expected\": 9223372036854775806, \"actual\": 18446744073709551615"
|
543
|
+
"}}"); // uint64_t max
|
544
|
+
}
|
545
|
+
|
546
|
+
TEST(SchemaValidator, Integer_RangeU64Boundary) {
|
547
|
+
Document sd;
|
548
|
+
sd.Parse("{\"type\":\"integer\",\"minimum\":9223372036854775808,\"maximum\":18446744073709551614}");
|
549
|
+
SchemaDocument s(sd);
|
550
|
+
|
551
|
+
INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
|
552
|
+
"{ \"minimum\": {"
|
553
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
554
|
+
" \"expected\": 9223372036854775808, \"actual\": -9223372036854775808"
|
555
|
+
"}}");
|
556
|
+
INVALIDATE(s, "9223372036854775807", "", "minimum", "",
|
557
|
+
"{ \"minimum\": {"
|
558
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
559
|
+
" \"expected\": 9223372036854775808, \"actual\": 9223372036854775807"
|
560
|
+
"}}");
|
561
|
+
INVALIDATE(s, "-2147483648", "", "minimum", "",
|
562
|
+
"{ \"minimum\": {"
|
563
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
564
|
+
" \"expected\": 9223372036854775808, \"actual\": -2147483648"
|
565
|
+
"}}"); // int min
|
566
|
+
INVALIDATE(s, "0", "", "minimum", "",
|
567
|
+
"{ \"minimum\": {"
|
568
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
569
|
+
" \"expected\": 9223372036854775808, \"actual\": 0"
|
570
|
+
"}}");
|
571
|
+
INVALIDATE(s, "2147483647", "", "minimum", "",
|
572
|
+
"{ \"minimum\": {"
|
573
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
574
|
+
" \"expected\": 9223372036854775808, \"actual\": 2147483647"
|
575
|
+
"}}"); // int max
|
576
|
+
INVALIDATE(s, "2147483648", "", "minimum", "",
|
577
|
+
"{ \"minimum\": {"
|
578
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
579
|
+
" \"expected\": 9223372036854775808, \"actual\": 2147483648"
|
580
|
+
"}}"); // unsigned first
|
581
|
+
INVALIDATE(s, "4294967295", "", "minimum", "",
|
582
|
+
"{ \"minimum\": {"
|
583
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
584
|
+
" \"expected\": 9223372036854775808, \"actual\": 4294967295"
|
585
|
+
"}}"); // unsigned max
|
586
|
+
VALIDATE(s, "9223372036854775808", true);
|
587
|
+
VALIDATE(s, "18446744073709551614", true);
|
588
|
+
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
589
|
+
"{ \"maximum\": {"
|
590
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
591
|
+
" \"expected\": 18446744073709551614, \"actual\": 18446744073709551615"
|
592
|
+
"}}");
|
593
|
+
}
|
594
|
+
|
595
|
+
TEST(SchemaValidator, Integer_Range64BoundaryExclusive) {
|
596
|
+
Document sd;
|
597
|
+
sd.Parse("{\"type\":\"integer\",\"minimum\":-9223372036854775808,\"maximum\":18446744073709551615,\"exclusiveMinimum\":true,\"exclusiveMaximum\":true}");
|
598
|
+
SchemaDocument s(sd);
|
599
|
+
|
600
|
+
INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
|
601
|
+
"{ \"minimum\": {"
|
602
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
603
|
+
" \"expected\": -9223372036854775808, \"exclusiveMinimum\": true, "
|
604
|
+
" \"actual\": -9223372036854775808"
|
605
|
+
"}}");
|
606
|
+
VALIDATE(s, "-9223372036854775807", true);
|
607
|
+
VALIDATE(s, "18446744073709551614", true);
|
608
|
+
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
609
|
+
"{ \"maximum\": {"
|
610
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
611
|
+
" \"expected\": 18446744073709551615, \"exclusiveMaximum\": true, "
|
612
|
+
" \"actual\": 18446744073709551615"
|
613
|
+
"}}");
|
614
|
+
}
|
615
|
+
|
616
|
+
TEST(SchemaValidator, Integer_MultipleOf) {
|
617
|
+
Document sd;
|
618
|
+
sd.Parse("{\"type\":\"integer\",\"multipleOf\":10}");
|
619
|
+
SchemaDocument s(sd);
|
620
|
+
|
621
|
+
VALIDATE(s, "0", true);
|
622
|
+
VALIDATE(s, "10", true);
|
623
|
+
VALIDATE(s, "-10", true);
|
624
|
+
VALIDATE(s, "20", true);
|
625
|
+
INVALIDATE(s, "23", "", "multipleOf", "",
|
626
|
+
"{ \"multipleOf\": {"
|
627
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
628
|
+
" \"expected\": 10, \"actual\": 23"
|
629
|
+
"}}");
|
630
|
+
INVALIDATE(s, "-23", "", "multipleOf", "",
|
631
|
+
"{ \"multipleOf\": {"
|
632
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
633
|
+
" \"expected\": 10, \"actual\": -23"
|
634
|
+
"}}");
|
635
|
+
}
|
636
|
+
|
637
|
+
TEST(SchemaValidator, Integer_MultipleOf64Boundary) {
|
638
|
+
Document sd;
|
639
|
+
sd.Parse("{\"type\":\"integer\",\"multipleOf\":18446744073709551615}");
|
640
|
+
SchemaDocument s(sd);
|
641
|
+
|
642
|
+
VALIDATE(s, "0", true);
|
643
|
+
VALIDATE(s, "18446744073709551615", true);
|
644
|
+
INVALIDATE(s, "18446744073709551614", "", "multipleOf", "",
|
645
|
+
"{ \"multipleOf\": {"
|
646
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
647
|
+
" \"expected\": 18446744073709551615, \"actual\": 18446744073709551614"
|
648
|
+
"}}");
|
649
|
+
}
|
650
|
+
|
651
|
+
TEST(SchemaValidator, Number_Range) {
|
652
|
+
Document sd;
|
653
|
+
sd.Parse("{\"type\":\"number\",\"minimum\":0,\"maximum\":100,\"exclusiveMaximum\":true}");
|
654
|
+
SchemaDocument s(sd);
|
655
|
+
|
656
|
+
INVALIDATE(s, "-1", "", "minimum", "",
|
657
|
+
"{ \"minimum\": {"
|
658
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
659
|
+
" \"expected\": 0, \"actual\": -1"
|
660
|
+
"}}");
|
661
|
+
VALIDATE(s, "0", true);
|
662
|
+
VALIDATE(s, "0.1", true);
|
663
|
+
VALIDATE(s, "10", true);
|
664
|
+
VALIDATE(s, "99", true);
|
665
|
+
VALIDATE(s, "99.9", true);
|
666
|
+
INVALIDATE(s, "100", "", "maximum", "",
|
667
|
+
"{ \"maximum\": {"
|
668
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
669
|
+
" \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100"
|
670
|
+
"}}");
|
671
|
+
INVALIDATE(s, "100.0", "", "maximum", "",
|
672
|
+
"{ \"maximum\": {"
|
673
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
674
|
+
" \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100.0"
|
675
|
+
"}}");
|
676
|
+
INVALIDATE(s, "101.5", "", "maximum", "",
|
677
|
+
"{ \"maximum\": {"
|
678
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
679
|
+
" \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 101.5"
|
680
|
+
"}}");
|
681
|
+
}
|
682
|
+
|
683
|
+
TEST(SchemaValidator, Number_RangeInt) {
|
684
|
+
Document sd;
|
685
|
+
sd.Parse("{\"type\":\"number\",\"minimum\":-100,\"maximum\":-1,\"exclusiveMaximum\":true}");
|
686
|
+
SchemaDocument s(sd);
|
687
|
+
|
688
|
+
INVALIDATE(s, "-101", "", "minimum", "",
|
689
|
+
"{ \"minimum\": {"
|
690
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
691
|
+
" \"expected\": -100, \"actual\": -101"
|
692
|
+
"}}");
|
693
|
+
INVALIDATE(s, "-100.1", "", "minimum", "",
|
694
|
+
"{ \"minimum\": {"
|
695
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
696
|
+
" \"expected\": -100, \"actual\": -100.1"
|
697
|
+
"}}");
|
698
|
+
VALIDATE(s, "-100", true);
|
699
|
+
VALIDATE(s, "-2", true);
|
700
|
+
INVALIDATE(s, "-1", "", "maximum", "",
|
701
|
+
"{ \"maximum\": {"
|
702
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
703
|
+
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": -1"
|
704
|
+
"}}");
|
705
|
+
INVALIDATE(s, "-0.9", "", "maximum", "",
|
706
|
+
"{ \"maximum\": {"
|
707
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
708
|
+
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": -0.9"
|
709
|
+
"}}");
|
710
|
+
INVALIDATE(s, "0", "", "maximum", "",
|
711
|
+
"{ \"maximum\": {"
|
712
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
713
|
+
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 0"
|
714
|
+
"}}");
|
715
|
+
INVALIDATE(s, "2147483647", "", "maximum", "",
|
716
|
+
"{ \"maximum\": {"
|
717
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
718
|
+
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 2147483647"
|
719
|
+
"}}"); // int max
|
720
|
+
INVALIDATE(s, "2147483648", "", "maximum", "",
|
721
|
+
"{ \"maximum\": {"
|
722
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
723
|
+
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 2147483648"
|
724
|
+
"}}"); // unsigned first
|
725
|
+
INVALIDATE(s, "4294967295", "", "maximum", "",
|
726
|
+
"{ \"maximum\": {"
|
727
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
728
|
+
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 4294967295"
|
729
|
+
"}}"); // unsigned max
|
730
|
+
INVALIDATE(s, "9223372036854775808", "", "maximum", "",
|
731
|
+
"{ \"maximum\": {"
|
732
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
733
|
+
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 9223372036854775808"
|
734
|
+
"}}");
|
735
|
+
INVALIDATE(s, "18446744073709551614", "", "maximum", "",
|
736
|
+
"{ \"maximum\": {"
|
737
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
738
|
+
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
|
739
|
+
"}}");
|
740
|
+
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
741
|
+
"{ \"maximum\": {"
|
742
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
743
|
+
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
|
744
|
+
"}}");
|
745
|
+
}
|
746
|
+
|
747
|
+
TEST(SchemaValidator, Number_RangeDouble) {
|
748
|
+
Document sd;
|
749
|
+
sd.Parse("{\"type\":\"number\",\"minimum\":0.1,\"maximum\":100.1,\"exclusiveMaximum\":true}");
|
750
|
+
SchemaDocument s(sd);
|
751
|
+
|
752
|
+
INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
|
753
|
+
"{ \"minimum\": {"
|
754
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
755
|
+
" \"expected\": 0.1, \"actual\": -9223372036854775808"
|
756
|
+
"}}");
|
757
|
+
INVALIDATE(s, "-2147483648", "", "minimum", "",
|
758
|
+
"{ \"minimum\": {"
|
759
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
760
|
+
" \"expected\": 0.1, \"actual\": -2147483648"
|
761
|
+
"}}"); // int min
|
762
|
+
INVALIDATE(s, "-1", "", "minimum", "",
|
763
|
+
"{ \"minimum\": {"
|
764
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
765
|
+
" \"expected\": 0.1, \"actual\": -1"
|
766
|
+
"}}");
|
767
|
+
VALIDATE(s, "0.1", true);
|
768
|
+
VALIDATE(s, "10", true);
|
769
|
+
VALIDATE(s, "99", true);
|
770
|
+
VALIDATE(s, "100", true);
|
771
|
+
INVALIDATE(s, "101", "", "maximum", "",
|
772
|
+
"{ \"maximum\": {"
|
773
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
774
|
+
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 101"
|
775
|
+
"}}");
|
776
|
+
INVALIDATE(s, "101.5", "", "maximum", "",
|
777
|
+
"{ \"maximum\": {"
|
778
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
779
|
+
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 101.5"
|
780
|
+
"}}");
|
781
|
+
INVALIDATE(s, "18446744073709551614", "", "maximum", "",
|
782
|
+
"{ \"maximum\": {"
|
783
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
784
|
+
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
|
785
|
+
"}}");
|
786
|
+
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
787
|
+
"{ \"maximum\": {"
|
788
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
789
|
+
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
|
790
|
+
"}}");
|
791
|
+
INVALIDATE(s, "2147483647", "", "maximum", "",
|
792
|
+
"{ \"maximum\": {"
|
793
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
794
|
+
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 2147483647"
|
795
|
+
"}}"); // int max
|
796
|
+
INVALIDATE(s, "2147483648", "", "maximum", "",
|
797
|
+
"{ \"maximum\": {"
|
798
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
799
|
+
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 2147483648"
|
800
|
+
"}}"); // unsigned first
|
801
|
+
INVALIDATE(s, "4294967295", "", "maximum", "",
|
802
|
+
"{ \"maximum\": {"
|
803
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
804
|
+
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 4294967295"
|
805
|
+
"}}"); // unsigned max
|
806
|
+
INVALIDATE(s, "9223372036854775808", "", "maximum", "",
|
807
|
+
"{ \"maximum\": {"
|
808
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
809
|
+
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 9223372036854775808"
|
810
|
+
"}}");
|
811
|
+
INVALIDATE(s, "18446744073709551614", "", "maximum", "",
|
812
|
+
"{ \"maximum\": {"
|
813
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
814
|
+
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
|
815
|
+
"}}");
|
816
|
+
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
817
|
+
"{ \"maximum\": {"
|
818
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
819
|
+
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
|
820
|
+
"}}");
|
821
|
+
}
|
822
|
+
|
823
|
+
TEST(SchemaValidator, Number_RangeDoubleU64Boundary) {
|
824
|
+
Document sd;
|
825
|
+
sd.Parse("{\"type\":\"number\",\"minimum\":9223372036854775808.0,\"maximum\":18446744073709550000.0}");
|
826
|
+
SchemaDocument s(sd);
|
827
|
+
|
828
|
+
INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
|
829
|
+
"{ \"minimum\": {"
|
830
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
831
|
+
" \"expected\": 9223372036854775808.0, \"actual\": -9223372036854775808"
|
832
|
+
"}}");
|
833
|
+
INVALIDATE(s, "-2147483648", "", "minimum", "",
|
834
|
+
"{ \"minimum\": {"
|
835
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
836
|
+
" \"expected\": 9223372036854775808.0, \"actual\": -2147483648"
|
837
|
+
"}}"); // int min
|
838
|
+
INVALIDATE(s, "0", "", "minimum", "",
|
839
|
+
"{ \"minimum\": {"
|
840
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
841
|
+
" \"expected\": 9223372036854775808.0, \"actual\": 0"
|
842
|
+
"}}");
|
843
|
+
INVALIDATE(s, "2147483647", "", "minimum", "",
|
844
|
+
"{ \"minimum\": {"
|
845
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
846
|
+
" \"expected\": 9223372036854775808.0, \"actual\": 2147483647"
|
847
|
+
"}}"); // int max
|
848
|
+
INVALIDATE(s, "2147483648", "", "minimum", "",
|
849
|
+
"{ \"minimum\": {"
|
850
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
851
|
+
" \"expected\": 9223372036854775808.0, \"actual\": 2147483648"
|
852
|
+
"}}"); // unsigned first
|
853
|
+
INVALIDATE(s, "4294967295", "", "minimum", "",
|
854
|
+
"{ \"minimum\": {"
|
855
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
856
|
+
" \"expected\": 9223372036854775808.0, \"actual\": 4294967295"
|
857
|
+
"}}"); // unsigned max
|
858
|
+
VALIDATE(s, "9223372036854775808", true);
|
859
|
+
VALIDATE(s, "18446744073709540000", true);
|
860
|
+
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
861
|
+
"{ \"maximum\": {"
|
862
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
863
|
+
" \"expected\": 18446744073709550000.0, \"actual\": 18446744073709551615"
|
864
|
+
"}}");
|
865
|
+
}
|
866
|
+
|
867
|
+
TEST(SchemaValidator, Number_MultipleOf) {
|
868
|
+
Document sd;
|
869
|
+
sd.Parse("{\"type\":\"number\",\"multipleOf\":10.0}");
|
870
|
+
SchemaDocument s(sd);
|
871
|
+
|
872
|
+
VALIDATE(s, "0", true);
|
873
|
+
VALIDATE(s, "10", true);
|
874
|
+
VALIDATE(s, "-10", true);
|
875
|
+
VALIDATE(s, "20", true);
|
876
|
+
INVALIDATE(s, "23", "", "multipleOf", "",
|
877
|
+
"{ \"multipleOf\": {"
|
878
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
879
|
+
" \"expected\": 10.0, \"actual\": 23"
|
880
|
+
"}}");
|
881
|
+
INVALIDATE(s, "-2147483648", "", "multipleOf", "",
|
882
|
+
"{ \"multipleOf\": {"
|
883
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
884
|
+
" \"expected\": 10.0, \"actual\": -2147483648"
|
885
|
+
"}}"); // int min
|
886
|
+
VALIDATE(s, "-2147483640", true);
|
887
|
+
INVALIDATE(s, "2147483647", "", "multipleOf", "",
|
888
|
+
"{ \"multipleOf\": {"
|
889
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
890
|
+
" \"expected\": 10.0, \"actual\": 2147483647"
|
891
|
+
"}}"); // int max
|
892
|
+
INVALIDATE(s, "2147483648", "", "multipleOf", "",
|
893
|
+
"{ \"multipleOf\": {"
|
894
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
895
|
+
" \"expected\": 10.0, \"actual\": 2147483648"
|
896
|
+
"}}"); // unsigned first
|
897
|
+
VALIDATE(s, "2147483650", true);
|
898
|
+
INVALIDATE(s, "4294967295", "", "multipleOf", "",
|
899
|
+
"{ \"multipleOf\": {"
|
900
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
901
|
+
" \"expected\": 10.0, \"actual\": 4294967295"
|
902
|
+
"}}"); // unsigned max
|
903
|
+
VALIDATE(s, "4294967300", true);
|
904
|
+
}
|
905
|
+
|
906
|
+
TEST(SchemaValidator, Number_MultipleOfOne) {
|
907
|
+
Document sd;
|
908
|
+
sd.Parse("{\"type\":\"number\",\"multipleOf\":1}");
|
909
|
+
SchemaDocument s(sd);
|
910
|
+
|
911
|
+
VALIDATE(s, "42", true);
|
912
|
+
VALIDATE(s, "42.0", true);
|
913
|
+
INVALIDATE(s, "3.1415926", "", "multipleOf", "",
|
914
|
+
"{ \"multipleOf\": {"
|
915
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
916
|
+
" \"expected\": 1, \"actual\": 3.1415926"
|
917
|
+
"}}");
|
918
|
+
}
|
919
|
+
|
920
|
+
TEST(SchemaValidator, Object) {
|
921
|
+
Document sd;
|
922
|
+
sd.Parse("{\"type\":\"object\"}");
|
923
|
+
SchemaDocument s(sd);
|
924
|
+
|
925
|
+
VALIDATE(s, "{\"key\":\"value\",\"another_key\":\"another_value\"}", true);
|
926
|
+
VALIDATE(s, "{\"Sun\":1.9891e30,\"Jupiter\":1.8986e27,\"Saturn\":5.6846e26,\"Neptune\":10.243e25,\"Uranus\":8.6810e25,\"Earth\":5.9736e24,\"Venus\":4.8685e24,\"Mars\":6.4185e23,\"Mercury\":3.3022e23,\"Moon\":7.349e22,\"Pluto\":1.25e22}", true);
|
927
|
+
INVALIDATE(s, "[\"An\", \"array\", \"not\", \"an\", \"object\"]", "", "type", "",
|
928
|
+
"{ \"type\": {"
|
929
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
930
|
+
" \"expected\": [\"object\"], \"actual\": \"array\""
|
931
|
+
"}}");
|
932
|
+
INVALIDATE(s, "\"Not an object\"", "", "type", "",
|
933
|
+
"{ \"type\": {"
|
934
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
935
|
+
" \"expected\": [\"object\"], \"actual\": \"string\""
|
936
|
+
"}}");
|
937
|
+
}
|
938
|
+
|
939
|
+
TEST(SchemaValidator, Object_Properties) {
|
940
|
+
Document sd;
|
941
|
+
sd.Parse(
|
942
|
+
"{"
|
943
|
+
" \"type\": \"object\","
|
944
|
+
" \"properties\" : {"
|
945
|
+
" \"number\": { \"type\": \"number\" },"
|
946
|
+
" \"street_name\" : { \"type\": \"string\" },"
|
947
|
+
" \"street_type\" : { \"type\": \"string\", \"enum\" : [\"Street\", \"Avenue\", \"Boulevard\"] }"
|
948
|
+
" }"
|
949
|
+
"}");
|
950
|
+
|
951
|
+
SchemaDocument s(sd);
|
952
|
+
|
953
|
+
VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }", true);
|
954
|
+
INVALIDATE(s, "{ \"number\": \"1600\", \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }", "/properties/number", "type", "/number",
|
955
|
+
"{ \"type\": {"
|
956
|
+
" \"instanceRef\": \"#/number\", \"schemaRef\": \"#/properties/number\","
|
957
|
+
" \"expected\": [\"number\"], \"actual\": \"string\""
|
958
|
+
"}}");
|
959
|
+
INVALIDATE(s, "{ \"number\": \"One\", \"street_name\": \"Microsoft\", \"street_type\": \"Way\" }",
|
960
|
+
"/properties/number", "type", "/number",
|
961
|
+
"{ \"type\": {"
|
962
|
+
" \"instanceRef\": \"#/number\", \"schemaRef\": \"#/properties/number\","
|
963
|
+
" \"expected\": [\"number\"], \"actual\": \"string\""
|
964
|
+
"}}"); // fail fast
|
965
|
+
VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\" }", true);
|
966
|
+
VALIDATE(s, "{}", true);
|
967
|
+
VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"direction\": \"NW\" }", true);
|
968
|
+
}
|
969
|
+
|
970
|
+
TEST(SchemaValidator, Object_AdditionalPropertiesBoolean) {
|
971
|
+
Document sd;
|
972
|
+
sd.Parse(
|
973
|
+
"{"
|
974
|
+
" \"type\": \"object\","
|
975
|
+
" \"properties\" : {"
|
976
|
+
" \"number\": { \"type\": \"number\" },"
|
977
|
+
" \"street_name\" : { \"type\": \"string\" },"
|
978
|
+
" \"street_type\" : { \"type\": \"string\","
|
979
|
+
" \"enum\" : [\"Street\", \"Avenue\", \"Boulevard\"]"
|
980
|
+
" }"
|
981
|
+
" },"
|
982
|
+
" \"additionalProperties\": false"
|
983
|
+
"}");
|
984
|
+
|
985
|
+
SchemaDocument s(sd);
|
986
|
+
|
987
|
+
VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }", true);
|
988
|
+
INVALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"direction\": \"NW\" }", "", "additionalProperties", "/direction",
|
989
|
+
"{ \"additionalProperties\": {"
|
990
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
991
|
+
" \"disallowed\": \"direction\""
|
992
|
+
"}}");
|
993
|
+
}
|
994
|
+
|
995
|
+
TEST(SchemaValidator, Object_AdditionalPropertiesObject) {
|
996
|
+
Document sd;
|
997
|
+
sd.Parse(
|
998
|
+
"{"
|
999
|
+
" \"type\": \"object\","
|
1000
|
+
" \"properties\" : {"
|
1001
|
+
" \"number\": { \"type\": \"number\" },"
|
1002
|
+
" \"street_name\" : { \"type\": \"string\" },"
|
1003
|
+
" \"street_type\" : { \"type\": \"string\","
|
1004
|
+
" \"enum\" : [\"Street\", \"Avenue\", \"Boulevard\"]"
|
1005
|
+
" }"
|
1006
|
+
" },"
|
1007
|
+
" \"additionalProperties\": { \"type\": \"string\" }"
|
1008
|
+
"}");
|
1009
|
+
SchemaDocument s(sd);
|
1010
|
+
|
1011
|
+
VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }", true);
|
1012
|
+
VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"direction\": \"NW\" }", true);
|
1013
|
+
INVALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"office_number\": 201 }", "/additionalProperties", "type", "/office_number",
|
1014
|
+
"{ \"type\": {"
|
1015
|
+
" \"instanceRef\": \"#/office_number\", \"schemaRef\": \"#/additionalProperties\","
|
1016
|
+
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
1017
|
+
"}}");
|
1018
|
+
}
|
1019
|
+
|
1020
|
+
TEST(SchemaValidator, Object_Required) {
|
1021
|
+
Document sd;
|
1022
|
+
sd.Parse(
|
1023
|
+
"{"
|
1024
|
+
" \"type\": \"object\","
|
1025
|
+
" \"properties\" : {"
|
1026
|
+
" \"name\": { \"type\": \"string\" },"
|
1027
|
+
" \"email\" : { \"type\": \"string\" },"
|
1028
|
+
" \"address\" : { \"type\": \"string\" },"
|
1029
|
+
" \"telephone\" : { \"type\": \"string\" }"
|
1030
|
+
" },"
|
1031
|
+
" \"required\":[\"name\", \"email\"]"
|
1032
|
+
"}");
|
1033
|
+
SchemaDocument s(sd);
|
1034
|
+
|
1035
|
+
VALIDATE(s, "{ \"name\": \"William Shakespeare\", \"email\" : \"bill@stratford-upon-avon.co.uk\" }", true);
|
1036
|
+
VALIDATE(s, "{ \"name\": \"William Shakespeare\", \"email\" : \"bill@stratford-upon-avon.co.uk\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\", \"authorship\" : \"in question\"}", true);
|
1037
|
+
INVALIDATE(s, "{ \"name\": \"William Shakespeare\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\" }", "", "required", "",
|
1038
|
+
"{ \"required\": {"
|
1039
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1040
|
+
" \"missing\": [\"email\"]"
|
1041
|
+
"}}");
|
1042
|
+
INVALIDATE(s, "{}", "", "required", "",
|
1043
|
+
"{ \"required\": {"
|
1044
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1045
|
+
" \"missing\": [\"name\", \"email\"]"
|
1046
|
+
"}}");
|
1047
|
+
}
|
1048
|
+
|
1049
|
+
|
1050
|
+
TEST(SchemaValidator, Object_PropertiesRange) {
|
1051
|
+
Document sd;
|
1052
|
+
sd.Parse("{\"type\":\"object\", \"minProperties\":2, \"maxProperties\":3}");
|
1053
|
+
SchemaDocument s(sd);
|
1054
|
+
|
1055
|
+
INVALIDATE(s, "{}", "", "minProperties", "",
|
1056
|
+
"{ \"minProperties\": {"
|
1057
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1058
|
+
" \"expected\": 2, \"actual\": 0"
|
1059
|
+
"}}");
|
1060
|
+
INVALIDATE(s, "{\"a\":0}", "", "minProperties", "",
|
1061
|
+
"{ \"minProperties\": {"
|
1062
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1063
|
+
" \"expected\": 2, \"actual\": 1"
|
1064
|
+
"}}");
|
1065
|
+
VALIDATE(s, "{\"a\":0,\"b\":1}", true);
|
1066
|
+
VALIDATE(s, "{\"a\":0,\"b\":1,\"c\":2}", true);
|
1067
|
+
INVALIDATE(s, "{\"a\":0,\"b\":1,\"c\":2,\"d\":3}", "", "maxProperties", "",
|
1068
|
+
"{ \"maxProperties\": {"
|
1069
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\", "
|
1070
|
+
" \"expected\": 3, \"actual\": 4"
|
1071
|
+
"}}");
|
1072
|
+
}
|
1073
|
+
|
1074
|
+
TEST(SchemaValidator, Object_PropertyDependencies) {
|
1075
|
+
Document sd;
|
1076
|
+
sd.Parse(
|
1077
|
+
"{"
|
1078
|
+
" \"type\": \"object\","
|
1079
|
+
" \"properties\": {"
|
1080
|
+
" \"name\": { \"type\": \"string\" },"
|
1081
|
+
" \"credit_card\": { \"type\": \"number\" },"
|
1082
|
+
" \"cvv_code\": { \"type\": \"number\" },"
|
1083
|
+
" \"billing_address\": { \"type\": \"string\" }"
|
1084
|
+
" },"
|
1085
|
+
" \"required\": [\"name\"],"
|
1086
|
+
" \"dependencies\": {"
|
1087
|
+
" \"credit_card\": [\"cvv_code\", \"billing_address\"]"
|
1088
|
+
" }"
|
1089
|
+
"}");
|
1090
|
+
SchemaDocument s(sd);
|
1091
|
+
|
1092
|
+
VALIDATE(s, "{ \"name\": \"John Doe\", \"credit_card\": 5555555555555555, \"cvv_code\": 777, "
|
1093
|
+
"\"billing_address\": \"555 Debtor's Lane\" }", true);
|
1094
|
+
INVALIDATE(s, "{ \"name\": \"John Doe\", \"credit_card\": 5555555555555555 }", "", "dependencies", "",
|
1095
|
+
"{ \"dependencies\": {"
|
1096
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1097
|
+
" \"errors\": {\"credit_card\": [\"cvv_code\", \"billing_address\"]}"
|
1098
|
+
"}}");
|
1099
|
+
VALIDATE(s, "{ \"name\": \"John Doe\"}", true);
|
1100
|
+
VALIDATE(s, "{ \"name\": \"John Doe\", \"cvv_code\": 777, \"billing_address\": \"555 Debtor's Lane\" }", true);
|
1101
|
+
}
|
1102
|
+
|
1103
|
+
TEST(SchemaValidator, Object_SchemaDependencies) {
|
1104
|
+
Document sd;
|
1105
|
+
sd.Parse(
|
1106
|
+
"{"
|
1107
|
+
" \"type\": \"object\","
|
1108
|
+
" \"properties\" : {"
|
1109
|
+
" \"name\": { \"type\": \"string\" },"
|
1110
|
+
" \"credit_card\" : { \"type\": \"number\" }"
|
1111
|
+
" },"
|
1112
|
+
" \"required\" : [\"name\"],"
|
1113
|
+
" \"dependencies\" : {"
|
1114
|
+
" \"credit_card\": {"
|
1115
|
+
" \"properties\": {"
|
1116
|
+
" \"billing_address\": { \"type\": \"string\" }"
|
1117
|
+
" },"
|
1118
|
+
" \"required\" : [\"billing_address\"]"
|
1119
|
+
" }"
|
1120
|
+
" }"
|
1121
|
+
"}");
|
1122
|
+
SchemaDocument s(sd);
|
1123
|
+
|
1124
|
+
VALIDATE(s, "{\"name\": \"John Doe\", \"credit_card\" : 5555555555555555,\"billing_address\" : \"555 Debtor's Lane\"}", true);
|
1125
|
+
INVALIDATE(s, "{\"name\": \"John Doe\", \"credit_card\" : 5555555555555555 }", "", "dependencies", "",
|
1126
|
+
"{ \"dependencies\": {"
|
1127
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1128
|
+
" \"errors\": {"
|
1129
|
+
" \"credit_card\": {"
|
1130
|
+
" \"required\": {"
|
1131
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/credit_card\","
|
1132
|
+
" \"missing\": [\"billing_address\"]"
|
1133
|
+
" } } }"
|
1134
|
+
"}}");
|
1135
|
+
VALIDATE(s, "{\"name\": \"John Doe\", \"billing_address\" : \"555 Debtor's Lane\"}", true);
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
#if RAPIDJSON_SCHEMA_HAS_REGEX
|
1139
|
+
TEST(SchemaValidator, Object_PatternProperties) {
|
1140
|
+
Document sd;
|
1141
|
+
sd.Parse(
|
1142
|
+
"{"
|
1143
|
+
" \"type\": \"object\","
|
1144
|
+
" \"patternProperties\": {"
|
1145
|
+
" \"^S_\": { \"type\": \"string\" },"
|
1146
|
+
" \"^I_\": { \"type\": \"integer\" }"
|
1147
|
+
" }"
|
1148
|
+
"}");
|
1149
|
+
SchemaDocument s(sd);
|
1150
|
+
|
1151
|
+
VALIDATE(s, "{ \"S_25\": \"This is a string\" }", true);
|
1152
|
+
VALIDATE(s, "{ \"I_0\": 42 }", true);
|
1153
|
+
INVALIDATE(s, "{ \"S_0\": 42 }", "", "patternProperties", "/S_0",
|
1154
|
+
"{ \"type\": {"
|
1155
|
+
" \"instanceRef\": \"#/S_0\", \"schemaRef\": \"#/patternProperties/%5ES_\","
|
1156
|
+
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
1157
|
+
"}}");
|
1158
|
+
INVALIDATE(s, "{ \"I_42\": \"This is a string\" }", "", "patternProperties", "/I_42",
|
1159
|
+
"{ \"type\": {"
|
1160
|
+
" \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/patternProperties/%5EI_\","
|
1161
|
+
" \"expected\": [\"integer\"], \"actual\": \"string\""
|
1162
|
+
"}}");
|
1163
|
+
VALIDATE(s, "{ \"keyword\": \"value\" }", true);
|
1164
|
+
}
|
1165
|
+
|
1166
|
+
TEST(SchemaValidator, Object_PattternProperties_ErrorConflict) {
|
1167
|
+
Document sd;
|
1168
|
+
sd.Parse(
|
1169
|
+
"{"
|
1170
|
+
" \"type\": \"object\","
|
1171
|
+
" \"patternProperties\": {"
|
1172
|
+
" \"^I_\": { \"multipleOf\": 5 },"
|
1173
|
+
" \"30$\": { \"multipleOf\": 6 }"
|
1174
|
+
" }"
|
1175
|
+
"}");
|
1176
|
+
SchemaDocument s(sd);
|
1177
|
+
|
1178
|
+
VALIDATE(s, "{ \"I_30\": 30 }", true);
|
1179
|
+
INVALIDATE(s, "{ \"I_30\": 7 }", "", "patternProperties", "/I_30",
|
1180
|
+
"{ \"multipleOf\": ["
|
1181
|
+
" {"
|
1182
|
+
" \"instanceRef\": \"#/I_30\", \"schemaRef\": \"#/patternProperties/%5EI_\","
|
1183
|
+
" \"expected\": 5, \"actual\": 7"
|
1184
|
+
" }, {"
|
1185
|
+
" \"instanceRef\": \"#/I_30\", \"schemaRef\": \"#/patternProperties/30%24\","
|
1186
|
+
" \"expected\": 6, \"actual\": 7"
|
1187
|
+
" }"
|
1188
|
+
"]}");
|
1189
|
+
}
|
1190
|
+
|
1191
|
+
TEST(SchemaValidator, Object_Properties_PatternProperties) {
|
1192
|
+
Document sd;
|
1193
|
+
sd.Parse(
|
1194
|
+
"{"
|
1195
|
+
" \"type\": \"object\","
|
1196
|
+
" \"properties\": {"
|
1197
|
+
" \"I_42\": { \"type\": \"integer\", \"minimum\": 73 }"
|
1198
|
+
" },"
|
1199
|
+
" \"patternProperties\": {"
|
1200
|
+
" \"^I_\": { \"type\": \"integer\", \"multipleOf\": 6 }"
|
1201
|
+
" }"
|
1202
|
+
"}");
|
1203
|
+
SchemaDocument s(sd);
|
1204
|
+
|
1205
|
+
VALIDATE(s, "{ \"I_6\": 6 }", true);
|
1206
|
+
VALIDATE(s, "{ \"I_42\": 78 }", true);
|
1207
|
+
INVALIDATE(s, "{ \"I_42\": 42 }", "", "patternProperties", "/I_42",
|
1208
|
+
"{ \"minimum\": {"
|
1209
|
+
" \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/properties/I_42\","
|
1210
|
+
" \"expected\": 73, \"actual\": 42"
|
1211
|
+
"}}");
|
1212
|
+
INVALIDATE(s, "{ \"I_42\": 7 }", "", "patternProperties", "/I_42",
|
1213
|
+
"{ \"minimum\": {"
|
1214
|
+
" \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/properties/I_42\","
|
1215
|
+
" \"expected\": 73, \"actual\": 7"
|
1216
|
+
" },"
|
1217
|
+
" \"multipleOf\": {"
|
1218
|
+
" \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/patternProperties/%5EI_\","
|
1219
|
+
" \"expected\": 6, \"actual\": 7"
|
1220
|
+
" }"
|
1221
|
+
"}");
|
1222
|
+
}
|
1223
|
+
|
1224
|
+
TEST(SchemaValidator, Object_PatternProperties_AdditionalProperties) {
|
1225
|
+
Document sd;
|
1226
|
+
sd.Parse(
|
1227
|
+
"{"
|
1228
|
+
" \"type\": \"object\","
|
1229
|
+
" \"properties\": {"
|
1230
|
+
" \"builtin\": { \"type\": \"number\" }"
|
1231
|
+
" },"
|
1232
|
+
" \"patternProperties\": {"
|
1233
|
+
" \"^S_\": { \"type\": \"string\" },"
|
1234
|
+
" \"^I_\": { \"type\": \"integer\" }"
|
1235
|
+
" },"
|
1236
|
+
" \"additionalProperties\": { \"type\": \"string\" }"
|
1237
|
+
"}");
|
1238
|
+
SchemaDocument s(sd);
|
1239
|
+
|
1240
|
+
VALIDATE(s, "{ \"builtin\": 42 }", true);
|
1241
|
+
VALIDATE(s, "{ \"keyword\": \"value\" }", true);
|
1242
|
+
INVALIDATE(s, "{ \"keyword\": 42 }", "/additionalProperties", "type", "/keyword",
|
1243
|
+
"{ \"type\": {"
|
1244
|
+
" \"instanceRef\": \"#/keyword\", \"schemaRef\": \"#/additionalProperties\","
|
1245
|
+
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
1246
|
+
"}}");
|
1247
|
+
}
|
1248
|
+
#endif
|
1249
|
+
|
1250
|
+
TEST(SchemaValidator, Array) {
|
1251
|
+
Document sd;
|
1252
|
+
sd.Parse("{\"type\":\"array\"}");
|
1253
|
+
SchemaDocument s(sd);
|
1254
|
+
|
1255
|
+
VALIDATE(s, "[1, 2, 3, 4, 5]", true);
|
1256
|
+
VALIDATE(s, "[3, \"different\", { \"types\" : \"of values\" }]", true);
|
1257
|
+
INVALIDATE(s, "{\"Not\": \"an array\"}", "", "type", "",
|
1258
|
+
"{ \"type\": {"
|
1259
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1260
|
+
" \"expected\": [\"array\"], \"actual\": \"object\""
|
1261
|
+
"}}");
|
1262
|
+
}
|
1263
|
+
|
1264
|
+
TEST(SchemaValidator, Array_ItemsList) {
|
1265
|
+
Document sd;
|
1266
|
+
sd.Parse(
|
1267
|
+
"{"
|
1268
|
+
" \"type\": \"array\","
|
1269
|
+
" \"items\" : {"
|
1270
|
+
" \"type\": \"number\""
|
1271
|
+
" }"
|
1272
|
+
"}");
|
1273
|
+
SchemaDocument s(sd);
|
1274
|
+
|
1275
|
+
VALIDATE(s, "[1, 2, 3, 4, 5]", true);
|
1276
|
+
INVALIDATE(s, "[1, 2, \"3\", 4, 5]", "/items", "type", "/2",
|
1277
|
+
"{ \"type\": {"
|
1278
|
+
" \"instanceRef\": \"#/2\", \"schemaRef\": \"#/items\","
|
1279
|
+
" \"expected\": [\"number\"], \"actual\": \"string\""
|
1280
|
+
"}}");
|
1281
|
+
VALIDATE(s, "[]", true);
|
1282
|
+
}
|
1283
|
+
|
1284
|
+
TEST(SchemaValidator, Array_ItemsTuple) {
|
1285
|
+
Document sd;
|
1286
|
+
sd.Parse(
|
1287
|
+
"{"
|
1288
|
+
" \"type\": \"array\","
|
1289
|
+
" \"items\": ["
|
1290
|
+
" {"
|
1291
|
+
" \"type\": \"number\""
|
1292
|
+
" },"
|
1293
|
+
" {"
|
1294
|
+
" \"type\": \"string\""
|
1295
|
+
" },"
|
1296
|
+
" {"
|
1297
|
+
" \"type\": \"string\","
|
1298
|
+
" \"enum\": [\"Street\", \"Avenue\", \"Boulevard\"]"
|
1299
|
+
" },"
|
1300
|
+
" {"
|
1301
|
+
" \"type\": \"string\","
|
1302
|
+
" \"enum\": [\"NW\", \"NE\", \"SW\", \"SE\"]"
|
1303
|
+
" }"
|
1304
|
+
" ]"
|
1305
|
+
"}");
|
1306
|
+
SchemaDocument s(sd);
|
1307
|
+
|
1308
|
+
VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\"]", true);
|
1309
|
+
INVALIDATE(s, "[24, \"Sussex\", \"Drive\"]", "/items/2", "enum", "/2",
|
1310
|
+
"{ \"enum\": { \"instanceRef\": \"#/2\", \"schemaRef\": \"#/items/2\" }}");
|
1311
|
+
INVALIDATE(s, "[\"Palais de l'Elysee\"]", "/items/0", "type", "/0",
|
1312
|
+
"{ \"type\": {"
|
1313
|
+
" \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items/0\","
|
1314
|
+
" \"expected\": [\"number\"], \"actual\": \"string\""
|
1315
|
+
"}}");
|
1316
|
+
INVALIDATE(s, "[\"Twenty-four\", \"Sussex\", \"Drive\"]", "/items/0", "type", "/0",
|
1317
|
+
"{ \"type\": {"
|
1318
|
+
" \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items/0\","
|
1319
|
+
" \"expected\": [\"number\"], \"actual\": \"string\""
|
1320
|
+
"}}"); // fail fast
|
1321
|
+
VALIDATE(s, "[10, \"Downing\", \"Street\"]", true);
|
1322
|
+
VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\", \"Washington\"]", true);
|
1323
|
+
}
|
1324
|
+
|
1325
|
+
TEST(SchemaValidator, Array_AdditionalItmes) {
|
1326
|
+
Document sd;
|
1327
|
+
sd.Parse(
|
1328
|
+
"{"
|
1329
|
+
" \"type\": \"array\","
|
1330
|
+
" \"items\": ["
|
1331
|
+
" {"
|
1332
|
+
" \"type\": \"number\""
|
1333
|
+
" },"
|
1334
|
+
" {"
|
1335
|
+
" \"type\": \"string\""
|
1336
|
+
" },"
|
1337
|
+
" {"
|
1338
|
+
" \"type\": \"string\","
|
1339
|
+
" \"enum\": [\"Street\", \"Avenue\", \"Boulevard\"]"
|
1340
|
+
" },"
|
1341
|
+
" {"
|
1342
|
+
" \"type\": \"string\","
|
1343
|
+
" \"enum\": [\"NW\", \"NE\", \"SW\", \"SE\"]"
|
1344
|
+
" }"
|
1345
|
+
" ],"
|
1346
|
+
" \"additionalItems\": false"
|
1347
|
+
"}");
|
1348
|
+
SchemaDocument s(sd);
|
1349
|
+
|
1350
|
+
VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\"]", true);
|
1351
|
+
VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\"]", true);
|
1352
|
+
INVALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\", \"Washington\"]", "", "items", "/4",
|
1353
|
+
"{ \"additionalItems\": {"
|
1354
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1355
|
+
" \"disallowed\": 4"
|
1356
|
+
"}}");
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
TEST(SchemaValidator, Array_ItemsRange) {
|
1360
|
+
Document sd;
|
1361
|
+
sd.Parse("{\"type\": \"array\",\"minItems\": 2,\"maxItems\" : 3}");
|
1362
|
+
SchemaDocument s(sd);
|
1363
|
+
|
1364
|
+
INVALIDATE(s, "[]", "", "minItems", "",
|
1365
|
+
"{ \"minItems\": {"
|
1366
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1367
|
+
" \"expected\": 2, \"actual\": 0"
|
1368
|
+
"}}");
|
1369
|
+
INVALIDATE(s, "[1]", "", "minItems", "",
|
1370
|
+
"{ \"minItems\": {"
|
1371
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1372
|
+
" \"expected\": 2, \"actual\": 1"
|
1373
|
+
"}}");
|
1374
|
+
VALIDATE(s, "[1, 2]", true);
|
1375
|
+
VALIDATE(s, "[1, 2, 3]", true);
|
1376
|
+
INVALIDATE(s, "[1, 2, 3, 4]", "", "maxItems", "",
|
1377
|
+
"{ \"maxItems\": {"
|
1378
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1379
|
+
" \"expected\": 3, \"actual\": 4"
|
1380
|
+
"}}");
|
1381
|
+
}
|
1382
|
+
|
1383
|
+
TEST(SchemaValidator, Array_UniqueItems) {
|
1384
|
+
Document sd;
|
1385
|
+
sd.Parse("{\"type\": \"array\", \"uniqueItems\": true}");
|
1386
|
+
SchemaDocument s(sd);
|
1387
|
+
|
1388
|
+
VALIDATE(s, "[1, 2, 3, 4, 5]", true);
|
1389
|
+
INVALIDATE(s, "[1, 2, 3, 3, 4]", "", "uniqueItems", "/3",
|
1390
|
+
"{ \"uniqueItems\": {"
|
1391
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1392
|
+
" \"duplicates\": [2, 3]"
|
1393
|
+
"}}");
|
1394
|
+
INVALIDATE(s, "[1, 2, 3, 3, 3]", "", "uniqueItems", "/3",
|
1395
|
+
"{ \"uniqueItems\": {"
|
1396
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1397
|
+
" \"duplicates\": [2, 3]"
|
1398
|
+
"}}"); // fail fast
|
1399
|
+
VALIDATE(s, "[]", true);
|
1400
|
+
}
|
1401
|
+
|
1402
|
+
TEST(SchemaValidator, Boolean) {
|
1403
|
+
Document sd;
|
1404
|
+
sd.Parse("{\"type\":\"boolean\"}");
|
1405
|
+
SchemaDocument s(sd);
|
1406
|
+
|
1407
|
+
VALIDATE(s, "true", true);
|
1408
|
+
VALIDATE(s, "false", true);
|
1409
|
+
INVALIDATE(s, "\"true\"", "", "type", "",
|
1410
|
+
"{ \"type\": {"
|
1411
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1412
|
+
" \"expected\": [\"boolean\"], \"actual\": \"string\""
|
1413
|
+
"}}");
|
1414
|
+
INVALIDATE(s, "0", "", "type", "",
|
1415
|
+
"{ \"type\": {"
|
1416
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1417
|
+
" \"expected\": [\"boolean\"], \"actual\": \"integer\""
|
1418
|
+
"}}");
|
1419
|
+
}
|
1420
|
+
|
1421
|
+
TEST(SchemaValidator, Null) {
|
1422
|
+
Document sd;
|
1423
|
+
sd.Parse("{\"type\":\"null\"}");
|
1424
|
+
SchemaDocument s(sd);
|
1425
|
+
|
1426
|
+
VALIDATE(s, "null", true);
|
1427
|
+
INVALIDATE(s, "false", "", "type", "",
|
1428
|
+
"{ \"type\": {"
|
1429
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1430
|
+
" \"expected\": [\"null\"], \"actual\": \"boolean\""
|
1431
|
+
"}}");
|
1432
|
+
INVALIDATE(s, "0", "", "type", "",
|
1433
|
+
"{ \"type\": {"
|
1434
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1435
|
+
" \"expected\": [\"null\"], \"actual\": \"integer\""
|
1436
|
+
"}}");
|
1437
|
+
INVALIDATE(s, "\"\"", "", "type", "",
|
1438
|
+
"{ \"type\": {"
|
1439
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1440
|
+
" \"expected\": [\"null\"], \"actual\": \"string\""
|
1441
|
+
"}}");
|
1442
|
+
}
|
1443
|
+
|
1444
|
+
// Additional tests
|
1445
|
+
|
1446
|
+
TEST(SchemaValidator, ObjectInArray) {
|
1447
|
+
Document sd;
|
1448
|
+
sd.Parse("{\"type\":\"array\", \"items\": { \"type\":\"string\" }}");
|
1449
|
+
SchemaDocument s(sd);
|
1450
|
+
|
1451
|
+
VALIDATE(s, "[\"a\"]", true);
|
1452
|
+
INVALIDATE(s, "[1]", "/items", "type", "/0",
|
1453
|
+
"{ \"type\": {"
|
1454
|
+
" \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items\","
|
1455
|
+
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
1456
|
+
"}}");
|
1457
|
+
INVALIDATE(s, "[{}]", "/items", "type", "/0",
|
1458
|
+
"{ \"type\": {"
|
1459
|
+
" \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items\","
|
1460
|
+
" \"expected\": [\"string\"], \"actual\": \"object\""
|
1461
|
+
"}}");
|
1462
|
+
}
|
1463
|
+
|
1464
|
+
TEST(SchemaValidator, MultiTypeInObject) {
|
1465
|
+
Document sd;
|
1466
|
+
sd.Parse(
|
1467
|
+
"{"
|
1468
|
+
" \"type\":\"object\","
|
1469
|
+
" \"properties\": {"
|
1470
|
+
" \"tel\" : {"
|
1471
|
+
" \"type\":[\"integer\", \"string\"]"
|
1472
|
+
" }"
|
1473
|
+
" }"
|
1474
|
+
"}");
|
1475
|
+
SchemaDocument s(sd);
|
1476
|
+
|
1477
|
+
VALIDATE(s, "{ \"tel\": 999 }", true);
|
1478
|
+
VALIDATE(s, "{ \"tel\": \"123-456\" }", true);
|
1479
|
+
INVALIDATE(s, "{ \"tel\": true }", "/properties/tel", "type", "/tel",
|
1480
|
+
"{ \"type\": {"
|
1481
|
+
" \"instanceRef\": \"#/tel\", \"schemaRef\": \"#/properties/tel\","
|
1482
|
+
" \"expected\": [\"string\", \"integer\"], \"actual\": \"boolean\""
|
1483
|
+
"}}");
|
1484
|
+
}
|
1485
|
+
|
1486
|
+
TEST(SchemaValidator, MultiTypeWithObject) {
|
1487
|
+
Document sd;
|
1488
|
+
sd.Parse(
|
1489
|
+
"{"
|
1490
|
+
" \"type\": [\"object\",\"string\"],"
|
1491
|
+
" \"properties\": {"
|
1492
|
+
" \"tel\" : {"
|
1493
|
+
" \"type\": \"integer\""
|
1494
|
+
" }"
|
1495
|
+
" }"
|
1496
|
+
"}");
|
1497
|
+
SchemaDocument s(sd);
|
1498
|
+
|
1499
|
+
VALIDATE(s, "\"Hello\"", true);
|
1500
|
+
VALIDATE(s, "{ \"tel\": 999 }", true);
|
1501
|
+
INVALIDATE(s, "{ \"tel\": \"fail\" }", "/properties/tel", "type", "/tel",
|
1502
|
+
"{ \"type\": {"
|
1503
|
+
" \"instanceRef\": \"#/tel\", \"schemaRef\": \"#/properties/tel\","
|
1504
|
+
" \"expected\": [\"integer\"], \"actual\": \"string\""
|
1505
|
+
"}}");
|
1506
|
+
}
|
1507
|
+
|
1508
|
+
TEST(SchemaValidator, AllOf_Nested) {
|
1509
|
+
Document sd;
|
1510
|
+
sd.Parse(
|
1511
|
+
"{"
|
1512
|
+
" \"allOf\": ["
|
1513
|
+
" { \"type\": \"string\", \"minLength\": 2 },"
|
1514
|
+
" { \"type\": \"string\", \"maxLength\": 5 },"
|
1515
|
+
" { \"allOf\": [ { \"enum\" : [\"ok\", \"okay\", \"OK\", \"o\"] }, { \"enum\" : [\"ok\", \"OK\", \"o\"]} ] }"
|
1516
|
+
" ]"
|
1517
|
+
"}");
|
1518
|
+
SchemaDocument s(sd);
|
1519
|
+
|
1520
|
+
VALIDATE(s, "\"ok\"", true);
|
1521
|
+
VALIDATE(s, "\"OK\"", true);
|
1522
|
+
INVALIDATE(s, "\"okay\"", "", "allOf", "",
|
1523
|
+
"{ \"enum\": {"
|
1524
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
|
1525
|
+
"}}");
|
1526
|
+
INVALIDATE(s, "\"o\"", "", "allOf", "",
|
1527
|
+
"{ \"minLength\": {"
|
1528
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
|
1529
|
+
" \"expected\": 2, \"actual\": \"o\""
|
1530
|
+
"}}");
|
1531
|
+
INVALIDATE(s, "\"n\"", "", "allOf", "",
|
1532
|
+
"{ \"minLength\": {"
|
1533
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
|
1534
|
+
" \"expected\": 2, \"actual\": \"n\""
|
1535
|
+
" },"
|
1536
|
+
" \"enum\": ["
|
1537
|
+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
|
1538
|
+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
|
1539
|
+
" ]"
|
1540
|
+
"}")
|
1541
|
+
INVALIDATE(s, "\"too long\"", "", "allOf", "",
|
1542
|
+
"{ \"maxLength\": {"
|
1543
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\","
|
1544
|
+
" \"expected\": 5, \"actual\": \"too long\""
|
1545
|
+
" },"
|
1546
|
+
" \"enum\": ["
|
1547
|
+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
|
1548
|
+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
|
1549
|
+
" ]"
|
1550
|
+
"}");
|
1551
|
+
INVALIDATE(s, "123", "", "allOf", "",
|
1552
|
+
"{ \"type\": ["
|
1553
|
+
" { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
|
1554
|
+
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
1555
|
+
" },"
|
1556
|
+
" { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\","
|
1557
|
+
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
1558
|
+
" }"
|
1559
|
+
" ],"
|
1560
|
+
" \"enum\": ["
|
1561
|
+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
|
1562
|
+
" {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
|
1563
|
+
" ]"
|
1564
|
+
"}");
|
1565
|
+
}
|
1566
|
+
|
1567
|
+
TEST(SchemaValidator, EscapedPointer) {
|
1568
|
+
Document sd;
|
1569
|
+
sd.Parse(
|
1570
|
+
"{"
|
1571
|
+
" \"type\": \"object\","
|
1572
|
+
" \"properties\": {"
|
1573
|
+
" \"~/\": { \"type\": \"number\" }"
|
1574
|
+
" }"
|
1575
|
+
"}");
|
1576
|
+
SchemaDocument s(sd);
|
1577
|
+
INVALIDATE(s, "{\"~/\":true}", "/properties/~0~1", "type", "/~0~1",
|
1578
|
+
"{ \"type\": {"
|
1579
|
+
" \"instanceRef\": \"#/~0~1\", \"schemaRef\": \"#/properties/~0~1\","
|
1580
|
+
" \"expected\": [\"number\"], \"actual\": \"boolean\""
|
1581
|
+
"}}");
|
1582
|
+
}
|
1583
|
+
|
1584
|
+
template <typename Allocator>
|
1585
|
+
static char* ReadFile(const char* filename, Allocator& allocator) {
|
1586
|
+
const char *paths[] = {
|
1587
|
+
"",
|
1588
|
+
"bin/",
|
1589
|
+
"../bin/",
|
1590
|
+
"../../bin/",
|
1591
|
+
"../../../bin/"
|
1592
|
+
};
|
1593
|
+
char buffer[1024];
|
1594
|
+
FILE *fp = 0;
|
1595
|
+
for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
|
1596
|
+
sprintf(buffer, "%s%s", paths[i], filename);
|
1597
|
+
fp = fopen(buffer, "rb");
|
1598
|
+
if (fp)
|
1599
|
+
break;
|
1600
|
+
}
|
1601
|
+
|
1602
|
+
if (!fp)
|
1603
|
+
return 0;
|
1604
|
+
|
1605
|
+
fseek(fp, 0, SEEK_END);
|
1606
|
+
size_t length = static_cast<size_t>(ftell(fp));
|
1607
|
+
fseek(fp, 0, SEEK_SET);
|
1608
|
+
char* json = reinterpret_cast<char*>(allocator.Malloc(length + 1));
|
1609
|
+
size_t readLength = fread(json, 1, length, fp);
|
1610
|
+
json[readLength] = '\0';
|
1611
|
+
fclose(fp);
|
1612
|
+
return json;
|
1613
|
+
}
|
1614
|
+
|
1615
|
+
TEST(SchemaValidator, ValidateMetaSchema) {
|
1616
|
+
CrtAllocator allocator;
|
1617
|
+
char* json = ReadFile("draft-04/schema", allocator);
|
1618
|
+
Document d;
|
1619
|
+
d.Parse(json);
|
1620
|
+
ASSERT_FALSE(d.HasParseError());
|
1621
|
+
SchemaDocument sd(d);
|
1622
|
+
SchemaValidator validator(sd);
|
1623
|
+
if (!d.Accept(validator)) {
|
1624
|
+
StringBuffer sb;
|
1625
|
+
validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
|
1626
|
+
printf("Invalid schema: %s\n", sb.GetString());
|
1627
|
+
printf("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());
|
1628
|
+
sb.Clear();
|
1629
|
+
validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
|
1630
|
+
printf("Invalid document: %s\n", sb.GetString());
|
1631
|
+
sb.Clear();
|
1632
|
+
Writer<StringBuffer> w(sb);
|
1633
|
+
validator.GetError().Accept(w);
|
1634
|
+
printf("Validation error: %s\n", sb.GetString());
|
1635
|
+
ADD_FAILURE();
|
1636
|
+
}
|
1637
|
+
CrtAllocator::Free(json);
|
1638
|
+
}
|
1639
|
+
|
1640
|
+
TEST(SchemaValidator, ValidateMetaSchema_UTF16) {
|
1641
|
+
typedef GenericDocument<UTF16<> > D;
|
1642
|
+
typedef GenericSchemaDocument<D::ValueType> SD;
|
1643
|
+
typedef GenericSchemaValidator<SD> SV;
|
1644
|
+
|
1645
|
+
CrtAllocator allocator;
|
1646
|
+
char* json = ReadFile("draft-04/schema", allocator);
|
1647
|
+
|
1648
|
+
D d;
|
1649
|
+
StringStream ss(json);
|
1650
|
+
d.ParseStream<0, UTF8<> >(ss);
|
1651
|
+
ASSERT_FALSE(d.HasParseError());
|
1652
|
+
SD sd(d);
|
1653
|
+
SV validator(sd);
|
1654
|
+
if (!d.Accept(validator)) {
|
1655
|
+
GenericStringBuffer<UTF16<> > sb;
|
1656
|
+
validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
|
1657
|
+
wprintf(L"Invalid schema: %ls\n", sb.GetString());
|
1658
|
+
wprintf(L"Invalid keyword: %ls\n", validator.GetInvalidSchemaKeyword());
|
1659
|
+
sb.Clear();
|
1660
|
+
validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
|
1661
|
+
wprintf(L"Invalid document: %ls\n", sb.GetString());
|
1662
|
+
sb.Clear();
|
1663
|
+
Writer<GenericStringBuffer<UTF16<> >, UTF16<> > w(sb);
|
1664
|
+
validator.GetError().Accept(w);
|
1665
|
+
printf("Validation error: %ls\n", sb.GetString());
|
1666
|
+
ADD_FAILURE();
|
1667
|
+
}
|
1668
|
+
CrtAllocator::Free(json);
|
1669
|
+
}
|
1670
|
+
|
1671
|
+
template <typename SchemaDocumentType = SchemaDocument>
|
1672
|
+
class RemoteSchemaDocumentProvider : public IGenericRemoteSchemaDocumentProvider<SchemaDocumentType> {
|
1673
|
+
public:
|
1674
|
+
RemoteSchemaDocumentProvider() :
|
1675
|
+
documentAllocator_(documentBuffer_, sizeof(documentBuffer_)),
|
1676
|
+
schemaAllocator_(schemaBuffer_, sizeof(schemaBuffer_))
|
1677
|
+
{
|
1678
|
+
const char* filenames[kCount] = {
|
1679
|
+
"jsonschema/remotes/integer.json",
|
1680
|
+
"jsonschema/remotes/subSchemas.json",
|
1681
|
+
"jsonschema/remotes/folder/folderInteger.json",
|
1682
|
+
"draft-04/schema"
|
1683
|
+
};
|
1684
|
+
const char* uris[kCount] = {
|
1685
|
+
"http://localhost:1234/integer.json",
|
1686
|
+
"http://localhost:1234/subSchemas.json",
|
1687
|
+
"http://localhost:1234/folder/folderInteger.json",
|
1688
|
+
"http://json-schema.org/draft-04/schema"
|
1689
|
+
};
|
1690
|
+
|
1691
|
+
for (size_t i = 0; i < kCount; i++) {
|
1692
|
+
sd_[i] = 0;
|
1693
|
+
|
1694
|
+
char jsonBuffer[8192];
|
1695
|
+
MemoryPoolAllocator<> jsonAllocator(jsonBuffer, sizeof(jsonBuffer));
|
1696
|
+
char* json = ReadFile(filenames[i], jsonAllocator);
|
1697
|
+
if (!json) {
|
1698
|
+
printf("json remote file %s not found", filenames[i]);
|
1699
|
+
ADD_FAILURE();
|
1700
|
+
}
|
1701
|
+
else {
|
1702
|
+
char stackBuffer[4096];
|
1703
|
+
MemoryPoolAllocator<> stackAllocator(stackBuffer, sizeof(stackBuffer));
|
1704
|
+
DocumentType d(&documentAllocator_, 1024, &stackAllocator);
|
1705
|
+
d.Parse(json);
|
1706
|
+
sd_[i] = new SchemaDocumentType(d, uris[i], static_cast<SizeType>(strlen(uris[i])), 0, &schemaAllocator_);
|
1707
|
+
MemoryPoolAllocator<>::Free(json);
|
1708
|
+
}
|
1709
|
+
};
|
1710
|
+
}
|
1711
|
+
|
1712
|
+
~RemoteSchemaDocumentProvider() {
|
1713
|
+
for (size_t i = 0; i < kCount; i++)
|
1714
|
+
delete sd_[i];
|
1715
|
+
}
|
1716
|
+
|
1717
|
+
virtual const SchemaDocumentType* GetRemoteDocument(const char* uri, SizeType length) {
|
1718
|
+
for (size_t i = 0; i < kCount; i++)
|
1719
|
+
if (typename SchemaDocumentType::URIType(uri, length) == sd_[i]->GetURI())
|
1720
|
+
return sd_[i];
|
1721
|
+
return 0;
|
1722
|
+
}
|
1723
|
+
|
1724
|
+
private:
|
1725
|
+
typedef GenericDocument<typename SchemaDocumentType::EncodingType, MemoryPoolAllocator<>, MemoryPoolAllocator<> > DocumentType;
|
1726
|
+
|
1727
|
+
RemoteSchemaDocumentProvider(const RemoteSchemaDocumentProvider&);
|
1728
|
+
RemoteSchemaDocumentProvider& operator=(const RemoteSchemaDocumentProvider&);
|
1729
|
+
|
1730
|
+
static const size_t kCount = 4;
|
1731
|
+
SchemaDocumentType* sd_[kCount];
|
1732
|
+
typename DocumentType::AllocatorType documentAllocator_;
|
1733
|
+
typename SchemaDocumentType::AllocatorType schemaAllocator_;
|
1734
|
+
char documentBuffer_[16384];
|
1735
|
+
char schemaBuffer_[128 * 1024];
|
1736
|
+
};
|
1737
|
+
|
1738
|
+
TEST(SchemaValidator, TestSuite) {
|
1739
|
+
const char* filenames[] = {
|
1740
|
+
"additionalItems.json",
|
1741
|
+
"additionalProperties.json",
|
1742
|
+
"allOf.json",
|
1743
|
+
"anyOf.json",
|
1744
|
+
"default.json",
|
1745
|
+
"definitions.json",
|
1746
|
+
"dependencies.json",
|
1747
|
+
"enum.json",
|
1748
|
+
"items.json",
|
1749
|
+
"maximum.json",
|
1750
|
+
"maxItems.json",
|
1751
|
+
"maxLength.json",
|
1752
|
+
"maxProperties.json",
|
1753
|
+
"minimum.json",
|
1754
|
+
"minItems.json",
|
1755
|
+
"minLength.json",
|
1756
|
+
"minProperties.json",
|
1757
|
+
"multipleOf.json",
|
1758
|
+
"not.json",
|
1759
|
+
"oneOf.json",
|
1760
|
+
"pattern.json",
|
1761
|
+
"patternProperties.json",
|
1762
|
+
"properties.json",
|
1763
|
+
"ref.json",
|
1764
|
+
"refRemote.json",
|
1765
|
+
"required.json",
|
1766
|
+
"type.json",
|
1767
|
+
"uniqueItems.json"
|
1768
|
+
};
|
1769
|
+
|
1770
|
+
const char* onlyRunDescription = 0;
|
1771
|
+
//const char* onlyRunDescription = "a string is a string";
|
1772
|
+
|
1773
|
+
unsigned testCount = 0;
|
1774
|
+
unsigned passCount = 0;
|
1775
|
+
|
1776
|
+
typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
|
1777
|
+
RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
|
1778
|
+
|
1779
|
+
char jsonBuffer[65536];
|
1780
|
+
char documentBuffer[65536];
|
1781
|
+
char documentStackBuffer[65536];
|
1782
|
+
char schemaBuffer[65536];
|
1783
|
+
char validatorBuffer[65536];
|
1784
|
+
MemoryPoolAllocator<> jsonAllocator(jsonBuffer, sizeof(jsonBuffer));
|
1785
|
+
MemoryPoolAllocator<> documentAllocator(documentBuffer, sizeof(documentBuffer));
|
1786
|
+
MemoryPoolAllocator<> documentStackAllocator(documentStackBuffer, sizeof(documentStackBuffer));
|
1787
|
+
MemoryPoolAllocator<> schemaAllocator(schemaBuffer, sizeof(schemaBuffer));
|
1788
|
+
MemoryPoolAllocator<> validatorAllocator(validatorBuffer, sizeof(validatorBuffer));
|
1789
|
+
|
1790
|
+
for (size_t i = 0; i < sizeof(filenames) / sizeof(filenames[0]); i++) {
|
1791
|
+
char filename[FILENAME_MAX];
|
1792
|
+
sprintf(filename, "jsonschema/tests/draft4/%s", filenames[i]);
|
1793
|
+
char* json = ReadFile(filename, jsonAllocator);
|
1794
|
+
if (!json) {
|
1795
|
+
printf("json test suite file %s not found", filename);
|
1796
|
+
ADD_FAILURE();
|
1797
|
+
}
|
1798
|
+
else {
|
1799
|
+
GenericDocument<UTF8<>, MemoryPoolAllocator<>, MemoryPoolAllocator<> > d(&documentAllocator, 1024, &documentStackAllocator);
|
1800
|
+
d.Parse(json);
|
1801
|
+
if (d.HasParseError()) {
|
1802
|
+
printf("json test suite file %s has parse error", filename);
|
1803
|
+
ADD_FAILURE();
|
1804
|
+
}
|
1805
|
+
else {
|
1806
|
+
for (Value::ConstValueIterator schemaItr = d.Begin(); schemaItr != d.End(); ++schemaItr) {
|
1807
|
+
{
|
1808
|
+
SchemaDocumentType schema((*schemaItr)["schema"], filenames[i], static_cast<SizeType>(strlen(filenames[i])), &provider, &schemaAllocator);
|
1809
|
+
GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > validator(schema, &validatorAllocator);
|
1810
|
+
const char* description1 = (*schemaItr)["description"].GetString();
|
1811
|
+
const Value& tests = (*schemaItr)["tests"];
|
1812
|
+
for (Value::ConstValueIterator testItr = tests.Begin(); testItr != tests.End(); ++testItr) {
|
1813
|
+
const char* description2 = (*testItr)["description"].GetString();
|
1814
|
+
if (!onlyRunDescription || strcmp(description2, onlyRunDescription) == 0) {
|
1815
|
+
const Value& data = (*testItr)["data"];
|
1816
|
+
bool expected = (*testItr)["valid"].GetBool();
|
1817
|
+
testCount++;
|
1818
|
+
validator.Reset();
|
1819
|
+
bool actual = data.Accept(validator);
|
1820
|
+
if (expected != actual)
|
1821
|
+
printf("Fail: %30s \"%s\" \"%s\"\n", filename, description1, description2);
|
1822
|
+
else
|
1823
|
+
passCount++;
|
1824
|
+
}
|
1825
|
+
}
|
1826
|
+
//printf("%zu %zu %zu\n", documentAllocator.Size(), schemaAllocator.Size(), validatorAllocator.Size());
|
1827
|
+
}
|
1828
|
+
schemaAllocator.Clear();
|
1829
|
+
validatorAllocator.Clear();
|
1830
|
+
}
|
1831
|
+
}
|
1832
|
+
}
|
1833
|
+
documentAllocator.Clear();
|
1834
|
+
MemoryPoolAllocator<>::Free(json);
|
1835
|
+
jsonAllocator.Clear();
|
1836
|
+
}
|
1837
|
+
printf("%d / %d passed (%2d%%)\n", passCount, testCount, passCount * 100 / testCount);
|
1838
|
+
// if (passCount != testCount)
|
1839
|
+
// ADD_FAILURE();
|
1840
|
+
}
|
1841
|
+
|
1842
|
+
TEST(SchemaValidatingReader, Simple) {
|
1843
|
+
Document sd;
|
1844
|
+
sd.Parse("{ \"type\": \"string\", \"enum\" : [\"red\", \"amber\", \"green\"] }");
|
1845
|
+
SchemaDocument s(sd);
|
1846
|
+
|
1847
|
+
Document d;
|
1848
|
+
StringStream ss("\"red\"");
|
1849
|
+
SchemaValidatingReader<kParseDefaultFlags, StringStream, UTF8<> > reader(ss, s);
|
1850
|
+
d.Populate(reader);
|
1851
|
+
EXPECT_TRUE(reader.GetParseResult());
|
1852
|
+
EXPECT_TRUE(reader.IsValid());
|
1853
|
+
EXPECT_TRUE(d.IsString());
|
1854
|
+
EXPECT_STREQ("red", d.GetString());
|
1855
|
+
}
|
1856
|
+
|
1857
|
+
TEST(SchemaValidatingReader, Invalid) {
|
1858
|
+
Document sd;
|
1859
|
+
sd.Parse("{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}");
|
1860
|
+
SchemaDocument s(sd);
|
1861
|
+
|
1862
|
+
Document d;
|
1863
|
+
StringStream ss("\"ABCD\"");
|
1864
|
+
SchemaValidatingReader<kParseDefaultFlags, StringStream, UTF8<> > reader(ss, s);
|
1865
|
+
d.Populate(reader);
|
1866
|
+
EXPECT_FALSE(reader.GetParseResult());
|
1867
|
+
EXPECT_FALSE(reader.IsValid());
|
1868
|
+
EXPECT_EQ(kParseErrorTermination, reader.GetParseResult().Code());
|
1869
|
+
EXPECT_STREQ("maxLength", reader.GetInvalidSchemaKeyword());
|
1870
|
+
EXPECT_TRUE(reader.GetInvalidSchemaPointer() == SchemaDocument::PointerType(""));
|
1871
|
+
EXPECT_TRUE(reader.GetInvalidDocumentPointer() == SchemaDocument::PointerType(""));
|
1872
|
+
EXPECT_TRUE(d.IsNull());
|
1873
|
+
Document e;
|
1874
|
+
e.Parse(
|
1875
|
+
"{ \"maxLength\": {"
|
1876
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1877
|
+
" \"expected\": 3, \"actual\": \"ABCD\""
|
1878
|
+
"}}");
|
1879
|
+
if (e != reader.GetError()) {
|
1880
|
+
ADD_FAILURE();
|
1881
|
+
}
|
1882
|
+
}
|
1883
|
+
|
1884
|
+
TEST(SchemaValidatingWriter, Simple) {
|
1885
|
+
Document sd;
|
1886
|
+
sd.Parse("{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}");
|
1887
|
+
SchemaDocument s(sd);
|
1888
|
+
|
1889
|
+
Document d;
|
1890
|
+
StringBuffer sb;
|
1891
|
+
Writer<StringBuffer> writer(sb);
|
1892
|
+
GenericSchemaValidator<SchemaDocument, Writer<StringBuffer> > validator(s, writer);
|
1893
|
+
|
1894
|
+
d.Parse("\"red\"");
|
1895
|
+
EXPECT_TRUE(d.Accept(validator));
|
1896
|
+
EXPECT_TRUE(validator.IsValid());
|
1897
|
+
EXPECT_STREQ("\"red\"", sb.GetString());
|
1898
|
+
|
1899
|
+
sb.Clear();
|
1900
|
+
validator.Reset();
|
1901
|
+
d.Parse("\"ABCD\"");
|
1902
|
+
EXPECT_FALSE(d.Accept(validator));
|
1903
|
+
EXPECT_FALSE(validator.IsValid());
|
1904
|
+
EXPECT_TRUE(validator.GetInvalidSchemaPointer() == SchemaDocument::PointerType(""));
|
1905
|
+
EXPECT_TRUE(validator.GetInvalidDocumentPointer() == SchemaDocument::PointerType(""));
|
1906
|
+
Document e;
|
1907
|
+
e.Parse(
|
1908
|
+
"{ \"maxLength\": {"
|
1909
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1910
|
+
" \"expected\": 3, \"actual\": \"ABCD\""
|
1911
|
+
"}}");
|
1912
|
+
EXPECT_EQ(e, validator.GetError());
|
1913
|
+
}
|
1914
|
+
|
1915
|
+
TEST(Schema, Issue848) {
|
1916
|
+
rapidjson::Document d;
|
1917
|
+
rapidjson::SchemaDocument s(d);
|
1918
|
+
rapidjson::GenericSchemaValidator<rapidjson::SchemaDocument, rapidjson::Document> v(s);
|
1919
|
+
}
|
1920
|
+
|
1921
|
+
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
|
1922
|
+
|
1923
|
+
static SchemaDocument ReturnSchemaDocument() {
|
1924
|
+
Document sd;
|
1925
|
+
sd.Parse("{ \"type\": [\"number\", \"string\"] }");
|
1926
|
+
SchemaDocument s(sd);
|
1927
|
+
return s;
|
1928
|
+
}
|
1929
|
+
|
1930
|
+
TEST(Schema, Issue552) {
|
1931
|
+
SchemaDocument s = ReturnSchemaDocument();
|
1932
|
+
VALIDATE(s, "42", true);
|
1933
|
+
VALIDATE(s, "\"Life, the universe, and everything\"", true);
|
1934
|
+
INVALIDATE(s, "[\"Life\", \"the universe\", \"and everything\"]", "", "type", "",
|
1935
|
+
"{ \"type\": {"
|
1936
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1937
|
+
" \"expected\": [\"string\", \"number\"], \"actual\": \"array\""
|
1938
|
+
"}}");
|
1939
|
+
}
|
1940
|
+
|
1941
|
+
#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
|
1942
|
+
|
1943
|
+
TEST(SchemaValidator, Issue608) {
|
1944
|
+
Document sd;
|
1945
|
+
sd.Parse("{\"required\": [\"a\", \"b\"] }");
|
1946
|
+
SchemaDocument s(sd);
|
1947
|
+
|
1948
|
+
VALIDATE(s, "{\"a\" : null, \"b\": null}", true);
|
1949
|
+
INVALIDATE(s, "{\"a\" : null, \"a\" : null}", "", "required", "",
|
1950
|
+
"{ \"required\": {"
|
1951
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1952
|
+
" \"missing\": [\"b\"]"
|
1953
|
+
"}}");
|
1954
|
+
}
|
1955
|
+
|
1956
|
+
// Fail to resolve $ref in allOf causes crash in SchemaValidator::StartObject()
|
1957
|
+
TEST(SchemaValidator, Issue728_AllOfRef) {
|
1958
|
+
Document sd;
|
1959
|
+
sd.Parse("{\"allOf\": [{\"$ref\": \"#/abc\"}]}");
|
1960
|
+
SchemaDocument s(sd);
|
1961
|
+
VALIDATE(s, "{\"key1\": \"abc\", \"key2\": \"def\"}", true);
|
1962
|
+
}
|
1963
|
+
|
1964
|
+
TEST(SchemaValidator, Issue825) {
|
1965
|
+
Document sd;
|
1966
|
+
sd.Parse("{\"type\": \"object\", \"additionalProperties\": false, \"patternProperties\": {\"^i\": { \"type\": \"string\" } } }");
|
1967
|
+
SchemaDocument s(sd);
|
1968
|
+
VALIDATE(s, "{ \"item\": \"hello\" }", true);
|
1969
|
+
}
|
1970
|
+
|
1971
|
+
TEST(SchemaValidator, Issue1017_allOfHandler) {
|
1972
|
+
Document sd;
|
1973
|
+
sd.Parse("{\"allOf\": [{\"type\": \"object\",\"properties\": {\"cyanArray2\": {\"type\": \"array\",\"items\": { \"type\": \"string\" }}}},{\"type\": \"object\",\"properties\": {\"blackArray\": {\"type\": \"array\",\"items\": { \"type\": \"string\" }}},\"required\": [ \"blackArray\" ]}]}");
|
1974
|
+
SchemaDocument s(sd);
|
1975
|
+
StringBuffer sb;
|
1976
|
+
Writer<StringBuffer> writer(sb);
|
1977
|
+
GenericSchemaValidator<SchemaDocument, Writer<StringBuffer> > validator(s, writer);
|
1978
|
+
EXPECT_TRUE(validator.StartObject());
|
1979
|
+
EXPECT_TRUE(validator.Key("cyanArray2", 10, false));
|
1980
|
+
EXPECT_TRUE(validator.StartArray());
|
1981
|
+
EXPECT_TRUE(validator.EndArray(0));
|
1982
|
+
EXPECT_TRUE(validator.Key("blackArray", 10, false));
|
1983
|
+
EXPECT_TRUE(validator.StartArray());
|
1984
|
+
EXPECT_TRUE(validator.EndArray(0));
|
1985
|
+
EXPECT_TRUE(validator.EndObject(0));
|
1986
|
+
EXPECT_TRUE(validator.IsValid());
|
1987
|
+
EXPECT_STREQ("{\"cyanArray2\":[],\"blackArray\":[]}", sb.GetString());
|
1988
|
+
}
|
1989
|
+
|
1990
|
+
TEST(SchemaValidator, Ref_remote) {
|
1991
|
+
typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
|
1992
|
+
RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
|
1993
|
+
Document sd;
|
1994
|
+
sd.Parse("{\"$ref\": \"http://localhost:1234/subSchemas.json#/integer\"}");
|
1995
|
+
SchemaDocumentType s(sd, 0, 0, &provider);
|
1996
|
+
typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
|
1997
|
+
typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
|
1998
|
+
INVALIDATE_(s, "null", "/integer", "type", "",
|
1999
|
+
"{ \"type\": {"
|
2000
|
+
" \"instanceRef\": \"#\","
|
2001
|
+
" \"schemaRef\": \"http://localhost:1234/subSchemas.json#/integer\","
|
2002
|
+
" \"expected\": [\"integer\"], \"actual\": \"null\""
|
2003
|
+
"}}",
|
2004
|
+
SchemaValidatorType, PointerType);
|
2005
|
+
}
|
2006
|
+
|
2007
|
+
#ifdef __clang__
|
2008
|
+
RAPIDJSON_DIAG_POP
|
2009
|
+
#endif
|