22RAPIDJSON_DIAG_OFF(variadic-macros)
23#elif defined(_MSC_VER)
25RAPIDJSON_DIAG_OFF(4822)
30#define TEST_HASHER(json1, json2, expected) \
34 ASSERT_FALSE(d1.HasParseError());\
36 ASSERT_FALSE(d2.HasParseError());\
37 internal::Hasher<Value, CrtAllocator> h1, h2;\
40 ASSERT_TRUE(h1.IsValid());\
41 ASSERT_TRUE(h2.IsValid());\
43 EXPECT_TRUE(expected == (h1.GetHashCode() == h2.GetHashCode()));\
61 TEST_HASHER(
"9223372036854775808",
"9223372036854775808",
true);
75 TEST_HASHER(
"\"Hello\\u0000\"",
"\"Hello\"",
false);
81 TEST_HASHER(
"[1, true, false]",
"[1, true, false]",
true);
82 TEST_HASHER(
"[1, true, false]",
"[1, true]",
false);
97 TEST_HASHER(
"{\"a\":1, \"b\":2}",
"{\"b\":2, \"a\":1}",
true);
108#define VALIDATE(schema, json, expected) \
110 SchemaValidator validator(schema);\
114 EXPECT_FALSE(d.HasParseError());\
115 EXPECT_TRUE(expected == d.Accept(validator));\
116 EXPECT_TRUE(expected == validator.IsValid());\
117 if ((expected) && !validator.IsValid()) {\
119 validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);\
120 printf("Invalid schema: %s\n", sb.GetString());\
121 printf("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());\
123 validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);\
124 printf("Invalid document: %s\n", sb.GetString());\
126 Writer<StringBuffer> w(sb);\
127 validator.GetError().Accept(w);\
128 printf("Validation error: %s\n", sb.GetString());\
132#define INVALIDATE(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error) \
134 INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, SchemaValidator, Pointer) \
137#define INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, \
138 SchemaValidatorType, PointerType) \
140 SchemaValidatorType validator(schema);\
144 EXPECT_FALSE(d.HasParseError());\
145 EXPECT_FALSE(d.Accept(validator));\
146 EXPECT_FALSE(validator.IsValid());\
147 if (validator.GetInvalidSchemaPointer() != PointerType(invalidSchemaPointer)) {\
149 validator.GetInvalidSchemaPointer().Stringify(sb);\
150 printf("GetInvalidSchemaPointer() Expected: %s Actual: %s\n", invalidSchemaPointer, sb.GetString());\
153 ASSERT_TRUE(validator.GetInvalidSchemaKeyword() != 0);\
154 if (strcmp(validator.GetInvalidSchemaKeyword(), invalidSchemaKeyword) != 0) {\
155 printf("GetInvalidSchemaKeyword() Expected: %s Actual %s\n", invalidSchemaKeyword, validator.GetInvalidSchemaKeyword());\
158 if (validator.GetInvalidDocumentPointer() != PointerType(invalidDocumentPointer)) {\
160 validator.GetInvalidDocumentPointer().Stringify(sb);\
161 printf("GetInvalidDocumentPointer() Expected: %s Actual: %s\n", invalidDocumentPointer, sb.GetString());\
166 if (validator.GetError() != e) {\
168 Writer<StringBuffer> w(sb);\
169 validator.GetError().Accept(w);\
170 printf("GetError() Expected: %s Actual: %s\n", error, sb.GetString());\
182 VALIDATE(
s,
"{ \"an\": [ \"arbitrarily\", \"nested\" ], \"data\": \"structure\" }",
true);
187 sd.
Parse(
"{ \"type\": [\"number\", \"string\"] }");
191 VALIDATE(
s,
"\"Life, the universe, and everything\"",
true);
192 INVALIDATE(
s,
"[\"Life\", \"the universe\", \"and everything\"]",
"",
"type",
"",
194 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
195 " \"expected\": [\"string\", \"number\"], \"actual\": \"array\""
201 sd.
Parse(
"{ \"type\": \"string\", \"enum\" : [\"red\", \"amber\", \"green\"] }");
206 "{ \"enum\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
211 sd.
Parse(
"{ \"enum\": [\"red\", \"amber\", \"green\", null, 42] }");
218 "{ \"enum\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
223 sd.
Parse(
"{ \"type\": \"string\", \"enum\": [\"red\", \"amber\", \"green\", null] }");
229 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
230 " \"expected\": [\"string\"], \"actual\": \"null\""
237 sd.
Parse(
"{\"allOf\": [{ \"type\": \"string\" }, { \"type\": \"string\", \"maxLength\": 5 }]}");
242 "{ \"maxLength\": { "
243 " \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\", "
244 " \"expected\": 5, \"actual\": \"too long\""
249 sd.
Parse(
"{\"allOf\": [{ \"type\": \"string\" }, { \"type\": \"number\" } ] }");
254 "{ \"type\": { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
255 " \"expected\": [\"string\"], \"actual\": \"integer\""
262 sd.
Parse(
"{\"anyOf\": [{ \"type\": \"string\" }, { \"type\": \"number\" } ] }");
267 INVALIDATE(
s,
"{ \"Not a\": \"string or number\" }",
"",
"anyOf",
"",
269 " \"instanceRef\": \"#\", \"schemaRef\": \"#\", "
272 " \"instanceRef\": \"#\", \"schemaRef\": \"#/anyOf/0\","
273 " \"expected\": [\"string\"], \"actual\": \"object\""
276 " \"instanceRef\": \"#\", \"schemaRef\": \"#/anyOf/1\","
277 " \"expected\": [\"number\"], \"actual\": \"object\""
285 sd.
Parse(
"{\"oneOf\": [{ \"type\": \"number\", \"multipleOf\": 5 }, { \"type\": \"number\", \"multipleOf\": 3 } ] }");
292 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
294 " { \"multipleOf\": {"
295 " \"instanceRef\": \"#\", \"schemaRef\": \"#/oneOf/0\","
296 " \"expected\": 5, \"actual\": 2"
298 " { \"multipleOf\": {"
299 " \"instanceRef\": \"#\", \"schemaRef\": \"#/oneOf/1\","
300 " \"expected\": 3, \"actual\": 2"
305 "{ \"oneOf\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\", \"errors\": [{}, {}]}}");
310 sd.
Parse(
"{\"not\":{ \"type\": \"string\"}}");
314 VALIDATE(
s,
"{ \"key\": \"value\" }",
true);
316 "{ \"not\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
323 " \"$schema\": \"http://json-schema.org/draft-04/schema#\","
325 " \"definitions\": {"
327 " \"type\": \"object\","
329 " \"street_address\": { \"type\": \"string\" },"
330 " \"city\": { \"type\": \"string\" },"
331 " \"state\": { \"type\": \"string\" }"
333 " \"required\": [\"street_address\", \"city\", \"state\"]"
336 " \"type\": \"object\","
338 " \"billing_address\": { \"$ref\": \"#/definitions/address\" },"
339 " \"shipping_address\": { \"$ref\": \"#/definitions/address\" }"
344 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);
351 " \"$schema\": \"http://json-schema.org/draft-04/schema#\","
353 " \"definitions\": {"
355 " \"type\": \"object\","
357 " \"street_address\": { \"type\": \"string\" },"
358 " \"city\": { \"type\": \"string\" },"
359 " \"state\": { \"type\": \"string\" }"
361 " \"required\": [\"street_address\", \"city\", \"state\"]"
364 " \"type\": \"object\","
366 " \"billing_address\": { \"$ref\": \"#/definitions/address\" },"
367 " \"shipping_address\": {"
369 " { \"$ref\": \"#/definitions/address\" },"
371 " { \"type\": { \"enum\": [ \"residential\", \"business\" ] } },"
372 " \"required\": [\"type\"]"
380 INVALIDATE(
s,
"{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\"} }",
"/properties/shipping_address",
"allOf",
"/shipping_address",
382 " \"instanceRef\": \"#/shipping_address\","
383 " \"schemaRef\": \"#/properties/shipping_address/allOf/1\","
384 " \"missing\": [\"type\"]"
386 VALIDATE(
s,
"{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\", \"type\": \"business\"} }",
true);
391 sd.
Parse(
"{\"type\":\"string\"}");
397 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
398 " \"expected\": [\"string\"], \"actual\": \"integer\""
402 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
403 " \"expected\": [\"string\"], \"actual\": \"integer\""
407 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
408 " \"expected\": [\"string\"], \"actual\": \"integer\""
412 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
413 " \"expected\": [\"string\"], \"actual\": \"integer\""
417 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
418 " \"expected\": [\"string\"], \"actual\": \"number\""
424 sd.
Parse(
"{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}");
429 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
430 " \"expected\": 2, \"actual\": \"A\""
436 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
437 " \"expected\": 3, \"actual\": \"ABCD\""
441#if RAPIDJSON_SCHEMA_HAS_REGEX
444 sd.
Parse(
"{\"type\":\"string\",\"pattern\":\"^(\\\\([0-9]{3}\\\\))?[0-9]{3}-[0-9]{4}$\"}");
449 INVALIDATE(
s,
"\"(888)555-1212 ext. 532\"",
"",
"pattern",
"",
451 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
452 " \"actual\": \"(888)555-1212 ext. 532\""
454 INVALIDATE(
s,
"\"(800)FLOWERS\"",
"",
"pattern",
"",
456 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
457 " \"actual\": \"(800)FLOWERS\""
463 sd.
Parse(
"{\"type\":\"string\",\"pattern\":\"a{0}\"}");
474 sd.
Parse(
"{\"type\":\"integer\"}");
485 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
486 " \"expected\": [\"integer\"], \"actual\": \"number\""
490 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
491 " \"expected\": [\"integer\"], \"actual\": \"string\""
497 sd.
Parse(
"{\"type\":\"integer\",\"minimum\":0,\"maximum\":100,\"exclusiveMaximum\":true}");
502 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
503 " \"expected\": 0, \"actual\": -1"
510 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
511 " \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100"
515 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
516 " \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 101"
522 sd.
Parse(
"{\"type\":\"integer\",\"minimum\":-9223372036854775807,\"maximum\":9223372036854775806}");
525 INVALIDATE(
s,
"-9223372036854775808",
"",
"minimum",
"",
527 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
528 " \"expected\": -9223372036854775807, \"actual\": -9223372036854775808"
530 VALIDATE(
s,
"-9223372036854775807",
true);
536 VALIDATE(
s,
"9223372036854775806",
true);
537 INVALIDATE(
s,
"9223372036854775807",
"",
"maximum",
"",
539 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
540 " \"expected\": 9223372036854775806, \"actual\": 9223372036854775807"
542 INVALIDATE(
s,
"18446744073709551615",
"",
"maximum",
"",
544 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
545 " \"expected\": 9223372036854775806, \"actual\": 18446744073709551615"
551 sd.
Parse(
"{\"type\":\"integer\",\"minimum\":9223372036854775808,\"maximum\":18446744073709551614}");
554 INVALIDATE(
s,
"-9223372036854775808",
"",
"minimum",
"",
556 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
557 " \"expected\": 9223372036854775808, \"actual\": -9223372036854775808"
559 INVALIDATE(
s,
"9223372036854775807",
"",
"minimum",
"",
561 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
562 " \"expected\": 9223372036854775808, \"actual\": 9223372036854775807"
566 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
567 " \"expected\": 9223372036854775808, \"actual\": -2147483648"
571 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
572 " \"expected\": 9223372036854775808, \"actual\": 0"
576 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
577 " \"expected\": 9223372036854775808, \"actual\": 2147483647"
581 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
582 " \"expected\": 9223372036854775808, \"actual\": 2147483648"
586 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
587 " \"expected\": 9223372036854775808, \"actual\": 4294967295"
589 VALIDATE(
s,
"9223372036854775808",
true);
590 VALIDATE(
s,
"18446744073709551614",
true);
591 INVALIDATE(
s,
"18446744073709551615",
"",
"maximum",
"",
593 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
594 " \"expected\": 18446744073709551614, \"actual\": 18446744073709551615"
600 sd.
Parse(
"{\"type\":\"integer\",\"minimum\":-9223372036854775808,\"maximum\":18446744073709551615,\"exclusiveMinimum\":true,\"exclusiveMaximum\":true}");
603 INVALIDATE(
s,
"-9223372036854775808",
"",
"minimum",
"",
605 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
606 " \"expected\": -9223372036854775808, \"exclusiveMinimum\": true, "
607 " \"actual\": -9223372036854775808"
609 VALIDATE(
s,
"-9223372036854775807",
true);
610 VALIDATE(
s,
"18446744073709551614",
true);
611 INVALIDATE(
s,
"18446744073709551615",
"",
"maximum",
"",
613 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
614 " \"expected\": 18446744073709551615, \"exclusiveMaximum\": true, "
615 " \"actual\": 18446744073709551615"
621 sd.
Parse(
"{\"type\":\"integer\",\"multipleOf\":10}");
629 "{ \"multipleOf\": {"
630 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
631 " \"expected\": 10, \"actual\": 23"
634 "{ \"multipleOf\": {"
635 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
636 " \"expected\": 10, \"actual\": -23"
642 sd.
Parse(
"{\"type\":\"integer\",\"multipleOf\":18446744073709551615}");
646 VALIDATE(
s,
"18446744073709551615",
true);
647 INVALIDATE(
s,
"18446744073709551614",
"",
"multipleOf",
"",
648 "{ \"multipleOf\": {"
649 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
650 " \"expected\": 18446744073709551615, \"actual\": 18446744073709551614"
656 sd.
Parse(
"{\"type\":\"number\",\"minimum\":0,\"maximum\":100,\"exclusiveMaximum\":true}");
661 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
662 " \"expected\": 0, \"actual\": -1"
671 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
672 " \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100"
676 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
677 " \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100.0"
681 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
682 " \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 101.5"
688 sd.
Parse(
"{\"type\":\"number\",\"minimum\":-100,\"maximum\":-1,\"exclusiveMaximum\":true}");
693 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
694 " \"expected\": -100, \"actual\": -101"
698 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
699 " \"expected\": -100, \"actual\": -100.1"
705 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
706 " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": -1"
710 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
711 " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": -0.9"
715 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
716 " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 0"
720 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
721 " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 2147483647"
725 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
726 " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 2147483648"
730 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
731 " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 4294967295"
733 INVALIDATE(
s,
"9223372036854775808",
"",
"maximum",
"",
735 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
736 " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 9223372036854775808"
738 INVALIDATE(
s,
"18446744073709551614",
"",
"maximum",
"",
740 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
741 " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
743 INVALIDATE(
s,
"18446744073709551615",
"",
"maximum",
"",
745 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
746 " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
752 sd.
Parse(
"{\"type\":\"number\",\"minimum\":0.1,\"maximum\":100.1,\"exclusiveMaximum\":true}");
755 INVALIDATE(
s,
"-9223372036854775808",
"",
"minimum",
"",
757 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
758 " \"expected\": 0.1, \"actual\": -9223372036854775808"
762 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
763 " \"expected\": 0.1, \"actual\": -2147483648"
767 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
768 " \"expected\": 0.1, \"actual\": -1"
776 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
777 " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 101"
781 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
782 " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 101.5"
784 INVALIDATE(
s,
"18446744073709551614",
"",
"maximum",
"",
786 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
787 " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
789 INVALIDATE(
s,
"18446744073709551615",
"",
"maximum",
"",
791 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
792 " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
796 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
797 " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 2147483647"
801 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
802 " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 2147483648"
806 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
807 " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 4294967295"
809 INVALIDATE(
s,
"9223372036854775808",
"",
"maximum",
"",
811 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
812 " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 9223372036854775808"
814 INVALIDATE(
s,
"18446744073709551614",
"",
"maximum",
"",
816 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
817 " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
819 INVALIDATE(
s,
"18446744073709551615",
"",
"maximum",
"",
821 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
822 " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
828 sd.
Parse(
"{\"type\":\"number\",\"minimum\":9223372036854775808.0,\"maximum\":18446744073709550000.0}");
831 INVALIDATE(
s,
"-9223372036854775808",
"",
"minimum",
"",
833 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
834 " \"expected\": 9223372036854775808.0, \"actual\": -9223372036854775808"
838 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
839 " \"expected\": 9223372036854775808.0, \"actual\": -2147483648"
843 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
844 " \"expected\": 9223372036854775808.0, \"actual\": 0"
848 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
849 " \"expected\": 9223372036854775808.0, \"actual\": 2147483647"
853 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
854 " \"expected\": 9223372036854775808.0, \"actual\": 2147483648"
858 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
859 " \"expected\": 9223372036854775808.0, \"actual\": 4294967295"
861 VALIDATE(
s,
"9223372036854775808",
true);
862 VALIDATE(
s,
"18446744073709540000",
true);
863 INVALIDATE(
s,
"18446744073709551615",
"",
"maximum",
"",
865 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
866 " \"expected\": 18446744073709550000.0, \"actual\": 18446744073709551615"
872 sd.
Parse(
"{\"type\":\"number\",\"multipleOf\":10.0}");
880 "{ \"multipleOf\": {"
881 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
882 " \"expected\": 10.0, \"actual\": 23"
885 "{ \"multipleOf\": {"
886 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
887 " \"expected\": 10.0, \"actual\": -2147483648"
891 "{ \"multipleOf\": {"
892 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
893 " \"expected\": 10.0, \"actual\": 2147483647"
896 "{ \"multipleOf\": {"
897 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
898 " \"expected\": 10.0, \"actual\": 2147483648"
902 "{ \"multipleOf\": {"
903 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
904 " \"expected\": 10.0, \"actual\": 4294967295"
911 sd.
Parse(
"{\"type\":\"number\",\"multipleOf\":1}");
917 "{ \"multipleOf\": {"
918 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
919 " \"expected\": 1, \"actual\": 3.1415926"
925 sd.
Parse(
"{\"type\":\"object\"}");
928 VALIDATE(
s,
"{\"key\":\"value\",\"another_key\":\"another_value\"}",
true);
929 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);
930 INVALIDATE(
s,
"[\"An\", \"array\", \"not\", \"an\", \"object\"]",
"",
"type",
"",
932 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
933 " \"expected\": [\"object\"], \"actual\": \"array\""
937 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
938 " \"expected\": [\"object\"], \"actual\": \"string\""
946 " \"type\": \"object\","
947 " \"properties\" : {"
948 " \"number\": { \"type\": \"number\" },"
949 " \"street_name\" : { \"type\": \"string\" },"
950 " \"street_type\" : { \"type\": \"string\", \"enum\" : [\"Street\", \"Avenue\", \"Boulevard\"] }"
956 VALIDATE(
s,
"{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }",
true);
957 INVALIDATE(
s,
"{ \"number\": \"1600\", \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }",
"/properties/number",
"type",
"/number",
959 " \"instanceRef\": \"#/number\", \"schemaRef\": \"#/properties/number\","
960 " \"expected\": [\"number\"], \"actual\": \"string\""
962 INVALIDATE(
s,
"{ \"number\": \"One\", \"street_name\": \"Microsoft\", \"street_type\": \"Way\" }",
963 "/properties/number",
"type",
"/number",
965 " \"instanceRef\": \"#/number\", \"schemaRef\": \"#/properties/number\","
966 " \"expected\": [\"number\"], \"actual\": \"string\""
968 VALIDATE(
s,
"{ \"number\": 1600, \"street_name\": \"Pennsylvania\" }",
true);
970 VALIDATE(
s,
"{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"direction\": \"NW\" }",
true);
977 " \"type\": \"object\","
978 " \"properties\" : {"
979 " \"number\": { \"type\": \"number\" },"
980 " \"street_name\" : { \"type\": \"string\" },"
981 " \"street_type\" : { \"type\": \"string\","
982 " \"enum\" : [\"Street\", \"Avenue\", \"Boulevard\"]"
985 " \"additionalProperties\": false"
990 VALIDATE(
s,
"{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }",
true);
991 INVALIDATE(
s,
"{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"direction\": \"NW\" }",
"",
"additionalProperties",
"/direction",
992 "{ \"additionalProperties\": {"
993 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
994 " \"disallowed\": \"direction\""
1002 " \"type\": \"object\","
1003 " \"properties\" : {"
1004 " \"number\": { \"type\": \"number\" },"
1005 " \"street_name\" : { \"type\": \"string\" },"
1006 " \"street_type\" : { \"type\": \"string\","
1007 " \"enum\" : [\"Street\", \"Avenue\", \"Boulevard\"]"
1010 " \"additionalProperties\": { \"type\": \"string\" }"
1014 VALIDATE(
s,
"{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }",
true);
1015 VALIDATE(
s,
"{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"direction\": \"NW\" }",
true);
1016 INVALIDATE(
s,
"{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"office_number\": 201 }",
"/additionalProperties",
"type",
"/office_number",
1018 " \"instanceRef\": \"#/office_number\", \"schemaRef\": \"#/additionalProperties\","
1019 " \"expected\": [\"string\"], \"actual\": \"integer\""
1027 " \"type\": \"object\","
1028 " \"properties\" : {"
1029 " \"name\": { \"type\": \"string\" },"
1030 " \"email\" : { \"type\": \"string\" },"
1031 " \"address\" : { \"type\": \"string\" },"
1032 " \"telephone\" : { \"type\": \"string\" }"
1034 " \"required\":[\"name\", \"email\"]"
1038 VALIDATE(
s,
"{ \"name\": \"William Shakespeare\", \"email\" : \"bill@stratford-upon-avon.co.uk\" }",
true);
1039 VALIDATE(
s,
"{ \"name\": \"William Shakespeare\", \"email\" : \"bill@stratford-upon-avon.co.uk\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\", \"authorship\" : \"in question\"}",
true);
1040 INVALIDATE(
s,
"{ \"name\": \"William Shakespeare\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\" }",
"",
"required",
"",
1042 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1043 " \"missing\": [\"email\"]"
1047 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1048 " \"missing\": [\"name\", \"email\"]"
1056 " \"type\": \"object\","
1057 " \"properties\" : {"
1058 " \"name\": { \"type\": \"string\", \"default\": \"William Shakespeare\" },"
1059 " \"email\" : { \"type\": \"string\", \"default\": \"\" },"
1060 " \"address\" : { \"type\": \"string\" },"
1061 " \"telephone\" : { \"type\": \"string\" }"
1063 " \"required\":[\"name\", \"email\"]"
1067 VALIDATE(
s,
"{ \"email\" : \"bill@stratford-upon-avon.co.uk\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\", \"authorship\" : \"in question\"}",
true);
1068 INVALIDATE(
s,
"{ \"name\": \"William Shakespeare\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\" }",
"",
"required",
"",
1070 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1071 " \"missing\": [\"email\"]"
1075 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1076 " \"missing\": [\"email\"]"
1082 sd.
Parse(
"{\"type\":\"object\", \"minProperties\":2, \"maxProperties\":3}");
1086 "{ \"minProperties\": {"
1087 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1088 " \"expected\": 2, \"actual\": 0"
1090 INVALIDATE(
s,
"{\"a\":0}",
"",
"minProperties",
"",
1091 "{ \"minProperties\": {"
1092 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1093 " \"expected\": 2, \"actual\": 1"
1096 VALIDATE(
s,
"{\"a\":0,\"b\":1,\"c\":2}",
true);
1097 INVALIDATE(
s,
"{\"a\":0,\"b\":1,\"c\":2,\"d\":3}",
"",
"maxProperties",
"",
1098 "{ \"maxProperties\": {"
1099 " \"instanceRef\": \"#\", \"schemaRef\": \"#\", "
1100 " \"expected\": 3, \"actual\": 4"
1108 " \"type\": \"object\","
1109 " \"properties\": {"
1110 " \"name\": { \"type\": \"string\" },"
1111 " \"credit_card\": { \"type\": \"number\" },"
1112 " \"cvv_code\": { \"type\": \"number\" },"
1113 " \"billing_address\": { \"type\": \"string\" }"
1115 " \"required\": [\"name\"],"
1116 " \"dependencies\": {"
1117 " \"credit_card\": [\"cvv_code\", \"billing_address\"]"
1122 VALIDATE(
s,
"{ \"name\": \"John Doe\", \"credit_card\": 5555555555555555, \"cvv_code\": 777, "
1123 "\"billing_address\": \"555 Debtor's Lane\" }",
true);
1124 INVALIDATE(
s,
"{ \"name\": \"John Doe\", \"credit_card\": 5555555555555555 }",
"",
"dependencies",
"",
1125 "{ \"dependencies\": {"
1126 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1127 " \"errors\": {\"credit_card\": [\"cvv_code\", \"billing_address\"]}"
1129 VALIDATE(
s,
"{ \"name\": \"John Doe\"}",
true);
1130 VALIDATE(
s,
"{ \"name\": \"John Doe\", \"cvv_code\": 777, \"billing_address\": \"555 Debtor's Lane\" }",
true);
1137 " \"type\": \"object\","
1138 " \"properties\" : {"
1139 " \"name\": { \"type\": \"string\" },"
1140 " \"credit_card\" : { \"type\": \"number\" }"
1142 " \"required\" : [\"name\"],"
1143 " \"dependencies\" : {"
1144 " \"credit_card\": {"
1145 " \"properties\": {"
1146 " \"billing_address\": { \"type\": \"string\" }"
1148 " \"required\" : [\"billing_address\"]"
1154 VALIDATE(
s,
"{\"name\": \"John Doe\", \"credit_card\" : 5555555555555555,\"billing_address\" : \"555 Debtor's Lane\"}",
true);
1155 INVALIDATE(
s,
"{\"name\": \"John Doe\", \"credit_card\" : 5555555555555555 }",
"",
"dependencies",
"",
1156 "{ \"dependencies\": {"
1157 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1159 " \"credit_card\": {"
1161 " \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/credit_card\","
1162 " \"missing\": [\"billing_address\"]"
1165 VALIDATE(
s,
"{\"name\": \"John Doe\", \"billing_address\" : \"555 Debtor's Lane\"}",
true);
1168#if RAPIDJSON_SCHEMA_HAS_REGEX
1173 " \"type\": \"object\","
1174 " \"patternProperties\": {"
1175 " \"^S_\": { \"type\": \"string\" },"
1176 " \"^I_\": { \"type\": \"integer\" }"
1181 VALIDATE(
s,
"{ \"S_25\": \"This is a string\" }",
true);
1183 INVALIDATE(
s,
"{ \"S_0\": 42 }",
"",
"patternProperties",
"/S_0",
1185 " \"instanceRef\": \"#/S_0\", \"schemaRef\": \"#/patternProperties/%5ES_\","
1186 " \"expected\": [\"string\"], \"actual\": \"integer\""
1188 INVALIDATE(
s,
"{ \"I_42\": \"This is a string\" }",
"",
"patternProperties",
"/I_42",
1190 " \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/patternProperties/%5EI_\","
1191 " \"expected\": [\"integer\"], \"actual\": \"string\""
1193 VALIDATE(
s,
"{ \"keyword\": \"value\" }",
true);
1200 " \"type\": \"object\","
1201 " \"patternProperties\": {"
1202 " \"^I_\": { \"multipleOf\": 5 },"
1203 " \"30$\": { \"multipleOf\": 6 }"
1209 INVALIDATE(
s,
"{ \"I_30\": 7 }",
"",
"patternProperties",
"/I_30",
1210 "{ \"multipleOf\": ["
1212 " \"instanceRef\": \"#/I_30\", \"schemaRef\": \"#/patternProperties/%5EI_\","
1213 " \"expected\": 5, \"actual\": 7"
1215 " \"instanceRef\": \"#/I_30\", \"schemaRef\": \"#/patternProperties/30%24\","
1216 " \"expected\": 6, \"actual\": 7"
1225 " \"type\": \"object\","
1226 " \"properties\": {"
1227 " \"I_42\": { \"type\": \"integer\", \"minimum\": 73 }"
1229 " \"patternProperties\": {"
1230 " \"^I_\": { \"type\": \"integer\", \"multipleOf\": 6 }"
1237 INVALIDATE(
s,
"{ \"I_42\": 42 }",
"",
"patternProperties",
"/I_42",
1239 " \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/properties/I_42\","
1240 " \"expected\": 73, \"actual\": 42"
1242 INVALIDATE(
s,
"{ \"I_42\": 7 }",
"",
"patternProperties",
"/I_42",
1244 " \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/properties/I_42\","
1245 " \"expected\": 73, \"actual\": 7"
1247 " \"multipleOf\": {"
1248 " \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/patternProperties/%5EI_\","
1249 " \"expected\": 6, \"actual\": 7"
1258 " \"type\": \"object\","
1259 " \"properties\": {"
1260 " \"builtin\": { \"type\": \"number\" }"
1262 " \"patternProperties\": {"
1263 " \"^S_\": { \"type\": \"string\" },"
1264 " \"^I_\": { \"type\": \"integer\" }"
1266 " \"additionalProperties\": { \"type\": \"string\" }"
1270 VALIDATE(
s,
"{ \"builtin\": 42 }",
true);
1271 VALIDATE(
s,
"{ \"keyword\": \"value\" }",
true);
1272 INVALIDATE(
s,
"{ \"keyword\": 42 }",
"/additionalProperties",
"type",
"/keyword",
1274 " \"instanceRef\": \"#/keyword\", \"schemaRef\": \"#/additionalProperties\","
1275 " \"expected\": [\"string\"], \"actual\": \"integer\""
1282 sd.
Parse(
"{\"type\":\"array\"}");
1286 VALIDATE(
s,
"[3, \"different\", { \"types\" : \"of values\" }]",
true);
1287 INVALIDATE(
s,
"{\"Not\": \"an array\"}",
"",
"type",
"",
1289 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1290 " \"expected\": [\"array\"], \"actual\": \"object\""
1298 " \"type\": \"array\","
1300 " \"type\": \"number\""
1306 INVALIDATE(
s,
"[1, 2, \"3\", 4, 5]",
"/items",
"type",
"/2",
1308 " \"instanceRef\": \"#/2\", \"schemaRef\": \"#/items\","
1309 " \"expected\": [\"number\"], \"actual\": \"string\""
1318 " \"type\": \"array\","
1321 " \"type\": \"number\""
1324 " \"type\": \"string\""
1327 " \"type\": \"string\","
1328 " \"enum\": [\"Street\", \"Avenue\", \"Boulevard\"]"
1331 " \"type\": \"string\","
1332 " \"enum\": [\"NW\", \"NE\", \"SW\", \"SE\"]"
1338 VALIDATE(
s,
"[1600, \"Pennsylvania\", \"Avenue\", \"NW\"]",
true);
1339 INVALIDATE(
s,
"[24, \"Sussex\", \"Drive\"]",
"/items/2",
"enum",
"/2",
1340 "{ \"enum\": { \"instanceRef\": \"#/2\", \"schemaRef\": \"#/items/2\" }}");
1341 INVALIDATE(
s,
"[\"Palais de l'Elysee\"]",
"/items/0",
"type",
"/0",
1343 " \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items/0\","
1344 " \"expected\": [\"number\"], \"actual\": \"string\""
1346 INVALIDATE(
s,
"[\"Twenty-four\", \"Sussex\", \"Drive\"]",
"/items/0",
"type",
"/0",
1348 " \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items/0\","
1349 " \"expected\": [\"number\"], \"actual\": \"string\""
1351 VALIDATE(
s,
"[10, \"Downing\", \"Street\"]",
true);
1352 VALIDATE(
s,
"[1600, \"Pennsylvania\", \"Avenue\", \"NW\", \"Washington\"]",
true);
1359 " \"type\": \"array\","
1362 " \"type\": \"number\""
1365 " \"type\": \"string\""
1368 " \"type\": \"string\","
1369 " \"enum\": [\"Street\", \"Avenue\", \"Boulevard\"]"
1372 " \"type\": \"string\","
1373 " \"enum\": [\"NW\", \"NE\", \"SW\", \"SE\"]"
1376 " \"additionalItems\": false"
1380 VALIDATE(
s,
"[1600, \"Pennsylvania\", \"Avenue\", \"NW\"]",
true);
1381 VALIDATE(
s,
"[1600, \"Pennsylvania\", \"Avenue\"]",
true);
1382 INVALIDATE(
s,
"[1600, \"Pennsylvania\", \"Avenue\", \"NW\", \"Washington\"]",
"",
"items",
"/4",
1383 "{ \"additionalItems\": {"
1384 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1385 " \"disallowed\": 4"
1391 sd.
Parse(
"{\"type\": \"array\",\"minItems\": 2,\"maxItems\" : 3}");
1396 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1397 " \"expected\": 2, \"actual\": 0"
1401 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1402 " \"expected\": 2, \"actual\": 1"
1408 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1409 " \"expected\": 3, \"actual\": 4"
1415 sd.
Parse(
"{\"type\": \"array\", \"uniqueItems\": true}");
1419 INVALIDATE(
s,
"[1, 2, 3, 3, 4]",
"",
"uniqueItems",
"/3",
1420 "{ \"uniqueItems\": {"
1421 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1422 " \"duplicates\": [2, 3]"
1424 INVALIDATE(
s,
"[1, 2, 3, 3, 3]",
"",
"uniqueItems",
"/3",
1425 "{ \"uniqueItems\": {"
1426 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1427 " \"duplicates\": [2, 3]"
1434 sd.
Parse(
"{\"type\":\"boolean\"}");
1441 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1442 " \"expected\": [\"boolean\"], \"actual\": \"string\""
1446 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1447 " \"expected\": [\"boolean\"], \"actual\": \"integer\""
1453 sd.
Parse(
"{\"type\":\"null\"}");
1459 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1460 " \"expected\": [\"null\"], \"actual\": \"boolean\""
1464 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1465 " \"expected\": [\"null\"], \"actual\": \"integer\""
1469 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1470 " \"expected\": [\"null\"], \"actual\": \"string\""
1478 sd.
Parse(
"{\"type\":\"array\", \"items\": { \"type\":\"string\" }}");
1484 " \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items\","
1485 " \"expected\": [\"string\"], \"actual\": \"integer\""
1489 " \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items\","
1490 " \"expected\": [\"string\"], \"actual\": \"object\""
1498 " \"type\":\"object\","
1499 " \"properties\": {"
1501 " \"type\":[\"integer\", \"string\"]"
1508 VALIDATE(
s,
"{ \"tel\": \"123-456\" }",
true);
1509 INVALIDATE(
s,
"{ \"tel\": true }",
"/properties/tel",
"type",
"/tel",
1511 " \"instanceRef\": \"#/tel\", \"schemaRef\": \"#/properties/tel\","
1512 " \"expected\": [\"string\", \"integer\"], \"actual\": \"boolean\""
1520 " \"type\": [\"object\",\"string\"],"
1521 " \"properties\": {"
1523 " \"type\": \"integer\""
1531 INVALIDATE(
s,
"{ \"tel\": \"fail\" }",
"/properties/tel",
"type",
"/tel",
1533 " \"instanceRef\": \"#/tel\", \"schemaRef\": \"#/properties/tel\","
1534 " \"expected\": [\"integer\"], \"actual\": \"string\""
1543 " { \"type\": \"string\", \"minLength\": 2 },"
1544 " { \"type\": \"string\", \"maxLength\": 5 },"
1545 " { \"allOf\": [ { \"enum\" : [\"ok\", \"okay\", \"OK\", \"o\"] }, { \"enum\" : [\"ok\", \"OK\", \"o\"]} ] }"
1554 " \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\""
1557 "{ \"minLength\": {"
1558 " \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
1559 " \"expected\": 2, \"actual\": \"o\""
1562 "{ \"minLength\": {"
1563 " \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
1564 " \"expected\": 2, \"actual\": \"n\""
1567 " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
1568 " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
1572 "{ \"maxLength\": {"
1573 " \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\","
1574 " \"expected\": 5, \"actual\": \"too long\""
1577 " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
1578 " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
1583 " { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\","
1584 " \"expected\": [\"string\"], \"actual\": \"integer\""
1586 " { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\","
1587 " \"expected\": [\"string\"], \"actual\": \"integer\""
1591 " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"},"
1592 " {\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}"
1601 " \"type\": \"object\","
1602 " \"properties\": {"
1603 " \"~/\": { \"type\": \"number\" }"
1607 INVALIDATE(
s,
"{\"~/\":true}",
"/properties/~0~1",
"type",
"/~0~1",
1609 " \"instanceRef\": \"#/~0~1\", \"schemaRef\": \"#/properties/~0~1\","
1610 " \"expected\": [\"number\"], \"actual\": \"boolean\""
1614template <
typename Allocator>
1615static char* ReadFile(
const char* filename,
Allocator& allocator) {
1616 const char *paths[] = {
1625 for (
size_t i = 0; i <
sizeof(paths) /
sizeof(paths[0]); i++) {
1626 sprintf(buffer,
"%s%s", paths[i], filename);
1627 fp = fopen(buffer,
"rb");
1635 fseek(fp, 0, SEEK_END);
1636 size_t length =
static_cast<size_t>(ftell(fp));
1637 fseek(fp, 0, SEEK_SET);
1638 char* json =
reinterpret_cast<char*
>(
allocator.Malloc(length + 1));
1639 size_t readLength = fread(json, 1, length, fp);
1640 json[readLength] =
'\0';
1647 char* json = ReadFile(
"draft-04/schema", allocator);
1653 if (!
d.Accept(validator)) {
1656 printf(
"Invalid schema: %s\n", sb.
GetString());
1660 printf(
"Invalid document: %s\n", sb.
GetString());
1664 printf(
"Validation error: %s\n", sb.
GetString());
1676 char* json = ReadFile(
"draft-04/schema", allocator);
1680 d.ParseStream<0,
UTF8<> >(ss);
1684 if (!
d.Accept(validator)) {
1686 validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
1687 wprintf(L
"Invalid schema: %ls\n", sb.
GetString());
1688 wprintf(L
"Invalid keyword: %ls\n", validator.GetInvalidSchemaKeyword());
1690 validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
1691 wprintf(L
"Invalid document: %ls\n", sb.
GetString());
1694 validator.GetError().Accept(w);
1695 printf(
"Validation error: %ls\n", sb.
GetString());
1701template <
typename SchemaDocumentType = SchemaDocument>
1705 documentAllocator_(documentBuffer_,
sizeof(documentBuffer_)),
1706 schemaAllocator_(schemaBuffer_,
sizeof(schemaBuffer_))
1708 const char* filenames[kCount] = {
1709 "jsonschema/remotes/integer.json",
1710 "jsonschema/remotes/subSchemas.json",
1711 "jsonschema/remotes/folder/folderInteger.json",
1714 const char* uris[kCount] = {
1715 "http://localhost:1234/integer.json",
1716 "http://localhost:1234/subSchemas.json",
1717 "http://localhost:1234/folder/folderInteger.json",
1718 "http://json-schema.org/draft-04/schema"
1721 for (
size_t i = 0; i < kCount; i++) {
1724 char jsonBuffer[8192];
1726 char* json = ReadFile(filenames[i], jsonAllocator);
1728 printf(
"json remote file %s not found", filenames[i]);
1732 char stackBuffer[4096];
1736 sd_[i] =
new SchemaDocumentType(
d, uris[i],
static_cast<SizeType>(strlen(uris[i])), 0, &schemaAllocator_);
1743 for (
size_t i = 0; i < kCount; i++)
1748 for (
size_t i = 0; i < kCount; i++)
1749 if (
typename SchemaDocumentType::URIType(uri, length) == sd_[i]->GetURI())
1760 static const size_t kCount = 4;
1761 SchemaDocumentType* sd_[kCount];
1763 typename SchemaDocumentType::AllocatorType schemaAllocator_;
1764 char documentBuffer_[16384];
1765 char schemaBuffer_[128u * 1024];
1769 const char* filenames[] = {
1770 "additionalItems.json",
1771 "additionalProperties.json",
1776 "dependencies.json",
1782 "maxProperties.json",
1786 "minProperties.json",
1791 "patternProperties.json",
1800 const char* onlyRunDescription = 0;
1803 unsigned testCount = 0;
1804 unsigned passCount = 0;
1809 char jsonBuffer[65536];
1810 char documentBuffer[65536];
1811 char documentStackBuffer[65536];
1812 char schemaBuffer[65536];
1813 char validatorBuffer[65536];
1820 for (
size_t i = 0; i <
sizeof(filenames) /
sizeof(filenames[0]); i++) {
1821 char filename[FILENAME_MAX];
1822 sprintf(filename,
"jsonschema/tests/draft4/%s", filenames[i]);
1823 char* json = ReadFile(filename, jsonAllocator);
1825 printf(
"json test suite file %s not found", filename);
1831 if (
d.HasParseError()) {
1832 printf(
"json test suite file %s has parse error", filename);
1838 SchemaDocumentType schema((*schemaItr)[
"schema"], filenames[i],
static_cast<SizeType>(strlen(filenames[i])), &provider, &schemaAllocator);
1840 const char* description1 = (*schemaItr)[
"description"].GetString();
1841 const Value& tests = (*schemaItr)[
"tests"];
1843 const char* description2 = (*testItr)[
"description"].GetString();
1844 if (!onlyRunDescription || strcmp(description2, onlyRunDescription) == 0) {
1845 const Value& data = (*testItr)[
"data"];
1846 bool expected = (*testItr)[
"valid"].GetBool();
1849 bool actual = data.Accept(validator);
1850 if (expected != actual)
1851 printf(
"Fail: %30s \"%s\" \"%s\"\n", filename, description1, description2);
1858 schemaAllocator.
Clear();
1859 validatorAllocator.
Clear();
1863 documentAllocator.
Clear();
1865 jsonAllocator.
Clear();
1867 printf(
"%d / %d passed (%2d%%)\n", passCount, testCount, passCount * 100 / testCount);
1874 sd.
Parse(
"{ \"type\": \"string\", \"enum\" : [\"red\", \"amber\", \"green\"] }");
1889 sd.
Parse(
"{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}");
1905 "{ \"maxLength\": {"
1906 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1907 " \"expected\": 3, \"actual\": \"ABCD\""
1914TEST(SchemaValidatingWriter, Simple) {
1916 sd.
Parse(
"{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}");
1931 d.Parse(
"\"ABCD\"");
1938 "{ \"maxLength\": {"
1939 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1940 " \"expected\": 3, \"actual\": \"ABCD\""
1946 rapidjson::Document
d;
1947 rapidjson::SchemaDocument
s(
d);
1948 rapidjson::GenericSchemaValidator<rapidjson::SchemaDocument, rapidjson::Document> v(
s);
1951#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
1955 sd.
Parse(
"{ \"type\": [\"number\", \"string\"] }");
1963 VALIDATE(
s,
"\"Life, the universe, and everything\"",
true);
1964 INVALIDATE(
s,
"[\"Life\", \"the universe\", \"and everything\"]",
"",
"type",
"",
1966 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1967 " \"expected\": [\"string\", \"number\"], \"actual\": \"array\""
1975 sd.
Parse(
"{\"required\": [\"a\", \"b\"] }");
1978 VALIDATE(
s,
"{\"a\" : null, \"b\": null}",
true);
1979 INVALIDATE(
s,
"{\"a\" : null, \"a\" : null}",
"",
"required",
"",
1981 " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1982 " \"missing\": [\"b\"]"
1989 sd.
Parse(
"{\"allOf\": [{\"$ref\": \"#/abc\"}]}");
1991 VALIDATE(
s,
"{\"key1\": \"abc\", \"key2\": \"def\"}",
true);
1996 sd.
Parse(
"{\"type\": \"object\", \"additionalProperties\": false, \"patternProperties\": {\"^i\": { \"type\": \"string\" } } }");
1998 VALIDATE(
s,
"{ \"item\": \"hello\" }",
true);
2003 sd.
Parse(
"{\"allOf\": [{\"type\": \"object\",\"properties\": {\"cyanArray2\": {\"type\": \"array\",\"items\": { \"type\": \"string\" }}}},{\"type\": \"object\",\"properties\": {\"blackArray\": {\"type\": \"array\",\"items\": { \"type\": \"string\" }}},\"required\": [ \"blackArray\" ]}]}");
2024 sd.
Parse(
"{\"$ref\": \"http://localhost:1234/subSchemas.json#/integer\"}");
2025 SchemaDocumentType
s(sd, 0, 0, &provider);
2030 " \"instanceRef\": \"#\","
2031 " \"schemaRef\": \"http://localhost:1234/subSchemas.json#/integer\","
2032 " \"expected\": [\"integer\"], \"actual\": \"null\""
2034 SchemaValidatorType, PointerType);
2041 SchemaDocumentProvider(
const SchemaDocumentProvider&);
2042 SchemaDocumentProvider& operator=(
const SchemaDocumentProvider&);
2045 SchemaDocumentProvider(
SchemaDocument** collection) : collection(collection) { }
2049 return collection[i];
2053 SchemaDocumentProvider provider(collection);
2056 x.
Parse(
"{\"properties\":{\"country\":{\"$ref\":\"y.json#/definitions/country_remote\"}},\"type\":\"object\"}");
2057 y.Parse(
"{\"definitions\":{\"country_remote\":{\"$ref\":\"z.json#/definitions/country_list\"}}}");
2058 z.
Parse(
"{\"definitions\":{\"country_list\":{\"enum\":[\"US\"]}}}");
2061 collection[0] = &sz;
2063 collection[1] = &sy;
2066 VALIDATE(sx,
"{\"country\":\"UK\"}",
false);
2067 VALIDATE(sx,
"{\"country\":\"US\"}",
true);
2070#if defined(_MSC_VER) || defined(__clang__)
C-runtime library allocator.
static void Free(void *ptr)
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Allocator AllocatorType
Allocator type from template parameter.
ValueType & GetError()
Gets the error object.
void Reset()
Reset the internal states.
PointerType GetInvalidSchemaPointer() const
Gets the JSON pointer pointed to the invalid schema.
bool EndArray(SizeType elementCount)
bool Key(const Ch *str, SizeType len, bool copy)
virtual bool IsValid() const
Checks whether the current state is valid.
bool EndObject(SizeType memberCount)
const Ch * GetInvalidSchemaKeyword() const
Gets the keyword of invalid schema.
PointerType GetInvalidDocumentPointer() const
Gets the JSON pointer pointed to the invalid value.
const Ch * GetString() const
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Default memory allocator used by the parser and DOM.
void Clear()
Deallocates all memory chunks, excluding the user-supplied buffer.
static void Free(void *ptr)
Frees a memory block (concept Allocator)
~RemoteSchemaDocumentProvider()
virtual const SchemaDocumentType * GetRemoteDocument(const char *uri, SizeType length)
RemoteSchemaDocumentProvider()
A helper class for parsing with validation.
const PointerType & GetInvalidDocumentPointer() const
const PointerType & GetInvalidSchemaPointer() const
const Ch * GetInvalidSchemaKeyword() const
const ParseResult & GetParseResult() const
const ValueType & GetError() const
Concept for allocating, resizing and freeing memory block.
#define D(var, file, col, who, lev,...)
@ kParseErrorTermination
Parsing was terminated.
#define EXPECT_EQ(val1, val2)
#define ASSERT_FALSE(condition)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define TEST(test_case_name, test_name)
#define EXPECT_FALSE(condition)
bip::allocator< T, pinnable_mapped_file::segment_manager > allocator
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
ParseErrorCode Code() const
Get the error code.
#define VALIDATE(schema, json, expected)
#define INVALIDATE(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error)
#define INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, SchemaValidatorType, PointerType)
#define TEST_HASHER(json1, json2, expected)
c_gkp_out sizeof(template))