gmock_faq.md (googletest-release-1.11.0) | : | gmock_faq.md (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 372 | skipping to change at line 372 | |||
### I want to define a custom action. Should I use Invoke() or implement the Act ionInterface interface? | ### I want to define a custom action. Should I use Invoke() or implement the Act ionInterface interface? | |||
Either way is fine - you want to choose the one that's more convenient for your | Either way is fine - you want to choose the one that's more convenient for your | |||
circumstance. | circumstance. | |||
Usually, if your action is for a particular function type, defining it using | Usually, if your action is for a particular function type, defining it using | |||
`Invoke()` should be easier; if your action can be used in functions of | `Invoke()` should be easier; if your action can be used in functions of | |||
different types (e.g. if you are defining `Return(*value*)`), | different types (e.g. if you are defining `Return(*value*)`), | |||
`MakePolymorphicAction()` is easiest. Sometimes you want precise control on what | `MakePolymorphicAction()` is easiest. Sometimes you want precise control on what | |||
types of functions the action can be used in, and implementing `ActionInterface` | types of functions the action can be used in, and implementing `ActionInterface` | |||
is the way to go here. See the implementation of `Return()` in | is the way to go here. See the implementation of `Return()` in `gmock-actions.h` | |||
`testing/base/public/gmock-actions.h` for an example. | for an example. | |||
### I use SetArgPointee() in WillOnce(), but gcc complains about "conflicting re turn type specified". What does it mean? | ### I use SetArgPointee() in WillOnce(), but gcc complains about "conflicting re turn type specified". What does it mean? | |||
You got this error as gMock has no idea what value it should return when the | You got this error as gMock has no idea what value it should return when the | |||
mock method is called. `SetArgPointee()` says what the side effect is, but | mock method is called. `SetArgPointee()` says what the side effect is, but | |||
doesn't say what the return value should be. You need `DoAll()` to chain a | doesn't say what the return value should be. You need `DoAll()` to chain a | |||
`SetArgPointee()` with a `Return()` that provides a value appropriate to the API | `SetArgPointee()` with a `Return()` that provides a value appropriate to the API | |||
being mocked. | being mocked. | |||
See this [recipe](gmock_cook_book.md#mocking-side-effects) for more details and | See this [recipe](gmock_cook_book.md#mocking-side-effects) for more details and | |||
End of changes. 1 change blocks. | ||||
2 lines changed or deleted | 2 lines changed or added |