Skip to content

Commit 3cd23b3

Browse files
committed
Fixed headings
1 parent 04a0a2b commit 3cd23b3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

mocking_manual.markdown

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The main idea is to make manual mocking easier, rather than to make automated mo
2929
* [C Interface](#c_interface)
3030

3131
<a id="simple_scenario"> </a>
32+
3233
### Simple Scenario
3334

3435
About the simplest scenario is to check that one particular function call has happened. The below code is an example of this:
@@ -99,6 +100,7 @@ If the call to productionCode wouldn't happen, then the test would fail with the
99100
<none>
100101

101102
<a id="objects"> </a>
103+
102104
### Using Objects
103105

104106
Simple scenario using objects
@@ -150,6 +152,7 @@ If the call to a wrong object happens, it would give the following error message
150152
<none>
151153

152154
<a id="parameters"> </a>
155+
153156
### Parameters
154157

155158
Of course, just checked whether a function is called is not particularly useful when we cannot check the parameters. Recording parameters on a function is done like this:
@@ -175,6 +178,7 @@ If a parameter isn't passed, it will give the following error:
175178
int p1, char* p2
176179

177180
<a id="objects_as_parameters"> </a>
181+
178182
### Objects as Parameters
179183

180184
withParameters can only use int, double, const char* or void* . However, parameters are often objects of other types and not of the basic types. How to handle objects as parameters? Below is an example:
@@ -230,6 +234,7 @@ Comparators are *not* copied, instead it uses the exact instance as passed to th
230234
When using the MockPlugin (recommended), then its best to install the comparators via the MockPlugin or put them in global space. The checkExpectations will be called *after* teardown and if your comparator was destroyed in the teardown then this will cause a crash.
231235

232236
<a id="output_parameters"> </a>
237+
233238
### Output Parameters
234239

235240
Some parameters do not represent data passed to the called function, but are passed by reference so that the function can 'return' a value by modifying the pointed-to data.
@@ -283,6 +288,7 @@ mock().expectOneCall("Foo").withOutputParameterReturning("bar", &doubleOutputVal
283288
* When an 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.
284289

285290
<a id="return_values"> </a>
291+
286292
### Return Values
287293

288294
Sometimes it is needed to let a mock function return a value which can then be used in production code. The test code would look like this:
@@ -311,6 +317,7 @@ int function () {
311317
The return value options are used to transfer data between the test and the mock object, they themselves do not cause the tests to fail.
312318

313319
<a id="other_data"> </a>
320+
314321
### Passing other data
315322

316323
Sometimes a test wants to pass more data to the mock object to, for example, vary only a couple of parameters in a calculation. This can be done like this:
@@ -332,6 +339,7 @@ pobject = (ClassFromProductionCode*) mock().getData("importantObject").getObject
332339
Like return values. Setting data will not ever make a test fail but it provides support in building mock objects.
333340

334341
<a id="other_mock_support"> </a>
342+
335343
### Other MockSupport - ignoring, enabling, clearing, crashing
336344

337345
MockSupport offers a couple of other useful functions, which will be covered in this section.
@@ -376,6 +384,7 @@ When using gdb, get a stack trace using:
376384
(r is run, it will run until crashes. bt is back trace which will produce a stack)
377385

378386
<a id="mock_scope"> </a>
387+
379388
### MockSupport Scope
380389

381390
MockSupport can be used hierarchically using MockSupport scope. This sounds really complex, but in reality it is very simple. When getting a mock support using the mock function, you can pass a namespace or scope and record the expectations (or do other things) inside this scope. For example:
@@ -404,6 +413,7 @@ mock("filesystem").ignoreOtherCalls();
404413
{% endhighlight %}
405414

406415
<a id="mock_plugin"> </a>
416+
407417
### MockPlugin
408418

409419
CppUTest plugins can be installed in the main and 'extent' the unit test framework. It is a place where you can put work that needs to be done in all unit tests. There is a MockPlugin to make the work with mocks easier. It does the following work:
@@ -424,6 +434,7 @@ TestRegistry::getCurrentRegistry()->installPlugin(&mockPlugin);
424434
{% endhighlight %}
425435

426436
<a id="c_interface"> </a>
437+
427438
### C Interface
428439

429440
This code creates a comparator for MyDummy and installs it at the plugin. This means the comparator is available for all test cases. It creates the plugin and installs it at the current test registry. After installing the plugin, you don't have to worry too much anymore about calling checkExpectations or cleaning your MockSupport.

0 commit comments

Comments
 (0)