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

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

View File

@ -24,8 +24,6 @@
*/
#pragma once
#ifndef __VALIJSON_ADAPTERS_POCO_JSON_ADAPTER_HPP
#define __VALIJSON_ADAPTERS_POCO_JSON_ADAPTER_HPP
#include <string>
#include <Poco/JSON/Object.h>
@ -34,10 +32,8 @@
#include <valijson/adapters/basic_adapter.hpp>
#include <valijson/adapters/frozen_value.hpp>
namespace valijson
{
namespace adapters
{
namespace valijson {
namespace adapters {
class PocoJsonAdapter;
class PocoJsonArrayValueIterator;
@ -718,11 +714,5 @@ namespace valijson
return PocoJsonAdapter(value).equalTo(other, strict);
}
} // namespace adapters
} // namespace valijson
#endif // __VALIJSON_ADAPTERS_POCO_JSON_ADAPTER_HPP

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

@ -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

@ -55,7 +55,6 @@ namespace json_reference {
return opt::optional<std::string>();
}
} // namespace json_reference
} // namespace internal
} // namespace valijson

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

@ -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>
@ -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)