Test: share SpyingAllocator

This commit is contained in:
Benoit Blanchon
2023-03-31 14:36:24 +02:00
parent 035c913c72
commit 912137ccfb
2 changed files with 31 additions and 28 deletions

View File

@ -5,38 +5,12 @@
#include <ArduinoJson.h>
#include <stdlib.h> // malloc, free
#include <catch.hpp>
#include <sstream>
#include <utility>
#include "Allocators.hpp"
using ArduinoJson::detail::sizeofObject;
class SpyingAllocator : public Allocator {
public:
virtual ~SpyingAllocator() {}
void* allocate(size_t n) override {
_log << "A" << n;
return malloc(n);
}
void deallocate(void* p) override {
_log << "F";
free(p);
}
void* reallocate(void* ptr, size_t n) override {
_log << "R" << n;
return realloc(ptr, n);
}
std::string log() const {
return _log.str();
}
private:
std::ostringstream _log;
};
class ControllableAllocator : public Allocator {
public:
ControllableAllocator() : _enabled(true) {}