compare.cpp 1.7 KB

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