Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
AsyncCanTest Class Reference

Test fixture base class for tests that need a CAN-based interface(but not necessary specific to OpenLCB). More...

#include <async_if_test_helper.hxx>

Inheritance diagram for AsyncCanTest:
openlcb::AsyncIfTest openlcb::AsyncNodeTest openlcb::AsyncDatagramTest openlcb::TractionTest openlcb::TwoNodeDatagramTest openlcb::StreamTestBase

Static Public Member Functions

static void SetUpTestCase ()
 Initializes test case with CAN0.
 
static void TearDownTestCase ()
 De-Initializes test case with CAN0.
 

Protected Member Functions

void wait ()
 Delays the current thread until we are certain that all asynchrnous processing has completed.
 
void twait ()
 Delays the current thread until all asynchronous processing and all pending timers have completed.
 
void expect_any_packet ()
 Ignores all produced packets.
 
void print_all_packets ()
 Prints all packets sent to the canbus until the end of the current test function.
 
void send_packet (const string &gc_packet)
 Injects a packet to the interface.
 
void clear_expect (bool strict=false)
 Clears all existing expectations on the CAN-bus packets.
 
void send_packet_and_flush_expect (const string &pkt)
 Sends a packet to the canbus, waits for the executor to clear, and then verifies all previous expectations.
 

Protected Attributes

NiceMock< MockSendcanBus_
 Helper object for setting expectations on the packets sent on the bus.
 
std::unique_ptr< HubPortprinter_
 Object for debug-printing every packet (if requested).
 

Detailed Description

Test fixture base class for tests that need a CAN-based interface(but not necessary specific to OpenLCB).

The direct use of this class is useful only when other CAN-based protocol flows need to be tested. The OpenLCB test fixtures are inheriting from this class.

Definition at line 86 of file async_if_test_helper.hxx.

Constructor & Destructor Documentation

◆ AsyncCanTest()

AsyncCanTest::AsyncCanTest ( )
inlineprotected

Definition at line 105 of file async_if_test_helper.hxx.

◆ ~AsyncCanTest()

AsyncCanTest::~AsyncCanTest ( )
inlineprotected

Definition at line 110 of file async_if_test_helper.hxx.

Member Function Documentation

◆ clear_expect()

void AsyncCanTest::clear_expect ( bool  strict = false)
inlineprotected

Clears all existing expectations on the CAN-bus packets.

Usually means that all previously expressed expectations must have been met by this point.

Parameters
strictif true, does not allow any unknown/unexpected/spurious packets to have arrived; i.e., fails the test if there was a packet coming with no expectation.

Definition at line 226 of file async_if_test_helper.hxx.

◆ expect_any_packet()

void AsyncCanTest::expect_any_packet ( )
inlineprotected

Ignores all produced packets.

Tihs can be used in tests where the expectations are tested in a higher level than monitoring the CANbus traffic.

Definition at line 180 of file async_if_test_helper.hxx.

◆ print_all_packets()

void AsyncCanTest::print_all_packets ( )
inlineprotected

Prints all packets sent to the canbus until the end of the current test function.

Definition at line 190 of file async_if_test_helper.hxx.

◆ send_packet()

void AsyncCanTest::send_packet ( const string &  gc_packet)
inlineprotected

Injects a packet to the interface.

This acts as if a different node on the CANbus had sent that packet.

Example: send_packet(":X195B4001N05010101FFFF0000;");

Parameters
gc_packetthe packet in GridConnect format, including the leading : and trailing ;

Definition at line 209 of file async_if_test_helper.hxx.

◆ send_packet_and_flush_expect()

void AsyncCanTest::send_packet_and_flush_expect ( const string &  pkt)
inlineprotected

Sends a packet to the canbus, waits for the executor to clear, and then verifies all previous expectations.

Parameters
pktgridconnnect-formatted packet to send.

Definition at line 258 of file async_if_test_helper.hxx.

◆ SetUpTestCase()

static void AsyncCanTest::SetUpTestCase ( )
inlinestatic

Initializes test case with CAN0.

Note: if a child test implements SetUpTestCase themself, they must ensure to call this function.

Definition at line 91 of file async_if_test_helper.hxx.

◆ TearDownTestCase()

static void AsyncCanTest::TearDownTestCase ( )
inlinestatic

De-Initializes test case with CAN0.

Note: if a child test implements TearDownTestCase themself, they must ensure to call this function.

Definition at line 99 of file async_if_test_helper.hxx.

◆ twait()

void AsyncCanTest::twait ( )
inlineprotected

Delays the current thread until all asynchronous processing and all pending timers have completed.

Definition at line 128 of file async_if_test_helper.hxx.

◆ wait()

void AsyncCanTest::wait ( )
inlineprotected

Delays the current thread until we are certain that all asynchrnous processing has completed.

Definition at line 121 of file async_if_test_helper.hxx.

Member Data Documentation

◆ canBus_

NiceMock<MockSend> AsyncCanTest::canBus_
protected

Helper object for setting expectations on the packets sent on the bus.

Definition at line 266 of file async_if_test_helper.hxx.

◆ printer_

std::unique_ptr<HubPort> AsyncCanTest::printer_
protected

Object for debug-printing every packet (if requested).

Definition at line 268 of file async_if_test_helper.hxx.


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