Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
55d28678
Commit
55d28678
authored
Jan 31, 2016
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SchemaValidatingReader ::IsValid()
parent
28e6a40f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
3 deletions
+30
-3
schema.h
include/rapidjson/schema.h
+4
-2
schematest.cpp
test/unittest/schematest.cpp
+26
-1
No files found.
include/rapidjson/schema.h
View file @
55d28678
...
...
@@ -1863,7 +1863,7 @@ public:
typedef
typename
SchemaDocumentType
::
PointerType
PointerType
;
typedef
typename
InputStream
::
Ch
Ch
;
SchemaValidatingReader
(
InputStream
&
is
,
const
SchemaDocumentType
&
sd
)
:
is_
(
is
),
sd_
(
sd
),
invalidSchemaKeyword_
()
{}
SchemaValidatingReader
(
InputStream
&
is
,
const
SchemaDocumentType
&
sd
)
:
is_
(
is
),
sd_
(
sd
),
invalidSchemaKeyword_
()
,
isValid_
(
true
)
{}
template
<
typename
Handler
>
bool
operator
()(
Handler
&
handler
)
{
...
...
@@ -1871,7 +1871,7 @@ public:
GenericSchemaValidator
<
SchemaDocumentType
,
Handler
>
validator
(
sd_
,
handler
);
parseResult_
=
reader
.
template
Parse
<
parseFlags
>
(
is_
,
validator
);
if
(
validator
.
IsValid
(
))
{
if
(
(
isValid_
=
validator
.
IsValid
()
))
{
invalidSchemaPointer_
=
PointerType
();
invalidSchemaKeyword_
=
0
;
invalidDocumentPointer_
=
PointerType
();
...
...
@@ -1886,6 +1886,7 @@ public:
}
const
ParseResult
&
GetParseResult
()
const
{
return
parseResult_
;
}
bool
IsValid
()
const
{
return
isValid_
;
}
const
PointerType
&
GetInvalidSchemaPointer
()
const
{
return
invalidSchemaPointer_
;
}
const
Ch
*
GetInvalidSchemaKeyword
()
const
{
return
invalidSchemaKeyword_
;
}
const
PointerType
&
GetInvalidDocumentPointer
()
const
{
return
invalidDocumentPointer_
;
}
...
...
@@ -1898,6 +1899,7 @@ private:
PointerType
invalidSchemaPointer_
;
const
Ch
*
invalidSchemaKeyword_
;
PointerType
invalidDocumentPointer_
;
bool
isValid_
;
};
RAPIDJSON_NAMESPACE_END
...
...
test/unittest/schematest.cpp
View file @
55d28678
...
...
@@ -15,6 +15,7 @@
#include "unittest.h"
#include "rapidjson/schema.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#ifdef __clang__
RAPIDJSON_DIAG_PUSH
...
...
@@ -1094,7 +1095,7 @@ TEST(SchemaValidator, TestSuite) {
// ADD_FAILURE();
}
TEST
(
SchemaValidatingReader
,
Valid
)
{
TEST
(
SchemaValidatingReader
,
Simple
)
{
Document
sd
;
sd
.
Parse
(
"{
\"
type
\"
:
\"
string
\"
,
\"
enum
\"
: [
\"
red
\"
,
\"
amber
\"
,
\"
green
\"
] }"
);
SchemaDocument
s
(
sd
);
...
...
@@ -1104,6 +1105,7 @@ TEST(SchemaValidatingReader, Valid) {
SchemaValidatingReader
<
kParseDefaultFlags
,
StringStream
,
UTF8
<>
>
reader
(
ss
,
s
);
d
.
Populate
(
reader
);
EXPECT_TRUE
(
reader
.
GetParseResult
());
EXPECT_TRUE
(
reader
.
IsValid
());
EXPECT_TRUE
(
d
.
IsString
());
EXPECT_STREQ
(
"red"
,
d
.
GetString
());
}
...
...
@@ -1118,6 +1120,7 @@ TEST(SchemaValidatingReader, Invalid) {
SchemaValidatingReader
<
kParseDefaultFlags
,
StringStream
,
UTF8
<>
>
reader
(
ss
,
s
);
d
.
Populate
(
reader
);
EXPECT_FALSE
(
reader
.
GetParseResult
());
EXPECT_FALSE
(
reader
.
IsValid
());
EXPECT_EQ
(
kParseErrorTermination
,
reader
.
GetParseResult
().
Code
());
EXPECT_STREQ
(
"maxLength"
,
reader
.
GetInvalidSchemaKeyword
());
EXPECT_TRUE
(
reader
.
GetInvalidSchemaPointer
()
==
SchemaDocument
::
PointerType
(
""
));
...
...
@@ -1125,6 +1128,28 @@ TEST(SchemaValidatingReader, Invalid) {
EXPECT_TRUE
(
d
.
IsNull
());
}
TEST
(
SchemaValidatingWriter
,
Simple
)
{
Document
sd
;
sd
.
Parse
(
"{
\"
type
\"
:
\"
string
\"
,
\"
minLength
\"
:2,
\"
maxLength
\"
:3}"
);
SchemaDocument
s
(
sd
);
Document
d
;
StringBuffer
sb
;
Writer
<
StringBuffer
>
writer
(
sb
);
GenericSchemaValidator
<
SchemaDocument
,
Writer
<
StringBuffer
>
>
validator
(
s
,
writer
);
d
.
Parse
(
"
\"
red
\"
"
);
EXPECT_TRUE
(
d
.
Accept
(
validator
));
EXPECT_TRUE
(
validator
.
IsValid
());
EXPECT_STREQ
(
"
\"
red
\"
"
,
sb
.
GetString
());
sb
.
Clear
();
validator
.
Reset
();
d
.
Parse
(
"
\"
ABCD
\"
"
);
EXPECT_FALSE
(
d
.
Accept
(
validator
));
EXPECT_FALSE
(
validator
.
IsValid
());
}
#ifdef __clang__
RAPIDJSON_DIAG_POP
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment