nullptr.cpp 988 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <ArduinoJson.h>
  2. #include <catch.hpp>
  3. #if !ARDUINOJSON_HAS_NULLPTR
  4. # error ARDUINOJSON_HAS_NULLPTR must be set to 1
  5. #endif
  6. TEST_CASE("nullptr") {
  7. DynamicJsonDocument doc(4096);
  8. JsonVariant variant = doc.to<JsonVariant>();
  9. SECTION("JsonVariant == nullptr") {
  10. REQUIRE((variant == nullptr));
  11. REQUIRE_FALSE((variant != nullptr));
  12. }
  13. SECTION("JsonVariant != nullptr") {
  14. variant.set(42);
  15. REQUIRE_FALSE((variant == nullptr));
  16. REQUIRE((variant != nullptr));
  17. }
  18. SECTION("JsonVariant.set(nullptr)") {
  19. variant.set(42);
  20. variant.set(nullptr);
  21. REQUIRE(variant.isNull());
  22. }
  23. SECTION("JsonVariant.set(nullptr) with unbound reference") {
  24. JsonVariant unboundReference;
  25. unboundReference.set(nullptr);
  26. REQUIRE(variant.isNull());
  27. }
  28. SECTION("JsonVariant.is<nullptr_t>()") {
  29. variant.set(42);
  30. REQUIRE(variant.is<std::nullptr_t>() == false);
  31. variant.clear();
  32. REQUIRE(variant.is<std::nullptr_t>() == true);
  33. }
  34. }