123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512 |
- // ArduinoJson - https://arduinojson.org
- // Copyright © 2014-2022, Benoit BLANCHON
- // MIT License
- #include <ArduinoJson.h>
- #include <catch.hpp>
- TEST_CASE("Compare JsonObject with JsonObject") {
- StaticJsonDocument<512> doc;
- SECTION("Compare with unbound") {
- JsonObject object = doc.to<JsonObject>();
- object["a"] = 1;
- object["b"] = "hello";
- JsonObject unbound;
- CHECK(object != unbound);
- CHECK_FALSE(object == unbound);
- CHECK_FALSE(object <= unbound);
- CHECK_FALSE(object >= unbound);
- CHECK_FALSE(object > unbound);
- CHECK_FALSE(object < unbound);
- CHECK(unbound != object);
- CHECK_FALSE(unbound == object);
- CHECK_FALSE(unbound <= object);
- CHECK_FALSE(unbound >= object);
- CHECK_FALSE(unbound > object);
- CHECK_FALSE(unbound < object);
- }
- SECTION("Compare with self") {
- JsonObject object = doc.to<JsonObject>();
- object["a"] = 1;
- object["b"] = "hello";
- CHECK(object == object);
- CHECK(object <= object);
- CHECK(object >= object);
- CHECK_FALSE(object != object);
- CHECK_FALSE(object > object);
- CHECK_FALSE(object < object);
- }
- SECTION("Compare with identical object") {
- JsonObject object1 = doc.createNestedObject();
- object1["a"] = 1;
- object1["b"] = "hello";
- object1["c"][0] = false;
- JsonObject object2 = doc.createNestedObject();
- object2["a"] = 1;
- object2["b"] = "hello";
- object2["c"][0] = false;
- CHECK(object1 == object2);
- CHECK(object1 <= object2);
- CHECK(object1 >= object2);
- CHECK_FALSE(object1 != object2);
- CHECK_FALSE(object1 > object2);
- CHECK_FALSE(object1 < object2);
- }
- SECTION("Compare with different object") {
- JsonObject object1 = doc.createNestedObject();
- object1["a"] = 1;
- object1["b"] = "hello1";
- object1["c"][0] = false;
- JsonObject object2 = doc.createNestedObject();
- object2["a"] = 1;
- object2["b"] = "hello2";
- object2["c"][0] = false;
- CHECK(object1 != object2);
- CHECK_FALSE(object1 == object2);
- CHECK_FALSE(object1 > object2);
- CHECK_FALSE(object1 < object2);
- CHECK_FALSE(object1 <= object2);
- CHECK_FALSE(object1 >= object2);
- }
- }
- TEST_CASE("Compare JsonObject with JsonVariant") {
- StaticJsonDocument<512> doc;
- SECTION("Compare with self") {
- JsonObject object = doc.to<JsonObject>();
- object["a"] = 1;
- object["b"] = "hello";
- JsonVariant variant = object;
- CHECK(object == variant);
- CHECK(object <= variant);
- CHECK(object >= variant);
- CHECK_FALSE(object != variant);
- CHECK_FALSE(object > variant);
- CHECK_FALSE(object < variant);
- CHECK(variant == object);
- CHECK(variant <= object);
- CHECK(variant >= object);
- CHECK_FALSE(variant != object);
- CHECK_FALSE(variant > object);
- CHECK_FALSE(variant < object);
- }
- SECTION("Compare with identical object") {
- JsonObject object = doc.createNestedObject();
- object["a"] = 1;
- object["b"] = "hello";
- object["c"][0] = false;
- JsonVariant variant = doc.createNestedObject();
- variant["a"] = 1;
- variant["b"] = "hello";
- variant["c"][0] = false;
- CHECK(object == variant);
- CHECK(object <= variant);
- CHECK(object >= variant);
- CHECK_FALSE(object != variant);
- CHECK_FALSE(object > variant);
- CHECK_FALSE(object < variant);
- CHECK(variant == object);
- CHECK(variant <= object);
- CHECK(variant >= object);
- CHECK_FALSE(variant != object);
- CHECK_FALSE(variant > object);
- CHECK_FALSE(variant < object);
- }
- SECTION("Compare with different object") {
- JsonObject object = doc.createNestedObject();
- object["a"] = 1;
- object["b"] = "hello1";
- object["c"][0] = false;
- JsonVariant variant = doc.createNestedObject();
- variant["a"] = 1;
- variant["b"] = "hello2";
- variant["c"][0] = false;
- CHECK(object != variant);
- CHECK_FALSE(object == variant);
- CHECK_FALSE(object > variant);
- CHECK_FALSE(object < variant);
- CHECK_FALSE(object <= variant);
- CHECK_FALSE(object >= variant);
- }
- }
- TEST_CASE("Compare JsonObject with JsonVariantConst") {
- StaticJsonDocument<512> doc;
- SECTION("Compare with unbound") {
- JsonObject object = doc.to<JsonObject>();
- object["a"] = 1;
- object["b"] = "hello";
- JsonVariantConst unbound;
- CHECK(object != unbound);
- CHECK_FALSE(object == unbound);
- CHECK_FALSE(object <= unbound);
- CHECK_FALSE(object >= unbound);
- CHECK_FALSE(object > unbound);
- CHECK_FALSE(object < unbound);
- CHECK(unbound != object);
- CHECK_FALSE(unbound == object);
- CHECK_FALSE(unbound <= object);
- CHECK_FALSE(unbound >= object);
- CHECK_FALSE(unbound > object);
- CHECK_FALSE(unbound < object);
- }
- SECTION("Compare with self") {
- JsonObject object = doc.to<JsonObject>();
- object["a"] = 1;
- object["b"] = "hello";
- JsonVariantConst variant = object;
- CHECK(object == variant);
- CHECK(object <= variant);
- CHECK(object >= variant);
- CHECK_FALSE(object != variant);
- CHECK_FALSE(object > variant);
- CHECK_FALSE(object < variant);
- CHECK(variant == object);
- CHECK(variant <= object);
- CHECK(variant >= object);
- CHECK_FALSE(variant != object);
- CHECK_FALSE(variant > object);
- CHECK_FALSE(variant < object);
- }
- SECTION("Compare with identical object") {
- JsonObject object = doc.createNestedObject();
- object["a"] = 1;
- object["b"] = "hello";
- object["c"][0] = false;
- JsonObject object2 = doc.createNestedObject();
- object2["a"] = 1;
- object2["b"] = "hello";
- object2["c"][0] = false;
- JsonVariantConst variant = object2;
- CHECK(object == variant);
- CHECK(object <= variant);
- CHECK(object >= variant);
- CHECK_FALSE(object != variant);
- CHECK_FALSE(object > variant);
- CHECK_FALSE(object < variant);
- CHECK(variant == object);
- CHECK(variant <= object);
- CHECK(variant >= object);
- CHECK_FALSE(variant != object);
- CHECK_FALSE(variant > object);
- CHECK_FALSE(variant < object);
- }
- SECTION("Compare with different object") {
- JsonObject object = doc.createNestedObject();
- object["a"] = 1;
- object["b"] = "hello1";
- object["c"][0] = false;
- JsonObject object2 = doc.createNestedObject();
- object2["a"] = 1;
- object2["b"] = "hello2";
- object2["c"][0] = false;
- JsonVariantConst variant = object2;
- CHECK(object != variant);
- CHECK_FALSE(object == variant);
- CHECK_FALSE(object > variant);
- CHECK_FALSE(object < variant);
- CHECK_FALSE(object <= variant);
- CHECK_FALSE(object >= variant);
- }
- }
- TEST_CASE("Compare JsonObject with JsonObjectConst") {
- StaticJsonDocument<512> doc;
- SECTION("Compare with unbound") {
- JsonObject object = doc.to<JsonObject>();
- object["a"] = 1;
- object["b"] = "hello";
- JsonObjectConst unbound;
- CHECK(object != unbound);
- CHECK_FALSE(object == unbound);
- CHECK_FALSE(object <= unbound);
- CHECK_FALSE(object >= unbound);
- CHECK_FALSE(object > unbound);
- CHECK_FALSE(object < unbound);
- CHECK(unbound != object);
- CHECK_FALSE(unbound == object);
- CHECK_FALSE(unbound <= object);
- CHECK_FALSE(unbound >= object);
- CHECK_FALSE(unbound > object);
- CHECK_FALSE(unbound < object);
- }
- SECTION("Compare with self") {
- JsonObject object = doc.to<JsonObject>();
- object["a"] = 1;
- object["b"] = "hello";
- JsonObjectConst cobject = object;
- CHECK(object == cobject);
- CHECK(object <= cobject);
- CHECK(object >= cobject);
- CHECK_FALSE(object != cobject);
- CHECK_FALSE(object > cobject);
- CHECK_FALSE(object < cobject);
- CHECK(cobject == object);
- CHECK(cobject <= object);
- CHECK(cobject >= object);
- CHECK_FALSE(cobject != object);
- CHECK_FALSE(cobject > object);
- CHECK_FALSE(cobject < object);
- }
- SECTION("Compare with identical object") {
- JsonObject object1 = doc.createNestedObject();
- object1["a"] = 1;
- object1["b"] = "hello";
- object1["c"][0] = false;
- JsonObject object2 = doc.createNestedObject();
- object2["a"] = 1;
- object2["b"] = "hello";
- object2["c"][0] = false;
- JsonObjectConst carray2 = object2;
- CHECK(object1 == carray2);
- CHECK(object1 <= carray2);
- CHECK(object1 >= carray2);
- CHECK_FALSE(object1 != carray2);
- CHECK_FALSE(object1 > carray2);
- CHECK_FALSE(object1 < carray2);
- CHECK(carray2 == object1);
- CHECK(carray2 <= object1);
- CHECK(carray2 >= object1);
- CHECK_FALSE(carray2 != object1);
- CHECK_FALSE(carray2 > object1);
- CHECK_FALSE(carray2 < object1);
- }
- SECTION("Compare with different object") {
- JsonObject object1 = doc.createNestedObject();
- object1["a"] = 1;
- object1["b"] = "hello1";
- object1["c"][0] = false;
- JsonObject object2 = doc.createNestedObject();
- object2["a"] = 1;
- object2["b"] = "hello2";
- object2["c"][0] = false;
- JsonObjectConst carray2 = object2;
- CHECK(object1 != carray2);
- CHECK_FALSE(object1 == carray2);
- CHECK_FALSE(object1 > carray2);
- CHECK_FALSE(object1 < carray2);
- CHECK_FALSE(object1 <= carray2);
- CHECK_FALSE(object1 >= carray2);
- CHECK(carray2 != object1);
- CHECK_FALSE(carray2 == object1);
- CHECK_FALSE(carray2 > object1);
- CHECK_FALSE(carray2 < object1);
- CHECK_FALSE(carray2 <= object1);
- CHECK_FALSE(carray2 >= object1);
- }
- }
- TEST_CASE("Compare JsonObjectConst with JsonObjectConst") {
- StaticJsonDocument<512> doc;
- SECTION("Compare with unbound") {
- JsonObject object = doc.to<JsonObject>();
- object["a"] = 1;
- object["b"] = "hello";
- JsonObjectConst cobject = object;
- JsonObjectConst unbound;
- CHECK(cobject != unbound);
- CHECK_FALSE(cobject == unbound);
- CHECK_FALSE(cobject <= unbound);
- CHECK_FALSE(cobject >= unbound);
- CHECK_FALSE(cobject > unbound);
- CHECK_FALSE(cobject < unbound);
- CHECK(unbound != cobject);
- CHECK_FALSE(unbound == cobject);
- CHECK_FALSE(unbound <= cobject);
- CHECK_FALSE(unbound >= cobject);
- CHECK_FALSE(unbound > cobject);
- CHECK_FALSE(unbound < cobject);
- }
- SECTION("Compare with self") {
- JsonObject object = doc.to<JsonObject>();
- object["a"] = 1;
- object["b"] = "hello";
- JsonObjectConst cobject = object;
- CHECK(cobject == cobject);
- CHECK(cobject <= cobject);
- CHECK(cobject >= cobject);
- CHECK_FALSE(cobject != cobject);
- CHECK_FALSE(cobject > cobject);
- CHECK_FALSE(cobject < cobject);
- }
- SECTION("Compare with identical object") {
- JsonObject object1 = doc.createNestedObject();
- object1["a"] = 1;
- object1["b"] = "hello";
- object1["c"][0] = false;
- JsonObjectConst carray1 = object1;
- JsonObject object2 = doc.createNestedObject();
- object2["a"] = 1;
- object2["b"] = "hello";
- object2["c"][0] = false;
- JsonObjectConst carray2 = object2;
- CHECK(carray1 == carray2);
- CHECK(carray1 <= carray2);
- CHECK(carray1 >= carray2);
- CHECK_FALSE(carray1 != carray2);
- CHECK_FALSE(carray1 > carray2);
- CHECK_FALSE(carray1 < carray2);
- }
- SECTION("Compare with different object") {
- JsonObject object1 = doc.createNestedObject();
- object1["a"] = 1;
- object1["b"] = "hello1";
- object1["c"][0] = false;
- JsonObjectConst carray1 = object1;
- JsonObject object2 = doc.createNestedObject();
- object2["a"] = 1;
- object2["b"] = "hello2";
- object2["c"][0] = false;
- JsonObjectConst carray2 = object2;
- CHECK(carray1 != carray2);
- CHECK_FALSE(carray1 == carray2);
- CHECK_FALSE(carray1 > carray2);
- CHECK_FALSE(carray1 < carray2);
- CHECK_FALSE(carray1 <= carray2);
- CHECK_FALSE(carray1 >= carray2);
- }
- }
- TEST_CASE("Compare JsonObjectConst with JsonVariant") {
- StaticJsonDocument<512> doc;
- SECTION("Compare with self") {
- JsonObject object = doc.to<JsonObject>();
- object["a"] = 1;
- object["b"] = "hello";
- JsonObjectConst cobject = object;
- JsonVariant variant = object;
- CHECK(cobject == variant);
- CHECK(cobject <= variant);
- CHECK(cobject >= variant);
- CHECK_FALSE(cobject != variant);
- CHECK_FALSE(cobject > variant);
- CHECK_FALSE(cobject < variant);
- CHECK(variant == cobject);
- CHECK(variant <= cobject);
- CHECK(variant >= cobject);
- CHECK_FALSE(variant != cobject);
- CHECK_FALSE(variant > cobject);
- CHECK_FALSE(variant < cobject);
- }
- SECTION("Compare with identical object") {
- JsonObject object1 = doc.createNestedObject();
- object1["a"] = 1;
- object1["b"] = "hello";
- object1["c"][0] = false;
- JsonObjectConst carray1 = object1;
- JsonObject object2 = doc.createNestedObject();
- object2["a"] = 1;
- object2["b"] = "hello";
- object2["c"][0] = false;
- JsonVariant variant2 = object2;
- CHECK(carray1 == variant2);
- CHECK(carray1 <= variant2);
- CHECK(carray1 >= variant2);
- CHECK_FALSE(carray1 != variant2);
- CHECK_FALSE(carray1 > variant2);
- CHECK_FALSE(carray1 < variant2);
- CHECK(variant2 == carray1);
- CHECK(variant2 <= carray1);
- CHECK(variant2 >= carray1);
- CHECK_FALSE(variant2 != carray1);
- CHECK_FALSE(variant2 > carray1);
- CHECK_FALSE(variant2 < carray1);
- }
- SECTION("Compare with different object") {
- JsonObject object1 = doc.createNestedObject();
- object1["a"] = 1;
- object1["b"] = "hello1";
- object1["c"][0] = false;
- JsonObjectConst carray1 = object1;
- JsonObject object2 = doc.createNestedObject();
- object2["a"] = 1;
- object2["b"] = "hello2";
- object2["c"][0] = false;
- JsonVariant variant2 = object2;
- CHECK(carray1 != variant2);
- CHECK_FALSE(carray1 == variant2);
- CHECK_FALSE(carray1 > variant2);
- CHECK_FALSE(carray1 < variant2);
- CHECK_FALSE(carray1 <= variant2);
- CHECK_FALSE(carray1 >= variant2);
- CHECK(variant2 != carray1);
- CHECK_FALSE(variant2 == carray1);
- CHECK_FALSE(variant2 > carray1);
- CHECK_FALSE(variant2 < carray1);
- CHECK_FALSE(variant2 <= carray1);
- CHECK_FALSE(variant2 >= carray1);
- }
- }
|