Include examples in CI tests

Also fix and update examples and documentation where required
This allows to make sure examples are actually runnable avoiding them to
become outdated
This commit is contained in:
Alexander Grund 2020-07-11 14:01:18 +02:00
parent a6aa140148
commit 5ef17d0e33
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
42 changed files with 400 additions and 285 deletions

View file

@ -7,7 +7,7 @@
// http://www.boost.org/LICENSE_1_0.txt)
//[ async_call_problem
namespace
namespace mock_test
{
class base_class
{
@ -17,6 +17,7 @@ namespace
class my_class
{
base_class& b;
public:
explicit my_class( base_class& );
@ -25,14 +26,23 @@ namespace
}
//]
namespace mock_test
{
my_class::my_class( base_class& b): b(b){}
void my_class::flush()
{
static int secret_value = 7;
if(--secret_value == 0)
b.method();
}
}
//[ async_call_solution
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/thread.hpp>
#include <turtle/mock.hpp>
namespace
namespace mock_test
{
template< typename F >
void check( bool& condition, F flush, int attempts = 100, int sleep = 100 )
@ -49,25 +59,15 @@ namespace
{
MOCK_METHOD( method, 0 )
};
void set_bool(bool& b)
{
b = true;
}
}
BOOST_AUTO_TEST_CASE( method_is_called )
{
using namespace mock_test;
mock_base_class m;
my_class c( m );
bool done = false;
// when method is called it will set done to true
// Note: Boost 1.57 introduced a bug preventing usage of the lambda with clang in C++98
// See: https://svn.boost.org/trac10/ticket/10785
#if defined(BOOST_CLANG) && (BOOST_VERSION >= 105700)
MOCK_EXPECT( m.method ).once().calls( std::bind(&set_bool, done) );
#else
MOCK_EXPECT( m.method ).once().calls( boost::lambda::var( done ) = true );
#endif
check( done, std::bind( &my_class::flush, &c ) ); // just wait on done, flushing from time to time
MOCK_EXPECT( m.method ).once().calls( [&done](){ done = true; } );
check( done, [&c](){ c.flush(); } ); // just wait on done, flushing from time to time
}
//]