mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Preview of clang-format changes and CI
This commit is contained in:
parent
bfd1701fcb
commit
805e3b02bf
98 changed files with 6339 additions and 11357 deletions
|
|
@ -7,67 +7,62 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ async_call_problem
|
||||
namespace
|
||||
namespace {
|
||||
class base_class
|
||||
{
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
virtual void method() = 0;
|
||||
};
|
||||
public:
|
||||
virtual void method() = 0;
|
||||
};
|
||||
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class( base_class& );
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class(base_class&);
|
||||
|
||||
void flush(); // repetitively calling this method will in turn call base_class::method at some point
|
||||
};
|
||||
}
|
||||
void flush(); // repetitively calling this method will in turn call base_class::method at some point
|
||||
};
|
||||
} // namespace
|
||||
//]
|
||||
|
||||
//[ 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>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
namespace
|
||||
namespace {
|
||||
template<typename F>
|
||||
void check(bool& condition, F flush, int attempts = 100, int sleep = 100)
|
||||
{
|
||||
template< typename F >
|
||||
void check( bool& condition, F flush, int attempts = 100, int sleep = 100 )
|
||||
while(!condition && attempts > 0)
|
||||
{
|
||||
while( !condition && attempts > 0 )
|
||||
{
|
||||
--attempts;
|
||||
boost::this_thread::sleep( boost::posix_time::milliseconds( sleep ) );
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
MOCK_BASE_CLASS( mock_base_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 0 )
|
||||
};
|
||||
void set_bool(bool& b)
|
||||
{
|
||||
b = true;
|
||||
--attempts;
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(sleep));
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( method_is_called )
|
||||
MOCK_BASE_CLASS(mock_base_class, base_class){MOCK_METHOD(method, 0)};
|
||||
void set_bool(bool& b)
|
||||
{
|
||||
b = true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(method_is_called)
|
||||
{
|
||||
mock_base_class m;
|
||||
my_class c( 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( boost::bind(&set_bool, done) );
|
||||
MOCK_EXPECT(m.method).once().calls(boost::bind(&set_bool, done));
|
||||
#else
|
||||
MOCK_EXPECT( m.method ).once().calls( boost::lambda::var( done ) = true );
|
||||
MOCK_EXPECT(m.method).once().calls(boost::lambda::var(done) = true);
|
||||
#endif
|
||||
check( done, boost::bind( &my_class::flush, &c ) ); // just wait on done, flushing from time to time
|
||||
check(done, boost::bind(&my_class::flush, &c)); // just wait on done, flushing from time to time
|
||||
}
|
||||
//]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue