2017-11-07 20:42:50 +01:00
|
|
|
// ArduinoJson - arduinojson.org
|
2018-01-05 09:20:01 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2018
|
2017-04-18 18:22:24 +02:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
struct NoMemoryAllocator {
|
|
|
|
void* allocate(size_t) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
void deallocate(void*) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_CASE("DynamicJsonBuffer no memory") {
|
|
|
|
DynamicJsonBufferBase<NoMemoryAllocator> _jsonBuffer;
|
|
|
|
|
|
|
|
SECTION("FixCodeCoverage") {
|
|
|
|
// call this function to fix code coverage
|
|
|
|
NoMemoryAllocator().deallocate(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("createArray()") {
|
|
|
|
REQUIRE_FALSE(_jsonBuffer.createArray().success());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("createObject()") {
|
|
|
|
REQUIRE_FALSE(_jsonBuffer.createObject().success());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("parseArray()") {
|
|
|
|
char json[] = "[]";
|
|
|
|
REQUIRE_FALSE(_jsonBuffer.parseArray(json).success());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("parseObject()") {
|
|
|
|
char json[] = "{}";
|
|
|
|
REQUIRE_FALSE(_jsonBuffer.parseObject(json).success());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("startString()") {
|
|
|
|
DynamicJsonBufferBase<NoMemoryAllocator>::String str =
|
|
|
|
_jsonBuffer.startString();
|
|
|
|
str.append('!');
|
|
|
|
REQUIRE(0 == str.c_str());
|
|
|
|
}
|
|
|
|
}
|