AUnit  1.0.0
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
Public Member Functions | Static Public Attributes | List of all members
aunit::internal::FCString Class Reference

A union of (const char*) and (const __FlashStringHelper*) with a discriminator. More...

#include <FCString.h>

Public Member Functions

 FCString ()
 Default constructor initializes to a nullptr of kCStringType. More...
 
 FCString (const char *s)
 Construct with a c-string. More...
 
 FCString (const __FlashStringHelper *s)
 Construct with a flash string. More...
 
uint8_t getType () const
 Get the internal type of string. More...
 
const char * getCString () const
 Get the c-string pointer. More...
 
const __FlashStringHelper * getFString () const
 Get the flash string pointer. More...
 
void print (Print *printer) const
 Convenience method for printing an FCString. More...
 
void println (Print *printer) const
 Convenience method for printing an FCString. More...
 
int compareTo (const FCString &that) const
 Compare to another FCString. More...
 
int compareToN (const char *that, size_t n) const
 Compare to C-string using the first n characters. More...
 
int compareToN (const __FlashStringHelper *that, size_t n) const
 Compare to a flash string using the first n characters. More...
 

Static Public Attributes

static const uint8_t kCStringType = 0
 
static const uint8_t kFStringType = 1
 

Detailed Description

A union of (const char*) and (const __FlashStringHelper*) with a discriminator.

This allows us to treat these 2 strings like a single object. The major reason this class is needed is because the F() cannot be used outside a function, it can only be used inside a function, so we are forced to use normal c-strings instead of F() strings when manually creating Test or TestOnce instances.

I deliberately decided not to inherit from Printable. While it is convenient to be able to call Print::print() with an instance of this class, the cost is 2 (AVR) or 4 (Teensy-ARM or ESP8266) extra bytes of static memory for the v-table pointer for each instance. But each instance is only 3 (AVR) or 5 (Teensy-ARM or ESP8266) bytes big, so the cost of 50-100 bytes of static memory for a large suite of 25 unit tests does not seem worth the minor convenience.

Instead, the print() and println() methods invert the dependency and accept a pointer to 'Print'.

Definition at line 55 of file FCString.h.

Constructor & Destructor Documentation

◆ FCString() [1/3]

aunit::internal::FCString::FCString ( )
inline

Default constructor initializes to a nullptr of kCStringType.

Definition at line 61 of file FCString.h.

◆ FCString() [2/3]

aunit::internal::FCString::FCString ( const char *  s)
inlineexplicit

Construct with a c-string.

Definition at line 64 of file FCString.h.

◆ FCString() [3/3]

aunit::internal::FCString::FCString ( const __FlashStringHelper *  s)
inlineexplicit

Construct with a flash string.

Definition at line 70 of file FCString.h.

Member Function Documentation

◆ compareTo()

int aunit::internal::FCString::compareTo ( const FCString that) const

Compare to another FCString.

Definition at line 55 of file FCString.cpp.

◆ compareToN() [1/2]

int aunit::internal::FCString::compareToN ( const char *  that,
size_t  n 
) const

Compare to C-string using the first n characters.

This is expected to be used only for TestRunner::exclude() and TestRunner::include().

Definition at line 71 of file FCString.cpp.

◆ compareToN() [2/2]

int aunit::internal::FCString::compareToN ( const __FlashStringHelper *  that,
size_t  n 
) const

Compare to a flash string using the first n characters.

This is expected to be used only for TestRunner::exclude() and TestRunner::include().

Definition at line 79 of file FCString.cpp.

◆ getCString()

const char* aunit::internal::FCString::getCString ( ) const
inline

Get the c-string pointer.

Definition at line 79 of file FCString.h.

◆ getFString()

const __FlashStringHelper* aunit::internal::FCString::getFString ( ) const
inline

Get the flash string pointer.

Definition at line 82 of file FCString.h.

◆ getType()

uint8_t aunit::internal::FCString::getType ( ) const
inline

Get the internal type of string.

Definition at line 76 of file FCString.h.

◆ print()

void aunit::internal::FCString::print ( Print *  printer) const

Convenience method for printing an FCString.

Definition at line 32 of file FCString.cpp.

◆ println()

void aunit::internal::FCString::println ( Print *  printer) const

Convenience method for printing an FCString.

Definition at line 42 of file FCString.cpp.


The documentation for this class was generated from the following files: