PullupDev/lib/ArduinoJson/extras/tests/JsonDocument/overflowed.cpp
tk 54adf4ad3f 【类 型】:chore
【主	题】:不从配置文件远端获取 ArduinoJson库 添加到根目录调用
【描	述】:
	[原因]:防止版本不同 造成bug
	[过程]:
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2024-07-03 13:46:41 +08:00

86 lines
2.2 KiB
C++

// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonDocument::overflowed()") {
SECTION("returns false on a fresh object") {
StaticJsonDocument<0> doc;
CHECK(doc.overflowed() == false);
}
SECTION("returns true after a failed insertion") {
StaticJsonDocument<0> doc;
doc.add(0);
CHECK(doc.overflowed() == true);
}
SECTION("returns false after successful insertion") {
StaticJsonDocument<JSON_ARRAY_SIZE(1)> doc;
doc.add(0);
CHECK(doc.overflowed() == false);
}
SECTION("returns true after a failed string copy") {
StaticJsonDocument<JSON_ARRAY_SIZE(1)> doc;
doc.add(std::string("example"));
CHECK(doc.overflowed() == true);
}
SECTION("returns false after a successful string copy") {
StaticJsonDocument<JSON_ARRAY_SIZE(1) + 8> doc;
doc.add(std::string("example"));
CHECK(doc.overflowed() == false);
}
SECTION("returns true after a failed member add") {
StaticJsonDocument<1> doc;
doc["example"] = true;
CHECK(doc.overflowed() == true);
}
SECTION("returns true after a failed deserialization") {
StaticJsonDocument<JSON_ARRAY_SIZE(1)> doc;
deserializeJson(doc, "[\"example\"]");
CHECK(doc.overflowed() == true);
}
SECTION("returns false after a successful deserialization") {
StaticJsonDocument<JSON_ARRAY_SIZE(1) + 8> doc;
deserializeJson(doc, "[\"example\"]");
CHECK(doc.overflowed() == false);
}
SECTION("returns false after clear()") {
StaticJsonDocument<0> doc;
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);
}
}