forked from lefticus/json2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalijson_tests.cpp
66 lines (50 loc) · 1.93 KB
/
valijson_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "allof_integers_and_numbers.schema.hpp"
#include "array_doubles_10_20_30_40.hpp"
#include "array_integers_10_20_30_40.hpp"
#include <catch2/catch.hpp>
#include <json2cpp/json2cpp_adapter.hpp>
#include <valijson/schema.hpp>
#include <valijson/schema_parser.hpp>
#include <valijson/validator.hpp>
TEST_CASE("Can load a valijson schema")
{
using valijson::Schema;
using valijson::SchemaParser;
using valijson::Validator;
using valijson::adapters::json2cppJsonAdapter;
// Parse JSON schema content using valijson
Schema mySchema;
SchemaParser parser;
json2cppJsonAdapter mySchemaAdapter(compiled_json::allof_integers_and_numbers_schema::get());
CHECK_NOTHROW(parser.populateSchema(mySchemaAdapter, mySchema));
}
TEST_CASE("Validation fails where expected")
{
using valijson::Schema;
using valijson::SchemaParser;
using valijson::Validator;
using valijson::adapters::json2cppJsonAdapter;
// Parse JSON schema content using valijson
Schema mySchema;
SchemaParser parser;
json2cppJsonAdapter mySchemaAdapter(compiled_json::allof_integers_and_numbers_schema::get());
CHECK_NOTHROW(parser.populateSchema(mySchemaAdapter, mySchema));
Validator validator;
json2cppJsonAdapter myTargetAdapter(compiled_json::array_doubles_10_20_30_40::get());
REQUIRE_FALSE(validator.validate(mySchema, myTargetAdapter, nullptr));
}
TEST_CASE("Can validate a document")
{
using valijson::Schema;
using valijson::SchemaParser;
using valijson::Validator;
using valijson::adapters::json2cppJsonAdapter;
// Parse JSON schema content using valijson
Schema mySchema;
SchemaParser parser;
json2cppJsonAdapter mySchemaAdapter(compiled_json::allof_integers_and_numbers_schema::get());
CHECK_NOTHROW(parser.populateSchema(mySchemaAdapter, mySchema));
Validator validator;
json2cppJsonAdapter myTargetAdapter(compiled_json::array_integers_10_20_30_40::get());
REQUIRE(validator.validate(mySchema, myTargetAdapter, nullptr));
}