Added documentation in the limitations section about why non-virtual methods cannot be mocked

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@693 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2013-10-03 07:59:17 +00:00
parent 7c3714169d
commit f77cac0103
2 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1,19 @@
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
#include <turtle/mock.hpp>
//[ limitations_non_virtual_method_problem
class base
{
public:
void method() // the method is not virtual
{}
};
//]
//[ limitations_non_virtual_method_problem_2
MOCK_BASE_CLASS( mock_base, base )
{
MOCK_METHOD( method, 0 )
};
//]

View file

@ -1,6 +1,7 @@
[section Limitations]
[import example/limitations_literal_zero.cpp]
[import example/limitations_throw_specifier.cpp]
[import example/limitations_non_virtual_method.cpp]
[import example/limitations_template_method.cpp]
[import example/limitations_private_method.cpp]
[import example/limitations_comma_in_macro.cpp]
@ -59,6 +60,22 @@ While still somewhat possible, mocking a template method is indeed a bit cumbers
[endsect]
[section Non-virtual methods cannot be mocked]
Given :
[limitations_non_virtual_method_problem]
the following code compiles but will not work as expected :
[limitations_non_virtual_method_problem_2]
The mock object will never be exercised because the library relies on polymorphism to hook the calls.
There is no other solution than to refactor the production code, the most simple being to change the method to virtual.
[endsect]
[section Private virtual methods cannot be mocked without spelling out the signature]
Given :