Merge remote-tracking branch 'origin/master' into v6-and-v7-support

This commit is contained in:
Tristan Penman 2019-08-27 12:38:34 +10:00
commit c8dfd94035
19 changed files with 838 additions and 825 deletions

View File

@ -61,7 +61,7 @@ include_directories(include SYSTEM
if(valijson_BUILD_TESTS)
if(NOT valijson_EXCLUDE_BOOST)
find_package(Boost 1.54.0)
find_package(Boost)
endif()
# Build local gtest
@ -77,22 +77,11 @@ if(valijson_BUILD_TESTS)
tests/test_nlohmann_json_adapter.cpp
tests/test_rapidjson_adapter.cpp
tests/test_picojson_adapter.cpp
tests/test_poco_json_adapter.cpp
tests/test_poly_constraint.cpp
tests/test_validation_errors.cpp
tests/test_validator.cpp
)
if(Qt5Core_FOUND)
include_directories(${Qt5Core_INCLUDE_DIRS})
list(APPEND TEST_SOURCES tests/test_qtjson_adapter.cpp)
endif()
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
list(APPEND TEST_SOURCES tests/test_property_tree_adapter.cpp)
endif()
# Unit tests executable
add_executable(test_suite ${TEST_SOURCES})
@ -102,20 +91,27 @@ if(valijson_BUILD_TESTS)
set(TEST_LIBS gtest gtest_main jsoncpp json11)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
list(APPEND TEST_SOURCES tests/test_property_tree_adapter.cpp)
add_definitions(-DBOOST_ALL_DYN_LINK)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
endif()
if(Qt5Core_FOUND)
list(APPEND TEST_LIBS Qt5::Core)
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_QT_ADAPTERS")
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_PROPERTY_TREE_ADAPTER")
endif()
if(Poco_FOUND)
include_directories(${Poco_INCLUDE_DIRS})
list(APPEND TEST_SOURCES tests/test_poco_json_adapter.cpp)
list(APPEND TEST_LIBS ${Poco_Foundation_LIBRARIES} ${Poco_JSON_LIBRARIES})
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_POCO_ADAPTERS")
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_POCO_ADAPTER")
endif()
if(Qt5Core_FOUND)
include_directories(${Qt5Core_INCLUDE_DIRS})
list(APPEND TEST_SOURCES tests/test_qtjson_adapter.cpp)
list(APPEND TEST_LIBS Qt5::Core)
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_QT_ADAPTER")
endif()
target_link_libraries(test_suite ${TEST_LIBS} ${Boost_LIBRARIES})

View File

@ -993,21 +993,21 @@ namespace std{
{
x.swap(y);
}
template <class T>
constexpr optional<typename decay<T>::type> make_optional(T&& v)
{
return optional<typename decay<T>::type>(constexpr_forward<T>(v));
}
template <class X>
constexpr optional<X&> make_optional(reference_wrapper<X> v)
{
return optional<X&>(v.get());
}
} // namespace experimental
} // namespace std
@ -1018,18 +1018,18 @@ namespace std
{
typedef typename hash<T>::result_type result_type;
typedef std::experimental::optional<T> argument_type;
constexpr result_type operator()(argument_type const& arg) const {
return arg ? std::hash<T>{}(*arg) : result_type{};
}
};
template <typename T>
struct hash<std::experimental::optional<T&>>
{
typedef typename hash<T>::result_type result_type;
typedef std::experimental::optional<T&> argument_type;
constexpr result_type operator()(argument_type const& arg) const {
return arg ? std::hash<T>{}(*arg) : result_type{};
}

View File

@ -25,7 +25,7 @@
#pragma once
#include <stdint.h>
#include <cstdint>
#include <string>
#include <iterator>

File diff suppressed because it is too large Load Diff

View File

@ -24,8 +24,6 @@
*/
#pragma once
#ifndef __VALIJSON_ADAPTERS_QTJSON_ADAPTER_HPP
#define __VALIJSON_ADAPTERS_QTJSON_ADAPTER_HPP
#include <string>
@ -33,7 +31,6 @@
#include <QJsonValue>
#include <QJsonArray>
#include <valijson/adapters/adapter.hpp>
#include <valijson/adapters/basic_adapter.hpp>
#include <valijson/adapters/frozen_value.hpp>
@ -721,5 +718,3 @@ inline QtJsonObjectMemberIterator QtJsonObject::find(
} // namespace adapters
} // namespace valijson
#endif

