equals.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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("JsonArray::operator==()") {
  7. DynamicJsonDocument doc1(4096);
  8. JsonArray array1 = doc1.to<JsonArray>();
  9. JsonArrayConst array1c = array1;
  10. DynamicJsonDocument doc2(4096);
  11. JsonArray array2 = doc2.to<JsonArray>();
  12. JsonArrayConst array2c = array2;
  13. SECTION("should return false when arrays differ") {
  14. array1.add("coucou");
  15. array2.add(1);
  16. REQUIRE_FALSE(array1 == array2);
  17. REQUIRE_FALSE(array1c == array2c);
  18. }
  19. SECTION("should return false when LHS has more elements") {
  20. array1.add(1);
  21. array1.add(2);
  22. array2.add(1);
  23. REQUIRE_FALSE(array1 == array2);
  24. REQUIRE_FALSE(array1c == array2c);
  25. }
  26. SECTION("should return false when RHS has more elements") {
  27. array1.add(1);
  28. array2.add(1);
  29. array2.add(2);
  30. REQUIRE_FALSE(array1 == array2);
  31. REQUIRE_FALSE(array1c == array2c);
  32. }
  33. SECTION("should return true when arrays equal") {
  34. array1.add("coucou");
  35. array2.add("coucou");
  36. REQUIRE(array1 == array2);
  37. REQUIRE(array1c == array2c);
  38. }
  39. SECTION("should return false when RHS is null") {
  40. JsonArray null;
  41. REQUIRE_FALSE(array1 == null);
  42. }
  43. SECTION("should return false when LHS is null") {
  44. JsonArray null;
  45. REQUIRE_FALSE(null == array1);
  46. }
  47. SECTION("should return true when both are null") {
  48. JsonArray null1;
  49. JsonArray null2;
  50. REQUIRE(null1 == null2);
  51. }
  52. }