forked from bblanchon/ArduinoJson
Don't use JsonBuffer to create or parse objects and arrays.
* Added DynamicJsonArray and StaticJsonArray * Added DynamicJsonObject and StaticJsonObject * Added DynamicJsonVariant and StaticJsonVariant * Added deserializeJson() * Removed JsonBuffer::parseArray(), parseObject() and parse() * Removed JsonBuffer::createArray() and createObject()
This commit is contained in:
@ -4,8 +4,6 @@
|
||||
|
||||
add_executable(DynamicJsonBufferTests
|
||||
alloc.cpp
|
||||
createArray.cpp
|
||||
createObject.cpp
|
||||
no_memory.cpp
|
||||
size.cpp
|
||||
startString.cpp
|
||||
|
@ -1,28 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("DynamicJsonBuffer::createArray()") {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonArray &array = jsonBuffer.createArray();
|
||||
|
||||
SECTION("GrowsWithArray") {
|
||||
REQUIRE(JSON_ARRAY_SIZE(0) == jsonBuffer.size());
|
||||
|
||||
array.add("hello");
|
||||
REQUIRE(JSON_ARRAY_SIZE(1) == jsonBuffer.size());
|
||||
|
||||
array.add("world");
|
||||
REQUIRE(JSON_ARRAY_SIZE(2) == jsonBuffer.size());
|
||||
}
|
||||
|
||||
SECTION("CanAdd1000Values") {
|
||||
for (size_t i = 1; i <= 1000; i++) {
|
||||
array.add("hello");
|
||||
REQUIRE(array.size() == i);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("DynamicJsonBuffer::createObject()") {
|
||||
DynamicJsonBuffer json;
|
||||
|
||||
JsonObject &obj = json.createObject();
|
||||
REQUIRE(JSON_OBJECT_SIZE(0) == json.size());
|
||||
|
||||
obj["hello"] = 1;
|
||||
REQUIRE(JSON_OBJECT_SIZE(1) == json.size());
|
||||
|
||||
obj["world"] = 2;
|
||||
REQUIRE(JSON_OBJECT_SIZE(2) == json.size());
|
||||
|
||||
obj["world"] = 3; // <- same key, should not grow
|
||||
REQUIRE(JSON_OBJECT_SIZE(2) == json.size());
|
||||
}
|
@ -22,23 +22,25 @@ TEST_CASE("DynamicJsonBuffer no memory") {
|
||||
NoMemoryAllocator().deallocate(NULL);
|
||||
}
|
||||
|
||||
SECTION("createArray()") {
|
||||
REQUIRE_FALSE(_jsonBuffer.createArray().success());
|
||||
}
|
||||
// TODO: uncomment
|
||||
// SECTION("parseArray()") {
|
||||
// char json[] = "[{}]";
|
||||
// DynamicJsonArray arr;
|
||||
|
||||
SECTION("createObject()") {
|
||||
REQUIRE_FALSE(_jsonBuffer.createObject().success());
|
||||
}
|
||||
// bool success = deserializeJson(arr, json);
|
||||
|
||||
SECTION("parseArray()") {
|
||||
char json[] = "[]";
|
||||
REQUIRE_FALSE(_jsonBuffer.parseArray(json).success());
|
||||
}
|
||||
// REQUIRE(success == false);
|
||||
// }
|
||||
|
||||
SECTION("parseObject()") {
|
||||
char json[] = "{}";
|
||||
REQUIRE_FALSE(_jsonBuffer.parseObject(json).success());
|
||||
}
|
||||
// TODO: uncomment
|
||||
// SECTION("parseObject()") {
|
||||
// char json[] = "{[]}";
|
||||
// DynamicJsonObject obj;
|
||||
|
||||
// bool success = deserializeJson(obj, json);
|
||||
|
||||
// REQUIRE(success == false);
|
||||
// }
|
||||
|
||||
SECTION("startString()") {
|
||||
DynamicJsonBufferBase<NoMemoryAllocator>::String str =
|
||||
|
Reference in New Issue
Block a user