BusBricks: arduinoMocking::MockSerial Class Reference
BusBricks  0.1
Customize bus-communication
Loading...
Searching...
No Matches
arduinoMocking::MockSerial Class Reference

Simulates Arduino's Serial class for testing purposes. More...

#include <mockArduino.h>

Public Member Functions

 MockSerial ()
 Constructs a MockSerial object.
 
void begin (unsigned long baudrate)
 Begins serial communication with the specified baud rate.
 
void print (const std::string &str)
 Prints a string to the serial output.
 
void print (char c)
 Prints a character to the serial output.
 
void print (int num)
 Prints an integer to the serial output.
 
void print (unsigned int num)
 Prints an unsigned integer to the serial output.
 
void print (long num)
 Prints a long integer to the serial output.
 
void print (unsigned long num)
 Prints an unsigned long integer to the serial output.
 
void print (double num)
 Prints a double to the serial output.
 
void println (const std::string &str)
 Prints a string followed by a newline to the serial output.
 
void println (char c)
 Prints a character followed by a newline to the serial output.
 
void println (int num)
 Prints an integer followed by a newline to the serial output.
 
void println (unsigned int num)
 Prints an unsigned integer followed by a newline to the serial output.
 
void println (long num)
 Prints a long integer followed by a newline to the serial output.
 
void println (unsigned long num)
 Prints an unsigned long integer followed by a newline to the serial output.
 
void println (double num)
 Prints a double followed by a newline to the serial output.
 
void println ()
 Prints a newline to the serial output.
 
int available ()
 Returns the number of bytes available to read from the serial input buffer.
 
int read ()
 Reads a byte from the serial input buffer.
 
size_t write (uint8_t byte)
 Writes a byte to the serial output.
 
void simulateInput ()
 Simulates user input by adding characters to the input buffer.
 
void simulateInput (std::string input)
 Simulates user input by adding a predefined string to the input buffer.
 

Detailed Description

Simulates Arduino's Serial class for testing purposes.

This class provides methods for serial communication, including print, println, and simulated input.

Member Function Documentation

◆ available()

int arduinoMocking::MockSerial::available ( )

Returns the number of bytes available to read from the serial input buffer.

Returns
The number of bytes available (size of input buffer).

◆ begin()

void arduinoMocking::MockSerial::begin ( unsigned long baudrate)

Begins serial communication with the specified baud rate.

Prints a message indicating the baud rate in the mock implementation.

Parameters
baudrateThe baud rate for serial communication.

◆ print() [1/7]

void arduinoMocking::MockSerial::print ( char c)

Prints a character to the serial output.

Parameters
cThe character to print.

◆ print() [2/7]

void arduinoMocking::MockSerial::print ( const std::string & str)

Prints a string to the serial output.

Parameters
strThe string to print.
Here is the caller graph for this function:

◆ print() [3/7]

void arduinoMocking::MockSerial::print ( double num)

Prints a double to the serial output.

Parameters
numThe double to print.

◆ print() [4/7]

void arduinoMocking::MockSerial::print ( int num)

Prints an integer to the serial output.

Parameters
numThe integer to print.

◆ print() [5/7]

void arduinoMocking::MockSerial::print ( long num)

Prints a long integer to the serial output.

Parameters
numThe long integer to print.

◆ print() [6/7]

void arduinoMocking::MockSerial::print ( unsigned int num)

Prints an unsigned integer to the serial output.

Parameters
numThe unsigned integer to print.

◆ print() [7/7]

void arduinoMocking::MockSerial::print ( unsigned long num)

Prints an unsigned long integer to the serial output.

Parameters
numThe unsigned long integer to print.

◆ println() [1/7]

void arduinoMocking::MockSerial::println ( char c)

Prints a character followed by a newline to the serial output.

Parameters
cThe character to print.

◆ println() [2/7]

void arduinoMocking::MockSerial::println ( const std::string & str)

Prints a string followed by a newline to the serial output.

Parameters
strThe string to print.
Here is the caller graph for this function:

◆ println() [3/7]

void arduinoMocking::MockSerial::println ( double num)

Prints a double followed by a newline to the serial output.

Parameters
numThe double to print.

◆ println() [4/7]

void arduinoMocking::MockSerial::println ( int num)

Prints an integer followed by a newline to the serial output.

Parameters
numThe integer to print.

◆ println() [5/7]

void arduinoMocking::MockSerial::println ( long num)

Prints a long integer followed by a newline to the serial output.

Parameters
numThe long integer to print.

◆ println() [6/7]

void arduinoMocking::MockSerial::println ( unsigned int num)

Prints an unsigned integer followed by a newline to the serial output.

Parameters
numThe unsigned integer to print.

◆ println() [7/7]

void arduinoMocking::MockSerial::println ( unsigned long num)

Prints an unsigned long integer followed by a newline to the serial output.

Parameters
numThe unsigned long integer to print.

◆ read()

int arduinoMocking::MockSerial::read ( )

Reads a byte from the serial input buffer.

Returns
The byte read, or -1 if no data is available.

◆ simulateInput() [1/2]

void arduinoMocking::MockSerial::simulateInput ( )

Simulates user input by adding characters to the input buffer.

Prompts the user to enter a string, which is added to the buffer.

◆ simulateInput() [2/2]

void arduinoMocking::MockSerial::simulateInput ( std::string input)

Simulates user input by adding a predefined string to the input buffer.

Parameters
inputThe string to add to the buffer.

◆ write()

size_t arduinoMocking::MockSerial::write ( uint8_t byte)

Writes a byte to the serial output.

Parameters
byteThe byte to write.
Returns
The number of bytes written (always 1 in the mock implementation).

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