From a7cdf638e741e4a3ff05f019191a9ef5d085ffa3 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 1 Apr 2023 15:06:24 +0200 Subject: [PATCH] Test: move `ControllableAllocator` --- extras/tests/Helpers/Allocators.hpp | 25 +++++++++++++++++++++++++ extras/tests/JsonDocument/allocator.cpp | 25 ------------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/extras/tests/Helpers/Allocators.hpp b/extras/tests/Helpers/Allocators.hpp index 64053cf3..49e868f3 100644 --- a/extras/tests/Helpers/Allocators.hpp +++ b/extras/tests/Helpers/Allocators.hpp @@ -129,3 +129,28 @@ class SpyingAllocator : public ArduinoJson::Allocator { AllocatorLog _log; }; + +class ControllableAllocator : public ArduinoJson::Allocator { + public: + ControllableAllocator() : _enabled(true) {} + virtual ~ControllableAllocator() {} + + void* allocate(size_t n) override { + return _enabled ? malloc(n) : 0; + } + + void deallocate(void* p) override { + free(p); + } + + void* reallocate(void* ptr, size_t n) override { + return realloc(ptr, n); + } + + void disable() { + _enabled = false; + } + + private: + bool _enabled; +}; diff --git a/extras/tests/JsonDocument/allocator.cpp b/extras/tests/JsonDocument/allocator.cpp index 62be1ce5..0e9f7402 100644 --- a/extras/tests/JsonDocument/allocator.cpp +++ b/extras/tests/JsonDocument/allocator.cpp @@ -11,31 +11,6 @@ using ArduinoJson::detail::sizeofObject; -class ControllableAllocator : public Allocator { - public: - ControllableAllocator() : _enabled(true) {} - virtual ~ControllableAllocator() {} - - void* allocate(size_t n) override { - return _enabled ? malloc(n) : 0; - } - - void deallocate(void* p) override { - free(p); - } - - void* reallocate(void* ptr, size_t n) override { - return realloc(ptr, n); - } - - void disable() { - _enabled = false; - } - - private: - bool _enabled; -}; - TEST_CASE("JsonDocument's allocator") { SpyingAllocator spyingAllocator; ControllableAllocator controllableAllocator;