enable_infinity_0.cpp 936 B

1234567891011121314151617181920212223242526272829303132333435
  1. #define ARDUINOJSON_ENABLE_INFINITY 0
  2. #include <ArduinoJson.h>
  3. #include <catch.hpp>
  4. #include <limits>
  5. static void assertParseFails(const char* json) {
  6. DynamicJsonDocument doc(4096);
  7. auto err = deserializeJson(doc, json);
  8. REQUIRE(err == DeserializationError::InvalidInput);
  9. }
  10. static void assertJsonEquals(const JsonDocument& doc,
  11. std::string expectedJson) {
  12. std::string actualJson;
  13. serializeJson(doc, actualJson);
  14. REQUIRE(actualJson == expectedJson);
  15. }
  16. TEST_CASE("ARDUINOJSON_ENABLE_INFINITY == 0") {
  17. SECTION("serializeJson()") {
  18. DynamicJsonDocument doc(4096);
  19. doc.add(std::numeric_limits<double>::infinity());
  20. doc.add(-std::numeric_limits<double>::infinity());
  21. assertJsonEquals(doc, "[null,null]");
  22. }
  23. SECTION("deserializeJson()") {
  24. assertParseFails("{\"X\":Infinity}");
  25. assertParseFails("{\"X\":-Infinity}");
  26. assertParseFails("{\"X\":+Infinity}");
  27. }
  28. }