mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-15 19:42:12 +02:00
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:
@ -7,8 +7,7 @@
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonArray::operator[]") {
|
||||
DynamicJsonBuffer _jsonBuffer;
|
||||
JsonArray& _array = _jsonBuffer.createArray();
|
||||
DynamicJsonArray _array;
|
||||
_array.add(0);
|
||||
|
||||
SECTION("int") {
|
||||
@ -52,7 +51,7 @@ TEST_CASE("JsonArray::operator[]") {
|
||||
}
|
||||
|
||||
SECTION("nested array") {
|
||||
JsonArray& arr = _jsonBuffer.createArray();
|
||||
DynamicJsonArray arr;
|
||||
|
||||
_array[0] = arr;
|
||||
|
||||
@ -65,7 +64,7 @@ TEST_CASE("JsonArray::operator[]") {
|
||||
}
|
||||
|
||||
SECTION("nested object") {
|
||||
JsonObject& obj = _jsonBuffer.createObject();
|
||||
DynamicJsonObject obj;
|
||||
|
||||
_array[0] = obj;
|
||||
|
||||
@ -78,7 +77,7 @@ TEST_CASE("JsonArray::operator[]") {
|
||||
}
|
||||
|
||||
SECTION("array subscript") {
|
||||
JsonArray& arr = _jsonBuffer.createArray();
|
||||
DynamicJsonArray arr;
|
||||
const char* str = "hello";
|
||||
|
||||
arr.add(str);
|
||||
@ -89,7 +88,7 @@ TEST_CASE("JsonArray::operator[]") {
|
||||
}
|
||||
|
||||
SECTION("object subscript") {
|
||||
JsonObject& obj = _jsonBuffer.createObject();
|
||||
DynamicJsonObject obj;
|
||||
const char* str = "hello";
|
||||
|
||||
obj["x"] = str;
|
||||
@ -102,18 +101,18 @@ TEST_CASE("JsonArray::operator[]") {
|
||||
SECTION("should not duplicate const char*") {
|
||||
_array[0] = "world";
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1);
|
||||
REQUIRE(expectedSize == _jsonBuffer.size());
|
||||
REQUIRE(expectedSize == _array.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate char*") {
|
||||
_array[0] = const_cast<char*>("world");
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + 6;
|
||||
REQUIRE(expectedSize == _jsonBuffer.size());
|
||||
REQUIRE(expectedSize == _array.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate std::string") {
|
||||
_array[0] = std::string("world");
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + 6;
|
||||
REQUIRE(expectedSize == _jsonBuffer.size());
|
||||
REQUIRE(expectedSize == _array.memoryUsage());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user