mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added DeserializationError::f_str() (issue #846)
				
					
				
			This commit is contained in:
		| @@ -5,6 +5,8 @@ | ||||
| #include <stdint.h>  // uint8_t | ||||
| #include <string.h>  // strcmp, strlen... | ||||
|  | ||||
| #define PROGMEM | ||||
|  | ||||
| class __FlashStringHelper; | ||||
|  | ||||
| inline const void* convertPtrToFlash(const void* s) { | ||||
| @@ -15,9 +17,13 @@ inline const void* convertFlashToPtr(const void* s) { | ||||
|   return reinterpret_cast<const char*>(s) - 42; | ||||
| } | ||||
|  | ||||
| #define F(X) reinterpret_cast<const __FlashStringHelper*>(convertPtrToFlash(X)) | ||||
| #define FC(X) reinterpret_cast<const char*>(convertPtrToFlash(X)) | ||||
| #define PSTR(X) reinterpret_cast<const char*>(convertPtrToFlash(X)) | ||||
| #define F(X) reinterpret_cast<const __FlashStringHelper*>(PSTR(X)) | ||||
|  | ||||
| inline uint8_t pgm_read_byte(const void* p) { | ||||
|   return *reinterpret_cast<const uint8_t*>(convertFlashToPtr(p)); | ||||
| } | ||||
|  | ||||
| inline const void* pgm_read_ptr(const void* p) { | ||||
|   return *reinterpret_cast<const void* const*>(convertFlashToPtr(p)); | ||||
| } | ||||
|   | ||||
| @@ -53,33 +53,33 @@ TEST_CASE("Flash strings") { | ||||
| } | ||||
|  | ||||
| TEST_CASE("strlen_P") { | ||||
|   CHECK(strlen_P(FC("")) == 0); | ||||
|   CHECK(strlen_P(FC("a")) == 1); | ||||
|   CHECK(strlen_P(FC("ac")) == 2); | ||||
|   CHECK(strlen_P(PSTR("")) == 0); | ||||
|   CHECK(strlen_P(PSTR("a")) == 1); | ||||
|   CHECK(strlen_P(PSTR("ac")) == 2); | ||||
| } | ||||
|  | ||||
| TEST_CASE("strncmp_P") { | ||||
|   CHECK(strncmp_P("a", FC("b"), 0) == 0); | ||||
|   CHECK(strncmp_P("a", FC("b"), 1) == -1); | ||||
|   CHECK(strncmp_P("b", FC("a"), 1) == 1); | ||||
|   CHECK(strncmp_P("a", FC("a"), 0) == 0); | ||||
|   CHECK(strncmp_P("a", FC("b"), 2) == -1); | ||||
|   CHECK(strncmp_P("b", FC("a"), 2) == 1); | ||||
|   CHECK(strncmp_P("a", FC("a"), 2) == 0); | ||||
|   CHECK(strncmp_P("a", PSTR("b"), 0) == 0); | ||||
|   CHECK(strncmp_P("a", PSTR("b"), 1) == -1); | ||||
|   CHECK(strncmp_P("b", PSTR("a"), 1) == 1); | ||||
|   CHECK(strncmp_P("a", PSTR("a"), 0) == 0); | ||||
|   CHECK(strncmp_P("a", PSTR("b"), 2) == -1); | ||||
|   CHECK(strncmp_P("b", PSTR("a"), 2) == 1); | ||||
|   CHECK(strncmp_P("a", PSTR("a"), 2) == 0); | ||||
| } | ||||
|  | ||||
| TEST_CASE("strcmp_P") { | ||||
|   CHECK(strcmp_P("a", FC("b")) == -1); | ||||
|   CHECK(strcmp_P("b", FC("a")) == 1); | ||||
|   CHECK(strcmp_P("a", FC("a")) == 0); | ||||
|   CHECK(strcmp_P("aa", FC("ab")) == -1); | ||||
|   CHECK(strcmp_P("ab", FC("aa")) == 1); | ||||
|   CHECK(strcmp_P("aa", FC("aa")) == 0); | ||||
|   CHECK(strcmp_P("a", PSTR("b")) == -1); | ||||
|   CHECK(strcmp_P("b", PSTR("a")) == 1); | ||||
|   CHECK(strcmp_P("a", PSTR("a")) == 0); | ||||
|   CHECK(strcmp_P("aa", PSTR("ab")) == -1); | ||||
|   CHECK(strcmp_P("ab", PSTR("aa")) == 1); | ||||
|   CHECK(strcmp_P("aa", PSTR("aa")) == 0); | ||||
| } | ||||
|  | ||||
| TEST_CASE("memcpy_P") { | ||||
|   char dst[4]; | ||||
|   CHECK(memcpy_P(dst, FC("ABC"), 4) == dst); | ||||
|   CHECK(memcpy_P(dst, PSTR("ABC"), 4) == dst); | ||||
|   CHECK(dst[0] == 'A'); | ||||
|   CHECK(dst[1] == 'B'); | ||||
|   CHECK(dst[2] == 'C'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user