Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wulfgarpro authored Dec 4, 2018
1 parent 5b930a1 commit 4e03141
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ macro. When the last custom fake is reached the fake will keep calling the last
fake in the sequence. This macro works much like the SET_RETURN_SEQ macro.
## Return value history
Say you have two functions f1 and f2. f2 must be called to release some resource
allocated by f1, but only in the cases where f1 returns zero. f1 could be
pthread_mutex_trylock and f2 could be pthread_mutex_unlock. <tt>fff</tt> will
Expand Down Expand Up @@ -432,6 +433,7 @@ could call the real <tt>fprintf()</tt> like this:
}
## How do I specify calling conventions for my fake functions?
FFF has a limited capability for enabling specification of Microsoft's Visual C/C++ calling conventions, but this support must be enabled when generating FFF's header file `fff.h`.
```bash
Expand All @@ -448,6 +450,7 @@ FAKE_VALUE_FUNC(long, __cdecl, longfunc0);
```
## How do I fake a function that returns a value by reference?
The basic mechanism that FFF provides you in this case is the custom_fake field described in the *Custom Return Value Delegate* example above.
You need to create a custom function (e.g. getTime_custom_fake) to produce the output optionally by use of a helper variable (e.g. getTime_custom_now) to retrieve that output from. Then some creativity to tie it all together. The most important part (IMHO) is to keep your test case readable and maintainable.
Expand Down Expand Up @@ -487,6 +490,7 @@ TEST_F(FFFTestSuite, when_value_custom_fake_called_THEN_it_returns_custom_output
```

## How do I fake a function with a function pointer parameter?

Using FFF to stub functions that have function pointer parameter can cause problems when trying to stub them. Presented here is an example how to deal with this situation.

If you need to stub a function that has a function pointer parameter, e.g. something like:
Expand Down Expand Up @@ -570,6 +574,7 @@ TEST_F(FFFTestSuite, test_fake_with_function_pointer)
}
```
## 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.
Expand Down Expand Up @@ -611,7 +616,7 @@ So whats the point?
* To work in both C and C++ test environments
## Under the hood:
## Under the Hood
* The fff.h header file is generated by a ruby script
* There are tests under src/test
* There is an example for testing an embedded UI and a hardware driver under src/examples
Expand All @@ -622,6 +627,6 @@ So whats the point?
|-------|-------------|---------|
| FAKE_VOID_FUNC(fn [,arg_types*]); | Define a fake function named fn returning void with n arguments | FAKE_VOID_FUNC(DISPLAY_output_message, const char*); |
| FAKE_VALUE_FUNC(return_type, fn [,arg_types*]); | Define a fake function returning a value with type return_type taking n arguments | FAKE_VALUE_FUNC(int, DISPLAY_get_line_insert_index); |
| FAKE_VOID_FUNC_VARARG(fn [,arg_types*], ...); | Define a fake variadic function returning a value with type return_type taking n arguments and n variadic arguments | FAKE_VOID_FUNC_VARARG(fn, const char*, ...) |
| FAKE_VOID_FUNC_VARARG(fn [,arg_types*], ...); | Define a fake variadic function returning void with type return_type taking n arguments and n variadic arguments | FAKE_VOID_FUNC_VARARG(fn, const char*, ...) |
| FAKE_VALUE_FUNC_VARARG(return_type, fn [,arg_types*], ...); | Define a fake variadic function returning a value with type return_type taking n arguments and n variadic arguments | FAKE_VALUE_FUNC_VARARG(int, fprintf, FILE*, const char*, ...) |
| RESET_FAKE(fn); | Reset the state of fake function called fn | RESET_FAKE(DISPLAY_init); |

0 comments on commit 4e03141

Please sign in to comment.