equals.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2024, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonObjectConst::operator==()") {
  7. JsonDocument doc1;
  8. JsonObjectConst obj1 = doc1.to<JsonObject>();
  9. JsonDocument doc2;
  10. JsonObjectConst obj2 = doc2.to<JsonObject>();
  11. SECTION("should return false when objs differ") {
  12. doc1["hello"] = "coucou";
  13. doc2["world"] = 1;
  14. REQUIRE_FALSE(obj1 == obj2);
  15. }
  16. SECTION("should return false when LHS has more elements") {
  17. doc1["hello"] = "coucou";
  18. doc1["world"] = 666;
  19. doc2["hello"] = "coucou";
  20. REQUIRE_FALSE(obj1 == obj2);
  21. }
  22. SECTION("should return false when RKS has more elements") {
  23. doc1["hello"] = "coucou";
  24. doc2["hello"] = "coucou";
  25. doc2["world"] = 666;
  26. REQUIRE_FALSE(obj1 == obj2);
  27. }
  28. SECTION("should return true when objs equal") {
  29. doc1["hello"] = "world";
  30. doc1["anwser"] = 42;
  31. // insert in different order
  32. doc2["anwser"] = 42;
  33. doc2["hello"] = "world";
  34. REQUIRE(obj1 == obj2);
  35. }
  36. SECTION("should return false when RHS is null") {
  37. JsonObjectConst null;
  38. REQUIRE_FALSE(obj1 == null);
  39. }
  40. SECTION("should return false when LHS is null") {
  41. JsonObjectConst null;
  42. REQUIRE_FALSE(null == obj2);
  43. }
  44. SECTION("should return true when both are null") {
  45. JsonObjectConst null1, null2;
  46. REQUIRE(null1 == null2);
  47. }
  48. }