forked from bblanchon/ArduinoJson
Added ARDUINOJSON_ENABLE_NAN
to enable NaN in JSON (closes #973)
This commit is contained in:
@ -12,6 +12,8 @@ add_executable(MixedConfigurationTests
|
||||
use_double_1.cpp
|
||||
use_long_long_0.cpp
|
||||
use_long_long_1.cpp
|
||||
enable_nan_0.cpp
|
||||
enable_nan_1.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MixedConfigurationTests catch)
|
||||
|
25
test/MixedConfiguration/enable_nan_0.cpp
Normal file
25
test/MixedConfiguration/enable_nan_0.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#define ARDUINOJSON_ENABLE_NAN 0
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
#include <limits>
|
||||
|
||||
TEST_CASE("ARDUINOJSON_ENABLE_NAN == 0") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
|
||||
SECTION("serializeJson()") {
|
||||
root["X"] = std::numeric_limits<double>::signaling_NaN();
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
|
||||
REQUIRE(json == "{\"X\":null}");
|
||||
}
|
||||
|
||||
SECTION("deserializeJson()") {
|
||||
auto err = deserializeJson(doc, "{\"X\":NaN}");
|
||||
|
||||
REQUIRE(err == DeserializationError::InvalidInput);
|
||||
}
|
||||
}
|
31
test/MixedConfiguration/enable_nan_1.cpp
Normal file
31
test/MixedConfiguration/enable_nan_1.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#define ARDUINOJSON_ENABLE_NAN 1
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
#include <limits>
|
||||
|
||||
namespace my {
|
||||
using ARDUINOJSON_NAMESPACE::isnan;
|
||||
} // namespace my
|
||||
|
||||
TEST_CASE("ARDUINOJSON_ENABLE_NAN == 1") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
|
||||
SECTION("serializeJson()") {
|
||||
root["X"] = std::numeric_limits<double>::signaling_NaN();
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
|
||||
REQUIRE(json == "{\"X\":NaN}");
|
||||
}
|
||||
|
||||
SECTION("deserializeJson()") {
|
||||
auto err = deserializeJson(doc, "{\"X\":NaN}");
|
||||
float x = doc["X"];
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(my::isnan(x));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user