From 2c47f8aa490852d4db1a9a4824415005e2ece8ad Mon Sep 17 00:00:00 2001 From: mj Date: Sun, 18 Dec 2016 15:19:08 +0100 Subject: [PATCH] Added simple explanation and example to readme file --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index fbac485..bf593d0 100644 --- a/README.md +++ b/README.md @@ -448,6 +448,32 @@ TEST_F(FFFTestSuite, test_fake_with_function_pointer) /* and ofcourse our custom fake correctly calls the registered callback */ ASSERT_EQ(cb_timeout_called, 1); } +``` +## How do I reuse a fake across multiple test-suites? +FFF functions like FAKE_VALUE_FUNC will perform both the declaration AND the definition of the fake function and the corresponding data structs. This cannot be placed in a header, since it will lead to multiple definitions of the fake functions. + +The solution is to separate declaration and definition of the fakes, and place the declaration into a public header file, and the definition into a private source file. + +Here is an example of how it could be done: + +``` +/* Public header file */ +#include "fff.h" + +DECLARE_FAKE_VALUE_FUNC(int, value_function, int, int); +DECLARE_FAKE_VOID_FUNC(void_function, int, int); +DECLARE_FAKE_VALUE_FUNC_VARARG(int, value_function_vargs, const char *, int, ...); +DECLARE_FAKE_VOID_FUNC_VARARG(void_function_vargs, const char *, int, ...); + + +/* Private source file file */ +#include "public_header.h" + +DEFINE_FAKE_VALUE_FUNC(int, value_function, int, int); +DEFINE_FAKE_VOID_FUNC(void_function, int, int); +DEFINE_FAKE_VALUE_FUNC_VARARG(int, value_function_vargs, const char *, int, ...); +DEFINE_FAKE_VOID_FUNC_VARARG(void_function_vargs, const char *, int, ...); + ``` ## Find out more...