diff --git a/README.md b/README.md index 2526170..4f9cbf2 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,6 @@ Here's how it works: They are reset by calling FFF_RESET_HISTORY(); - ## Default Argument History The framework will by default store the arguments for the last ten calls made @@ -329,6 +328,27 @@ The fake will call your custom functions in the order specified by the SET_CUSTO macro. When the last custom fake is reached the fake will keep calling the last custom 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. fff will +save the history of returned values so this can be easily checked, even when +you use a sequence of custom fakes. Here's a simple example: + + TEST_F(FFFTestSuite, return_value_sequence_saved_in_history) + { + long myReturnVals[3] = { 3, 7, 9 }; + SET_RETURN_SEQ(longfunc0, myReturnVals, 3); + longfunc0(); + longfunc0(); + longfunc0(); + ASSERT_EQ(myReturnVals[0], longfunc0_fake.return_val_history[0]); + ASSERT_EQ(myReturnVals[1], longfunc0_fake.return_val_history[1]); + ASSERT_EQ(myReturnVals[2], longfunc0_fake.return_val_history[2]); + } + +You access the returned values in the return_val_history field. + ## 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.