Added tests for FlashStringAdapter

This commit is contained in:
Benoit Blanchon
2020-02-16 17:56:47 +01:00
parent e6ddfc7afb
commit 85499be855
15 changed files with 86 additions and 18 deletions

View File

@ -5,6 +5,7 @@
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Polyfills/assert.hpp>
namespace ARDUINOJSON_NAMESPACE {
// Wraps a const char* so that the our functions are picked only if the
@ -18,6 +19,7 @@ struct pgm_p {
#ifndef strlen_P
inline size_t strlen_P(ARDUINOJSON_NAMESPACE::pgm_p s) {
const char* p = s.address;
ARDUINOJSON_ASSERT(p != NULL);
while (pgm_read_byte(p)) p++;
return size_t(p - s.address);
}
@ -27,6 +29,8 @@ inline size_t strlen_P(ARDUINOJSON_NAMESPACE::pgm_p s) {
inline int strncmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b, size_t n) {
const char* s1 = a;
const char* s2 = b.address;
ARDUINOJSON_ASSERT(s1 != NULL);
ARDUINOJSON_ASSERT(s2 != NULL);
while (n-- > 0) {
char c1 = *s1++;
char c2 = static_cast<char>(pgm_read_byte(s2++));
@ -45,6 +49,8 @@ inline int strncmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b, size_t n) {
inline int strcmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b) {
const char* s1 = a;
const char* s2 = b.address;
ARDUINOJSON_ASSERT(s1 != NULL);
ARDUINOJSON_ASSERT(s2 != NULL);
for (;;) {
char c1 = *s1++;
char c2 = static_cast<char>(pgm_read_byte(s2++));
@ -62,6 +68,8 @@ inline int strcmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b) {
inline void* memcpy_P(void* dst, ARDUINOJSON_NAMESPACE::pgm_p src, size_t n) {
uint8_t* d = reinterpret_cast<uint8_t*>(dst);
const char* s = src.address;
ARDUINOJSON_ASSERT(d != NULL);
ARDUINOJSON_ASSERT(s != NULL);
while (n-- > 0) {
*d++ = pgm_read_byte(s++);
}

View File

@ -6,6 +6,8 @@
#include <ArduinoJson/Namespace.hpp>
#include <stdint.h> // int8_t
namespace ARDUINOJSON_NAMESPACE {
inline int8_t safe_strcmp(const char* a, const char* b) {

View File

@ -7,6 +7,7 @@
#include <WString.h>
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE {

View File

@ -8,6 +8,7 @@
#include <string.h> // strcmp
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE {

View File

@ -4,7 +4,9 @@
#pragma once
#include <ArduinoJson/Memory/MemoryPool.hpp>
#include <ArduinoJson/Polyfills/pgmspace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE {

View File

@ -0,0 +1,18 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// MIT License
#pragma once
#include <ArduinoJson/Polyfills/type_traits.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <typename>
struct IsString : false_type {};
template <typename T>
struct IsString<const T> : IsString<T> {};
template <typename T>
struct IsString<T&> : IsString<T> {};
} // namespace ARDUINOJSON_NAMESPACE

View File

@ -4,7 +4,9 @@
#pragma once
#include <ArduinoJson/Memory/MemoryPool.hpp>
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE {

View File

@ -5,6 +5,7 @@
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE {

View File

@ -5,6 +5,7 @@
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <string.h> // strcmp

View File

@ -4,7 +4,9 @@
#pragma once
#include <ArduinoJson/Memory/MemoryPool.hpp>
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <string>

View File

@ -5,6 +5,7 @@
#pragma once
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE {

View File

@ -4,20 +4,6 @@
#pragma once
#include <ArduinoJson/Memory/MemoryPool.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <typename>
struct IsString : false_type {};
template <typename T>
struct IsString<const T> : IsString<T> {};
template <typename T>
struct IsString<T&> : IsString<T> {};
} // namespace ARDUINOJSON_NAMESPACE
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
#include <ArduinoJson/Strings/RamStringAdapter.hpp>
#include <ArduinoJson/Strings/SizedRamStringAdapter.hpp>