equals.cpp 1.5 KB

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