enable_infinity_1.cpp 865 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #define ARDUINOJSON_ENABLE_INFINITY 1
  2. #include <ArduinoJson.h>
  3. #include <catch.hpp>
  4. #include <limits>
  5. namespace my {
  6. using ARDUINOJSON_NAMESPACE::isinf;
  7. } // namespace my
  8. TEST_CASE("ARDUINOJSON_ENABLE_INFINITY == 1") {
  9. DynamicJsonDocument doc(4096);
  10. SECTION("serializeJson()") {
  11. doc.add(std::numeric_limits<double>::infinity());
  12. doc.add(-std::numeric_limits<double>::infinity());
  13. std::string json;
  14. serializeJson(doc, json);
  15. REQUIRE(json == "[Infinity,-Infinity]");
  16. }
  17. SECTION("deserializeJson()") {
  18. auto err = deserializeJson(doc, "[Infinity,-Infinity,+Infinity]");
  19. float a = doc[0];
  20. float b = doc[1];
  21. float c = doc[2];
  22. REQUIRE(err == DeserializationError::Ok);
  23. REQUIRE(my::isinf(a));
  24. REQUIRE(a > 0);
  25. REQUIRE(my::isinf(b));
  26. REQUIRE(b < 0);
  27. REQUIRE(my::isinf(c));
  28. REQUIRE(c > 0);
  29. }
  30. }