Cpp Unit Examples

Here are some examples as to how to use CppUnit. Some are sketchy.


(This example extracted from the CppUnit discussion)

I'm wondering if I can use CppUnit to verify the pre-condition and post-condition of the input parameters. For example, for a function like this

 void swap(int &a, int &b) {...skip}

how can I use CppUnit to make sure that a and b are exchanged? Thanks.

Derek

I'd write something like this (using my particular flavor of CppUnit):

 void SomeTestClass::TestSwap()
 {
int a = 13;
int b = -57;
swap(a, b);
unit_AssertEquals(-57, a);
unit_AssertEquals(13, b);
 }


EditText of this page (last edited March 9, 2003) or FindPage with title or text search