forked from bblanchon/ArduinoJson
Test: extracted executable Cpp11Tests
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
# Copyright Benoit Blanchon 2014-2021
|
||||
# MIT License
|
||||
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.3)
|
||||
|
||||
project(ArduinoJson VERSION 6.18.0)
|
||||
|
||||
|
@ -23,12 +23,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||
-Wundef
|
||||
)
|
||||
|
||||
if(NOT MINGW)
|
||||
add_compile_options(
|
||||
-std=c++98
|
||||
)
|
||||
endif()
|
||||
|
||||
if(${COVERAGE})
|
||||
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
|
||||
endif()
|
||||
|
@ -2,11 +2,15 @@
|
||||
# Copyright Benoit Blanchon 2014-2021
|
||||
# MIT License
|
||||
|
||||
set(CMAKE_CXX_STANDARD 98)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_subdirectory(catch)
|
||||
|
||||
link_libraries(ArduinoJson catch)
|
||||
|
||||
include_directories(Helpers)
|
||||
add_subdirectory(Cpp11)
|
||||
add_subdirectory(FailingBuilds)
|
||||
add_subdirectory(IntegrationTests)
|
||||
add_subdirectory(JsonArray)
|
||||
|
32
extras/tests/Cpp11/CMakeLists.txt
Normal file
32
extras/tests/Cpp11/CMakeLists.txt
Normal file
@ -0,0 +1,32 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2021
|
||||
# MIT License
|
||||
|
||||
if("cxx_nullptr" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
|
||||
list(APPEND SOURCES nullptr.cpp)
|
||||
add_definitions(-DARDUINOJSON_HAS_NULLPTR=1)
|
||||
endif()
|
||||
|
||||
if("cxx_auto_type" IN_LIST CMAKE_CXX_COMPILE_FEATURES AND "cxx_constexpr" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
|
||||
list(APPEND SOURCES issue1120.cpp)
|
||||
endif()
|
||||
|
||||
if("cxx_long_long_type" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
|
||||
list(APPEND SOURCES use_long_long_0.cpp use_long_long_1.cpp)
|
||||
endif()
|
||||
|
||||
if(NOT SOURCES)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_executable(Cpp11Tests ${SOURCES})
|
||||
|
||||
add_test(Cpp11 Cpp11Tests)
|
||||
|
||||
set_tests_properties(Cpp11
|
||||
PROPERTIES
|
||||
LABELS "Catch"
|
||||
)
|
@ -2,40 +2,6 @@
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
|
||||
TEST_CASE("nullptr") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonVariant variant = doc.to<JsonVariant>();
|
||||
|
||||
SECTION("JsonVariant == nullptr") {
|
||||
REQUIRE((variant == nullptr));
|
||||
REQUIRE_FALSE((variant != nullptr));
|
||||
}
|
||||
|
||||
SECTION("JsonVariant != nullptr") {
|
||||
variant.set(42);
|
||||
|
||||
REQUIRE_FALSE((variant == nullptr));
|
||||
REQUIRE((variant != nullptr));
|
||||
}
|
||||
|
||||
SECTION("JsonVariant.set(nullptr)") {
|
||||
variant.set(42);
|
||||
variant.set(nullptr);
|
||||
|
||||
REQUIRE(variant.isNull());
|
||||
}
|
||||
|
||||
SECTION("JsonVariant.is<nullptr_t>()") {
|
||||
variant.set(42);
|
||||
REQUIRE(variant.is<std::nullptr_t>() == false);
|
||||
|
||||
variant.clear();
|
||||
REQUIRE(variant.is<std::nullptr_t>() == true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Issue #1120") {
|
||||
StaticJsonDocument<500> doc;
|
||||
constexpr char str[] =
|
||||
@ -90,5 +56,3 @@ TEST_CASE("Issue #1120") {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
39
extras/tests/Cpp11/nullptr.cpp
Normal file
39
extras/tests/Cpp11/nullptr.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#if !ARDUINOJSON_HAS_NULLPTR
|
||||
# error ARDUINOJSON_HAS_NULLPTR must be set to 1
|
||||
#endif
|
||||
|
||||
TEST_CASE("nullptr") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonVariant variant = doc.to<JsonVariant>();
|
||||
|
||||
SECTION("JsonVariant == nullptr") {
|
||||
REQUIRE((variant == nullptr));
|
||||
REQUIRE_FALSE((variant != nullptr));
|
||||
}
|
||||
|
||||
SECTION("JsonVariant != nullptr") {
|
||||
variant.set(42);
|
||||
|
||||
REQUIRE_FALSE((variant == nullptr));
|
||||
REQUIRE((variant != nullptr));
|
||||
}
|
||||
|
||||
SECTION("JsonVariant.set(nullptr)") {
|
||||
variant.set(42);
|
||||
variant.set(nullptr);
|
||||
|
||||
REQUIRE(variant.isNull());
|
||||
}
|
||||
|
||||
SECTION("JsonVariant.is<nullptr_t>()") {
|
||||
variant.set(42);
|
||||
REQUIRE(variant.is<std::nullptr_t>() == false);
|
||||
|
||||
variant.clear();
|
||||
REQUIRE(variant.is<std::nullptr_t>() == true);
|
||||
}
|
||||
}
|
@ -2,11 +2,7 @@
|
||||
# Copyright Benoit Blanchon 2014-2021
|
||||
# MIT License
|
||||
|
||||
# we need C++11 for 'long long'
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_executable(MixedConfigurationTests
|
||||
cpp11.cpp
|
||||
decode_unicode_0.cpp
|
||||
decode_unicode_1.cpp
|
||||
enable_alignment_0.cpp
|
||||
@ -22,8 +18,6 @@ add_executable(MixedConfigurationTests
|
||||
enable_string_deduplication_1.cpp
|
||||
use_double_0.cpp
|
||||
use_double_1.cpp
|
||||
use_long_long_0.cpp
|
||||
use_long_long_1.cpp
|
||||
)
|
||||
|
||||
set_target_properties(MixedConfigurationTests PROPERTIES UNITY_BUILD OFF)
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
static void assertParseFails(const char* json) {
|
||||
DynamicJsonDocument doc(4096);
|
||||
auto err = deserializeJson(doc, json);
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
|
||||
REQUIRE(err == DeserializationError::InvalidInput);
|
||||
}
|
||||
|
@ -22,7 +22,8 @@ TEST_CASE("ARDUINOJSON_ENABLE_INFINITY == 1") {
|
||||
}
|
||||
|
||||
SECTION("deserializeJson()") {
|
||||
auto err = deserializeJson(doc, "[Infinity,-Infinity,+Infinity]");
|
||||
DeserializationError err =
|
||||
deserializeJson(doc, "[Infinity,-Infinity,+Infinity]");
|
||||
float a = doc[0];
|
||||
float b = doc[1];
|
||||
float c = doc[2];
|
||||
|
@ -18,7 +18,7 @@ TEST_CASE("ARDUINOJSON_ENABLE_NAN == 0") {
|
||||
}
|
||||
|
||||
SECTION("deserializeJson()") {
|
||||
auto err = deserializeJson(doc, "{\"X\":NaN}");
|
||||
DeserializationError err = deserializeJson(doc, "{\"X\":NaN}");
|
||||
|
||||
REQUIRE(err == DeserializationError::InvalidInput);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ TEST_CASE("ARDUINOJSON_ENABLE_NAN == 1") {
|
||||
}
|
||||
|
||||
SECTION("deserializeJson()") {
|
||||
auto err = deserializeJson(doc, "{\"X\":NaN}");
|
||||
DeserializationError err = deserializeJson(doc, "{\"X\":NaN}");
|
||||
float x = doc["X"];
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
|
@ -6,14 +6,20 @@
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
# define ARDUINOJSON_HAS_LONG_LONG 1
|
||||
# define ARDUINOJSON_HAS_NULLPTR 1
|
||||
# define ARDUINOJSON_HAS_RVALUE_REFERENCES 1
|
||||
#else
|
||||
# define ARDUINOJSON_HAS_LONG_LONG 0
|
||||
# define ARDUINOJSON_HAS_NULLPTR 0
|
||||
# define ARDUINOJSON_HAS_RVALUE_REFERENCES 0
|
||||
#endif
|
||||
|
||||
#ifndef ARDUINOJSON_HAS_NULLPTR
|
||||
# if __cplusplus >= 201103L
|
||||
# define ARDUINOJSON_HAS_NULLPTR 1
|
||||
# else
|
||||
# define ARDUINOJSON_HAS_NULLPTR 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && !ARDUINOJSON_HAS_LONG_LONG
|
||||
# define ARDUINOJSON_HAS_INT64 1
|
||||
#else
|
||||
|
Reference in New Issue
Block a user