Electroneum
schematest.cpp File Reference
#include "unittest.h"
#include "rapidjson/schema.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
Include dependency graph for schematest.cpp:

Go to the source code of this file.

Macros

#define TEST_HASHER(json1, json2, expected)
 
#define VALIDATE(schema, json, expected)
 
#define INVALIDATE(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error)
 
#define INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, SchemaValidatorType, PointerType)
 

Functions

 TEST (SchemaValidator, Hasher)
 

Macro Definition Documentation

◆ INVALIDATE

#define INVALIDATE (   schema,
  json,
  invalidSchemaPointer,
  invalidSchemaKeyword,
  invalidDocumentPointer,
  error 
)
Value:
{\
INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, SchemaValidator, Pointer) \
}
JSON Schema Validator.
Definition: fwd.h:145
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition: fwd.h:126
error
Tracks LMDB error codes.
Definition: error.h:44
rapidjson::Document json
Definition: transport.cpp:49

◆ INVALIDATE_

#define INVALIDATE_ (   schema,
  json,
  invalidSchemaPointer,
  invalidSchemaKeyword,
  invalidDocumentPointer,
  error,
  SchemaValidatorType,
  PointerType 
)

◆ TEST_HASHER

#define TEST_HASHER (   json1,
  json2,
  expected 
)
Value:
{\
Document d1, d2;\
d1.Parse(json1);\
ASSERT_FALSE(d1.HasParseError());\
d2.Parse(json2);\
ASSERT_FALSE(d2.HasParseError());\
internal::Hasher<Value, CrtAllocator> h1, h2;\
d1.Accept(h1);\
d2.Accept(h2);\
ASSERT_TRUE(h1.IsValid());\
ASSERT_TRUE(h2.IsValid());\
/*printf("%s: 0x%016llx\n%s: 0x%016llx\n\n", json1, h1.GetHashCode(), json2, h2.GetHashCode());*/\
EXPECT_TRUE(expected == (h1.GetHashCode() == h2.GetHashCode()));\
}

Definition at line 30 of file schematest.cpp.

◆ VALIDATE

#define VALIDATE (   schema,
  json,
  expected 
)
Value:
{\
SchemaValidator validator(schema);\
Document d;\
/*printf("\n%s\n", json);*/\
d.Parse(json);\
EXPECT_FALSE(d.HasParseError());\
EXPECT_TRUE(expected == d.Accept(validator));\
EXPECT_TRUE(expected == validator.IsValid());\
if ((expected) && !validator.IsValid()) {\
StringBuffer sb;\
validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);\
printf("Invalid schema: %s\n", sb.GetString());\
printf("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());\
sb.Clear();\
validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);\
printf("Invalid document: %s\n", sb.GetString());\
sb.Clear();\
Writer<StringBuffer> w(sb);\
validator.GetError().Accept(w);\
printf("Validation error: %s\n", sb.GetString());\
}\
}
rapidjson::Document json
Definition: transport.cpp:49

Function Documentation

◆ TEST()

TEST ( SchemaValidator  ,
Hasher   
)

Definition at line 46 of file schematest.cpp.