Electroneum
Schema Class Reference
Inheritance diagram for Schema:
Collaboration diagram for Schema:

Classes

struct  TestSuite
 

Public Member Functions

 Schema ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 

Protected Types

typedef std::vector< Document * > DocumentList
 
typedef std::vector< TestSuite *> TestSuiteList
 

Protected Attributes

TestSuiteList testSuites
 

Detailed Description

Definition at line 45 of file schematest.cpp.

Member Typedef Documentation

◆ DocumentList

typedef std::vector<Document*> Schema::DocumentList
protected

Definition at line 174 of file schematest.cpp.

◆ TestSuiteList

typedef std::vector<TestSuite* > Schema::TestSuiteList
protected

Definition at line 187 of file schematest.cpp.

Constructor & Destructor Documentation

◆ Schema()

Schema::Schema ( )
inline

Definition at line 47 of file schematest.cpp.

47 {}

Member Function Documentation

◆ SetUp()

virtual void Schema::SetUp ( )
inlinevirtual

Definition at line 49 of file schematest.cpp.

49  {
50  PerfTest::SetUp();
51 
52  const char* filenames[] = {
53  "additionalItems.json",
54  "additionalProperties.json",
55  "allOf.json",
56  "anyOf.json",
57  "default.json",
58  "definitions.json",
59  "dependencies.json",
60  "enum.json",
61  "items.json",
62  "maximum.json",
63  "maxItems.json",
64  "maxLength.json",
65  "maxProperties.json",
66  "minimum.json",
67  "minItems.json",
68  "minLength.json",
69  "minProperties.json",
70  "multipleOf.json",
71  "not.json",
72  "oneOf.json",
73  "pattern.json",
74  "patternProperties.json",
75  "properties.json",
76  "ref.json",
77  "refRemote.json",
78  "required.json",
79  "type.json",
80  "uniqueItems.json"
81  };
82 
83  char jsonBuffer[65536];
84  MemoryPoolAllocator<> jsonAllocator(jsonBuffer, sizeof(jsonBuffer));
85 
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]);
89  char* json = ReadFile(filename, jsonAllocator);
90  if (!json) {
91  printf("json test suite file %s not found", filename);
92  return;
93  }
94 
95  Document d;
96  d.Parse(json);
97  if (d.HasParseError()) {
98  printf("json test suite file %s has parse error", filename);
99  return;
100  }
101 
102  for (Value::ConstValueIterator schemaItr = d.Begin(); schemaItr != d.End(); ++schemaItr) {
103  std::string schemaDescription = (*schemaItr)["description"].GetString();
104  if (IsExcludeTestSuite(schemaDescription))
105  continue;
106 
107  TestSuite* ts = new TestSuite;
108  ts->schema = new SchemaDocument((*schemaItr)["schema"]);
109 
110  const Value& tests = (*schemaItr)["tests"];
111  for (Value::ConstValueIterator testItr = tests.Begin(); testItr != tests.End(); ++testItr) {
112  if (IsExcludeTest(schemaDescription + ", " + (*testItr)["description"].GetString()))
113  continue;
114 
115  Document* d2 = new Document;
116  d2->CopyFrom((*testItr)["data"], d2->GetAllocator());
117  ts->tests.push_back(d2);
118  }
119  testSuites.push_back(ts);
120  }
121  }
122  }
::std::string string
Definition: gtest-port.h:1097
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:57
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:2418
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition: document.h:2394
#define ARRAY_SIZE(a)
Definition: schematest.cpp:10
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2512
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition: document.h:2331
TestSuiteList testSuites
Definition: schematest.cpp:188
GenericSchemaDocument< Value, CrtAllocator > SchemaDocument
Definition: fwd.h:136
rapidjson::Document json
Definition: transport.cpp:49

◆ TearDown()

virtual void Schema::TearDown ( )
inlinevirtual

Definition at line 124 of file schematest.cpp.

124  {
125  PerfTest::TearDown();
126  for (TestSuiteList::const_iterator itr = testSuites.begin(); itr != testSuites.end(); ++itr)
127  delete *itr;
128  testSuites.clear();
129  }
TestSuiteList testSuites
Definition: schematest.cpp:188

Member Data Documentation

◆ testSuites

TestSuiteList Schema::testSuites
protected

Definition at line 188 of file schematest.cpp.


The documentation for this class was generated from the following file: