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
05968b70
Commit
05968b70
authored
Jan 27, 2016
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix schema tests and added SchemaValidatingReader
parent
6978f878
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
11 deletions
+77
-11
document.h
include/rapidjson/document.h
+17
-1
regex.h
include/rapidjson/internal/regex.h
+10
-0
schema.h
include/rapidjson/schema.h
+0
-0
schematest.cpp
test/unittest/schematest.cpp
+50
-10
No files found.
include/rapidjson/document.h
View file @
05968b70
...
...
@@ -1869,6 +1869,21 @@ public:
*/
friend
inline
void
swap
(
GenericDocument
&
a
,
GenericDocument
&
b
)
RAPIDJSON_NOEXCEPT
{
a
.
Swap
(
b
);
}
//! Populate this document by a generator which produces SAX events.
/*! \tparam Generator A functor with <tt>bool f(Handler)</tt> prototype.
\param g Generator functor which sends SAX events to the parameter.
\return The document itself for fluent API.
*/
template
<
typename
Generator
>
GenericDocument
&
Populate
(
Generator
&
g
)
{
ClearStackOnExit
scope
(
*
this
);
if
(
g
(
*
this
))
{
RAPIDJSON_ASSERT
(
stack_
.
GetSize
()
==
sizeof
(
ValueType
));
// Got one and only one root object
ValueType
::
operator
=
(
*
stack_
.
template
Pop
<
ValueType
>
(
1
));
// Move value from stack to document
}
return
*
this
;
}
//!@name Parse from stream
//!@{
...
...
@@ -2017,9 +2032,10 @@ private:
};
// callers of the following private Handler functions
template
<
typename
,
typename
,
typename
>
friend
class
GenericReader
;
// for parsing
//
template <typename,typename,typename> friend class GenericReader; // for parsing
template
<
typename
,
typename
>
friend
class
GenericValue
;
// for deep copying
public
:
// Implementation of Handler
bool
Null
()
{
new
(
stack_
.
template
Push
<
ValueType
>
())
ValueType
();
return
true
;
}
bool
Bool
(
bool
b
)
{
new
(
stack_
.
template
Push
<
ValueType
>
())
ValueType
(
b
);
return
true
;
}
...
...
include/rapidjson/internal/regex.h
View file @
05968b70
...
...
@@ -18,6 +18,12 @@
#include "../rapidjson.h"
#include "stack.h"
#ifdef __clang__
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF
(
padded
)
RAPIDJSON_DIAG_OFF
(
switch
-
enum
)
#endif
#ifndef RAPIDJSON_REGEX_VERBOSE
#define RAPIDJSON_REGEX_VERBOSE 0
#endif
...
...
@@ -639,4 +645,8 @@ typedef GenericRegex<UTF8<> > Regex;
}
// namespace internal
RAPIDJSON_NAMESPACE_END
#ifdef __clang__
RAPIDJSON_DIAG_POP
#endif
#endif // RAPIDJSON_INTERNAL_REGEX_H_
include/rapidjson/schema.h
View file @
05968b70
This diff is collapsed.
Click to expand it.
test/unittest/schematest.cpp
View file @
05968b70
...
...
@@ -16,6 +16,11 @@
#include "rapidjson/schema.h"
#include "rapidjson/stringbuffer.h"
#ifdef __clang__
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF
(
variadic
-
macros
)
#endif
using
namespace
rapidjson
;
#define TEST_HASHER(json1, json2, expected) \
...
...
@@ -95,7 +100,7 @@ TEST(SchemaValidator, Hasher) {
{\
SchemaValidator validator(schema);\
Document d;\
printf("\n%s\n", json);
\
/*printf("\n%s\n", json);*/
\
d.Parse(json);\
EXPECT_FALSE(d.HasParseError());\
EXPECT_TRUE(expected == d.Accept(validator));\
...
...
@@ -115,7 +120,7 @@ TEST(SchemaValidator, Hasher) {
{\
SchemaValidator validator(schema);\
Document d;\
printf("\n%s\n", json);
\
/*printf("\n%s\n", json);*/
\
d.Parse(json);\
EXPECT_FALSE(d.HasParseError());\
EXPECT_FALSE(d.Accept(validator));\
...
...
@@ -841,16 +846,16 @@ TEST(SchemaValidator, AllOf_Nested) {
template
<
typename
Allocator
>
static
char
*
ReadFile
(
const
char
*
filename
,
Allocator
&
allocator
)
{
const
char
*
paths
[]
=
{
"
%s
"
,
"bin/
%s
"
,
"../bin/
%s
"
,
"../../bin/
%s
"
,
"../../../bin/
%s
"
""
,
"bin/"
,
"../bin/"
,
"../../bin/"
,
"../../../bin/"
};
char
buffer
[
1024
];
FILE
*
fp
=
0
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
paths
)
/
sizeof
(
paths
[
0
]);
i
++
)
{
sprintf
(
buffer
,
paths
[
i
],
filename
);
sprintf
(
buffer
,
"%s%s"
,
paths
[
i
],
filename
);
fp
=
fopen
(
buffer
,
"rb"
);
if
(
fp
)
break
;
...
...
@@ -860,9 +865,9 @@ static char* ReadFile(const char* filename, Allocator& allocator) {
return
0
;
fseek
(
fp
,
0
,
SEEK_END
);
size_t
length
=
(
size_t
)
ftell
(
fp
);
size_t
length
=
static_cast
<
size_t
>
(
ftell
(
fp
)
);
fseek
(
fp
,
0
,
SEEK_SET
);
char
*
json
=
(
char
*
)
allocator
.
Malloc
(
length
+
1
);
char
*
json
=
reinterpret_cast
<
char
*>
(
allocator
.
Malloc
(
length
+
1
)
);
size_t
readLength
=
fread
(
json
,
1
,
length
,
fp
);
json
[
readLength
]
=
'\0'
;
fclose
(
fp
);
...
...
@@ -1088,3 +1093,38 @@ TEST(SchemaValidator, TestSuite) {
// if (passCount != testCount)
// ADD_FAILURE();
}
TEST
(
SchemaValidatingReader
,
Valid
)
{
Document
sd
;
sd
.
Parse
(
"{
\"
type
\"
:
\"
string
\"
,
\"
enum
\"
: [
\"
red
\"
,
\"
amber
\"
,
\"
green
\"
] }"
);
SchemaDocument
s
(
sd
);
Document
d
;
StringStream
ss
(
"
\"
red
\"
"
);
SchemaValidatingReader
<
kParseDefaultFlags
,
StringStream
,
UTF8
<>
>
reader
(
ss
,
s
);
d
.
Populate
(
reader
);
EXPECT_TRUE
(
reader
.
GetParseResult
());
EXPECT_TRUE
(
d
.
IsString
());
EXPECT_STREQ
(
"red"
,
d
.
GetString
());
}
TEST
(
SchemaValidatingReader
,
Invalid
)
{
Document
sd
;
sd
.
Parse
(
"{
\"
type
\"
:
\"
string
\"
,
\"
minLength
\"
:2,
\"
maxLength
\"
:3}"
);
SchemaDocument
s
(
sd
);
Document
d
;
StringStream
ss
(
"
\"
ABCD
\"
"
);
SchemaValidatingReader
<
kParseDefaultFlags
,
StringStream
,
UTF8
<>
>
reader
(
ss
,
s
);
d
.
Populate
(
reader
);
EXPECT_FALSE
(
reader
.
GetParseResult
());
EXPECT_EQ
(
kParseErrorTermination
,
reader
.
GetParseResult
().
Code
());
EXPECT_STREQ
(
"maxLength"
,
reader
.
GetInvalidSchemaKeyword
());
EXPECT_TRUE
(
reader
.
GetInvalidSchemaPointer
()
==
SchemaDocument
::
PointerType
(
""
));
EXPECT_TRUE
(
reader
.
GetInvalidDocumentPointer
()
==
SchemaDocument
::
PointerType
(
""
));
EXPECT_TRUE
(
d
.
IsNull
());
}
#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