10 #define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0]) 14 template <
typename Allocator>
16 const char *paths[] = {
25 for (
size_t i = 0; i <
sizeof(paths) /
sizeof(paths[0]); i++) {
26 sprintf(buffer,
"%s%s", paths[i], filename);
27 fp = fopen(buffer,
"rb");
35 fseek(fp, 0, SEEK_END);
36 size_t length =
static_cast<size_t>(ftell(fp));
37 fseek(fp, 0, SEEK_SET);
38 char*
json =
reinterpret_cast<char*
>(allocator.Malloc(length + 1));
39 size_t readLength = fread(json, 1, length, fp);
40 json[readLength] =
'\0';
52 const char* filenames[] = {
53 "additionalItems.json",
54 "additionalProperties.json",
74 "patternProperties.json",
83 char jsonBuffer[65536];
86 for (
size_t i = 0; i <
ARRAY_SIZE(filenames); i++) {
87 char filename[FILENAME_MAX];
88 sprintf(filename,
"jsonschema/tests/draft4/%s", filenames[i]);
91 printf(
"json test suite file %s not found", filename);
98 printf(
"json test suite file %s has parse error", filename);
103 std::string schemaDescription = (*schemaItr)[
"description"].GetString();
104 if (IsExcludeTestSuite(schemaDescription))
110 const Value& tests = (*schemaItr)[
"tests"];
112 if (IsExcludeTest(schemaDescription +
", " + (*testItr)[
"description"].GetString()))
117 ts->
tests.push_back(d2);
119 testSuites.push_back(ts);
125 PerfTest::TearDown();
126 for (TestSuiteList::const_iterator itr = testSuites.begin(); itr != testSuites.end(); ++itr)
134 const char* excludeTestSuites[] = {
137 "remote ref, containing refs itself",
138 "fragment within remote ref",
139 "ref within remote ref",
140 "change resolution scope",
142 "uniqueItems validation",
147 for (
size_t i = 0; i <
ARRAY_SIZE(excludeTestSuites); i++)
148 if (excludeTestSuites[i] == description)
155 const char* excludeTests[] = {
157 "invalid definition, invalid definition schema",
158 "maxLength validation, two supplementary Unicode code points is long enough",
159 "minLength validation, one supplementary Unicode code point is not long enough",
161 "heterogeneous enum validation, something else is invalid" 164 for (
size_t i = 0; i <
ARRAY_SIZE(excludeTests); i++)
165 if (excludeTests[i] == description)
180 for (DocumentList::iterator itr = tests.begin(); itr != tests.end(); ++itr)
192 char validatorBuffer[65536];
195 const int trialCount = 100000;
197 clock_t
start = clock();
198 for (
int i = 0; i < trialCount; i++) {
199 for (TestSuiteList::const_iterator itr = testSuites.begin(); itr != testSuites.end(); ++itr) {
200 const TestSuite& ts = **itr;
202 for (DocumentList::const_iterator testItr = ts.tests.begin(); testItr != ts.tests.end(); ++testItr) {
204 (*testItr)->Accept(validator);
207 validatorAllocator.
Clear();
210 clock_t end = clock();
211 double duration = double(end - start) / CLOCKS_PER_SEC;
212 printf(
"%d trials in %f s -> %f trials per sec\n", trialCount, duration, trialCount / duration);
213 printf(
"%d tests per trial\n", testCount / trialCount);
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
void Reset()
Reset the internal states.
static bool IsExcludeTestSuite(const std::string &description)
void Clear()
Deallocates all memory chunks, excluding the user-supplied buffer.
static char * ReadFile(const char *filename, Allocator &allocator)
Concept for allocating, resizing and freeing memory block.
Allocator & GetAllocator()
Get the allocator of this document.
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
TEST_F(Schema, TestSuite)
std::vector< Document * > DocumentList
static bool IsExcludeTest(const std::string &description)
GenericSchemaDocument< Value, CrtAllocator > SchemaDocument
std::vector< TestSuite * > TestSuiteList
bool HasParseError() const
Whether a parse error has occured in the last parsing.