mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 20:12:16 +02:00
Disabled lazy number deserialization (fixes #772)
This commit is contained in:
@ -67,13 +67,13 @@ endif()
|
||||
add_subdirectory(DynamicJsonBuffer)
|
||||
add_subdirectory(IntegrationTests)
|
||||
add_subdirectory(JsonArray)
|
||||
add_subdirectory(JsonObject)
|
||||
add_subdirectory(JsonDeserializer)
|
||||
add_subdirectory(JsonObject)
|
||||
add_subdirectory(JsonSerializer)
|
||||
add_subdirectory(JsonVariant)
|
||||
add_subdirectory(JsonWriter)
|
||||
add_subdirectory(Misc)
|
||||
add_subdirectory(MsgPackDeserializer)
|
||||
add_subdirectory(MsgPackSerializer)
|
||||
add_subdirectory(Polyfills)
|
||||
add_subdirectory(Numbers)
|
||||
add_subdirectory(StaticJsonBuffer)
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
add_executable(IntegrationTests
|
||||
gbathree.cpp
|
||||
issue772.cpp
|
||||
round_trip.cpp
|
||||
)
|
||||
|
||||
|
27
test/IntegrationTests/issue772.cpp
Normal file
27
test/IntegrationTests/issue772.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
// https://github.com/bblanchon/ArduinoJson/issues/772
|
||||
|
||||
TEST_CASE("Issue772") {
|
||||
DynamicJsonDocument doc1, doc2;
|
||||
DeserializationError err;
|
||||
std::string data =
|
||||
"{\"state\":{\"reported\":{\"timestamp\":\"2018-07-02T09:40:12Z\","
|
||||
"\"mac\":\"2C3AE84FC076\",\"firmwareVersion\":\"v0.2.7-5-gf4d4d78\","
|
||||
"\"visibleLight\":261,\"infraRed\":255,\"ultraViolet\":0.02,"
|
||||
"\"Temperature\":26.63,\"Pressure\":101145.7,\"Humidity\":54.79883,"
|
||||
"\"Vbat\":4.171261,\"soilMoisture\":0,\"ActB\":0}}}";
|
||||
err = deserializeJson(doc1, data);
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
|
||||
data = "";
|
||||
serializeMsgPack(doc1, data);
|
||||
err = deserializeMsgPack(doc2, data);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
}
|
@ -128,12 +128,7 @@ TEST_CASE("deserialize JSON array") {
|
||||
|
||||
SECTION("No quotes") {
|
||||
DeserializationError err = deserializeJson(doc, "[ hello , world ]");
|
||||
JsonArray arr = doc.as<JsonArray>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(2 == arr.size());
|
||||
REQUIRE(arr[0] == "hello");
|
||||
REQUIRE(arr[1] == "world");
|
||||
REQUIRE(err == DeserializationError::InvalidInput);
|
||||
}
|
||||
|
||||
SECTION("Double quotes (empty strings)") {
|
||||
|
@ -39,7 +39,7 @@ TEST_CASE("deserialize JSON object") {
|
||||
}
|
||||
|
||||
SECTION("No quotes") {
|
||||
DeserializationError err = deserializeJson(doc, "{key:value}");
|
||||
DeserializationError err = deserializeJson(doc, "{key:'value'}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
|
@ -21,7 +21,7 @@ TEST_CASE("deserializeJson(std::istream&)") {
|
||||
}
|
||||
|
||||
SECTION("object") {
|
||||
std::istringstream json(" { hello : world // comment\n }");
|
||||
std::istringstream json(" { hello : 'world' // comment\n }");
|
||||
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
@ -2,12 +2,12 @@
|
||||
# Copyright Benoit Blanchon 2014-2018
|
||||
# MIT License
|
||||
|
||||
add_executable(PolyfillsTests
|
||||
add_executable(NumbersTests
|
||||
isFloat.cpp
|
||||
isInteger.cpp
|
||||
parseFloat.cpp
|
||||
parseInteger.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(PolyfillsTests catch)
|
||||
add_test(Polyfills PolyfillsTests)
|
||||
target_link_libraries(NumbersTests catch)
|
||||
add_test(Numbers NumbersTests)
|
80
test/Numbers/isFloat.cpp
Normal file
80
test/Numbers/isFloat.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Numbers/isFloat.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
TEST_CASE("isFloat()") {
|
||||
SECTION("Input is NULL") {
|
||||
REQUIRE(isFloat(NULL) == false);
|
||||
}
|
||||
|
||||
SECTION("Empty string") {
|
||||
REQUIRE(isFloat("") == false);
|
||||
}
|
||||
|
||||
SECTION("NoExponent") {
|
||||
REQUIRE(isFloat("3.14") == true);
|
||||
REQUIRE(isFloat("-3.14") == true);
|
||||
REQUIRE(isFloat("+3.14") == true);
|
||||
}
|
||||
|
||||
SECTION("IntegralPartMissing") {
|
||||
REQUIRE(isFloat(".14") == true);
|
||||
REQUIRE(isFloat("-.14") == true);
|
||||
REQUIRE(isFloat("+.14") == true);
|
||||
}
|
||||
|
||||
SECTION("FractionalPartMissing") {
|
||||
REQUIRE(isFloat("3.") == true);
|
||||
REQUIRE(isFloat("-3.e14") == true);
|
||||
REQUIRE(isFloat("+3.e-14") == true);
|
||||
}
|
||||
|
||||
SECTION("NoDot") {
|
||||
REQUIRE(isFloat("3e14") == true);
|
||||
REQUIRE(isFloat("3e-14") == true);
|
||||
REQUIRE(isFloat("3e+14") == true);
|
||||
}
|
||||
|
||||
SECTION("Integer") {
|
||||
REQUIRE(isFloat("14") == true);
|
||||
REQUIRE(isFloat("-14") == true);
|
||||
REQUIRE(isFloat("+14") == true);
|
||||
}
|
||||
|
||||
SECTION("ExponentMissing") {
|
||||
REQUIRE(isFloat("3.14e") == false);
|
||||
REQUIRE(isFloat("3.14e-") == false);
|
||||
REQUIRE(isFloat("3.14e+") == false);
|
||||
}
|
||||
|
||||
SECTION("JustASign") {
|
||||
REQUIRE(isFloat("-") == false);
|
||||
REQUIRE(isFloat("+") == false);
|
||||
}
|
||||
|
||||
SECTION("Empty") {
|
||||
REQUIRE(isFloat("") == false);
|
||||
}
|
||||
|
||||
SECTION("NaN") {
|
||||
REQUIRE(isFloat("NaN") == true);
|
||||
REQUIRE(isFloat("n") == false);
|
||||
REQUIRE(isFloat("N") == false);
|
||||
REQUIRE(isFloat("nan") == false);
|
||||
REQUIRE(isFloat("-NaN") == false);
|
||||
REQUIRE(isFloat("+NaN") == false);
|
||||
}
|
||||
|
||||
SECTION("Infinity") {
|
||||
REQUIRE(isFloat("Infinity") == true);
|
||||
REQUIRE(isFloat("+Infinity") == true);
|
||||
REQUIRE(isFloat("-Infinity") == true);
|
||||
REQUIRE(isFloat("infinity") == false);
|
||||
REQUIRE(isFloat("Inf") == false);
|
||||
}
|
||||
}
|
40
test/Numbers/isInteger.cpp
Normal file
40
test/Numbers/isInteger.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Numbers/isInteger.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
TEST_CASE("isInteger()") {
|
||||
SECTION("Null") {
|
||||
REQUIRE(isInteger(NULL) == false);
|
||||
}
|
||||
|
||||
SECTION("Empty string") {
|
||||
REQUIRE(isInteger("") == false);
|
||||
}
|
||||
|
||||
SECTION("FloatNotInteger") {
|
||||
REQUIRE(isInteger("3.14") == false);
|
||||
REQUIRE(isInteger("-3.14") == false);
|
||||
REQUIRE(isInteger("+3.14") == false);
|
||||
}
|
||||
|
||||
SECTION("Spaces") {
|
||||
REQUIRE(isInteger("42 ") == false);
|
||||
REQUIRE(isInteger(" 42") == false);
|
||||
}
|
||||
|
||||
SECTION("Valid") {
|
||||
REQUIRE(isInteger("42") == true);
|
||||
REQUIRE(isInteger("-42") == true);
|
||||
REQUIRE(isInteger("+42") == true);
|
||||
}
|
||||
|
||||
SECTION("ExtraSign") {
|
||||
REQUIRE(isInteger("--42") == false);
|
||||
REQUIRE(isInteger("++42") == false);
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Numbers/isFloat.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
TEST_CASE("isFloat()") {
|
||||
SECTION("Input is NULL") {
|
||||
REQUIRE(isFloat(NULL) == false);
|
||||
}
|
||||
|
||||
SECTION("NoExponent") {
|
||||
REQUIRE(isFloat("3.14"));
|
||||
REQUIRE(isFloat("-3.14"));
|
||||
REQUIRE(isFloat("+3.14"));
|
||||
}
|
||||
|
||||
SECTION("IntegralPartMissing") {
|
||||
REQUIRE(isFloat(".14"));
|
||||
REQUIRE(isFloat("-.14"));
|
||||
REQUIRE(isFloat("+.14"));
|
||||
}
|
||||
|
||||
SECTION("FractionalPartMissing") {
|
||||
REQUIRE(isFloat("3."));
|
||||
REQUIRE(isFloat("-3.e14"));
|
||||
REQUIRE(isFloat("+3.e-14"));
|
||||
}
|
||||
|
||||
SECTION("NoDot") {
|
||||
REQUIRE(isFloat("3e14"));
|
||||
REQUIRE(isFloat("3e-14"));
|
||||
REQUIRE(isFloat("3e+14"));
|
||||
}
|
||||
|
||||
SECTION("Integer") {
|
||||
REQUIRE(isFloat("14"));
|
||||
REQUIRE(isFloat("-14"));
|
||||
REQUIRE(isFloat("+14"));
|
||||
}
|
||||
|
||||
SECTION("ExponentMissing") {
|
||||
REQUIRE_FALSE(isFloat("3.14e"));
|
||||
REQUIRE_FALSE(isFloat("3.14e-"));
|
||||
REQUIRE_FALSE(isFloat("3.14e+"));
|
||||
}
|
||||
|
||||
SECTION("JustASign") {
|
||||
REQUIRE_FALSE(isFloat("-"));
|
||||
REQUIRE_FALSE(isFloat("+"));
|
||||
}
|
||||
|
||||
SECTION("Empty") {
|
||||
REQUIRE_FALSE(isFloat(""));
|
||||
}
|
||||
|
||||
SECTION("NaN") {
|
||||
REQUIRE(isFloat("NaN"));
|
||||
REQUIRE_FALSE(isFloat("n"));
|
||||
REQUIRE_FALSE(isFloat("N"));
|
||||
REQUIRE_FALSE(isFloat("nan"));
|
||||
REQUIRE_FALSE(isFloat("-NaN"));
|
||||
REQUIRE_FALSE(isFloat("+NaN"));
|
||||
}
|
||||
|
||||
SECTION("Infinity") {
|
||||
REQUIRE(isFloat("Infinity"));
|
||||
REQUIRE(isFloat("+Infinity"));
|
||||
REQUIRE(isFloat("-Infinity"));
|
||||
REQUIRE_FALSE(isFloat("infinity"));
|
||||
REQUIRE_FALSE(isFloat("Inf"));
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Numbers/isInteger.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
TEST_CASE("isInteger()") {
|
||||
SECTION("Null") {
|
||||
REQUIRE_FALSE(isInteger(NULL));
|
||||
}
|
||||
|
||||
SECTION("FloatNotInteger") {
|
||||
REQUIRE_FALSE(isInteger("3.14"));
|
||||
REQUIRE_FALSE(isInteger("-3.14"));
|
||||
REQUIRE_FALSE(isInteger("+3.14"));
|
||||
}
|
||||
|
||||
SECTION("Spaces") {
|
||||
REQUIRE_FALSE(isInteger("42 "));
|
||||
REQUIRE_FALSE(isInteger(" 42"));
|
||||
}
|
||||
|
||||
SECTION("Valid") {
|
||||
REQUIRE(isInteger("42"));
|
||||
REQUIRE(isInteger("-42"));
|
||||
REQUIRE(isInteger("+42"));
|
||||
}
|
||||
|
||||
SECTION("ExtraSign") {
|
||||
REQUIRE_FALSE(isInteger("--42"));
|
||||
REQUIRE_FALSE(isInteger("++42"));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user