Skip to content

Commit

Permalink
Added simple explanation and example to readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
aunsbjerg committed Dec 18, 2016
1 parent f4b03ca commit 2c47f8a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down

0 comments on commit 2c47f8a

Please sign in to comment.