From eda20ec3c162fe2b10f9d088d84861724d06fbb7 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 4 Jun 2013 18:16:38 +0200 Subject: doc: Add some more documentation for Mock Objects. --- include/cmocka.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'include') diff --git a/include/cmocka.h b/include/cmocka.h index b6416ac..372e134 100644 --- a/include/cmocka.h +++ b/include/cmocka.h @@ -131,6 +131,42 @@ cast_to_largest_integral_type(cast_to_pointer_integral_type(value)) * real objects. Instead of calling the real objects, the tested object calls a * mock object that merely asserts that the correct methods were called, with * the expected parameters, in the correct order. + * + * + * + * Because the will_return() and mock() are intended to be used in pairs, the + * cmocka library would fail the test if there are more values pushed onto the + * stack using will_return() than consumed with mock() and vice-versa. + * + * The following unit test stub illustrates how would a unit test instruct the + * mock object to return a particular value: + * + * @code + * will_return(chef_cook, "hotdog"); + * will_return(chef_cook, 0); + * @endcode + * + * Now the mock object can check if the parameter it received is the parameter + * which is expected by the test driver. This can be done the following way: + * + * @code + * int chef_cook(const char *order, char **dish_out) + * { + * check_expected(order); + * } + * @endcode + * + * For a complete example please at a look + * here. * * @{ */ -- cgit v1.2.3