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
|
|
|
|
|
2018-11-09 17:27:32 +01:00
|
|
|
#include <ArduinoJson/Memory/DynamicMemoryPool.hpp>
|
|
|
|
#include <ArduinoJson/Memory/StringBuilder.hpp>
|
2017-04-18 18:22:24 +02:00
|
|
|
#include <catch.hpp>
|
|
|
|
|
2018-10-02 16:54:05 +02:00
|
|
|
using namespace ARDUINOJSON_NAMESPACE;
|
2018-01-19 08:32:15 +01:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
struct NoMemoryAllocator {
|
|
|
|
void* allocate(size_t) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
void deallocate(void*) {}
|
|
|
|
};
|
|
|
|
|
2018-09-03 16:14:21 +02:00
|
|
|
TEST_CASE("DynamicMemoryPool no memory") {
|
|
|
|
DynamicMemoryPoolBase<NoMemoryAllocator> _memoryPool;
|
2017-04-18 18:22:24 +02:00
|
|
|
|
|
|
|
SECTION("FixCodeCoverage") {
|
|
|
|
// call this function to fix code coverage
|
|
|
|
NoMemoryAllocator().deallocate(NULL);
|
|
|
|
}
|
|
|
|
|
2018-02-26 16:05:16 +01:00
|
|
|
// TODO: uncomment
|
2018-04-17 21:27:45 +02:00
|
|
|
// SECTION("deserializeJson()") {
|
2018-02-26 16:05:16 +01:00
|
|
|
// char json[] = "{[]}";
|
2018-04-17 21:27:45 +02:00
|
|
|
// DynamicJsonDocument obj;
|
2018-02-26 16:05:16 +01:00
|
|
|
|
2018-05-15 18:23:09 +02:00
|
|
|
// DeserializationError err = deserializeJson(obj, json);
|
2018-02-26 16:05:16 +01:00
|
|
|
|
2018-05-15 18:23:09 +02:00
|
|
|
// REQUIRE(err != DeserializationError::Ok);
|
2018-02-26 16:05:16 +01:00
|
|
|
// }
|
2017-04-18 18:22:24 +02:00
|
|
|
|
2018-11-09 17:27:32 +01:00
|
|
|
SECTION("StringBuilder returns null") {
|
|
|
|
StringBuilder str(&_memoryPool);
|
2017-04-18 18:22:24 +02:00
|
|
|
str.append('!');
|
2018-10-04 11:16:23 +02:00
|
|
|
REQUIRE(str.complete().isNull());
|
2017-04-18 18:22:24 +02:00
|
|
|
}
|
|
|
|
}
|