ReactOS 0.4.15-dev-8241-g63935f8
TestClass.h
Go to the documentation of this file.
1/***********************************************************************************
2 TestClass.h
3
4 * Copyright (c) 1997-1998
5 * Mark of the Unicorn, Inc.
6 *
7 * Permission to use, copy, modify, distribute and sell this software
8 * and its documentation for any purpose is hereby granted without fee,
9 * provided that the above copyright notice appear in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation. Mark of the Unicorn makes no
12 * representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
14
15 SUMMARY: TestClass simulates a class that uses resources. It is designed to
16 cause exceptions when it is constructed or copied.
17
18***********************************************************************************/
19#ifndef INCLUDED_MOTU_TestClass
20#define INCLUDED_MOTU_TestClass 1
21
22# include "Prefix.h"
23
24# include <functional>
25# include <utility>
26# include <climits>
27
28#include <iosfwd>
29#include "random_number.h"
30#include "nc_alloc.h"
31
33{
34public:
35 inline TestClass();
36 inline TestClass( int value );
37 inline TestClass( const TestClass& rhs );
38 inline ~TestClass();
39
40 inline TestClass& operator=( const TestClass& rhs );
41 inline int value() const;
42
43 inline TestClass operator!() const;
44
45 bool operator==( const TestClass& rhs ) const
46 {
47 return value() == rhs.value();
48 }
49
50 bool operator<( const TestClass& rhs ) const {
51 return value() < rhs.value();
52 }
53
54protected:
55 static inline unsigned int get_random(unsigned range = UINT_MAX);
56private:
57 inline void Init( int value );
58
59#if TESTCLASS_DEEP_DATA
60 int *p;
61#else
62 int v;
63#endif
64};
65
66#if defined( __MWERKS__ ) && __MWERKS__ <= 0x3000 && !__SGI_STL
67# if defined( __MSL__ ) && __MSL__ < 0x2406
68# include <iterator.h>
71typedef EH_STD::pair<const TestClass, TestClass> pair_testclass_testclass;
72__MSL_FIX_ITERATORS__( pair_testclass_testclass );
73__MSL_FIX_ITERATORS__( const pair_testclass_testclass );
74# endif
75#endif
76
77inline void TestClass::Init( int value )
78{
79#if TESTCLASS_DEEP_DATA
80 p = new int( value );
81#else
83 v = value;
84#endif
85}
86
88{
89 Init( int(get_random()) );
90}
91
93{
94 Init( value );
95}
96
97inline TestClass::TestClass( const TestClass& rhs )
98{
99 Init( rhs.value() );
100}
101
103{
104#if TESTCLASS_DEEP_DATA
105 delete p;
106#else
108#endif
109}
110
112{
113#if TESTCLASS_DEEP_DATA
114 int *newP = new int( rhs.value() );
115 delete p;
116 p = newP;
117#else
119 v = rhs.value();
120#endif
121 return *this;
122}
123
124inline int TestClass::value() const
125{
126#if TESTCLASS_DEEP_DATA
127 return *p;
128#else
129 return v;
130#endif
131}
132
134{
135 return TestClass( value()+1 );
136}
137
138inline bool operator>( const TestClass& lhs, const TestClass& rhs ) {
139 return rhs < lhs;
140}
141
142inline bool operator>=( const TestClass& lhs, const TestClass& rhs ) {
143 return !(lhs < rhs);
144}
145
146inline bool operator<=( const TestClass& lhs, const TestClass& rhs ) {
147 return !(rhs < lhs);
148}
149
150inline bool operator != ( const TestClass& lhs, const TestClass& rhs ) {
151 return lhs.value() != rhs.value();
152}
153
154inline unsigned int TestClass::get_random( unsigned range )
155{
156 return random_number( range );
157}
158
159extern std::ostream& operator << ( std::ostream& s, const TestClass&);
160
161#endif // INCLUDED_MOTU_TestClass
bool operator>(const TestClass &lhs, const TestClass &rhs)
Definition: TestClass.h:138
bool operator>=(const TestClass &lhs, const TestClass &rhs)
Definition: TestClass.h:142
std::ostream & operator<<(std::ostream &s, const TestClass &)
Definition: TestClass.cpp:20
bool operator!=(const TestClass &lhs, const TestClass &rhs)
Definition: TestClass.h:150
bool operator<=(const TestClass &lhs, const TestClass &rhs)
Definition: TestClass.h:146
#define __MSL_FIX_ITERATORS__(myType)
Definition: _mwerks.h:39
#define get_random(x)
Definition: maze.c:105
int * p
Definition: TestClass.h:60
TestClass()
Definition: TestClass.h:87
static unsigned int get_random(unsigned range=UINT_MAX)
Definition: TestClass.h:154
TestClass operator!() const
Definition: TestClass.h:133
void Init(int value)
Definition: TestClass.h:77
bool operator<(const TestClass &rhs) const
Definition: TestClass.h:50
int value() const
Definition: TestClass.h:124
bool operator==(const TestClass &rhs) const
Definition: TestClass.h:45
TestClass & operator=(const TestClass &rhs)
Definition: TestClass.h:111
~TestClass()
Definition: TestClass.h:102
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
const GLdouble * v
Definition: gl.h:2040
GLdouble s
Definition: gl.h:2039
GLenum GLint * range
Definition: glext.h:7539
GLfloat GLfloat p
Definition: glext.h:8902
#define UINT_MAX
Definition: limits.h:41
void simulate_constructor()
Definition: nc_alloc.h:121
void simulate_possible_failure()
Definition: nc_alloc.h:117
void simulate_destructor()
Definition: nc_alloc.h:126
unsigned random_number(size_t range)
Definition: pdh_main.c:94