mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Change naming convention from _member to member_ (fixes #1905)
				
					
				
			This commit is contained in:
		| @@ -10,29 +10,29 @@ | ||||
|  | ||||
| class SpyingAllocator { | ||||
|  public: | ||||
|   SpyingAllocator(const SpyingAllocator& src) : _log(src._log) {} | ||||
|   SpyingAllocator(std::ostream& log) : _log(log) {} | ||||
|   SpyingAllocator(const SpyingAllocator& src) : log_(src.log_) {} | ||||
|   SpyingAllocator(std::ostream& log) : log_(log) {} | ||||
|   SpyingAllocator& operator=(const SpyingAllocator& src) = delete; | ||||
|  | ||||
|   void* allocate(size_t n) { | ||||
|     _log << "A" << n; | ||||
|     log_ << "A" << n; | ||||
|     return malloc(n); | ||||
|   } | ||||
|   void deallocate(void* p) { | ||||
|     _log << "F"; | ||||
|     log_ << "F"; | ||||
|     free(p); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   std::ostream& _log; | ||||
|   std::ostream& log_; | ||||
| }; | ||||
|  | ||||
| class ControllableAllocator { | ||||
|  public: | ||||
|   ControllableAllocator() : _enabled(true) {} | ||||
|   ControllableAllocator() : enabled_(true) {} | ||||
|  | ||||
|   void* allocate(size_t n) { | ||||
|     return _enabled ? malloc(n) : 0; | ||||
|     return enabled_ ? malloc(n) : 0; | ||||
|   } | ||||
|  | ||||
|   void deallocate(void* p) { | ||||
| @@ -40,11 +40,11 @@ class ControllableAllocator { | ||||
|   } | ||||
|  | ||||
|   void disable() { | ||||
|     _enabled = false; | ||||
|     enabled_ = false; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   bool _enabled; | ||||
|   bool enabled_; | ||||
| }; | ||||
|  | ||||
| TEST_CASE("BasicJsonDocument") { | ||||
|   | ||||
| @@ -10,36 +10,36 @@ | ||||
|  | ||||
| class ArmoredAllocator { | ||||
|  public: | ||||
|   ArmoredAllocator() : _ptr(0), _size(0) {} | ||||
|   ArmoredAllocator() : ptr_(0), size_(0) {} | ||||
|  | ||||
|   void* allocate(size_t size) { | ||||
|     _ptr = malloc(size); | ||||
|     _size = size; | ||||
|     return _ptr; | ||||
|     ptr_ = malloc(size); | ||||
|     size_ = size; | ||||
|     return ptr_; | ||||
|   } | ||||
|  | ||||
|   void deallocate(void* ptr) { | ||||
|     REQUIRE(ptr == _ptr); | ||||
|     REQUIRE(ptr == ptr_); | ||||
|     free(ptr); | ||||
|     _ptr = 0; | ||||
|     _size = 0; | ||||
|     ptr_ = 0; | ||||
|     size_ = 0; | ||||
|   } | ||||
|  | ||||
|   void* reallocate(void* ptr, size_t new_size) { | ||||
|     REQUIRE(ptr == _ptr); | ||||
|     REQUIRE(ptr == ptr_); | ||||
|     // don't call realloc, instead alloc a new buffer and erase the old one | ||||
|     // this way we make sure we support relocation | ||||
|     void* new_ptr = malloc(new_size); | ||||
|     memcpy(new_ptr, _ptr, std::min(new_size, _size)); | ||||
|     memset(_ptr, '#', _size);  // erase | ||||
|     free(_ptr); | ||||
|     _ptr = new_ptr; | ||||
|     memcpy(new_ptr, ptr_, std::min(new_size, size_)); | ||||
|     memset(ptr_, '#', size_);  // erase | ||||
|     free(ptr_); | ||||
|     ptr_ = new_ptr; | ||||
|     return new_ptr; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   void* _ptr; | ||||
|   size_t _size; | ||||
|   void* ptr_; | ||||
|   size_t size_; | ||||
| }; | ||||
|  | ||||
| typedef BasicJsonDocument<ArmoredAllocator> ShrinkToFitTestDocument; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user