Skip to content

Commit ba5cdab

Browse files
committed
Test: extracted executable Cpp11Tests
1 parent eab5ae2 commit ba5cdab

14 files changed

+90
-56
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright Benoit Blanchon 2014-2021
33
# MIT License
44

5-
cmake_minimum_required(VERSION 3.0)
5+
cmake_minimum_required(VERSION 3.3)
66

77
project(ArduinoJson VERSION 6.18.0)
88

extras/CompileOptions.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
2323
-Wundef
2424
)
2525

26-
if(NOT MINGW)
27-
add_compile_options(
28-
-std=c++98
29-
)
30-
endif()
31-
3226
if(${COVERAGE})
3327
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
3428
endif()

extras/tests/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
# Copyright Benoit Blanchon 2014-2021
33
# MIT License
44

5+
set(CMAKE_CXX_STANDARD 98)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
58
add_subdirectory(catch)
69

710
link_libraries(ArduinoJson catch)
811

912
include_directories(Helpers)
13+
add_subdirectory(Cpp11)
1014
add_subdirectory(FailingBuilds)
1115
add_subdirectory(IntegrationTests)
1216
add_subdirectory(JsonArray)

extras/tests/Cpp11/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# ArduinoJson - https://arduinojson.org
2+
# Copyright Benoit Blanchon 2014-2021
3+
# MIT License
4+
5+
if("cxx_nullptr" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
6+
list(APPEND SOURCES nullptr.cpp)
7+
add_definitions(-DARDUINOJSON_HAS_NULLPTR=1)
8+
endif()
9+
10+
if("cxx_auto_type" IN_LIST CMAKE_CXX_COMPILE_FEATURES AND "cxx_constexpr" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
11+
list(APPEND SOURCES issue1120.cpp)
12+
endif()
13+
14+
if("cxx_long_long_type" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
15+
list(APPEND SOURCES use_long_long_0.cpp use_long_long_1.cpp)
16+
endif()
17+
18+
if(NOT SOURCES)
19+
return()
20+
endif()
21+
22+
set(CMAKE_CXX_STANDARD 11)
23+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
24+
25+
add_executable(Cpp11Tests ${SOURCES})
26+
27+
add_test(Cpp11 Cpp11Tests)
28+
29+
set_tests_properties(Cpp11
30+
PROPERTIES
31+
LABELS "Catch"
32+
)

extras/tests/MixedConfiguration/cpp11.cpp renamed to extras/tests/Cpp11/issue1120.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,6 @@
22

33
#include <catch.hpp>
44

5-
#if __cplusplus >= 201103L
6-
7-
TEST_CASE("nullptr") {
8-
DynamicJsonDocument doc(4096);
9-
JsonVariant variant = doc.to<JsonVariant>();
10-
11-
SECTION("JsonVariant == nullptr") {
12-
REQUIRE((variant == nullptr));
13-
REQUIRE_FALSE((variant != nullptr));
14-
}
15-
16-
SECTION("JsonVariant != nullptr") {
17-
variant.set(42);
18-
19-
REQUIRE_FALSE((variant == nullptr));
20-
REQUIRE((variant != nullptr));
21-
}
22-
23-
SECTION("JsonVariant.set(nullptr)") {
24-
variant.set(42);
25-
variant.set(nullptr);
26-
27-
REQUIRE(variant.isNull());
28-
}
29-
30-
SECTION("JsonVariant.is<nullptr_t>()") {
31-
variant.set(42);
32-
REQUIRE(variant.is<std::nullptr_t>() == false);
33-
34-
variant.clear();
35-
REQUIRE(variant.is<std::nullptr_t>() == true);
36-
}
37-
}
38-
395
TEST_CASE("Issue #1120") {
406
StaticJsonDocument<500> doc;
417
constexpr char str[] =
@@ -90,5 +56,3 @@ TEST_CASE("Issue #1120") {
9056
}
9157
}
9258
}
93-
94-
#endif

extras/tests/Cpp11/nullptr.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <ArduinoJson.h>
2+
3+
#include <catch.hpp>
4+
5+
#if !ARDUINOJSON_HAS_NULLPTR
6+
# error ARDUINOJSON_HAS_NULLPTR must be set to 1
7+
#endif
8+
9+
TEST_CASE("nullptr") {
10+
DynamicJsonDocument doc(4096);
11+
JsonVariant variant = doc.to<JsonVariant>();
12+
13+
SECTION("JsonVariant == nullptr") {
14+
REQUIRE((variant == nullptr));
15+
REQUIRE_FALSE((variant != nullptr));
16+
}
17+
18+
SECTION("JsonVariant != nullptr") {
19+
variant.set(42);
20+
21+
REQUIRE_FALSE((variant == nullptr));
22+
REQUIRE((variant != nullptr));
23+
}
24+
25+
SECTION("JsonVariant.set(nullptr)") {
26+
variant.set(42);
27+
variant.set(nullptr);
28+
29+
REQUIRE(variant.isNull());
30+
}
31+
32+
SECTION("JsonVariant.is<nullptr_t>()") {
33+
variant.set(42);
34+
REQUIRE(variant.is<std::nullptr_t>() == false);
35+
36+
variant.clear();
37+
REQUIRE(variant.is<std::nullptr_t>() == true);
38+
}
39+
}

extras/tests/MixedConfiguration/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
# Copyright Benoit Blanchon 2014-2021
33
# MIT License
44

5-
# we need C++11 for 'long long'
6-
set(CMAKE_CXX_STANDARD 11)
7-
85
add_executable(MixedConfigurationTests
9-
cpp11.cpp
106
decode_unicode_0.cpp
117
decode_unicode_1.cpp
128
enable_alignment_0.cpp
@@ -22,8 +18,6 @@ add_executable(MixedConfigurationTests
2218
enable_string_deduplication_1.cpp
2319
use_double_0.cpp
2420
use_double_1.cpp
25-
use_long_long_0.cpp
26-
use_long_long_1.cpp
2721
)
2822

2923
set_target_properties(MixedConfigurationTests PROPERTIES UNITY_BUILD OFF)
@@ -33,4 +27,4 @@ add_test(MixedConfiguration MixedConfigurationTests)
3327
set_tests_properties(MixedConfiguration
3428
PROPERTIES
3529
LABELS "Catch"
36-
)
30+
)

extras/tests/MixedConfiguration/enable_infinity_0.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
static void assertParseFails(const char* json) {
88
DynamicJsonDocument doc(4096);
9-
auto err = deserializeJson(doc, json);
9+
DeserializationError err = deserializeJson(doc, json);
1010

1111
REQUIRE(err == DeserializationError::InvalidInput);
1212
}

0 commit comments

Comments
 (0)