Added tests for Flash strings (closes #1070)

This commit is contained in:
Benoit Blanchon
2019-08-11 10:47:19 +02:00
parent 63d7d87080
commit 0d339300f9
6 changed files with 104 additions and 9 deletions

View File

@@ -14,7 +14,7 @@ class FlashStringAdapter {
if (!other && !_str) return 0;
if (!_str) return -1;
if (!other) return 1;
return -strcmp_P(other, reinterpret_cast<const char*>(_str));
return int8_t(-strcmp_P(other, reinterpret_cast<const char*>(_str)));
}
bool equals(const char* expected) const {

View File

@@ -15,7 +15,8 @@ class SizedFlashStringAdapter {
if (!other && !_str) return 0;
if (!_str) return -1;
if (!other) return 1;
return -strncmp_P(other, reinterpret_cast<const char*>(_str), _size);
return int8_t(
-strncmp_P(other, reinterpret_cast<const char*>(_str), _size));
}
bool equals(const char* expected) const {
@@ -29,7 +30,7 @@ class SizedFlashStringAdapter {
char* save(MemoryPool* pool) const {
if (!_str) return NULL;
char* dup = pool->allocFrozenString(_size);
if (dup) memcpy_P(dup, (const char*)_str, _size);
if (dup) memcpy_P(dup, reinterpret_cast<const char*>(_str), _size);
return dup;
}