Added tests for DeserializationError::f_str()

This commit is contained in:
Benoit Blanchon
2020-09-18 09:37:59 +02:00
parent 6a878ee444
commit c3504ddf0a
4 changed files with 48 additions and 12 deletions

View File

@ -86,18 +86,20 @@ class DeserializationError {
return messages[_code];
}
#define ARDUINOJSON_EXPAND7(a, b, c, d, e, f, g) a, b, c, d, e, f, g
#if ARDUINOJSON_ENABLE_PROGMEM
const __FlashStringHelper* f_str() const {
static const char s0[] PROGMEM = "Ok";
static const char s1[] PROGMEM = "EmptyInput";
static const char s2[] PROGMEM = "IncompleteInput";
static const char s3[] PROGMEM = "InvalidInput";
static const char s4[] PROGMEM = "NoMemory";
static const char s5[] PROGMEM = "NotSupported";
static const char s6[] PROGMEM = "TooDeep";
static const char* const messages[] PROGMEM = {s0, s1, s2, s3, s4, s5, s6};
ARDUINOJSON_ASSERT(static_cast<size_t>(_code) <
sizeof(messages) / sizeof(messages[0]));
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s0, "Ok");
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s1, "EmptyInput");
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s2, "IncompleteInput");
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s3, "InvalidInput");
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s4, "NoMemory");
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s5, "NotSupported");
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s6, "TooDeep");
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(
const char*, messages,
ARDUINOJSON_EXPAND7({s0, s1, s2, s3, s4, s5, s6}));
return reinterpret_cast<const __FlashStringHelper*>(
pgm_read_ptr(messages + _code));
}

View File

@ -76,3 +76,13 @@ inline void* memcpy_P(void* dst, ARDUINOJSON_NAMESPACE::pgm_p src, size_t n) {
return dst;
}
#endif
#ifndef ARDUINOJSON_DEFINE_PROGMEM_ARRAY
#ifdef PROGMEM
#define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value) \
static type const name[] PROGMEM = value;
#else
#define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value) \
static type const name[] = value;
#endif
#endif