~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to CppUnit/include/CppUnit/Orthodox.h

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

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