AUnit
1.1
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
|
Various macros to smooth over the differences among the various platforms with regards to their support for flash strings and the various macros used to create and access them. More...
Go to the source code of this file.
Macros | |
#define | AUNIT_FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer)) |
The FPSTR() macro is defined on ESP8266, not defined on Teensy and AVR, and broken on ESP32. More... | |
Various macros to smooth over the differences among the various platforms with regards to their support for flash strings and the various macros used to create and access them.
On AVR, flash strings are fully supported through the F() and PSTR() macros, and the (const __FlashStringHelper*) pointer. However, the useful FPSTR() macro is not defined.
On Teensy-ARM, flash strings are not supported, but F(), PSTR() and (const __FlashStringHelper*) are defined. The useful FPSTR() macro is not defined.
On the ESP8266 platform, flash strings are implemented, and the F(), PSTR() and __FlashStringHelper are defined, but the implementation is brittle and can fail with obscure errors messages. For a single compilation unit, a flash string cannot be defined in both an inline and non-inline contexts (see https://github.com/esp8266/Arduino/issues/3369). In some cases (e.g. TestMacros.h), we were able to move the F() macro into a non-inline context. But in other cases (e.g. AssertVerboseMacros.h), the end-user can choose to use an assertXxx() macro inside an inline function, which breaks the compiler. Therefore, I chose to use normal (const char*) strings instead of flash strings in those assertXxx() macros. In addition, the ESP8266 platform defines a useful FPSTR() macro which converts a (const char*) returned by PSTR() into a (const __FlashStringHelper*) pointer.
On the ESP32, flash strings are not implemented, but the various F(), PSTR() and __FlashStringHelper symbols are defined for compatibility, similar to Teensy-ARM. However, the implementation of FPSTR() is incorrect, see https://github.com/espressif/arduino-esp32/issues/1371. That macro should return a (const __FlashStringHelper*) pointer, but is defined to return a (const char*) pointer.
To make AUnit work under all of the above platforms, I chose to support flash strings only on the AVR. I create custom versions of the F() and FPSTR() macros below to accomplish this.
Definition in file Flash.h.
#define AUNIT_FPSTR | ( | pstr_pointer | ) | (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer)) |
The FPSTR() macro is defined on ESP8266, not defined on Teensy and AVR, and broken on ESP32.
We define our onw version to make this work on all 4 platforms. We might be able to use just FPSTR() if https://github.com/espressif/arduino-esp32/issues/1371 is fixed.