forked from bblanchon/ArduinoJson
Remove capacity from JsonDocument
's constructor
This commit is contained in:
@ -139,7 +139,7 @@ TEST_CASE("Writer<custom_string>") {
|
||||
}
|
||||
|
||||
TEST_CASE("serializeJson(doc, String)") {
|
||||
JsonDocument doc(1024);
|
||||
JsonDocument doc;
|
||||
doc["hello"] = "world";
|
||||
::String output;
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
using namespace ArduinoJson::detail;
|
||||
|
||||
static void testCodepoint(uint32_t codepoint, std::string expected) {
|
||||
ResourceManager resources(4096);
|
||||
ResourceManager resources;
|
||||
StringBuilder str(&resources);
|
||||
str.startString();
|
||||
|
||||
|
@ -53,7 +53,7 @@ struct PrintableString : public Printable {
|
||||
|
||||
TEST_CASE("Printable") {
|
||||
SECTION("Doesn't overflow") {
|
||||
JsonDocument doc(8);
|
||||
JsonDocument doc;
|
||||
const char* value = "example";
|
||||
|
||||
doc.set(666); // to make sure we override the value
|
||||
@ -81,7 +81,7 @@ TEST_CASE("Printable") {
|
||||
|
||||
SECTION("First allocation fails") {
|
||||
SpyingAllocator spyingAllocator(FailingAllocator::instance());
|
||||
JsonDocument doc(0, &spyingAllocator);
|
||||
JsonDocument doc(&spyingAllocator);
|
||||
const char* value = "hello world";
|
||||
|
||||
doc.set(666); // to make sure we override the value
|
||||
@ -118,7 +118,7 @@ TEST_CASE("Printable") {
|
||||
SECTION("Reallocation fails") {
|
||||
TimebombAllocator timebombAllocator(1);
|
||||
SpyingAllocator spyingAllocator(&timebombAllocator);
|
||||
JsonDocument doc(0, &spyingAllocator);
|
||||
JsonDocument doc(&spyingAllocator);
|
||||
const char* value = "Lorem ipsum dolor sit amet, cons"; // > 31 chars
|
||||
|
||||
doc.set(666); // to make sure we override the value
|
||||
@ -167,7 +167,7 @@ TEST_CASE("Printable") {
|
||||
}
|
||||
|
||||
SECTION("String deduplication") {
|
||||
JsonDocument doc(128);
|
||||
JsonDocument doc;
|
||||
doc.add(PrintableString<PrintOneCharacterAtATime>("Hello World!"));
|
||||
doc.add(PrintableString<PrintAllAtOnce>("Hello World!"));
|
||||
REQUIRE(doc.size() == 2);
|
||||
|
@ -9,13 +9,11 @@
|
||||
# define CONFLICTS_WITH_BUILTIN_OPERATOR
|
||||
#endif
|
||||
|
||||
using ArduinoJson::detail::sizeofObject;
|
||||
|
||||
TEST_CASE("unsigned char[]") {
|
||||
SECTION("deserializeJson()") {
|
||||
unsigned char input[] = "{\"a\":42}";
|
||||
|
||||
JsonDocument doc(sizeofObject(1));
|
||||
JsonDocument doc;
|
||||
DeserializationError err = deserializeJson(doc, input);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
@ -24,7 +22,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("deserializeMsgPack()") {
|
||||
unsigned char input[] = "\xDE\x00\x01\xA5Hello\xA5world";
|
||||
|
||||
JsonDocument doc(sizeofObject(2));
|
||||
JsonDocument doc;
|
||||
DeserializationError err = deserializeMsgPack(doc, input);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
@ -32,7 +30,7 @@ TEST_CASE("unsigned char[]") {
|
||||
|
||||
SECTION("serializeMsgPack(unsigned char[])") {
|
||||
unsigned char buffer[32];
|
||||
JsonDocument doc(sizeofObject(2));
|
||||
JsonDocument doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeMsgPack(doc, buffer);
|
||||
@ -43,7 +41,7 @@ TEST_CASE("unsigned char[]") {
|
||||
|
||||
SECTION("serializeMsgPack(unsigned char*)") {
|
||||
unsigned char buffer[32];
|
||||
JsonDocument doc(sizeofObject(2));
|
||||
JsonDocument doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeMsgPack(doc, buffer, sizeof(buffer));
|
||||
@ -54,7 +52,7 @@ TEST_CASE("unsigned char[]") {
|
||||
|
||||
SECTION("serializeJson(unsigned char[])") {
|
||||
unsigned char buffer[32];
|
||||
JsonDocument doc(sizeofObject(2));
|
||||
JsonDocument doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeJson(doc, buffer);
|
||||
@ -65,7 +63,7 @@ TEST_CASE("unsigned char[]") {
|
||||
|
||||
SECTION("serializeJson(unsigned char*)") {
|
||||
unsigned char buffer[32];
|
||||
JsonDocument doc(sizeofObject(2));
|
||||
JsonDocument doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeJson(doc, buffer, sizeof(buffer));
|
||||
@ -76,7 +74,7 @@ TEST_CASE("unsigned char[]") {
|
||||
|
||||
SECTION("serializeJsonPretty(unsigned char[])") {
|
||||
unsigned char buffer[32];
|
||||
JsonDocument doc(sizeofObject(2));
|
||||
JsonDocument doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeJsonPretty(doc, buffer);
|
||||
@ -86,7 +84,7 @@ TEST_CASE("unsigned char[]") {
|
||||
|
||||
SECTION("serializeJsonPretty(unsigned char*)") {
|
||||
unsigned char buffer[32];
|
||||
JsonDocument doc(sizeofObject(2));
|
||||
JsonDocument doc;
|
||||
doc["hello"] = "world";
|
||||
|
||||
size_t n = serializeJsonPretty(doc, buffer, sizeof(buffer));
|
||||
@ -95,7 +93,7 @@ TEST_CASE("unsigned char[]") {
|
||||
}
|
||||
|
||||
SECTION("JsonVariant") {
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
|
||||
SECTION("set") {
|
||||
unsigned char value[] = "42";
|
||||
@ -158,7 +156,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("operator[]") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj[key] = "world";
|
||||
|
||||
@ -168,7 +166,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("JsonObject::operator[] const") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
@ -179,7 +177,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("containsKey()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
REQUIRE(true == obj.containsKey(key));
|
||||
@ -188,7 +186,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("remove()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
obj.remove(key);
|
||||
@ -199,7 +197,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("createNestedArray()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj.createNestedArray(key);
|
||||
}
|
||||
@ -207,7 +205,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("createNestedObject()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj.createNestedObject(key);
|
||||
}
|
||||
@ -217,7 +215,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("operator=") { // issue #416
|
||||
unsigned char value[] = "world";
|
||||
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj["hello"] = value;
|
||||
|
||||
@ -227,7 +225,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("set()") {
|
||||
unsigned char value[] = "world";
|
||||
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj["hello"].set(value);
|
||||
|
||||
@ -239,7 +237,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("add()") {
|
||||
unsigned char value[] = "world";
|
||||
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
arr.add(value);
|
||||
|
||||
@ -251,7 +249,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("set()") {
|
||||
unsigned char value[] = "world";
|
||||
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
arr.add("hello");
|
||||
arr[0].set(value);
|
||||
@ -262,7 +260,7 @@ TEST_CASE("unsigned char[]") {
|
||||
SECTION("operator=") {
|
||||
unsigned char value[] = "world";
|
||||
|
||||
JsonDocument doc(4096);
|
||||
JsonDocument doc;
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
arr.add("hello");
|
||||
arr[0] = value;
|
||||
|
Reference in New Issue
Block a user