equals.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2019
  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. }