isnull.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2019
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonVariant::isNull()") {
  7. DynamicJsonDocument doc(4096);
  8. JsonVariant variant = doc.to<JsonVariant>();
  9. SECTION("return true when Undefined") {
  10. REQUIRE(variant.isNull() == true);
  11. }
  12. SECTION("return false when Integer") {
  13. variant.set(42);
  14. REQUIRE(variant.isNull() == false);
  15. }
  16. SECTION("return false when EmptyArray") {
  17. DynamicJsonDocument doc2(4096);
  18. JsonArray array = doc2.to<JsonArray>();
  19. variant.set(array);
  20. REQUIRE(variant.isNull() == false);
  21. }
  22. SECTION("return false when EmptyObject") {
  23. DynamicJsonDocument doc2(4096);
  24. JsonObject obj = doc2.to<JsonObject>();
  25. variant.set(obj);
  26. REQUIRE(variant.isNull() == false);
  27. }
  28. SECTION("return true after set(JsonArray())") {
  29. variant.set(JsonArray());
  30. REQUIRE(variant.isNull() == true);
  31. }
  32. SECTION("return true after set(JsonObject())") {
  33. variant.set(JsonObject());
  34. REQUIRE(variant.isNull() == true);
  35. }
  36. SECTION("return false after set('hello')") {
  37. variant.set("hello");
  38. REQUIRE(variant.isNull() == false);
  39. }
  40. SECTION("return true after set((char*)0)") {
  41. variant.set(static_cast<char*>(0));
  42. REQUIRE(variant.isNull() == true);
  43. }
  44. SECTION("return true after set((const char*)0)") {
  45. variant.set(static_cast<const char*>(0));
  46. REQUIRE(variant.isNull() == true);
  47. }
  48. SECTION("return true after set(serialized((char*)0))") {
  49. variant.set(serialized(static_cast<char*>(0)));
  50. REQUIRE(variant.isNull() == true);
  51. }
  52. SECTION("return true after set(serialized((const char*)0))") {
  53. variant.set(serialized(static_cast<const char*>(0)));
  54. REQUIRE(variant.isNull() == true);
  55. }
  56. SECTION("works with JsonVariantConst") {
  57. variant.set(42);
  58. JsonVariantConst cvar = variant;
  59. REQUIRE(cvar.isNull() == false);
  60. }
  61. }