mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Change naming convention from _member to member_ (fixes #1905)
				
					
				
			This commit is contained in:
		| @@ -7,18 +7,18 @@ | ||||
| #include <sstream> | ||||
|  | ||||
| class CustomReader { | ||||
|   std::stringstream _stream; | ||||
|   std::stringstream stream_; | ||||
|  | ||||
|  public: | ||||
|   CustomReader(const char* input) : _stream(input) {} | ||||
|   CustomReader(const char* input) : stream_(input) {} | ||||
|   CustomReader(const CustomReader&) = delete; | ||||
|  | ||||
|   int read() { | ||||
|     return _stream.get(); | ||||
|     return stream_.get(); | ||||
|   } | ||||
|  | ||||
|   size_t readBytes(char* buffer, size_t length) { | ||||
|     _stream.read(buffer, static_cast<std::streamsize>(length)); | ||||
|     return static_cast<size_t>(_stream.gcount()); | ||||
|     stream_.read(buffer, static_cast<std::streamsize>(length)); | ||||
|     return static_cast<size_t>(stream_.gcount()); | ||||
|   } | ||||
| }; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -12,21 +12,21 @@ class CustomWriter { | ||||
|   CustomWriter& operator=(const CustomWriter&) = delete; | ||||
|  | ||||
|   size_t write(uint8_t c) { | ||||
|     _str.append(1, static_cast<char>(c)); | ||||
|     str_.append(1, static_cast<char>(c)); | ||||
|     return 1; | ||||
|   } | ||||
|  | ||||
|   size_t write(const uint8_t* s, size_t n) { | ||||
|     _str.append(reinterpret_cast<const char*>(s), n); | ||||
|     str_.append(reinterpret_cast<const char*>(s), n); | ||||
|     return n; | ||||
|   } | ||||
|  | ||||
|   const std::string& str() const { | ||||
|     return _str; | ||||
|     return str_; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   std::string _str; | ||||
|   std::string str_; | ||||
| }; | ||||
|  | ||||
| TEST_CASE("CustomWriter") { | ||||
|   | ||||
| @@ -74,18 +74,18 @@ TEST_CASE("Custom converter with overloading") { | ||||
|  | ||||
| class Complex { | ||||
|  public: | ||||
|   explicit Complex(double r, double i) : _real(r), _imag(i) {} | ||||
|   explicit Complex(double r, double i) : real_(r), imag_(i) {} | ||||
|  | ||||
|   double real() const { | ||||
|     return _real; | ||||
|     return real_; | ||||
|   } | ||||
|  | ||||
|   double imag() const { | ||||
|     return _imag; | ||||
|     return imag_; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   double _real, _imag; | ||||
|   double real_, imag_; | ||||
| }; | ||||
|  | ||||
| namespace ArduinoJson { | ||||
|   | ||||
| @@ -170,19 +170,19 @@ TEST_CASE("IteratorReader") { | ||||
|  | ||||
| class StreamStub : public Stream { | ||||
|  public: | ||||
|   StreamStub(const char* s) : _stream(s) {} | ||||
|   StreamStub(const char* s) : stream_(s) {} | ||||
|  | ||||
|   int read() { | ||||
|     return _stream.get(); | ||||
|     return stream_.get(); | ||||
|   } | ||||
|  | ||||
|   size_t readBytes(char* buffer, size_t length) { | ||||
|     _stream.read(buffer, static_cast<std::streamsize>(length)); | ||||
|     return static_cast<size_t>(_stream.gcount()); | ||||
|     stream_.read(buffer, static_cast<std::streamsize>(length)); | ||||
|     return static_cast<size_t>(stream_.gcount()); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   std::istringstream _stream; | ||||
|   std::istringstream stream_; | ||||
| }; | ||||
|  | ||||
| TEST_CASE("Reader<Stream>") { | ||||
|   | ||||
| @@ -52,5 +52,8 @@ | ||||
| #define BLOCKSIZE | ||||
| #define CAPACITY | ||||
|  | ||||
| // issue #1905 | ||||
| #define _current | ||||
|  | ||||
| // catch.hpp mutes several warnings, this file also allows to detect them | ||||
| #include "ArduinoJson.h" | ||||
|   | ||||
| @@ -29,21 +29,21 @@ struct PrintAllAtOnce { | ||||
|  | ||||
| template <typename PrintPolicy> | ||||
| struct PrintableString : public Printable { | ||||
|   PrintableString(const char* s) : _str(s), _total(0) {} | ||||
|   PrintableString(const char* s) : str_(s), total_(0) {} | ||||
|  | ||||
|   virtual size_t printTo(Print& p) const { | ||||
|     size_t result = PrintPolicy::printStringTo(_str, p); | ||||
|     _total += result; | ||||
|     size_t result = PrintPolicy::printStringTo(str_, p); | ||||
|     total_ += result; | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   size_t totalBytesWritten() const { | ||||
|     return _total; | ||||
|     return total_; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   std::string _str; | ||||
|   mutable size_t _total; | ||||
|   std::string str_; | ||||
|   mutable size_t total_; | ||||
| }; | ||||
|  | ||||
| TEST_CASE("Printable") { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user