AUnit  1.7.1
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
All Classes Files Functions Variables Typedefs Macros Pages
Public Member Functions | Static Public Attributes | List of all members
aunit::fake::FakePrint Class Reference

An implementation of Print that writes to an in-memory buffer. More...

#include <FakePrint.h>

Inheritance diagram for aunit::fake::FakePrint:
Inheritance graph
[legend]
Collaboration diagram for aunit::fake::FakePrint:
Collaboration graph
[legend]

Public Member Functions

size_t write (uint8_t c) override
 
size_t write (const uint8_t *buffer, size_t size) override
 
void flush () override
 
const char * getBuffer () const
 Return the NUL terminated string buffer. More...
 

Static Public Attributes

static const uint8_t kBufSize = 8 * sizeof(long long) + 2 + 1
 Size of the internal buffer. More...
 

Detailed Description

An implementation of Print that writes to an in-memory buffer.

The buffer can be retrieved using getBuffer() to verify that the expected string was written to the Print object.

Usage:

* {
*   FakePrint fakePrint;
*   object.printTo(fakePrint);
*   assertEqual("expected", fakePrint.getBuffer());
*   fakePrint.flush();
*   ...
* }
* 

The internal buffer size is just big enough to hold a long long (8 bytes) with 3 bytes to hold the \\r\\n from a println() statement and the terminating NUL character.

This class is an early version of the PrintStr class of the AceCommon library. We don't want to change AUnit to use PrintStr instead because we use AUnit to write the unit tests for AceCommon itself, and it would cause a conceptual cyclic dependency. Also we want AUnit to be self-contained without additional dependencies.

Definition at line 60 of file FakePrint.h.

Member Function Documentation

◆ getBuffer()

const char* aunit::fake::FakePrint::getBuffer ( ) const
inline

Return the NUL terminated string buffer.

After the buffer is no longer needed, the flush() method should be called to reset the internal buffer index to 0.

Definition at line 104 of file FakePrint.h.

Member Data Documentation

◆ kBufSize

const uint8_t aunit::fake::FakePrint::kBufSize = 8 * sizeof(long long) + 2 + 1
static

Size of the internal buffer.

This is just large enough to hold the string representation of one 64-bit integer in binary format (64 bytes), including 2 bytes for the '\r\n' from println() and 1 byte for the terminating NUL.

Definition at line 68 of file FakePrint.h.


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