2021-03-29 17:14:01 +02:00
|
|
|
// ArduinoJson - https://arduinojson.org
|
2023-02-16 11:45:01 +01:00
|
|
|
// Copyright © 2014-2023, Benoit BLANCHON
|
2020-09-05 10:54:46 +02:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
TEST_CASE("JsonDocument::overflowed()") {
|
|
|
|
SECTION("returns false on a fresh object") {
|
2023-03-15 14:54:55 +01:00
|
|
|
DynamicJsonDocument doc(0);
|
2020-09-05 10:54:46 +02:00
|
|
|
CHECK(doc.overflowed() == false);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("returns true after a failed insertion") {
|
2023-03-15 14:54:55 +01:00
|
|
|
DynamicJsonDocument doc(0);
|
2020-09-05 10:54:46 +02:00
|
|
|
doc.add(0);
|
|
|
|
CHECK(doc.overflowed() == true);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("returns false after successful insertion") {
|
2023-03-15 14:54:55 +01:00
|
|
|
DynamicJsonDocument doc(JSON_ARRAY_SIZE(1));
|
2020-09-05 10:54:46 +02:00
|
|
|
doc.add(0);
|
|
|
|
CHECK(doc.overflowed() == false);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("returns true after a failed string copy") {
|
2023-03-15 14:54:55 +01:00
|
|
|
DynamicJsonDocument doc(JSON_ARRAY_SIZE(1));
|
2020-09-05 10:54:46 +02:00
|
|
|
doc.add(std::string("example"));
|
|
|
|
CHECK(doc.overflowed() == true);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("returns false after a successful string copy") {
|
2023-03-15 14:54:55 +01:00
|
|
|
DynamicJsonDocument doc(JSON_ARRAY_SIZE(1) + 8);
|
2020-09-05 10:54:46 +02:00
|
|
|
doc.add(std::string("example"));
|
|
|
|
CHECK(doc.overflowed() == false);
|
|
|
|
}
|
|
|
|
|
2022-01-13 11:52:29 +01:00
|
|
|
SECTION("returns true after a failed member add") {
|
2023-03-15 14:54:55 +01:00
|
|
|
DynamicJsonDocument doc(1);
|
2022-01-13 11:52:29 +01:00
|
|
|
doc["example"] = true;
|
|
|
|
CHECK(doc.overflowed() == true);
|
|
|
|
}
|
|
|
|
|
2020-09-05 10:54:46 +02:00
|
|
|
SECTION("returns true after a failed deserialization") {
|
2023-03-15 14:54:55 +01:00
|
|
|
DynamicJsonDocument doc(JSON_ARRAY_SIZE(1));
|
2020-09-05 10:54:46 +02:00
|
|
|
deserializeJson(doc, "[\"example\"]");
|
|
|
|
CHECK(doc.overflowed() == true);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("returns false after a successful deserialization") {
|
2023-03-15 14:54:55 +01:00
|
|
|
DynamicJsonDocument doc(JSON_ARRAY_SIZE(1) + 8);
|
2020-09-05 10:54:46 +02:00
|
|
|
deserializeJson(doc, "[\"example\"]");
|
|
|
|
CHECK(doc.overflowed() == false);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("returns false after clear()") {
|
2023-03-15 14:54:55 +01:00
|
|
|
DynamicJsonDocument doc(0);
|
2020-09-05 10:54:46 +02:00
|
|
|
doc.add(0);
|
|
|
|
doc.clear();
|
|
|
|
CHECK(doc.overflowed() == false);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("remains false after shrinkToFit()") {
|
|
|
|
DynamicJsonDocument doc(JSON_ARRAY_SIZE(1));
|
|
|
|
doc.add(0);
|
|
|
|
doc.shrinkToFit();
|
|
|
|
CHECK(doc.overflowed() == false);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("remains true after shrinkToFit()") {
|
|
|
|
DynamicJsonDocument doc(JSON_ARRAY_SIZE(1));
|
|
|
|
doc.add(0);
|
|
|
|
doc.add(0);
|
|
|
|
doc.shrinkToFit();
|
|
|
|
CHECK(doc.overflowed() == true);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("return false after garbageCollect()") {
|
|
|
|
DynamicJsonDocument doc(JSON_ARRAY_SIZE(1));
|
|
|
|
doc.add(0);
|
|
|
|
doc.add(0);
|
|
|
|
doc.garbageCollect();
|
|
|
|
CHECK(doc.overflowed() == false);
|
|
|
|
}
|
|
|
|
}
|