2017-01-06 21:07:34 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2017
|
2015-08-01 16:31:59 +02:00
|
|
|
// MIT License
|
|
|
|
//
|
|
|
|
// Arduino JSON library
|
|
|
|
// https://github.com/bblanchon/ArduinoJson
|
2016-01-07 22:35:12 +01:00
|
|
|
// If you like this project, please add a star!
|
2015-08-01 16:31:59 +02:00
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
2016-12-29 17:26:16 +01:00
|
|
|
#include <gtest/gtest.h>
|
2015-08-01 16:31:59 +02:00
|
|
|
|
2015-09-29 22:02:12 +02:00
|
|
|
class NoMemoryAllocator {
|
|
|
|
public:
|
2016-12-29 17:26:16 +01:00
|
|
|
void* allocate(size_t) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-09-29 22:02:12 +02:00
|
|
|
void deallocate(void*) {}
|
|
|
|
};
|
2015-08-01 16:31:59 +02:00
|
|
|
|
2015-09-29 22:02:12 +02:00
|
|
|
class DynamicJsonBuffer_NoMemory_Tests : public ::testing::Test {
|
2015-08-01 16:31:59 +02:00
|
|
|
protected:
|
2016-12-29 17:26:16 +01:00
|
|
|
DynamicJsonBufferBase<NoMemoryAllocator> _jsonBuffer;
|
2015-08-01 16:31:59 +02:00
|
|
|
};
|
|
|
|
|
2015-09-29 22:02:12 +02:00
|
|
|
TEST_F(DynamicJsonBuffer_NoMemory_Tests, FixCodeCoverage) {
|
|
|
|
// call this function to fix code coverage
|
|
|
|
NoMemoryAllocator().deallocate(NULL);
|
|
|
|
}
|
|
|
|
|
2015-08-01 16:31:59 +02:00
|
|
|
TEST_F(DynamicJsonBuffer_NoMemory_Tests, CreateArray) {
|
|
|
|
ASSERT_FALSE(_jsonBuffer.createArray().success());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DynamicJsonBuffer_NoMemory_Tests, CreateObject) {
|
|
|
|
ASSERT_FALSE(_jsonBuffer.createObject().success());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DynamicJsonBuffer_NoMemory_Tests, ParseArray) {
|
|
|
|
char json[] = "[]";
|
|
|
|
ASSERT_FALSE(_jsonBuffer.parseArray(json).success());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DynamicJsonBuffer_NoMemory_Tests, ParseObject) {
|
|
|
|
char json[] = "{}";
|
|
|
|
ASSERT_FALSE(_jsonBuffer.parseObject(json).success());
|
|
|
|
}
|
2017-01-31 10:06:40 +01:00
|
|
|
|
|
|
|
TEST_F(DynamicJsonBuffer_NoMemory_Tests, String) {
|
|
|
|
DynamicJsonBufferBase<NoMemoryAllocator>::String str = _jsonBuffer.startString();
|
|
|
|
str.append('!');
|
|
|
|
ASSERT_EQ(NULL, str.c_str());
|
|
|
|
}
|