mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 12:02:14 +02:00
Added tests for DeserializationError::f_str()
This commit is contained in:
@ -24,6 +24,11 @@ inline uint8_t pgm_read_byte(const void* p) {
|
|||||||
return *reinterpret_cast<const uint8_t*>(convertFlashToPtr(p));
|
return *reinterpret_cast<const uint8_t*>(convertFlashToPtr(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const void* pgm_read_ptr(const void* p) {
|
inline void* pgm_read_ptr(const void* p) {
|
||||||
return *reinterpret_cast<const void* const*>(convertFlashToPtr(p));
|
return *reinterpret_cast<void* const*>(convertFlashToPtr(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value) \
|
||||||
|
static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = value; \
|
||||||
|
static type const* name = reinterpret_cast<type const*>( \
|
||||||
|
convertPtrToFlash(ARDUINOJSON_CONCAT2(name, _progmem)));
|
||||||
|
@ -165,3 +165,22 @@ TEST_CASE("Reader<const __FlashStringHelper*>") {
|
|||||||
REQUIRE(buffer[6] == 'g');
|
REQUIRE(buffer[6] == 'g');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void testStringification(DeserializationError error,
|
||||||
|
std::string expected) {
|
||||||
|
const __FlashStringHelper* s = error.f_str();
|
||||||
|
CHECK(reinterpret_cast<const char*>(convertFlashToPtr(s)) == expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TEST_STRINGIFICATION(symbol) \
|
||||||
|
testStringification(DeserializationError::symbol, #symbol)
|
||||||
|
|
||||||
|
TEST_CASE("DeserializationError::f_str()") {
|
||||||
|
TEST_STRINGIFICATION(Ok);
|
||||||
|
TEST_STRINGIFICATION(EmptyInput);
|
||||||
|
TEST_STRINGIFICATION(IncompleteInput);
|
||||||
|
TEST_STRINGIFICATION(InvalidInput);
|
||||||
|
TEST_STRINGIFICATION(NoMemory);
|
||||||
|
TEST_STRINGIFICATION(NotSupported);
|
||||||
|
TEST_STRINGIFICATION(TooDeep);
|
||||||
|
}
|
||||||
|
@ -86,18 +86,20 @@ class DeserializationError {
|
|||||||
return messages[_code];
|
return messages[_code];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ARDUINOJSON_EXPAND7(a, b, c, d, e, f, g) a, b, c, d, e, f, g
|
||||||
|
|
||||||
#if ARDUINOJSON_ENABLE_PROGMEM
|
#if ARDUINOJSON_ENABLE_PROGMEM
|
||||||
const __FlashStringHelper* f_str() const {
|
const __FlashStringHelper* f_str() const {
|
||||||
static const char s0[] PROGMEM = "Ok";
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s0, "Ok");
|
||||||
static const char s1[] PROGMEM = "EmptyInput";
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s1, "EmptyInput");
|
||||||
static const char s2[] PROGMEM = "IncompleteInput";
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s2, "IncompleteInput");
|
||||||
static const char s3[] PROGMEM = "InvalidInput";
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s3, "InvalidInput");
|
||||||
static const char s4[] PROGMEM = "NoMemory";
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s4, "NoMemory");
|
||||||
static const char s5[] PROGMEM = "NotSupported";
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s5, "NotSupported");
|
||||||
static const char s6[] PROGMEM = "TooDeep";
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s6, "TooDeep");
|
||||||
static const char* const messages[] PROGMEM = {s0, s1, s2, s3, s4, s5, s6};
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(
|
||||||
ARDUINOJSON_ASSERT(static_cast<size_t>(_code) <
|
const char*, messages,
|
||||||
sizeof(messages) / sizeof(messages[0]));
|
ARDUINOJSON_EXPAND7({s0, s1, s2, s3, s4, s5, s6}));
|
||||||
return reinterpret_cast<const __FlashStringHelper*>(
|
return reinterpret_cast<const __FlashStringHelper*>(
|
||||||
pgm_read_ptr(messages + _code));
|
pgm_read_ptr(messages + _code));
|
||||||
}
|
}
|
||||||
|
@ -76,3 +76,13 @@ inline void* memcpy_P(void* dst, ARDUINOJSON_NAMESPACE::pgm_p src, size_t n) {
|
|||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
||||||
|
Reference in New Issue
Block a user