Test: extracted executable Cpp11Tests

This commit is contained in:
Benoit Blanchon
2021-06-15 18:52:18 +02:00
parent eab5ae2f07
commit ba5cdab619
14 changed files with 90 additions and 56 deletions

View File

@ -2,7 +2,7 @@
# Copyright Benoit Blanchon 2014-2021 # Copyright Benoit Blanchon 2014-2021
# MIT License # MIT License
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.3)
project(ArduinoJson VERSION 6.18.0) project(ArduinoJson VERSION 6.18.0)

View File

@ -23,12 +23,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
-Wundef -Wundef
) )
if(NOT MINGW)
add_compile_options(
-std=c++98
)
endif()
if(${COVERAGE}) if(${COVERAGE})
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage") set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
endif() endif()

View File

@ -2,11 +2,15 @@
# Copyright Benoit Blanchon 2014-2021 # Copyright Benoit Blanchon 2014-2021
# MIT License # MIT License
set(CMAKE_CXX_STANDARD 98)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_subdirectory(catch) add_subdirectory(catch)
link_libraries(ArduinoJson catch) link_libraries(ArduinoJson catch)
include_directories(Helpers) include_directories(Helpers)
add_subdirectory(Cpp11)
add_subdirectory(FailingBuilds) add_subdirectory(FailingBuilds)
add_subdirectory(IntegrationTests) add_subdirectory(IntegrationTests)
add_subdirectory(JsonArray) add_subdirectory(JsonArray)

View 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"
)

View File

@ -2,40 +2,6 @@
#include <catch.hpp> #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") { TEST_CASE("Issue #1120") {
StaticJsonDocument<500> doc; StaticJsonDocument<500> doc;
constexpr char str[] = constexpr char str[] =
@ -90,5 +56,3 @@ TEST_CASE("Issue #1120") {
} }
} }
} }
#endif

View 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);
}
}

View File

@ -2,11 +2,7 @@
# Copyright Benoit Blanchon 2014-2021 # Copyright Benoit Blanchon 2014-2021
# MIT License # MIT License
# we need C++11 for 'long long'
set(CMAKE_CXX_STANDARD 11)
add_executable(MixedConfigurationTests add_executable(MixedConfigurationTests
cpp11.cpp
decode_unicode_0.cpp decode_unicode_0.cpp
decode_unicode_1.cpp decode_unicode_1.cpp
enable_alignment_0.cpp enable_alignment_0.cpp
@ -22,8 +18,6 @@ add_executable(MixedConfigurationTests
enable_string_deduplication_1.cpp enable_string_deduplication_1.cpp
use_double_0.cpp use_double_0.cpp
use_double_1.cpp use_double_1.cpp
use_long_long_0.cpp
use_long_long_1.cpp
) )
set_target_properties(MixedConfigurationTests PROPERTIES UNITY_BUILD OFF) set_target_properties(MixedConfigurationTests PROPERTIES UNITY_BUILD OFF)

View File

@ -6,7 +6,7 @@
static void assertParseFails(const char* json) { static void assertParseFails(const char* json) {
DynamicJsonDocument doc(4096); DynamicJsonDocument doc(4096);
auto err = deserializeJson(doc, json); DeserializationError err = deserializeJson(doc, json);
REQUIRE(err == DeserializationError::InvalidInput); REQUIRE(err == DeserializationError::InvalidInput);
} }

View File

@ -22,7 +22,8 @@ TEST_CASE("ARDUINOJSON_ENABLE_INFINITY == 1") {
} }
SECTION("deserializeJson()") { SECTION("deserializeJson()") {
auto err = deserializeJson(doc, "[Infinity,-Infinity,+Infinity]"); DeserializationError err =
deserializeJson(doc, "[Infinity,-Infinity,+Infinity]");
float a = doc[0]; float a = doc[0];
float b = doc[1]; float b = doc[1];
float c = doc[2]; float c = doc[2];

View File

@ -18,7 +18,7 @@ TEST_CASE("ARDUINOJSON_ENABLE_NAN == 0") {
} }
SECTION("deserializeJson()") { SECTION("deserializeJson()") {
auto err = deserializeJson(doc, "{\"X\":NaN}"); DeserializationError err = deserializeJson(doc, "{\"X\":NaN}");
REQUIRE(err == DeserializationError::InvalidInput); REQUIRE(err == DeserializationError::InvalidInput);
} }

View File

@ -22,7 +22,7 @@ TEST_CASE("ARDUINOJSON_ENABLE_NAN == 1") {
} }
SECTION("deserializeJson()") { SECTION("deserializeJson()") {
auto err = deserializeJson(doc, "{\"X\":NaN}"); DeserializationError err = deserializeJson(doc, "{\"X\":NaN}");
float x = doc["X"]; float x = doc["X"];
REQUIRE(err == DeserializationError::Ok); REQUIRE(err == DeserializationError::Ok);

View File

@ -6,14 +6,20 @@
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
# define ARDUINOJSON_HAS_LONG_LONG 1 # define ARDUINOJSON_HAS_LONG_LONG 1
# define ARDUINOJSON_HAS_NULLPTR 1
# define ARDUINOJSON_HAS_RVALUE_REFERENCES 1 # define ARDUINOJSON_HAS_RVALUE_REFERENCES 1
#else #else
# define ARDUINOJSON_HAS_LONG_LONG 0 # define ARDUINOJSON_HAS_LONG_LONG 0
# define ARDUINOJSON_HAS_NULLPTR 0
# define ARDUINOJSON_HAS_RVALUE_REFERENCES 0 # define ARDUINOJSON_HAS_RVALUE_REFERENCES 0
#endif #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 #if defined(_MSC_VER) && !ARDUINOJSON_HAS_LONG_LONG
# define ARDUINOJSON_HAS_INT64 1 # define ARDUINOJSON_HAS_INT64 1
#else #else