Skip to content

Commit e1ac4c6

Browse files
committed
Merge pull request #22 from devMichaelJones/master
Wiki changes
2 parents bbc9d61 + 118c1d1 commit e1ac4c6

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

index.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ For Windows users, the above work with cygwin. There are also several MS VC++ pr
8585

8686
## Where to find more information
8787

88-
* If you have any question, check out the [Google Groups](https://groups.google.com/forum/?fromgroups#!forum/cpputest)
88+
* If you have any questions, check out the [Google Groups](https://groups.google.com/forum/?fromgroups#!forum/cpputest)
8989
* The source is at the [main github page](https://github.com/cpputest/cpputest)
9090
* You can report bugs or features at [the issues page](https://github.com/cpputest/cpputest/issues)
9191
* You can follow [CppUTest on twitter](https://twitter.com/CppUTest)
@@ -127,7 +127,7 @@ int main(int ac, char** av)
127127
}
128128
{% endhighlight %}
129129

130-
For more information, We'd recommend to [read the manual](http://www.cpputest.org) or, even better, check some [existing tests](https://github.com/cpputest/cpputest/tree/master/tests) such as [SimpleStringTest](https://github.com/cpputest/cpputest/blob/master/tests/SimpleStringTest.cpp) or (a bit more complicated) [MemoryLeakDetectorTest](https://github.com/cpputest/cpputest/blob/master/tests/MemoryLeakDetectorTest.cpp) or the [mocking tests](https://github.com/cpputest/cpputest/blob/master/tests/CppUTestExt/TestMockSupport.cpp) or just check out the [Cheat Sheet](https://github.com/cpputest/cpputest/blob/master/tests/CheatSheetTest.cpp)
130+
For more information, We'd recommend [reading the manual](http://www.cpputest.org) or, even better, check some [existing tests](https://github.com/cpputest/cpputest/tree/master/tests) such as [SimpleStringTest](https://github.com/cpputest/cpputest/blob/master/tests/SimpleStringTest.cpp) or (a bit more complicated) [MemoryLeakDetectorTest](https://github.com/cpputest/cpputest/blob/master/tests/MemoryLeakDetectorTest.cpp) or the [mocking tests](https://github.com/cpputest/cpputest/blob/master/tests/CppUTestExt/TestMockSupport.cpp) or just check out the [Cheat Sheet](https://github.com/cpputest/cpputest/blob/master/tests/CheatSheetTest.cpp)
131131

132132
## Related projects
133133

@@ -141,4 +141,4 @@ Prerequisites:
141141

142142
## Authors and Contributors
143143

144-
CppUTest has had many contributions from its users. We can't remember all, but we appreciate it a lot!. Much of the original code was written by Michael Feathers (based on CppUnit Lite). The current main maintainers are [@jwgrenning](https://github.com/jwgrenning) and [@basvodde](https://github.com/basvodde)
144+
CppUTest has had many contributions from its users. We can't remember all, but we appreciate it a lot! Much of the original code was written by Michael Feathers (based on CppUnit Lite). The current main maintainers are [@jwgrenning](https://github.com/jwgrenning) and [@basvodde](https://github.com/basvodde)

manual.markdown

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ CppUTest's core design principles
3434

3535
To write your first test, all you need is a new cpp file with a TEST_GROUP and a TEST, like:
3636
{% highlight c++ %}
37+
#include "CppUTest/TestHarness.h"
38+
3739
TEST_GROUP(FirstTestGroup)
3840
{
3941
};
@@ -60,6 +62,8 @@ One of the key design goals in CppUTest is to make it *very easy* to add and rem
6062
Of course, in order to get it to run, you'll need to create a main. Most of the mains in CppUTest are very similar. They typically are in an AllTests.cpp file and look like this:
6163

6264
{% highlight c++ %}
65+
#include "CppUTest/CommandLineTestRunner.h"
66+
6367
int main(int ac, char** av)
6468
{
6569
return CommandLineTestRunner::RunAllTests(ac, av);
@@ -107,7 +111,7 @@ You need to add CppUTest library to the linker flags, for example, like:
107111
LD_LIBRARIES = -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt
108112
{% endhighlight %}
109113

110-
(The last flags is only needed when you want to use extensions such as mocking)
114+
(The last flag is only needed when you want to use extensions such as mocking)
111115

112116
<a id="test_macros"> </a>
113117

@@ -144,9 +148,9 @@ The failure of one of these macros causes the current test to immediately exit:
144148

145149
<a id="setup_teardown"> </a>
146150

147-
*CHECK_EQUALS Warning:*
151+
*CHECK_EQUAL Warning:*
148152

149-
CHECK_EQUAL(expected, actual) can produce misleading error reports as it will evaluate expected and actual more than ones. THis especially leads to confusions when used with mocks. This happens if the mock function expects to be called exactly once, since the macro needs to evaluate the actual expression more than once. The problem does not occur with type specific checks (e.g. LONGS_EQUAL()), so it is recommended to use them if possible. Instead of:
153+
CHECK_EQUAL(expected, actual) can produce misleading error reports as it will evaluate expected and actual more than ones. This especially leads to confusions when used with mocks. This happens if the mock function expects to be called exactly once, since the macro needs to evaluate the actual expression more than once. The problem does not occur with type specific checks (e.g. LONGS_EQUAL()), so it is recommended to use them if possible. Instead of:
150154

151155
{% highlight c++ %}
152156
CHECK_EQUAL(10, mock_returning_11())
@@ -266,7 +270,7 @@ These are added by default when you use the CppUTest Makefile helpers.
266270

267271
### Turning memory leak detection off and on
268272

269-
If you want to disable the memory leak detection (because you got too much memory leaks?) then you can do so in several ways. However, it is strongly recommended to keep the memory leak detector on and fix your memory leaks (and your static initialization issues) as this tends to lead to higher quality code.
273+
If you want to disable the memory leak detection (because you have too many memory leaks?) then you can do so in several ways. However, it is strongly recommended to keep the memory leak detector on and fix your memory leaks (and your static initialization issues) as this tends to lead to higher quality code.
270274

271275
You can turn the memory leak detection completely off by adding this to your main:
272276

@@ -316,7 +320,7 @@ Now the call to the compiler needs to be -include MyOwnNewMacros.h and this will
316320

317321
### Conflicts with my own overload!
318322

319-
This one is harder (and luckily less common). You can solve this the same way as the conflict in STL, but its probably better to use a finer grained control. So, instead you can temporary disable the new macros, overload operator new, enable the new macro again. This can be done with the following code:
323+
This one is harder (and luckily less common). You can solve this the same way as the conflict in STL, but it's probably better to use a finer grained control. So, instead you can temporary disable the new macros, overload operator new, enable the new macro again. This can be done with the following code:
320324

321325
{% highlight c++ %}
322326
class NewDummyClass
@@ -608,7 +612,7 @@ The most important line to add is the GTestConvertor. Make sure you define the C
608612

609613
## Running Google Tests in CppUTest
610614

611-
People feel wonderfully religious about unit testing tools. Of course, we feel strongly that CppUTest beats other tools when you actually test-drive your software. But unfortunately, people still use tools like GoogleTest (which is actually not as bad as e.g. CppUnit). It is unlikely that we're going to convince people to use CppUTest instead, so therefore we've written some integration code where you can actually link google test and CppUTest tests together in one binary (with the CppUTest test runner). THis also gives you some additional benefits:
615+
People feel wonderfully religious about unit testing tools. Of course, we feel strongly that CppUTest beats other tools when you actually test-drive your software. But unfortunately, people still use tools like GoogleTest (which is actually not as bad as e.g. CppUnit). It is unlikely that we're going to convince people to use CppUTest instead, so therefore we've written some integration code where you can actually link google test and CppUTest tests together in one binary (with the CppUTest test runner). This also gives you some additional benefits:
612616

613617
* You get memory leak detection over your google tests...
614618
* You don't get the verbose gtest output

mocking_manual.markdown

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: default
33
title: CppUTest Mocking Manual
44
---
55

6-
CppUTest has support for building mocks. This document described the mocking support. A couple of design goals for the mocking support were:
6+
CppUTest has support for building mocks. This document describes the mocking support. A couple of design goals for the mocking support were:
77

88

99
* Same design goals as CppuTest -- limited C++ set to make it well suitable for embedded soft.
@@ -67,7 +67,7 @@ The TEST(MockDocumentation, SimpleScenario) contains the recording of the expect
6767
mock().expectOneCall("productionCode");
6868
{% endhighlight %}
6969

70-
The call to mock() return the global MockSupport (more about that later) on which we can record our expectations. In this example, we'll call expectOneCall("productionCode") which... records an expectation for *one* call to a function called productionCode.
70+
The call to mock() returns the global MockSupport (more about that later) on which we can record our expectations. In this example, we'll call expectOneCall("productionCode") which... records an expectation for *one* call to a function called productionCode.
7171

7272
The productionCode call is to show a call to whatever your real code is. The test ends with checking whether the expectations have been met. This is done with the:
7373

@@ -88,7 +88,7 @@ void productionCode()
8888

8989
where we use MockSupport by calling mock() and then record the actual call to the productionCode function.
9090

91-
This scenario is quite common when using linker stubbing of e.g. a 3rd partly library.
91+
This scenario is quite common when using linker stubbing of e.g. a 3rd party library.
9292

9393
If the call to productionCode wouldn't happen, then the test would fail with the following error message:
9494

@@ -155,7 +155,7 @@ If the call to a wrong object happens, it would give the following error message
155155

156156
### Parameters
157157

158-
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:
158+
Of course, just checking whether a function is called is not particularly useful when we cannot check the parameters. Recording parameters on a function is done like this:
159159

160160
{% highlight c++ %}
161161
mock().expectOneCall("function").onObject(object).withParameter("p1", 2).withParameter("p2", "hah");
@@ -200,11 +200,11 @@ MyTypeComparator is a custom comparator, which implements the MockNamedValueComp
200200
class MyTypeComparator : public MockNamedValueComparator
201201
{
202202
public:
203-
virtual bool isEqual(void* object1, void* object2)
203+
virtual bool isEqual(const void* object1, const void* object2)
204204
{
205205
return object1 == object2;
206206
}
207-
virtual SimpleString valueToString(void* object)
207+
virtual SimpleString valueToString(cont void* object)
208208
{
209209
return StringFrom(object);
210210
}
@@ -219,7 +219,7 @@ To remove the comparators, all you needs to do is call removeAllComparators, lik
219219
mock().removeAllComparators();
220220
{% endhighlight %}
221221

222-
Comparators sometimes lead to surprised, so a couple of warnings on its usage:
222+
Comparators sometimes lead to surprises, so a couple of warnings on its usage:
223223

224224
*Warning 1:*
225225

@@ -231,7 +231,7 @@ Comparators are *not* copied, instead it uses the exact instance as passed to th
231231

232232
* Pay extra attention to scope when using the MockPlugin
233233

234-
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.
234+
When using the MockPlugin (recommended), then it's 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.
235235

236236
<a id="output_parameters"> </a>
237237

@@ -285,7 +285,7 @@ mock().expectOneCall("Foo").withOutputParameterReturning("bar", &doubleOutputVal
285285

286286
*Warning 2:*
287287

288-
* 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.
288+
* 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.
289289

290290
<a id="return_values"> </a>
291291

@@ -336,15 +336,15 @@ int value = mock().getData("importantValue").getIntValue();
336336
pobject = (ClassFromProductionCode*) mock().getData("importantObject").getObjectPointer();
337337
{% endhighlight %}
338338

339-
Like return values. Setting data will not ever make a test fail but it provides support in building mock objects.
339+
Like return values, setting data will not ever make a test fail but it provides support in building mock objects.
340340

341341
<a id="other_mock_support"> </a>
342342

343343
### Other MockSupport - ignoring, enabling, clearing, crashing
344344

345345
MockSupport offers a couple of other useful functions, which will be covered in this section.
346346

347-
Frequently, you only want to check a couple of calls in your test and ignore all the other calls. If you add expectOneCall for each of these calls, you're tests might become too large (though, it might be a smell that your test is indeed too large). One way to prevent this is the ignoreOtherCalls, like:
347+
Frequently, you only want to check a couple of calls in your test and ignore all the other calls. If you add expectOneCall for each of these calls, your tests might become too large (though, it might be a smell that your test is indeed too large). One way to prevent this is the ignoreOtherCalls, like:
348348

349349
{% highlight c++ %}
350350
mock().expectOneCall("foo");
@@ -373,7 +373,7 @@ int function () {
373373

374374
If you try to ignore it or disable the framework, it will explode. Why ? The return value is not defined so there is no way to define the return value of the mocked function.
375375

376-
To cases like these there is a series of return value functions that allows you to define a default return value, that will be returned when the mock function is ignored.
376+
To cases like these there is a series of return value functions that allows you to define a default return value that will be returned when the mock function is ignored.
377377

378378
The example above could be written as:
379379

0 commit comments

Comments
 (0)