10#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0])
15#if defined(__GNUC__) && __GNUC__ >= 7
19template <
typename Allocator>
20static char* ReadFile(
const char* filename,
Allocator& allocator) {
21 const char *paths[] = {
30 for (
size_t i = 0; i <
sizeof(paths) /
sizeof(paths[0]); i++) {
31 sprintf(buffer,
"%s%s", paths[i], filename);
32 fp = fopen(buffer,
"rb");
40 fseek(fp, 0, SEEK_END);
41 size_t length =
static_cast<size_t>(ftell(fp));
42 fseek(fp, 0, SEEK_SET);
43 char* json =
reinterpret_cast<char*
>(allocator.Malloc(length + 1));
44 size_t readLength = fread(json, 1, length, fp);
45 json[readLength] =
'\0';
59 const char* filenames[] = {
60 "additionalItems.json",
61 "additionalProperties.json",
81 "patternProperties.json",
90 char jsonBuffer[65536];
93 for (
size_t i = 0; i <
ARRAY_SIZE(filenames); i++) {
94 char filename[FILENAME_MAX];
95 sprintf(filename,
"jsonschema/tests/draft4/%s", filenames[i]);
96 char* json = ReadFile(filename, jsonAllocator);
98 printf(
"json test suite file %s not found", filename);
104 if (
d.HasParseError()) {
105 printf(
"json test suite file %s has parse error", filename);
110 std::string schemaDescription = (*schemaItr)[
"description"].GetString();
111 if (IsExcludeTestSuite(schemaDescription))
117 const Value& tests = (*schemaItr)[
"tests"];
119 if (IsExcludeTest(schemaDescription +
", " + (*testItr)[
"description"].GetString()))
124 ts->
tests.push_back(d2);
132 PerfTest::TearDown();
140 static bool IsExcludeTestSuite(
const std::string& description) {
141 const char* excludeTestSuites[] = {
144 "remote ref, containing refs itself",
145 "fragment within remote ref",
146 "ref within remote ref",
147 "change resolution scope",
149 "uniqueItems validation",
154 for (
size_t i = 0; i <
ARRAY_SIZE(excludeTestSuites); i++)
155 if (excludeTestSuites[i] == description)
161 static bool IsExcludeTest(
const std::string& description) {
162 const char* excludeTests[] = {
164 "invalid definition, invalid definition schema",
165 "maxLength validation, two supplementary Unicode code points is long enough",
166 "minLength validation, one supplementary Unicode code point is not long enough",
168 "heterogeneous enum validation, something else is invalid"
171 for (
size_t i = 0; i <
ARRAY_SIZE(excludeTests); i++)
172 if (excludeTests[i] == description)
187 for (DocumentList::iterator itr =
tests.begin(); itr !=
tests.end(); ++itr)
199 char validatorBuffer[65536];
202 const int trialCount = 100000;
204 clock_t start = clock();
205 for (
int i = 0; i < trialCount; i++) {
206 for (TestSuiteList::const_iterator itr = testSuites.begin(); itr != testSuites.end(); ++itr) {
207 const TestSuite& ts = **itr;
209 for (DocumentList::const_iterator testItr = ts.tests.begin(); testItr != ts.tests.end(); ++testItr) {
211 (*testItr)->Accept(validator);
214 validatorAllocator.
Clear();
217 clock_t end = clock();
218 double duration = double(end - start) / CLOCKS_PER_SEC;
219 printf(
"%d trials in %f s -> %f trials per sec\n", trialCount, duration, trialCount / duration);
220 printf(
"%d tests per trial\n", testCount / trialCount);
Allocator & GetAllocator()
Get the allocator of this document.
void Reset()
Reset the internal states.
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.
std::vector< TestSuite * > TestSuiteList
std::vector< Document * > DocumentList
Concept for allocating, resizing and freeing memory block.
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
GenericSchemaDocument< Value, CrtAllocator > SchemaDocument
#define TEST_F(test_fixture, test_name)