parseNumber.cpp 884 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2021
  3. // MIT License
  4. #include <ArduinoJson.hpp>
  5. #include <catch.hpp>
  6. using namespace ARDUINOJSON_NAMESPACE;
  7. TEST_CASE("Test unsigned integer overflow") {
  8. VariantData first, second;
  9. first.init();
  10. second.init();
  11. // Avoids MSVC warning C4127 (conditional expression is constant)
  12. size_t integerSize = sizeof(Integer);
  13. if (integerSize == 8) {
  14. parseNumber("18446744073709551615", first);
  15. parseNumber("18446744073709551616", second);
  16. } else {
  17. parseNumber("4294967295", first);
  18. parseNumber("4294967296", second);
  19. }
  20. REQUIRE(first.type() == uint8_t(VALUE_IS_POSITIVE_INTEGER));
  21. REQUIRE(second.type() == uint8_t(VALUE_IS_FLOAT));
  22. }
  23. TEST_CASE("Invalid value") {
  24. VariantData result;
  25. result.init();
  26. parseNumber("6a3", result);
  27. REQUIRE(result.type() == uint8_t(VALUE_IS_NULL));
  28. }