2021-03-29 17:14:01 +02:00
|
|
|
// ArduinoJson - https://arduinojson.org
|
2021-01-25 09:14:15 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2021
|
2019-03-06 15:31:37 +01:00
|
|
|
// MIT License
|
|
|
|
|
2021-03-20 14:52:47 +01:00
|
|
|
#include <ArduinoJson.hpp>
|
2019-03-06 15:31:37 +01:00
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
using namespace ARDUINOJSON_NAMESPACE;
|
|
|
|
|
2020-09-04 09:23:40 +02:00
|
|
|
TEST_CASE("Test unsigned integer overflow") {
|
|
|
|
VariantData first, second;
|
|
|
|
first.init();
|
|
|
|
second.init();
|
|
|
|
|
|
|
|
// Avoids MSVC warning C4127 (conditional expression is constant)
|
|
|
|
size_t integerSize = sizeof(Integer);
|
|
|
|
|
|
|
|
if (integerSize == 8) {
|
|
|
|
parseNumber("18446744073709551615", first);
|
|
|
|
parseNumber("18446744073709551616", second);
|
|
|
|
} else {
|
|
|
|
parseNumber("4294967295", first);
|
|
|
|
parseNumber("4294967296", second);
|
|
|
|
}
|
2019-03-06 15:31:37 +01:00
|
|
|
|
2021-04-14 11:42:53 +02:00
|
|
|
REQUIRE(first.type() == uint8_t(VALUE_IS_UNSIGNED_INTEGER));
|
|
|
|
REQUIRE(second.type() == uint8_t(VALUE_IS_FLOAT));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Test signed integer overflow") {
|
|
|
|
VariantData first, second;
|
|
|
|
first.init();
|
|
|
|
second.init();
|
|
|
|
|
|
|
|
// Avoids MSVC warning C4127 (conditional expression is constant)
|
|
|
|
size_t integerSize = sizeof(Integer);
|
|
|
|
|
|
|
|
if (integerSize == 8) {
|
|
|
|
parseNumber("-9223372036854775808", first);
|
|
|
|
parseNumber("-9223372036854775809", second);
|
|
|
|
} else {
|
|
|
|
parseNumber("-2147483648", first);
|
|
|
|
parseNumber("-2147483649", second);
|
|
|
|
}
|
|
|
|
|
|
|
|
REQUIRE(first.type() == uint8_t(VALUE_IS_SIGNED_INTEGER));
|
2019-03-06 15:31:37 +01:00
|
|
|
REQUIRE(second.type() == uint8_t(VALUE_IS_FLOAT));
|
|
|
|
}
|
2019-04-20 15:12:29 +02:00
|
|
|
|
|
|
|
TEST_CASE("Invalid value") {
|
2020-09-04 09:23:40 +02:00
|
|
|
VariantData result;
|
|
|
|
result.init();
|
|
|
|
|
2020-07-26 12:23:55 +02:00
|
|
|
parseNumber("6a3", result);
|
2019-04-20 15:12:29 +02:00
|
|
|
|
|
|
|
REQUIRE(result.type() == uint8_t(VALUE_IS_NULL));
|
|
|
|
}
|