os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/TestClass.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/TestClass.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,161 @@
     1.4 +/***********************************************************************************
     1.5 +  TestClass.h
     1.6 +
     1.7 + * Copyright (c) 1997-1998
     1.8 + * Mark of the Unicorn, Inc.
     1.9 + *
    1.10 + * Permission to use, copy, modify, distribute and sell this software
    1.11 + * and its documentation for any purpose is hereby granted without fee,
    1.12 + * provided that the above copyright notice appear in all copies and
    1.13 + * that both that copyright notice and this permission notice appear
    1.14 + * in supporting documentation.  Mark of the Unicorn makes no
    1.15 + * representations about the suitability of this software for any
    1.16 + * purpose.  It is provided "as is" without express or implied warranty.
    1.17 +
    1.18 +    SUMMARY: TestClass simulates a class that uses resources. It is designed to
    1.19 +      cause exceptions when it is constructed or copied.
    1.20 +
    1.21 +***********************************************************************************/
    1.22 +#ifndef INCLUDED_MOTU_TestClass
    1.23 +#define INCLUDED_MOTU_TestClass 1
    1.24 +
    1.25 +# include "Prefix.h"
    1.26 +
    1.27 +#  include <functional>
    1.28 +#  include <utility>
    1.29 +#  include <climits>
    1.30 +
    1.31 +#include <iosfwd>
    1.32 +#include "random_number.h"
    1.33 +#include "nc_alloc.h"
    1.34 +
    1.35 +class TestClass
    1.36 +{
    1.37 +public:
    1.38 +    inline TestClass();
    1.39 +    inline TestClass( int value );
    1.40 +    inline TestClass( const TestClass& rhs );
    1.41 +    inline ~TestClass();
    1.42 +
    1.43 +    inline TestClass& operator=( const TestClass& rhs );
    1.44 +    inline int value() const;
    1.45 +
    1.46 +    inline TestClass operator!() const;
    1.47 +
    1.48 +    bool operator==( const TestClass& rhs ) const
    1.49 +    {
    1.50 +      return value() == rhs.value();
    1.51 +    }
    1.52 +
    1.53 +    bool operator<( const TestClass& rhs ) const {
    1.54 +      return value() < rhs.value();
    1.55 +    }
    1.56 +
    1.57 +protected:
    1.58 +    static inline unsigned int get_random(unsigned range = UINT_MAX);
    1.59 +private:
    1.60 +  inline void Init( int value );
    1.61 +
    1.62 +#if TESTCLASS_DEEP_DATA
    1.63 +    int *p;
    1.64 +#else
    1.65 +  int v;
    1.66 +#endif
    1.67 +};
    1.68 +
    1.69 +#if defined( __MWERKS__ ) && __MWERKS__ <= 0x3000 && !__SGI_STL
    1.70 +# if defined( __MSL__ ) && __MSL__ < 0x2406
    1.71 +#  include <iterator.h>
    1.72 +__MSL_FIX_ITERATORS__(TestClass);
    1.73 +__MSL_FIX_ITERATORS__(const TestClass);
    1.74 +typedef EH_STD::pair<const TestClass, TestClass> pair_testclass_testclass;
    1.75 +__MSL_FIX_ITERATORS__( pair_testclass_testclass );
    1.76 +__MSL_FIX_ITERATORS__( const pair_testclass_testclass );
    1.77 +# endif
    1.78 +#endif
    1.79 +
    1.80 +inline void TestClass::Init( int value )
    1.81 +{
    1.82 +#if TESTCLASS_DEEP_DATA
    1.83 +  p = new int( value );
    1.84 +#else
    1.85 +  simulate_constructor();
    1.86 +  v = value;
    1.87 +#endif
    1.88 +}
    1.89 +
    1.90 +inline TestClass::TestClass()
    1.91 +{
    1.92 +  Init( int(get_random()) );
    1.93 +}
    1.94 +
    1.95 +inline TestClass::TestClass( int value )
    1.96 +{
    1.97 +  Init( value );
    1.98 +}
    1.99 +
   1.100 +inline TestClass::TestClass( const TestClass& rhs )
   1.101 +{
   1.102 +  Init( rhs.value() );
   1.103 +}
   1.104 +
   1.105 +inline TestClass::~TestClass()
   1.106 +{
   1.107 +#if TESTCLASS_DEEP_DATA
   1.108 +  delete p;
   1.109 +#else
   1.110 +  simulate_destructor();
   1.111 +#endif
   1.112 +}
   1.113 +
   1.114 +inline TestClass& TestClass::operator=( const TestClass& rhs )
   1.115 +{
   1.116 +#if TESTCLASS_DEEP_DATA
   1.117 +  int *newP = new int( rhs.value() );
   1.118 +  delete p;
   1.119 +  p = newP;
   1.120 +#else
   1.121 +  simulate_possible_failure();
   1.122 +    v = rhs.value();
   1.123 +#endif
   1.124 +    return *this;
   1.125 +}
   1.126 +
   1.127 +inline int TestClass::value() const
   1.128 +{
   1.129 +#if TESTCLASS_DEEP_DATA
   1.130 +  return *p;
   1.131 +#else
   1.132 +  return v;
   1.133 +#endif
   1.134 +}
   1.135 +
   1.136 +inline TestClass TestClass::operator!() const
   1.137 +{
   1.138 +    return TestClass( value()+1 );
   1.139 +}
   1.140 +
   1.141 +inline bool operator>( const TestClass& lhs, const TestClass& rhs ) {
   1.142 +    return rhs < lhs;
   1.143 +}
   1.144 +
   1.145 +inline bool operator>=( const TestClass& lhs, const TestClass& rhs ) {
   1.146 +    return !(lhs < rhs);
   1.147 +}
   1.148 +
   1.149 +inline bool operator<=( const TestClass& lhs, const TestClass& rhs ) {
   1.150 +    return !(rhs < lhs);
   1.151 +}
   1.152 +
   1.153 +inline bool operator != ( const TestClass& lhs, const TestClass& rhs ) {
   1.154 +    return lhs.value() != rhs.value();
   1.155 +}
   1.156 +
   1.157 +inline unsigned int TestClass::get_random( unsigned range )
   1.158 +{
   1.159 +    return random_number( range );
   1.160 +}
   1.161 +
   1.162 +extern std::ostream& operator << ( std::ostream& s, const TestClass&);
   1.163 +
   1.164 +#endif // INCLUDED_MOTU_TestClass