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
3f1e2c40
Commit
3f1e2c40
authored
May 10, 2015
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use allocator in SchemaDocument
parent
c54b7faf
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
25 deletions
+33
-25
schema.h
include/rapidjson/schema.h
+0
-0
schematest.cpp
test/unittest/schematest.cpp
+33
-25
No files found.
include/rapidjson/schema.h
View file @
3f1e2c40
This diff is collapsed.
Click to expand it.
test/unittest/schematest.cpp
View file @
3f1e2c40
...
...
@@ -806,7 +806,6 @@ public:
};
for
(
size_t
i
=
0
;
i
<
kCount
;
i
++
)
{
d_
[
i
]
=
0
;
sd_
[
i
]
=
0
;
size_t
length
;
...
...
@@ -816,19 +815,17 @@ public:
ADD_FAILURE
();
}
else
{
d_
[
i
]
=
new
Document
;
d
_
[
i
]
->
Parse
(
json
);
sd_
[
i
]
=
new
SchemaDocument
(
*
d_
[
i
]
);
Document
d
(
&
documentAllocator_
)
;
d
.
Parse
(
json
);
sd_
[
i
]
=
new
SchemaDocument
(
d
,
0
,
&
schemaAllocator_
);
free
(
json
);
}
};
}
~
RemoteSchemaDocumentProvider
()
{
for
(
size_t
i
=
0
;
i
<
kCount
;
i
++
)
{
delete
d_
[
i
];
for
(
size_t
i
=
0
;
i
<
kCount
;
i
++
)
delete
sd_
[
i
];
}
}
virtual
const
SchemaDocument
*
GetRemoteDocument
(
const
char
*
uri
,
SizeType
length
)
{
...
...
@@ -850,8 +847,9 @@ private:
RemoteSchemaDocumentProvider
&
operator
=
(
const
RemoteSchemaDocumentProvider
&
);
static
const
size_t
kCount
=
4
;
Document
*
d_
[
kCount
];
SchemaDocument
*
sd_
[
kCount
];
typename
Document
::
AllocatorType
documentAllocator_
;
typename
SchemaDocument
::
AllocatorType
schemaAllocator_
;
};
TEST
(
SchemaValidator
,
TestSuite
)
{
...
...
@@ -894,6 +892,11 @@ TEST(SchemaValidator, TestSuite) {
RemoteSchemaDocumentProvider
provider
;
char
documentBuffer
[
65536
];
char
schemaBuffer
[
65536
];
Document
::
AllocatorType
documentAllocator
(
documentBuffer
,
sizeof
(
documentBuffer
));
SchemaDocument
::
AllocatorType
schemaAllocator
(
schemaBuffer
,
sizeof
(
schemaBuffer
));
for
(
size_t
i
=
0
;
i
<
sizeof
(
filenames
)
/
sizeof
(
filenames
[
0
]);
i
++
)
{
char
filename
[
FILENAME_MAX
];
sprintf
(
filename
,
"jsonschema/tests/draft4/%s"
,
filenames
[
i
]);
...
...
@@ -904,7 +907,7 @@ TEST(SchemaValidator, TestSuite) {
ADD_FAILURE
();
}
else
{
Document
d
;
Document
d
(
&
documentAllocator
)
;
d
.
Parse
(
json
);
if
(
d
.
HasParseError
())
{
printf
(
"json test suite file %s has parse error"
,
filename
);
...
...
@@ -912,27 +915,32 @@ TEST(SchemaValidator, TestSuite) {
}
else
{
for
(
Value
::
ConstValueIterator
schemaItr
=
d
.
Begin
();
schemaItr
!=
d
.
End
();
++
schemaItr
)
{
SchemaDocument
schema
((
*
schemaItr
)[
"schema"
],
&
provider
);
SchemaValidator
validator
(
schema
);
const
char
*
description1
=
(
*
schemaItr
)[
"description"
].
GetString
();
const
Value
&
tests
=
(
*
schemaItr
)[
"tests"
];
for
(
Value
::
ConstValueIterator
testItr
=
tests
.
Begin
();
testItr
!=
tests
.
End
();
++
testItr
)
{
const
char
*
description2
=
(
*
testItr
)[
"description"
].
GetString
();
if
(
!
onlyRunDescription
||
strcmp
(
description2
,
onlyRunDescription
)
==
0
)
{
const
Value
&
data
=
(
*
testItr
)[
"data"
];
bool
expected
=
(
*
testItr
)[
"valid"
].
GetBool
();
testCount
++
;
validator
.
Reset
();
bool
actual
=
data
.
Accept
(
validator
);
if
(
expected
!=
actual
)
printf
(
"Fail: %30s
\"
%s
\"
\"
%s
\"\n
"
,
filename
,
description1
,
description2
);
else
passCount
++
;
{
SchemaDocument
schema
((
*
schemaItr
)[
"schema"
],
&
provider
,
&
schemaAllocator
);
SchemaValidator
validator
(
schema
);
const
char
*
description1
=
(
*
schemaItr
)[
"description"
].
GetString
();
const
Value
&
tests
=
(
*
schemaItr
)[
"tests"
];
for
(
Value
::
ConstValueIterator
testItr
=
tests
.
Begin
();
testItr
!=
tests
.
End
();
++
testItr
)
{
const
char
*
description2
=
(
*
testItr
)[
"description"
].
GetString
();
if
(
!
onlyRunDescription
||
strcmp
(
description2
,
onlyRunDescription
)
==
0
)
{
const
Value
&
data
=
(
*
testItr
)[
"data"
];
bool
expected
=
(
*
testItr
)[
"valid"
].
GetBool
();
testCount
++
;
validator
.
Reset
();
bool
actual
=
data
.
Accept
(
validator
);
if
(
expected
!=
actual
)
printf
(
"Fail: %30s
\"
%s
\"
\"
%s
\"\n
"
,
filename
,
description1
,
description2
);
else
passCount
++
;
}
}
//printf("%zu %zu\n", documentAllocator.Size(), schemaAllocator.Size());
}
schemaAllocator
.
Clear
();
}
}
}
documentAllocator
.
Clear
();
free
(
json
);
}
printf
(
"%d / %d passed (%2d%%)
\n
"
,
passCount
,
testCount
,
passCount
*
100
/
testCount
);
...
...
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