You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mocking_manual.markdown
+51-2Lines changed: 51 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@ The main idea is to make manual mocking easier, rather than to make automated mo
21
21
*[Using Parameters](#parameters)
22
22
*[Objects as Parameters](#objects_as_parameters)
23
23
*[Output Parameters](#output_parameters)
24
+
*[Output Parameters Using Objects](#output_parameters_using_objects)
24
25
*[Return Values](#return_values)
25
26
*[Passing other data](#other_data)
26
27
*[Other MockSupport](#other_mock_support)
@@ -214,10 +215,10 @@ public:
214
215
215
216
The isEqual is called to compare the two parameters. The valueToString is called when an error message is printed and it needs to print the actual and expected values. If you want to use normal C functions, you can use the MockFunctionComparator which accepts pointers to functions in the constructor.
216
217
217
-
To remove the comparators, all you needs to do is call removeAllComparators, like:
218
+
To remove the comparators, all you needs to do is call removeAllComparatorsAndCopiers, like:
218
219
219
220
{% highlight c++ %}
220
-
mock().removeAllComparators();
221
+
mock().removeAllComparatorsAndCopiers();
221
222
{% endhighlight %}
222
223
223
224
Comparators sometimes lead to surprises, so a couple of warnings on its usage:
* When a char, int, etc. array is passed to withOutputParameter, you must use the generic withOutputParameterReturning and provide the actual size of the array or only one element will be copied.
290
291
292
+
<aid="output_parameters_using_objects"> </a>
293
+
294
+
### Output Parameters Using Objects
295
+
296
+
By far the best way to handle output parameters is by using a custom type copier (3.8). The general principle is similar to the custom comparators described above:
When using withOutputParameterOfTypeReturning, the mocking framework needs to know how to copy the type and therefore a Copier has to be installed before using parameters of this type. This is done using installCopier, as below:
313
+
314
+
{% highlight c++ %}
315
+
MyTypeCopier copier;
316
+
mock().installCopier("myType", copier);
317
+
{% endhighlight %}
318
+
319
+
MyTypeCopier is a custom copier, which implements the MockNamedValueCopier interface. For example:
320
+
321
+
{% highlight c++ %}
322
+
class MyTypeCopier : public MockNamedValueCopier
323
+
{
324
+
public:
325
+
virtual void copy(void* out, const void* in)
326
+
{
327
+
*(MyType*)out = *(const MyType*)in;
328
+
}
329
+
};
330
+
{% endhighlight %}
331
+
332
+
To remove the copier, you need to call removeAllComparatorsAndCopiers, like:
333
+
334
+
{% highlight c++ %}
335
+
mock().removeAllComparatorsAndCopiers();
336
+
{% endhighlight %}
337
+
338
+
*Warning 1* and *Warning 2* above apply to copiers as well.
0 commit comments