View File

@ -48,4 +48,3 @@ struct Constraint
} // namespace constraints
} // namespace valijson

View File

@ -34,7 +34,7 @@ class ConstraintVisitor
{
protected:
virtual ~ConstraintVisitor() {}
// Shorten type names for derived classes outside of this namespace
typedef constraints::AllOfConstraint AllOfConstraint;
typedef constraints::AnyOfConstraint AnyOfConstraint;

View File

@ -1,5 +1,4 @@
#ifndef __VALIJSON_DEBUG_HPP
#define __VALIJSON_DEBUG_HPP
#pragma once
#include <string>
@ -29,5 +28,3 @@ std::string nodeTypeAsString(const AdapterType &node) {
} // end namespace internal
} // end namespace valijson
#endif

View File

@ -9,52 +9,51 @@ namespace valijson {
namespace internal {
namespace json_reference {
/**
* @brief Extract URI from JSON Reference relative to the current schema
*
* @param jsonRef JSON Reference to extract from
* @param schema Schema that JSON Reference URI is relative to
*
* @return Optional string containing URI
*/
inline opt::optional<std::string> getJsonReferenceUri(
const std::string &jsonRef)
{
const size_t ptrPos = jsonRef.find("#");
if (ptrPos == 0) {
// The JSON Reference does not contain a URI, but might contain a
// JSON Pointer that refers to the current document
return opt::optional<std::string>();
} else if (ptrPos != std::string::npos) {
// The JSON Reference contains a URI and possibly a JSON Pointer
return jsonRef.substr(0, ptrPos);
}
// The entire JSON Reference should be treated as a URI
return jsonRef;
}
/**
* @brief Extract JSON Pointer portion of a JSON Reference
*
* @param jsonRef JSON Reference to extract from
*
* @return Optional string containing JSON Pointer
*/
inline opt::optional<std::string> getJsonReferencePointer(
const std::string &jsonRef)
{
// Attempt to extract JSON Pointer if '#' character is present. Note
// that a valid pointer would contain at least a leading forward
// slash character.
const size_t ptrPos = jsonRef.find("#");
if (ptrPos != std::string::npos) {
return jsonRef.substr(ptrPos + 1);
}
/**
* @brief Extract URI from JSON Reference relative to the current schema
*
* @param jsonRef JSON Reference to extract from
* @param schema Schema that JSON Reference URI is relative to
*
* @return Optional string containing URI
*/
inline opt::optional<std::string> getJsonReferenceUri(
const std::string &jsonRef)
{
const size_t ptrPos = jsonRef.find("#");
if (ptrPos == 0) {
// The JSON Reference does not contain a URI, but might contain a
// JSON Pointer that refers to the current document
return opt::optional<std::string>();
} else if (ptrPos != std::string::npos) {
// The JSON Reference contains a URI and possibly a JSON Pointer
return jsonRef.substr(0, ptrPos);
}
// The entire JSON Reference should be treated as a URI
return jsonRef;
}
/**
* @brief Extract JSON Pointer portion of a JSON Reference
*
* @param jsonRef JSON Reference to extract from
*
* @return Optional string containing JSON Pointer
*/
inline opt::optional<std::string> getJsonReferencePointer(
const std::string &jsonRef)
{
// Attempt to extract JSON Pointer if '#' character is present. Note
// that a valid pointer would contain at least a leading forward
// slash character.
const size_t ptrPos = jsonRef.find("#");
if (ptrPos != std::string::npos) {
return jsonRef.substr(ptrPos + 1);
}
return opt::optional<std::string>();
}
} // namespace json_reference
} // namespace internal

View File

@ -1,6 +1,4 @@
#pragma once
#ifndef __VALIJSON_OPTIONAL_HPP
#define __VALIJSON_OPTIONAL_HPP
#if __cplusplus >= 201703
// Visual C++ only supports __has_include in versions 14.12 and greater
@ -14,5 +12,3 @@ namespace opt = std;
# include <compat/optional.hpp>
namespace opt = std::experimental;
#endif
#endif

View File

@ -6,27 +6,27 @@ namespace valijson {
namespace internal {
namespace uri {
/**
* @brief Placeholder function to check whether a URI is absolute
*
* This function just checks for '://'
*/
inline bool isUriAbsolute(const std::string &documentUri)
{
static const char * placeholderMarker = "://";
/**
* @brief Placeholder function to check whether a URI is absolute
*
* This function just checks for '://'
*/
inline bool isUriAbsolute(const std::string &documentUri)
{
static const char * placeholderMarker = "://";
return documentUri.find(placeholderMarker) != std::string::npos;
}
return documentUri.find(placeholderMarker) != std::string::npos;
}
/**
* Placeholder function to resolve a relative URI within a given scope
*/
inline std::string resolveRelativeUri(
const std::string &resolutionScope,
const std::string &relativeUri)
{
return resolutionScope + relativeUri;
}
/**
* Placeholder function to resolve a relative URI within a given scope
*/
inline std::string resolveRelativeUri(
const std::string &resolutionScope,
const std::string &relativeUri)
{
return resolutionScope + relativeUri;
}
} // namespace uri
} // namespace internal

View File

@ -15,7 +15,7 @@ namespace valijson {
* While all JSON Schemas have at least one sub-schema, the root, some will
* have additional sub-schemas that are defined as part of constraints that are
* included in the schema. For example, a 'oneOf' constraint maintains a set of
* references to one or more nested sub-schemas. As per the definition of a
* references to one or more nested sub-schemas. As per the definition of a
* oneOf constraint, a document is valid within that constraint if it validates
* against one of the nested sub-schemas.
*/
@ -242,7 +242,7 @@ public:
*
* The title will not be used for validation, but may be used as part
* of the user interface for interacting with schemas and sub-schema. As an
* example, it may be used as part of the validation error descriptions
* example, it may be used as part of the validation error descriptions
* that are produced by the Validator and ValidationVisitor classes.
*
* @param title new title

View File

@ -8,7 +8,8 @@
namespace valijson {
namespace utils {
inline bool loadDocument(const std::string &path, nlohmann::json &document) {
inline bool loadDocument(const std::string &path, nlohmann::json &document)
{
// Load schema JSON from file
std::string file;
if (!loadFile(path, file)) {

View File

@ -1,6 +1,4 @@
#pragma once
#ifndef VALIJSON_POCO_JSON_UTILS_HPP
#define VALIJSON_POCO_JSON_UTILS_HPP
#include <iostream>
@ -13,7 +11,8 @@
namespace valijson {
namespace utils {
inline bool loadDocument(const std::string &path, Poco::Dynamic::Var &document) {
inline bool loadDocument(const std::string &path, Poco::Dynamic::Var &document)
{
// Load schema JSON from file
std::string file;
if (!loadFile(path, file)) {
@ -36,5 +35,3 @@ inline bool loadDocument(const std::string &path, Poco::Dynamic::Var &document)
} // namespace utils
} // namespace valijson
#endif //VALIJSON_POCO_JSON_UTILS_HPP

View File

@ -1,6 +1,4 @@
#pragma once
#ifndef __VALIJSON_UTILS_QTJSON_UTILS_HPP
#define __VALIJSON_UTILS_QTJSON_UTILS_HPP
#include <QFile>
@ -44,5 +42,3 @@ inline bool loadDocument(const std::string &path, QJsonValue &root)
} // namespace utils
} // namespace valijson
#endif

View File

@ -244,7 +244,7 @@ public:
/**
* @brief Validate a value against a LinearItemsConstraint
*
* A LinearItemsConstraint represents an 'items' constraint that specifies,
* for each item in array, an individual sub-schema that the item must
* validate against. The LinearItemsConstraint class also captures the

View File

@ -5,25 +5,29 @@
#include <valijson/adapters/json11_adapter.hpp>
#include <valijson/adapters/jsoncpp_adapter.hpp>
#include <valijson/adapters/nlohmann_json_adapter.hpp>
#include <valijson/adapters/property_tree_adapter.hpp>
#include <valijson/adapters/rapidjson_adapter.hpp>
#include <valijson/adapters/picojson_adapter.hpp>
#include <valijson/adapters/rapidjson_adapter.hpp>
#include <valijson/utils/json11_utils.hpp>
#include <valijson/utils/jsoncpp_utils.hpp>
#include <valijson/utils/nlohmann_json_utils.hpp>
#include <valijson/utils/property_tree_utils.hpp>
#include <valijson/utils/rapidjson_utils.hpp>
#include <valijson/utils/picojson_utils.hpp>
#include <valijson/utils/rapidjson_utils.hpp>
#ifdef VALIJSON_BUILD_QT_ADAPTERS
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
#include <valijson/adapters/property_tree_adapter.hpp>
#include <valijson/utils/property_tree_utils.hpp>
#endif
#ifdef VALIJSON_BUILD_QT_ADAPTER
#include <valijson/adapters/qtjson_adapter.hpp>
#include <valijson/utils/qtjson_utils.hpp>
#endif // VALIJSON_BUILD_QT_ADAPTERS
#endif
#ifdef VALIJSON_BUILD_POCO_ADAPTERS
#ifdef VALIJSON_BUILD_POCO_ADAPTER
#include <valijson/adapters/poco_json_adapter.hpp>
#include <valijson/utils/poco_json_utils.hpp>
#endif // VALIJSON_BUILD_POCO_ADAPTERS
#endif
#define TEST_DATA_DIR "../tests/data/documents/"
@ -129,6 +133,10 @@ protected:
std::vector<TestAdapterComparison::JsonFile> TestAdapterComparison::jsonFiles;
//
// JsonCppAdapter vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, JsonCppVsJsonCpp)
{
testComparison<
@ -143,6 +151,8 @@ TEST_F(TestAdapterComparison, JsonCppVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, JsonCppVsPropertyTree)
{
testComparison<
@ -150,6 +160,8 @@ TEST_F(TestAdapterComparison, JsonCppVsPropertyTree)
valijson::adapters::PropertyTreeAdapter>();
}
#endif
TEST_F(TestAdapterComparison, JsonCppVsRapidJson)
{
testComparison<
@ -166,6 +178,12 @@ TEST_F(TestAdapterComparison, JsonCppVsRapidJsonCrtAlloc)
rapidjson::CrtAllocator> > >();
}
//
// PropertyTreeAdapter vs X
// ------------------------------------------------------------------------------------------------
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, PropertyTreeVsPicoJson)
{
testComparison<
@ -196,6 +214,12 @@ TEST_F(TestAdapterComparison, PropertyTreeVsRapidJsonCrtAlloc)
rapidjson::CrtAllocator> > >();
}
#endif
//
// RapidJson vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, RapidJsonVsRapidJson)
{
testComparison<
@ -219,6 +243,10 @@ TEST_F(TestAdapterComparison, RapidJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
//
// PicoJsonAdapter vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, PicoJsonVsPicoJson)
{
testComparison<
@ -246,6 +274,10 @@ TEST_F(TestAdapterComparison, RapidJsonCrtAllocVsRapidJsonCrtAlloc)
rapidjson::CrtAllocator> > >();
}
//
// Json11Adapter vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, Json11VsJson11)
{
testComparison<
@ -284,6 +316,8 @@ TEST_F(TestAdapterComparison, Json11VsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, Json11VsPropertyTree)
{
testComparison<
@ -291,6 +325,12 @@ TEST_F(TestAdapterComparison, Json11VsPropertyTree)
valijson::adapters::PropertyTreeAdapter>();
}
#endif // VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
//
// NlohmannJsonAdapter vs X
// ------------------------------------------------------------------------------------------------
TEST_F(TestAdapterComparison, NlohmannJsonVsNlohmannJson) {
testComparison<
valijson::adapters::NlohmannJsonAdapter,
@ -335,6 +375,8 @@ TEST_F(TestAdapterComparison, NlohmannJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, NlohmannJsonVsPropertyTree)
{
testComparison<
@ -342,7 +384,13 @@ TEST_F(TestAdapterComparison, NlohmannJsonVsPropertyTree)
valijson::adapters::PropertyTreeAdapter>();
}
#ifdef VALIJSON_BUILD_QT_ADAPTERS
#endif // VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
//
// QtJsonAdapter vs X
// ------------------------------------------------------------------------------------------------
#ifdef VALIJSON_BUILD_QT_ADAPTER
TEST_F(TestAdapterComparison, QtJsonVsQtJson) {
testComparison<
@ -380,6 +428,8 @@ TEST_F(TestAdapterComparison, QtJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, QtJsonVsPropertyTree)
{
testComparison<
@ -387,9 +437,7 @@ TEST_F(TestAdapterComparison, QtJsonVsPropertyTree)
valijson::adapters::PropertyTreeAdapter>();
}
#endif // VALIJSON_BUILD_QT_ADAPTERS
#if defined(VALIJSON_BUILD_QT_ADAPTERS)
#endif // VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, QtJsonVsJson11)
{
@ -405,9 +453,13 @@ TEST_F(TestAdapterComparison, QtJsonVsNlohmannJson)
valijson::adapters::NlohmannJsonAdapter>();
}
#endif
#endif // VALIJSON_BUILD_QT_ADAPTER
#ifdef VALIJSON_BUILD_POCO_ADAPTERS
//
// PocoJsonAdapter vs X
// ------------------------------------------------------------------------------------------------
#ifdef VALIJSON_BUILD_POCO_ADAPTER
TEST_F(TestAdapterComparison, PocoJsonVsPocoJson)
{
@ -446,6 +498,8 @@ TEST_F(TestAdapterComparison, PocoJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter>();
}
#ifdef VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, PocoJsonVsPropertyTree)
{
testComparison<
@ -453,9 +507,7 @@ TEST_F(TestAdapterComparison, PocoJsonVsPropertyTree)
valijson::adapters::PropertyTreeAdapter>();
}
#endif
#if defined(VALIJSON_BUILD_POCO_ADAPTERS)
#endif // VALIJSON_BUILD_PROPERTY_TREE_ADAPTER
TEST_F(TestAdapterComparison, PocoJsonVsJson11)
{
@ -471,9 +523,7 @@ TEST_F(TestAdapterComparison, PocoJsonVsNlohmannJsonAdapter)
valijson::adapters::NlohmannJsonAdapter>();
}
#endif
#if defined(VALIJSON_BUILD_POCO_ADAPTERS) && defined(VALIJSON_BUILD_QT_ADAPTERS)
#ifdef VALIJSON_BUILD_QT_ADAPTER
TEST_F(TestAdapterComparison, PocoJsonVsQtJson)
{
@ -482,4 +532,6 @@ TEST_F(TestAdapterComparison, PocoJsonVsQtJson)
valijson::adapters::QtJsonAdapter>();
}
#endif
#endif // VALIJSON_BUILD_QT_ADAPTER
#endif // VALIJSON_BUILD_POCO_ADAPTER

View File

@ -1,5 +1,3 @@
#ifdef VALIJSON_BUILD_POCO_ADAPTERS
#include <gtest/gtest.h>
#include <valijson/adapters/poco_json_adapter.hpp>
@ -15,7 +13,7 @@ TEST_F(TestPocoJsonAdapter, BasicArrayIteration)
// Create a Json document that consists of an array of numbers
Poco::JSON::Array::Ptr documentImpl = new Poco::JSON::Array();
for (unsigned int i = 0; i < numElements; i++) {
documentImpl->set(i, static_cast<double>(i));
}
@ -84,6 +82,3 @@ TEST_F(TestPocoJsonAdapter, BasicObjectIteration)
// Ensure that the correct number of elements were iterated over
EXPECT_EQ( numElements, expectedValue );
}
#endif // VALIJSON_BUILD_POCO_ADAPTERS

View File

@ -10,17 +10,17 @@
#include <valijson/adapters/picojson_adapter.hpp>
#include <valijson/utils/json11_utils.hpp>
#include <valijson/utils/jsoncpp_utils.hpp>
#include <valijson/utils/rapidjson_utils.hpp>
#include <valijson/utils/picojson_utils.hpp>
#include <valijson/utils/rapidjson_utils.hpp>
#include <valijson/schema.hpp>
#include <valijson/schema_parser.hpp>
#include <valijson/validation_results.hpp>
#include <valijson/validator.hpp>
#ifdef VALIJSON_BUILD_POCO_ADAPTERS
#ifdef VALIJSON_BUILD_POCO_ADAPTER
#include <valijson/adapters/poco_json_adapter.hpp>
#include <valijson/utils/poco_json_utils.hpp>
#endif // VALIJSON_BUILD_POCO_ADAPTERS
#endif
#define REMOTES_DIR "../thirdparty/JSON-Schema-Test-Suite/remotes/"
@ -169,9 +169,9 @@ protected:
processTestFile<valijson::adapters::RapidJsonAdapter>(testFile, version);
processTestFile<valijson::adapters::PicoJsonAdapter>(testFile, version);
#ifdef VALIJSON_BUILD_POCO_ADAPTERS
#ifdef VALIJSON_BUILD_POCO_ADAPTER
processTestFile<valijson::adapters::PocoJsonAdapter>(testFile, version);
#endif // VALIJSON_BUILD_POCO_ADAPTERS
#endif // VALIJSON_BUILD_POCO_ADAPTER
}
void processDraft3TestFile(const std::string &testFile)