Commit 3f1e2c40 authored by miloyip's avatar miloyip

Use allocator in SchemaDocument

parent c54b7faf
This diff is collapsed.
...@@ -806,7 +806,6 @@ public: ...@@ -806,7 +806,6 @@ public:
}; };
for (size_t i = 0; i < kCount; i++) { for (size_t i = 0; i < kCount; i++) {
d_[i] = 0;
sd_[i] = 0; sd_[i] = 0;
size_t length; size_t length;
...@@ -816,19 +815,17 @@ public: ...@@ -816,19 +815,17 @@ public:
ADD_FAILURE(); ADD_FAILURE();
} }
else { else {
d_[i] = new Document; Document d(&documentAllocator_);
d_[i]->Parse(json); d.Parse(json);
sd_[i] = new SchemaDocument(*d_[i]); sd_[i] = new SchemaDocument(d, 0, &schemaAllocator_);
free(json); free(json);
} }
}; };
} }
~RemoteSchemaDocumentProvider() { ~RemoteSchemaDocumentProvider() {
for (size_t i = 0; i < kCount; i++) { for (size_t i = 0; i < kCount; i++)
delete d_[i];
delete sd_[i]; delete sd_[i];
}
} }
virtual const SchemaDocument* GetRemoteDocument(const char* uri, SizeType length) { virtual const SchemaDocument* GetRemoteDocument(const char* uri, SizeType length) {
...@@ -850,8 +847,9 @@ private: ...@@ -850,8 +847,9 @@ private:
RemoteSchemaDocumentProvider& operator=(const RemoteSchemaDocumentProvider&); RemoteSchemaDocumentProvider& operator=(const RemoteSchemaDocumentProvider&);
static const size_t kCount = 4; static const size_t kCount = 4;
Document* d_[kCount];
SchemaDocument* sd_[kCount]; SchemaDocument* sd_[kCount];
typename Document::AllocatorType documentAllocator_;
typename SchemaDocument::AllocatorType schemaAllocator_;
}; };
TEST(SchemaValidator, TestSuite) { TEST(SchemaValidator, TestSuite) {
...@@ -894,6 +892,11 @@ TEST(SchemaValidator, TestSuite) { ...@@ -894,6 +892,11 @@ TEST(SchemaValidator, TestSuite) {
RemoteSchemaDocumentProvider provider; 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++) { for (size_t i = 0; i < sizeof(filenames) / sizeof(filenames[0]); i++) {
char filename[FILENAME_MAX]; char filename[FILENAME_MAX];
sprintf(filename, "jsonschema/tests/draft4/%s", filenames[i]); sprintf(filename, "jsonschema/tests/draft4/%s", filenames[i]);
...@@ -904,7 +907,7 @@ TEST(SchemaValidator, TestSuite) { ...@@ -904,7 +907,7 @@ TEST(SchemaValidator, TestSuite) {
ADD_FAILURE(); ADD_FAILURE();
} }
else { else {
Document d; Document d(&documentAllocator);
d.Parse(json); d.Parse(json);
if (d.HasParseError()) { if (d.HasParseError()) {
printf("json test suite file %s has parse error", filename); printf("json test suite file %s has parse error", filename);
...@@ -912,27 +915,32 @@ TEST(SchemaValidator, TestSuite) { ...@@ -912,27 +915,32 @@ TEST(SchemaValidator, TestSuite) {
} }
else { else {
for (Value::ConstValueIterator schemaItr = d.Begin(); schemaItr != d.End(); ++schemaItr) { for (Value::ConstValueIterator schemaItr = d.Begin(); schemaItr != d.End(); ++schemaItr) {
SchemaDocument schema((*schemaItr)["schema"], &provider); {
SchemaValidator validator(schema); SchemaDocument schema((*schemaItr)["schema"], &provider, &schemaAllocator);
const char* description1 = (*schemaItr)["description"].GetString(); SchemaValidator validator(schema);
const Value& tests = (*schemaItr)["tests"]; const char* description1 = (*schemaItr)["description"].GetString();
for (Value::ConstValueIterator testItr = tests.Begin(); testItr != tests.End(); ++testItr) { const Value& tests = (*schemaItr)["tests"];
const char* description2 = (*testItr)["description"].GetString(); for (Value::ConstValueIterator testItr = tests.Begin(); testItr != tests.End(); ++testItr) {
if (!onlyRunDescription || strcmp(description2, onlyRunDescription) == 0) { const char* description2 = (*testItr)["description"].GetString();
const Value& data = (*testItr)["data"]; if (!onlyRunDescription || strcmp(description2, onlyRunDescription) == 0) {
bool expected = (*testItr)["valid"].GetBool(); const Value& data = (*testItr)["data"];
testCount++; bool expected = (*testItr)["valid"].GetBool();
validator.Reset(); testCount++;
bool actual = data.Accept(validator); validator.Reset();
if (expected != actual) bool actual = data.Accept(validator);
printf("Fail: %30s \"%s\" \"%s\"\n", filename, description1, description2); if (expected != actual)
else printf("Fail: %30s \"%s\" \"%s\"\n", filename, description1, description2);
passCount++; else
passCount++;
}
} }
//printf("%zu %zu\n", documentAllocator.Size(), schemaAllocator.Size());
} }
schemaAllocator.Clear();
} }
} }
} }
documentAllocator.Clear();
free(json); free(json);
} }
printf("%d / %d passed (%2d%%)\n", passCount, testCount, passCount * 100 / testCount); printf("%d / %d passed (%2d%%)\n", passCount, testCount, passCount * 100 / testCount);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment