ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

TestClass.h
Go to the documentation of this file.
00001 /***********************************************************************************
00002   TestClass.h
00003 
00004  * Copyright (c) 1997-1998
00005  * Mark of the Unicorn, Inc.
00006  *
00007  * Permission to use, copy, modify, distribute and sell this software
00008  * and its documentation for any purpose is hereby granted without fee,
00009  * provided that the above copyright notice appear in all copies and
00010  * that both that copyright notice and this permission notice appear
00011  * in supporting documentation.  Mark of the Unicorn makes no
00012  * representations about the suitability of this software for any
00013  * purpose.  It is provided "as is" without express or implied warranty.
00014 
00015     SUMMARY: TestClass simulates a class that uses resources. It is designed to
00016       cause exceptions when it is constructed or copied.
00017 
00018 ***********************************************************************************/
00019 #ifndef INCLUDED_MOTU_TestClass
00020 #define INCLUDED_MOTU_TestClass 1
00021 
00022 # include "Prefix.h"
00023 
00024 #  include <functional>
00025 #  include <utility>
00026 #  include <climits>
00027 
00028 #include <iosfwd>
00029 #include "random_number.h"
00030 #include "nc_alloc.h"
00031 
00032 class TestClass
00033 {
00034 public:
00035     inline TestClass();
00036     inline TestClass( int value );
00037     inline TestClass( const TestClass& rhs );
00038     inline ~TestClass();
00039 
00040     inline TestClass& operator=( const TestClass& rhs );
00041     inline int value() const;
00042 
00043     inline TestClass operator!() const;
00044 
00045     bool operator==( const TestClass& rhs ) const
00046     {
00047       return value() == rhs.value();
00048     }
00049 
00050     bool operator<( const TestClass& rhs ) const {
00051       return value() < rhs.value();
00052     }
00053 
00054 protected:
00055     static inline unsigned int get_random(unsigned range = UINT_MAX);
00056 private:
00057   inline void Init( int value );
00058 
00059 #if TESTCLASS_DEEP_DATA
00060     int *p;
00061 #else
00062   int v;
00063 #endif
00064 };
00065 
00066 #if defined( __MWERKS__ ) && __MWERKS__ <= 0x3000 && !__SGI_STL
00067 # if defined( __MSL__ ) && __MSL__ < 0x2406
00068 #  include <iterator.h>
00069 __MSL_FIX_ITERATORS__(TestClass);
00070 __MSL_FIX_ITERATORS__(const TestClass);
00071 typedef EH_STD::pair<const TestClass, TestClass> pair_testclass_testclass;
00072 __MSL_FIX_ITERATORS__( pair_testclass_testclass );
00073 __MSL_FIX_ITERATORS__( const pair_testclass_testclass );
00074 # endif
00075 #endif
00076 
00077 inline void TestClass::Init( int value )
00078 {
00079 #if TESTCLASS_DEEP_DATA
00080   p = new int( value );
00081 #else
00082   simulate_constructor();
00083   v = value;
00084 #endif
00085 }
00086 
00087 inline TestClass::TestClass()
00088 {
00089   Init( int(get_random()) );
00090 }
00091 
00092 inline TestClass::TestClass( int value )
00093 {
00094   Init( value );
00095 }
00096 
00097 inline TestClass::TestClass( const TestClass& rhs )
00098 {
00099   Init( rhs.value() );
00100 }
00101 
00102 inline TestClass::~TestClass()
00103 {
00104 #if TESTCLASS_DEEP_DATA
00105   delete p;
00106 #else
00107   simulate_destructor();
00108 #endif
00109 }
00110 
00111 inline TestClass& TestClass::operator=( const TestClass& rhs )
00112 {
00113 #if TESTCLASS_DEEP_DATA
00114   int *newP = new int( rhs.value() );
00115   delete p;
00116   p = newP;
00117 #else
00118   simulate_possible_failure();
00119     v = rhs.value();
00120 #endif
00121     return *this;
00122 }
00123 
00124 inline int TestClass::value() const
00125 {
00126 #if TESTCLASS_DEEP_DATA
00127   return *p;
00128 #else
00129   return v;
00130 #endif
00131 }
00132 
00133 inline TestClass TestClass::operator!() const
00134 {
00135     return TestClass( value()+1 );
00136 }
00137 
00138 inline bool operator>( const TestClass& lhs, const TestClass& rhs ) {
00139     return rhs < lhs;
00140 }
00141 
00142 inline bool operator>=( const TestClass& lhs, const TestClass& rhs ) {
00143     return !(lhs < rhs);
00144 }
00145 
00146 inline bool operator<=( const TestClass& lhs, const TestClass& rhs ) {
00147     return !(rhs < lhs);
00148 }
00149 
00150 inline bool operator != ( const TestClass& lhs, const TestClass& rhs ) {
00151     return lhs.value() != rhs.value();
00152 }
00153 
00154 inline unsigned int TestClass::get_random( unsigned range )
00155 {
00156     return random_number( range );
00157 }
00158 
00159 extern std::ostream& operator << ( std::ostream& s, const TestClass&);
00160 
00161 #endif // INCLUDED_MOTU_TestClass

Generated on Mon May 28 2012 04:35:02 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.