~ubuntu-branches/ubuntu/jaunty/psi/jaunty

« back to all changes in this revision

Viewing changes to third-party/cppunit/cppunit/include/cppunit/extensions/Orthodox.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef CPPUNIT_EXTENSIONS_ORTHODOX_H
 
2
#define CPPUNIT_EXTENSIONS_ORTHODOX_H
 
3
 
 
4
#include <cppunit/TestCase.h>
 
5
 
 
6
CPPUNIT_NS_BEGIN
 
7
 
 
8
 
 
9
/*
 
10
 * Orthodox performs a simple set of tests on an arbitary
 
11
 * class to make sure that it supports at least the
 
12
 * following operations:
 
13
 *
 
14
 *      default construction    - constructor
 
15
 *      equality/inequality     - operator== && operator!=
 
16
 *      assignment              - operator=
 
17
 *      negation                - operator!
 
18
 *      safe passage            - copy construction
 
19
 *
 
20
 * If operations for each of these are not declared
 
21
 * the template will not instantiate.  If it does 
 
22
 * instantiate, tests are performed to make sure
 
23
 * that the operations have correct semantics.
 
24
 *      
 
25
 * Adding an orthodox test to a suite is very 
 
26
 * easy: 
 
27
 * 
 
28
 * public: Test *suite ()  {
 
29
 *     TestSuite *suiteOfTests = new TestSuite;
 
30
 *     suiteOfTests->addTest (new ComplexNumberTest ("testAdd");
 
31
 *     suiteOfTests->addTest (new TestCaller<Orthodox<Complex> > ());
 
32
 *     return suiteOfTests;
 
33
 *  }
 
34
 *
 
35
 * Templated test cases be very useful when you are want to
 
36
 * make sure that a group of classes have the same form.
 
37
 *
 
38
 * see TestSuite
 
39
 */
 
40
 
 
41
 
 
42
template <class ClassUnderTest> class Orthodox : public TestCase
 
43
{
 
44
public:
 
45
                    Orthodox () : TestCase ("Orthodox") {}
 
46
 
 
47
protected:
 
48
    ClassUnderTest  call (ClassUnderTest object);
 
49
    void            runTest ();
 
50
 
 
51
 
 
52
};
 
53
 
 
54
 
 
55
// Run an orthodoxy test
 
56
template <class ClassUnderTest> void Orthodox<ClassUnderTest>::runTest ()
 
57
{
 
58
    // make sure we have a default constructor
 
59
    ClassUnderTest   a, b, c;
 
60
 
 
61
    // make sure we have an equality operator
 
62
    CPPUNIT_ASSERT (a == b);
 
63
 
 
64
    // check the inverse
 
65
    b.operator= (a.operator! ());
 
66
    CPPUNIT_ASSERT (a != b);
 
67
 
 
68
    // double inversion
 
69
    b = !!a;
 
70
    CPPUNIT_ASSERT (a == b);
 
71
 
 
72
    // invert again
 
73
    b = !a;
 
74
 
 
75
    // check calls
 
76
    c = a;
 
77
    CPPUNIT_ASSERT (c == call (a));
 
78
 
 
79
    c = b;
 
80
    CPPUNIT_ASSERT (c == call (b));
 
81
 
 
82
}
 
83
 
 
84
 
 
85
// Exercise a call
 
86
template <class ClassUnderTest> 
 
87
ClassUnderTest Orthodox<ClassUnderTest>::call (ClassUnderTest object)
 
88
{
 
89
    return object;
 
90
}
 
91
 
 
92
 
 
93
CPPUNIT_NS_END
 
94
 
 
95
#endif