summaryrefslogtreecommitdiff
path: root/examples/cppunittest/OrthodoxTest.h
blob: 8fc2a08caa0c0697664fa9fa1f9ef00ad197bb80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef ORTHODOXTEST_H
#define ORTHODOXTEST_H

#include <cppunit/extensions/HelperMacros.h>
#include "MockTestListener.h"


class OrthodoxTest : public CPPUNIT_NS::TestFixture
{
  CPPUNIT_TEST_SUITE( OrthodoxTest );
  CPPUNIT_TEST( testValue );
  CPPUNIT_TEST( testValueBadConstructor );
  CPPUNIT_TEST( testValueBadInvert );
  CPPUNIT_TEST( testValueBadEqual );
  CPPUNIT_TEST( testValueBadNotEqual );
  CPPUNIT_TEST( testValueBadCall );
  CPPUNIT_TEST( testValueBadAssignment );
  CPPUNIT_TEST_SUITE_END();

public:
  OrthodoxTest();
  virtual ~OrthodoxTest();

  virtual void setUp();
  virtual void tearDown();

  void testValue();
  void testValueBadConstructor();
  void testValueBadInvert();
  void testValueBadEqual();
  void testValueBadNotEqual();
  void testValueBadCall();
  void testValueBadAssignment();

private:
  class Value
  {
  public:
    Value( int value =0 ) : m_value( value ) {}

    Value& operator= ( const Value& v )
    {
      m_value = v.m_value;
      return *this;
    }

    bool operator ==( const Value &other ) const
    {
      return m_value == other.m_value;
    }

    bool operator !=( const Value &other )
    {
      return !( *this == other );
    }

    Value operator !()
    {
      return Value( -1 - m_value );
    }

  protected:
    int m_value;
  };


  class ValueBadConstructor : public Value
  {
  public:
    ValueBadConstructor()
    {
      static int serialNumber = 0;
      m_value = ++serialNumber;
    }

    ValueBadConstructor( int value ) : Value( value ) {}

    ValueBadConstructor operator !()
    {
      return ValueBadConstructor( -1 - m_value );
    }
  };

  
  class ValueBadInvert : public Value
  {
  public:
    ValueBadInvert( int value =0 ) : Value( value ) {}

    ValueBadInvert operator !()
    {
      return ValueBadInvert( 1 );
    }
  };

  
  class ValueBadEqual : public Value
  {
  public:
    ValueBadEqual( int value =0 ) : Value( value ) {}

    ValueBadEqual operator !()
    {
      return ValueBadEqual( -1 - m_value );
    }

    bool operator ==( const ValueBadEqual &other ) const
    {
      return m_value != other.m_value;
    }
  };

  
  class ValueBadNotEqual : public Value
  {
  public:
    ValueBadNotEqual( int value =0 ) : Value( value ) {}

    ValueBadNotEqual operator !()
    {
      return ValueBadNotEqual( -1 - m_value );
    }

    bool operator !=( const ValueBadNotEqual &other )
    {
      return m_value == other.m_value;
    }
  };


  class ValueBadCall : public Value
  {
  public:
    ValueBadCall( int value =0 ) : Value( value ) {}

    ValueBadCall( const ValueBadCall & ) : Value()
    {
      static int serialNumber = 0;
      m_value = ++serialNumber;
    }

    ValueBadCall operator !()
    {
      return ValueBadCall( -1 - m_value );
    }
  };


  class ValueBadAssignment: public Value
  {
  public:
    ValueBadAssignment( int value =0 ) : Value( value ) {}

    ValueBadAssignment operator !()
    {
      return ValueBadAssignment( -1 - m_value );
    }

    ValueBadAssignment &operator =( const ValueBadAssignment & )
    {
      ++m_value;
      return *this;
    }
  };



  OrthodoxTest( const OrthodoxTest &copy );
  void operator =( const OrthodoxTest &copy );

private:
  CPPUNIT_NS::TestResult *m_result;
  MockTestListener *m_testListener;
};



#endif  // ORTHODOXTEST_H