enable_infinity_1.cpp 889 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. DeserializationError err =
  19. deserializeJson(doc, "[Infinity,-Infinity,+Infinity]");
  20. float a = doc[0];
  21. float b = doc[1];
  22. float c = doc[2];
  23. REQUIRE(err == DeserializationError::Ok);
  24. REQUIRE(my::isinf(a));
  25. REQUIRE(a > 0);
  26. REQUIRE(my::isinf(b));
  27. REQUIRE(b < 0);
  28. REQUIRE(my::isinf(c));
  29. REQUIRE(c > 0);
  30. }
  31. }