compare.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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("DynamicJsonDocument::operator==(const DynamicJsonDocument&)") {
  7. DynamicJsonDocument doc1(4096);
  8. DynamicJsonDocument doc2(4096);
  9. SECTION("Empty") {
  10. REQUIRE(doc1 == doc2);
  11. REQUIRE_FALSE(doc1 != doc2);
  12. }
  13. SECTION("With same object") {
  14. doc1["hello"] = "world";
  15. doc2["hello"] = "world";
  16. REQUIRE(doc1 == doc2);
  17. REQUIRE_FALSE(doc1 != doc2);
  18. }
  19. SECTION("With different object") {
  20. doc1["hello"] = "world";
  21. doc2["world"] = "hello";
  22. REQUIRE_FALSE(doc1 == doc2);
  23. REQUIRE(doc1 != doc2);
  24. }
  25. }
  26. TEST_CASE("DynamicJsonDocument::operator==(const StaticJsonDocument&)") {
  27. DynamicJsonDocument doc1(4096);
  28. StaticJsonDocument<256> doc2;
  29. SECTION("Empty") {
  30. REQUIRE(doc1 == doc2);
  31. REQUIRE_FALSE(doc1 != doc2);
  32. }
  33. SECTION("With same object") {
  34. doc1["hello"] = "world";
  35. doc2["hello"] = "world";
  36. REQUIRE(doc1 == doc2);
  37. REQUIRE_FALSE(doc1 != doc2);
  38. }
  39. SECTION("With different object") {
  40. doc1["hello"] = "world";
  41. doc2["world"] = "hello";
  42. REQUIRE_FALSE(doc1 == doc2);
  43. REQUIRE(doc1 != doc2);
  44. }
  45. }
  46. TEST_CASE("StaticJsonDocument::operator==(const DynamicJsonDocument&)") {
  47. StaticJsonDocument<256> doc1;
  48. DynamicJsonDocument doc2(4096);
  49. SECTION("Empty") {
  50. REQUIRE(doc1 == doc2);
  51. REQUIRE_FALSE(doc1 != doc2);
  52. }
  53. SECTION("With same object") {
  54. doc1["hello"] = "world";
  55. doc2["hello"] = "world";
  56. REQUIRE(doc1 == doc2);
  57. REQUIRE_FALSE(doc1 != doc2);
  58. }
  59. SECTION("With different object") {
  60. doc1["hello"] = "world";
  61. doc2["world"] = "hello";
  62. REQUIRE_FALSE(doc1 == doc2);
  63. REQUIRE(doc1 != doc2);
  64. }
  65. }
  66. TEST_CASE("JsonDocument::operator==(const JsonDocument&)") {
  67. StaticJsonDocument<256> doc1;
  68. StaticJsonDocument<256> doc2;
  69. const JsonDocument& ref1 = doc1;
  70. const JsonDocument& ref2 = doc2;
  71. SECTION("Empty") {
  72. REQUIRE(ref1 == ref2);
  73. REQUIRE_FALSE(ref1 != ref2);
  74. }
  75. SECTION("With same object") {
  76. doc1["hello"] = "world";
  77. doc2["hello"] = "world";
  78. REQUIRE(ref1 == ref2);
  79. REQUIRE_FALSE(ref1 != ref2);
  80. }
  81. SECTION("With different object") {
  82. doc1["hello"] = "world";
  83. doc2["world"] = "hello";
  84. REQUIRE_FALSE(ref1 == ref2);
  85. REQUIRE(ref1 != ref2);
  86. }
  87. }