From 5a74beb7e2aa2f987c5452e728ca17b750783f6a Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 11 Dec 2014 21:05:45 +0100 Subject: [PATCH] Test initial size() of DynamicJsonBuffer --- include/ArduinoJson/DynamicJsonBuffer.hpp | 25 +++++++++++++++++++++++ test/DynamicJsonBuffer_Basic_Tests.cpp | 21 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 include/ArduinoJson/DynamicJsonBuffer.hpp create mode 100644 test/DynamicJsonBuffer_Basic_Tests.cpp diff --git a/include/ArduinoJson/DynamicJsonBuffer.hpp b/include/ArduinoJson/DynamicJsonBuffer.hpp new file mode 100644 index 00000000..5c42a02a --- /dev/null +++ b/include/ArduinoJson/DynamicJsonBuffer.hpp @@ -0,0 +1,25 @@ +// Copyright Benoit Blanchon 2014 +// MIT License +// +// Arduino JSON library +// https://github.com/bblanchon/ArduinoJson + +#pragma once + +#include "JsonBuffer.hpp" + +namespace ArduinoJson { + +// Implements a JsonBuffer with dynamic memory allocation. +// You are strongly encouraged to consider using StaticJsonBuffer which is much +// more suitable for embedded systems. +class DynamicJsonBuffer : public JsonBuffer { + public: + explicit DynamicJsonBuffer() {} + + size_t size() const { return 0; } + + protected: + virtual void* alloc(size_t bytes) { return NULL; } +}; +} diff --git a/test/DynamicJsonBuffer_Basic_Tests.cpp b/test/DynamicJsonBuffer_Basic_Tests.cpp new file mode 100644 index 00000000..a506d003 --- /dev/null +++ b/test/DynamicJsonBuffer_Basic_Tests.cpp @@ -0,0 +1,21 @@ +// Copyright Benoit Blanchon 2014 +// MIT License +// +// Arduino JSON library +// https://github.com/bblanchon/ArduinoJson + +#include + +#define protected public +#include + +using namespace ArduinoJson; + +class DynamicJsonBuffer_Basic_Tests : public testing::Test { + protected: + DynamicJsonBuffer buffer; +}; + +TEST_F(DynamicJsonBuffer_Basic_Tests, InitialSizeIsZero) { + ASSERT_EQ(0, buffer.size()); +}