Update contrib.
1 /***********************************************************************************
4 * Copyright (c) 1997-1998
5 * Mark of the Unicorn, Inc.
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.
15 SUMMARY: TestClass simulates a class that uses resources. It is designed to
16 cause exceptions when it is constructed or copied.
18 ***********************************************************************************/
19 #ifndef INCLUDED_MOTU_TestClass
20 #define INCLUDED_MOTU_TestClass 1
24 # include <functional>
29 #include "random_number.h"
36 inline TestClass( int value );
37 inline TestClass( const TestClass& rhs );
40 inline TestClass& operator=( const TestClass& rhs );
41 inline int value() const;
43 inline TestClass operator!() const;
45 bool operator==( const TestClass& rhs ) const
47 return value() == rhs.value();
50 bool operator<( const TestClass& rhs ) const {
51 return value() < rhs.value();
55 static inline unsigned int get_random(unsigned range = UINT_MAX);
57 inline void Init( int value );
59 #if TESTCLASS_DEEP_DATA
66 #if defined( __MWERKS__ ) && __MWERKS__ <= 0x3000 && !__SGI_STL
67 # if defined( __MSL__ ) && __MSL__ < 0x2406
68 # include <iterator.h>
69 __MSL_FIX_ITERATORS__(TestClass);
70 __MSL_FIX_ITERATORS__(const TestClass);
71 typedef EH_STD::pair<const TestClass, TestClass> pair_testclass_testclass;
72 __MSL_FIX_ITERATORS__( pair_testclass_testclass );
73 __MSL_FIX_ITERATORS__( const pair_testclass_testclass );
77 inline void TestClass::Init( int value )
79 #if TESTCLASS_DEEP_DATA
82 simulate_constructor();
87 inline TestClass::TestClass()
89 Init( int(get_random()) );
92 inline TestClass::TestClass( int value )
97 inline TestClass::TestClass( const TestClass& rhs )
102 inline TestClass::~TestClass()
104 #if TESTCLASS_DEEP_DATA
107 simulate_destructor();
111 inline TestClass& TestClass::operator=( const TestClass& rhs )
113 #if TESTCLASS_DEEP_DATA
114 int *newP = new int( rhs.value() );
118 simulate_possible_failure();
124 inline int TestClass::value() const
126 #if TESTCLASS_DEEP_DATA
133 inline TestClass TestClass::operator!() const
135 return TestClass( value()+1 );
138 inline bool operator>( const TestClass& lhs, const TestClass& rhs ) {
142 inline bool operator>=( const TestClass& lhs, const TestClass& rhs ) {
146 inline bool operator<=( const TestClass& lhs, const TestClass& rhs ) {
150 inline bool operator != ( const TestClass& lhs, const TestClass& rhs ) {
151 return lhs.value() != rhs.value();
154 inline unsigned int TestClass::get_random( unsigned range )
156 return random_number( range );
159 extern std::ostream& operator << ( std::ostream& s, const TestClass&);
161 #endif // INCLUDED_MOTU_TestClass