Merge DynamicJsonDocument with JsonDocument

This commit is contained in:
Benoit Blanchon
2023-03-20 10:49:01 +01:00
parent db9258bcd7
commit 540901e219
164 changed files with 550 additions and 666 deletions

View File

@ -6,7 +6,7 @@
#include <catch.hpp>
TEST_CASE("deserialize JSON array") {
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
SECTION("An empty array") {
DeserializationError err = deserializeJson(doc, "[]");
@ -254,7 +254,7 @@ TEST_CASE("deserialize JSON array") {
TEST_CASE("deserialize JSON array under memory constraints") {
SECTION("buffer of the right size for an empty array") {
DynamicJsonDocument doc(JSON_ARRAY_SIZE(0));
JsonDocument doc(JSON_ARRAY_SIZE(0));
char input[] = "[]";
DeserializationError err = deserializeJson(doc, input);
@ -263,7 +263,7 @@ TEST_CASE("deserialize JSON array under memory constraints") {
}
SECTION("buffer too small for an array with one element") {
DynamicJsonDocument doc(JSON_ARRAY_SIZE(0));
JsonDocument doc(JSON_ARRAY_SIZE(0));
char input[] = "[1]";
DeserializationError err = deserializeJson(doc, input);
@ -272,7 +272,7 @@ TEST_CASE("deserialize JSON array under memory constraints") {
}
SECTION("buffer of the right size for an array with one element") {
DynamicJsonDocument doc(JSON_ARRAY_SIZE(1));
JsonDocument doc(JSON_ARRAY_SIZE(1));
char input[] = "[1]";
DeserializationError err = deserializeJson(doc, input);
@ -281,7 +281,7 @@ TEST_CASE("deserialize JSON array under memory constraints") {
}
SECTION("buffer too small for an array with a nested object") {
DynamicJsonDocument doc(JSON_ARRAY_SIZE(0) + JSON_OBJECT_SIZE(0));
JsonDocument doc(JSON_ARRAY_SIZE(0) + JSON_OBJECT_SIZE(0));
char input[] = "[{}]";
DeserializationError err = deserializeJson(doc, input);
@ -290,7 +290,7 @@ TEST_CASE("deserialize JSON array under memory constraints") {
}
SECTION("buffer of the right size for an array with a nested object") {
DynamicJsonDocument doc(JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0));
JsonDocument doc(JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0));
char input[] = "[{}]";
DeserializationError err = deserializeJson(doc, input);
@ -299,7 +299,7 @@ TEST_CASE("deserialize JSON array under memory constraints") {
}
SECTION("don't store space characters") {
DynamicJsonDocument doc(100);
JsonDocument doc(100);
deserializeJson(doc, " [ \"1234567\" ] ");
@ -309,7 +309,7 @@ TEST_CASE("deserialize JSON array under memory constraints") {
}
SECTION("Should clear the JsonArray") {
DynamicJsonDocument doc(JSON_ARRAY_SIZE(4));
JsonDocument doc(JSON_ARRAY_SIZE(4));
char input[] = "[1,2,3,4]";
deserializeJson(doc, input);
@ -321,7 +321,7 @@ TEST_CASE("deserialize JSON array under memory constraints") {
}
SECTION("buffer of the right size for an array with two element") {
DynamicJsonDocument doc(JSON_ARRAY_SIZE(2));
JsonDocument doc(JSON_ARRAY_SIZE(2));
char input[] = "[1,2]";
DeserializationError err = deserializeJson(doc, input);

View File

@ -685,8 +685,8 @@ TEST_CASE("Filtering") {
for (size_t i = 0; i < sizeof(testCases) / sizeof(testCases[0]); i++) {
CAPTURE(i);
DynamicJsonDocument filter(256);
DynamicJsonDocument doc(256);
JsonDocument filter(256);
JsonDocument doc(256);
TestCase& tc = testCases[i];
CAPTURE(tc.filter);
@ -706,10 +706,10 @@ TEST_CASE("Filtering") {
TEST_CASE("Zero-copy mode") { // issue #1697
char input[] = "{\"include\":42,\"exclude\":666}";
DynamicJsonDocument filter(256);
JsonDocument filter(256);
filter["include"] = true;
DynamicJsonDocument doc(256);
JsonDocument doc(256);
DeserializationError err =
deserializeJson(doc, input, DeserializationOption::Filter(filter));
@ -718,8 +718,8 @@ TEST_CASE("Zero-copy mode") { // issue #1697
}
TEST_CASE("Overloads") {
DynamicJsonDocument doc(256);
DynamicJsonDocument filter(256);
JsonDocument doc(256);
JsonDocument filter(256);
using namespace DeserializationOption;

View File

@ -18,7 +18,7 @@ TEST_CASE("Truncated JSON input") {
"{", "{a", "{a:", "{a:1", "{a:1,", "{a:1,"};
const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
for (size_t i = 0; i < testCount; i++) {
const char* input = testCases[i];

View File

@ -10,7 +10,7 @@
#include "CustomReader.hpp"
TEST_CASE("deserializeJson(char*)") {
DynamicJsonDocument doc(1024);
JsonDocument doc(1024);
SECTION("should not duplicate strings") {
char input[] = "{\"hello\":\"world\"}";
@ -25,7 +25,7 @@ TEST_CASE("deserializeJson(char*)") {
}
TEST_CASE("deserializeJson(const std::string&)") {
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
SECTION("should accept const string") {
const std::string input("[42]");
@ -54,7 +54,7 @@ TEST_CASE("deserializeJson(const std::string&)") {
}
TEST_CASE("deserializeJson(std::istream&)") {
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
SECTION("array") {
std::istringstream json(" [ 42 ] ");
@ -125,7 +125,7 @@ TEST_CASE("deserializeJson(VLA)") {
char vla[i];
strcpy(vla, "{\"a\":42}");
DynamicJsonDocument doc(JSON_OBJECT_SIZE(1));
JsonDocument doc(JSON_OBJECT_SIZE(1));
DeserializationError err = deserializeJson(doc, vla);
REQUIRE(err == DeserializationError::Ok);
@ -133,7 +133,7 @@ TEST_CASE("deserializeJson(VLA)") {
#endif
TEST_CASE("deserializeJson(CustomReader)") {
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
CustomReader reader("[4,2]");
DeserializationError err = deserializeJson(doc, reader);
@ -144,10 +144,10 @@ TEST_CASE("deserializeJson(CustomReader)") {
}
TEST_CASE("deserializeJson(JsonDocument&, MemberProxy)") {
DynamicJsonDocument doc1(4096);
JsonDocument doc1(4096);
doc1["payload"] = "[4,2]";
DynamicJsonDocument doc2(4096);
JsonDocument doc2(4096);
DeserializationError err = deserializeJson(doc2, doc1["payload"]);
REQUIRE(err == DeserializationError::Ok);
@ -157,10 +157,10 @@ TEST_CASE("deserializeJson(JsonDocument&, MemberProxy)") {
}
TEST_CASE("deserializeJson(JsonDocument&, JsonVariant)") {
DynamicJsonDocument doc1(4096);
JsonDocument doc1(4096);
doc1["payload"] = "[4,2]";
DynamicJsonDocument doc2(4096);
JsonDocument doc2(4096);
DeserializationError err =
deserializeJson(doc2, doc1["payload"].as<JsonVariant>());
@ -171,10 +171,10 @@ TEST_CASE("deserializeJson(JsonDocument&, JsonVariant)") {
}
TEST_CASE("deserializeJson(JsonDocument&, JsonVariantConst)") {
DynamicJsonDocument doc1(4096);
JsonDocument doc1(4096);
doc1["payload"] = "[4,2]";
DynamicJsonDocument doc2(4096);
JsonDocument doc2(4096);
DeserializationError err =
deserializeJson(doc2, doc1["payload"].as<JsonVariantConst>());
@ -185,10 +185,10 @@ TEST_CASE("deserializeJson(JsonDocument&, JsonVariantConst)") {
}
TEST_CASE("deserializeJson(JsonDocument&, ElementProxy)") {
DynamicJsonDocument doc1(4096);
JsonDocument doc1(4096);
doc1[0] = "[4,2]";
DynamicJsonDocument doc2(4096);
JsonDocument doc2(4096);
DeserializationError err = deserializeJson(doc2, doc1[0]);
REQUIRE(err == DeserializationError::Ok);

View File

@ -13,7 +13,7 @@ TEST_CASE("Invalid JSON input") {
"3}"};
const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
for (size_t i = 0; i < testCount; i++) {
const char* input = testCases[i];
@ -30,7 +30,7 @@ TEST_CASE("Invalid JSON input that should pass") {
};
const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
for (size_t i = 0; i < testCount; i++) {
const char* input = testCases[i];

View File

@ -7,8 +7,8 @@
using namespace Catch::Matchers;
TEST_CASE("deserializeJson(DynamicJsonDocument&)") {
DynamicJsonDocument doc(4096);
TEST_CASE("deserializeJson(JsonDocument&)") {
JsonDocument doc(4096);
SECTION("Edge cases") {
SECTION("null char*") {

View File

@ -12,7 +12,7 @@
REQUIRE(DeserializationError::TooDeep == expression);
TEST_CASE("JsonDeserializer nesting") {
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
SECTION("Input = const char*") {
SECTION("limit = 0") {

View File

@ -16,7 +16,7 @@ using ArduinoJson::detail::isnan;
} // namespace my
TEST_CASE("deserialize an integer") {
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
SECTION("Integer") {
SECTION("0") {

View File

@ -6,7 +6,7 @@
#include <catch.hpp>
TEST_CASE("deserialize JSON object") {
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
SECTION("An empty object") {
DeserializationError err = deserializeJson(doc, "{}");
@ -316,7 +316,7 @@ TEST_CASE("deserialize JSON object") {
TEST_CASE("deserialize JSON object under memory constraints") {
SECTION("buffer for the right size for an empty object") {
DynamicJsonDocument doc(JSON_OBJECT_SIZE(0));
JsonDocument doc(JSON_OBJECT_SIZE(0));
char input[] = "{}";
DeserializationError err = deserializeJson(doc, input);
@ -325,7 +325,7 @@ TEST_CASE("deserialize JSON object under memory constraints") {
}
SECTION("buffer too small for an empty object") {
DynamicJsonDocument doc(JSON_OBJECT_SIZE(0));
JsonDocument doc(JSON_OBJECT_SIZE(0));
char input[] = "{\"a\":1}";
DeserializationError err = deserializeJson(doc, input);
@ -334,7 +334,7 @@ TEST_CASE("deserialize JSON object under memory constraints") {
}
SECTION("buffer of the right size for an object with one member") {
DynamicJsonDocument doc(JSON_OBJECT_SIZE(1));
JsonDocument doc(JSON_OBJECT_SIZE(1));
char input[] = "{\"a\":1}";
DeserializationError err = deserializeJson(doc, input);
@ -343,7 +343,7 @@ TEST_CASE("deserialize JSON object under memory constraints") {
}
SECTION("buffer too small for an object with a nested array") {
DynamicJsonDocument doc(JSON_OBJECT_SIZE(0) + JSON_ARRAY_SIZE(0));
JsonDocument doc(JSON_OBJECT_SIZE(0) + JSON_ARRAY_SIZE(0));
char input[] = "{\"a\":[]}";
DeserializationError err = deserializeJson(doc, input);
@ -352,7 +352,7 @@ TEST_CASE("deserialize JSON object under memory constraints") {
}
SECTION("buffer of the right size for an object with a nested array") {
DynamicJsonDocument doc(JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(0));
JsonDocument doc(JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(0));
char input[] = "{\"a\":[]}";
DeserializationError err = deserializeJson(doc, input);
@ -361,7 +361,7 @@ TEST_CASE("deserialize JSON object under memory constraints") {
}
SECTION("Should clear the JsonObject") {
DynamicJsonDocument doc(JSON_OBJECT_SIZE(1));
JsonDocument doc(JSON_OBJECT_SIZE(1));
char input[] = "{\"hello\":\"world\"}";
deserializeJson(doc, input);

View File

@ -35,7 +35,7 @@ TEST_CASE("Valid JSON strings value") {
};
const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
for (size_t i = 0; i < testCount; i++) {
const TestCase& testCase = testCases[i];
@ -47,7 +47,7 @@ TEST_CASE("Valid JSON strings value") {
}
TEST_CASE("\\u0000") {
DynamicJsonDocument doc(200);
JsonDocument doc(200);
DeserializationError err = deserializeJson(doc, "\"wx\\u0000yz\"");
REQUIRE(err == DeserializationError::Ok);
@ -68,7 +68,7 @@ TEST_CASE("Truncated JSON string") {
const char* testCases[] = {"\"hello", "\'hello", "'\\u", "'\\u00", "'\\u000"};
const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
for (size_t i = 0; i < testCount; i++) {
const char* input = testCases[i];
@ -83,7 +83,7 @@ TEST_CASE("Invalid JSON string") {
"'\\u000G'", "'\\u000/'", "'\\x1234'"};
const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
DynamicJsonDocument doc(4096);
JsonDocument doc(4096);
for (size_t i = 0; i < testCount; i++) {
const char* input = testCases[i];
@ -93,7 +93,7 @@ TEST_CASE("Invalid JSON string") {
}
TEST_CASE("Not enough room to save the key") {
DynamicJsonDocument doc(JSON_OBJECT_SIZE(1) + 8);
JsonDocument doc(JSON_OBJECT_SIZE(1) + 8);
SECTION("Quoted string") {
REQUIRE(deserializeJson(doc, "{\"example\":1}") ==
@ -115,7 +115,7 @@ TEST_CASE("Not enough room to save the key") {
TEST_CASE("Empty memory pool") {
// NOLINTNEXTLINE(clang-analyzer-optin.portability.UnixAPI)
DynamicJsonDocument doc(0);
JsonDocument doc(0);
SECTION("Input is const char*") {
REQUIRE(deserializeJson(doc, "\"hello\"") ==