KiCad PCB EDA Suite
test_coroutine.cpp File Reference

Test suite for coroutines. More...

Go to the source code of this file.

Classes

struct  COROUTINE_TEST_EVENT
 An event in a simple coroutine harness. More...
 
class  COROUTINE_INCREMENTING_HARNESS
 Simple coroutine harness that runs a coroutine that increments a number up to a pre-set limit, spitting out coroutine events as it goes. More...
 

Functions

std::ostream & operator<< (std::ostream &os, const COROUTINE_TEST_EVENT &aObj)
 Define a stream function for logging this type. More...
 
 BOOST_AUTO_TEST_CASE (Increment)
 Declare the test suite. More...
 

Detailed Description

Test suite for coroutines.

See also the coroutine utility in qa/common_tools for a command line test utility.

Definition in file test_coroutine.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( Increment  )

Declare the test suite.

A basic test to repeatedly call a coroutine and check that it yields values as expected.

Definition at line 149 of file test_coroutine.cpp.

150 {
151  const int count = 2;
152 
153  const std::vector<COROUTINE_TEST_EVENT> exp_events = {
161  };
162 
163  std::vector<COROUTINE_TEST_EVENT> received_events;
164 
165  auto handler = [&]( const COROUTINE_TEST_EVENT& aEvent ) {
166  received_events.push_back( aEvent );
167  };
168 
169  COROUTINE_INCREMENTING_HARNESS harness( handler, count );
170 
171  harness.Run();
172 
173  BOOST_CHECK_EQUAL_COLLECTIONS(
174  received_events.begin(), received_events.end(), exp_events.begin(), exp_events.end() );
175 }
An event in a simple coroutine harness.
Simple coroutine harness that runs a coroutine that increments a number up to a pre-set limit,...

References COROUTINE_TEST_EVENT::CALL, COROUTINE_TEST_EVENT::END, COROUTINE_TEST_EVENT::RETURNED, COROUTINE_INCREMENTING_HARNESS::Run(), COROUTINE_TEST_EVENT::START, and COROUTINE_TEST_EVENT::YIELD.

◆ operator<<()

std::ostream& operator<< ( std::ostream &  os,
const COROUTINE_TEST_EVENT aObj 
)

Define a stream function for logging this type.

TODO: convert to boost_test_print_type when Boost minver > 1.64

Definition at line 73 of file test_coroutine.cpp.

74 {
75  os << "COROUTINE_TEST_EVENT[ type: " << (int) aObj.m_type << ", value: " << aObj.m_value
76  << " ]";
77  return os;
78 }

References COROUTINE_TEST_EVENT::m_type, and COROUTINE_TEST_EVENT::m_value.