mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-23 07:17:30 +02:00
Allow mixed configuration in compilation units (issue #809)
This commit is contained in:
16
test/MixedConfiguration/CMakeLists.txt
Normal file
16
test/MixedConfiguration/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2018
|
||||
# MIT License
|
||||
|
||||
# we need C++11 for 'long long'
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_executable(MixedConfigurationTests
|
||||
use_double_0.cpp
|
||||
use_double_1.cpp
|
||||
use_long_long_0.cpp
|
||||
use_long_long_1.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MixedConfigurationTests catch)
|
||||
add_test(MixedConfiguration MixedConfigurationTests)
|
17
test/MixedConfiguration/use_double_0.cpp
Normal file
17
test/MixedConfiguration/use_double_0.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#define ARDUINOJSON_USE_DOUBLE 0
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("ARDUINOJSON_USE_DOUBLE == 0") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
|
||||
root["pi"] = 3.14;
|
||||
root["e"] = 2.72;
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
|
||||
REQUIRE(json == "{\"pi\":3.14,\"e\":2.72}");
|
||||
}
|
17
test/MixedConfiguration/use_double_1.cpp
Normal file
17
test/MixedConfiguration/use_double_1.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#define ARDUINOJSON_USE_DOUBLE 1
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("ARDUINOJSON_USE_DOUBLE == 1") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
|
||||
root["pi"] = 3.14;
|
||||
root["e"] = 2.72;
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
|
||||
REQUIRE(json == "{\"pi\":3.14,\"e\":2.72}");
|
||||
}
|
30
test/MixedConfiguration/use_long_long_0.cpp
Normal file
30
test/MixedConfiguration/use_long_long_0.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#define ARDUINOJSON_USE_LONG_LONG 0
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
template <size_t size_of_long>
|
||||
std::string get_expected_json();
|
||||
|
||||
template <>
|
||||
std::string get_expected_json<4>() {
|
||||
return "{\"A\":2899336981,\"B\":2129924785}";
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string get_expected_json<8>() {
|
||||
return "{\"A\":123456789123456789,\"B\":987654321987654321}";
|
||||
}
|
||||
|
||||
TEST_CASE("ARDUINOJSON_USE_LONG_LONG == 0") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
|
||||
root["A"] = 123456789123456789;
|
||||
root["B"] = 987654321987654321;
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
|
||||
REQUIRE(json == get_expected_json<sizeof(long)>());
|
||||
}
|
17
test/MixedConfiguration/use_long_long_1.cpp
Normal file
17
test/MixedConfiguration/use_long_long_1.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#define ARDUINOJSON_USE_LONG_LONG 1
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("ARDUINOJSON_USE_LONG_LONG == 1") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
|
||||
root["A"] = 123456789123456789;
|
||||
root["B"] = 987654321987654321;
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
|
||||
REQUIRE(json == "{\"A\":123456789123456789,\"B\":987654321987654321}");
|
||||
}
|
Reference in New Issue
Block a user