mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Documented quick constraint
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@632 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
62adee5d3d
commit
927748731f
3 changed files with 60 additions and 0 deletions
|
|
@ -50,3 +50,4 @@ compile example/customisation.cpp ;
|
||||||
compile example/async_call.cpp ;
|
compile example/async_call.cpp ;
|
||||||
compile example/retrieve_cref.cpp ;
|
compile example/retrieve_cref.cpp ;
|
||||||
compile example/invoke_functor.cpp ;
|
compile example/invoke_functor.cpp ;
|
||||||
|
compile example/quick_constraint.cpp ;
|
||||||
|
|
|
||||||
46
build/boost/doc/example/quick_constraint.cpp
Normal file
46
build/boost/doc/example/quick_constraint.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
//[ quick_constraint_problem
|
||||||
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
#include <turtle/mock.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class my_class
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit my_class( int data )
|
||||||
|
: data_( data )
|
||||||
|
{}
|
||||||
|
int data_;
|
||||||
|
};
|
||||||
|
std::ostream& operator<<( std::ostream& os, const my_class& c ) // my_class is serializable to an std::ostream
|
||||||
|
{
|
||||||
|
return os << "my_class( " << c.data_ << " )";
|
||||||
|
}
|
||||||
|
|
||||||
|
MOCK_CLASS( my_mock )
|
||||||
|
{
|
||||||
|
MOCK_METHOD( method, 1, void( const my_class& ) ) // how to simply write a custom constraint ?
|
||||||
|
};
|
||||||
|
}
|
||||||
|
//]
|
||||||
|
|
||||||
|
//[ quick_constraint_solution
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
namespace mock // it could also be in the namespace of 'my_class'
|
||||||
|
{
|
||||||
|
bool operator==( const my_class& actual, const std::string& expected ) // the trick is to compare to a string
|
||||||
|
{
|
||||||
|
return boost::lexical_cast< std::string >( actual ) == expected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( method_is_called )
|
||||||
|
{
|
||||||
|
my_mock mock;
|
||||||
|
MOCK_EXPECT( mock.method ).once().with( "my_class( 42 )" ); // the constraint is given as a string
|
||||||
|
mock.method( my_class( 42 ) );
|
||||||
|
}
|
||||||
|
//]
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
[import example/async_call.cpp]
|
[import example/async_call.cpp]
|
||||||
[import example/retrieve_cref.cpp]
|
[import example/retrieve_cref.cpp]
|
||||||
[import example/invoke_functor.cpp]
|
[import example/invoke_functor.cpp]
|
||||||
|
[import example/quick_constraint.cpp]
|
||||||
|
|
||||||
This section highlights not-so-obvious features of the library gathered from real use cases.
|
This section highlights not-so-obvious features of the library gathered from real use cases.
|
||||||
|
|
||||||
|
|
@ -41,4 +42,16 @@ Solution :
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
[section Quickly writing a custom constraint for a serializable type]
|
||||||
|
|
||||||
|
Problem :
|
||||||
|
|
||||||
|
[quick_constraint_problem]
|
||||||
|
|
||||||
|
Solution :
|
||||||
|
|
||||||
|
[quick_constraint_solution]
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue