test_construct.h

00001 /***********************************************************************************
00002         test_construct.h
00003         
00004  * Copyright (c) 1997
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 ***********************************************************************************/
00016 #ifndef test_construct_H_
00017 #define test_construct_H_
00018 
00019 # include "Prefix.h"
00020 # if defined (EH_NEW_HEADERS)
00021 #  include <algorithm>
00022 #  include <cassert>
00023 #  include <cstdlib>
00024 # else
00025 #  include <algo.h>
00026 #  include <assert.h>
00027 #  include <stdlib.h>
00028 # endif
00029 
00030 
00031 USING_CSTD_NAME(size_t)
00032 
00033 template <class T>
00034 struct test_copy_construct
00035 {
00036     test_copy_construct()
00037     {
00038         gTestController.SetCurrentTestName("copy constructor");
00039     }
00040     
00041         void operator()( const T& t ) const
00042         {
00043                 T aCopy( t );
00044                 // Prevent simulated failures during verification
00045                 gTestController.CancelFailureCountdown();
00046                 EH_ASSERT( aCopy == t );
00047                 CheckInvariant(t);
00048         }
00049 };
00050 
00051 template <class T>
00052 struct test_default_construct
00053 {
00054     test_default_construct()
00055     {
00056         gTestController.SetCurrentTestName("default constructor");
00057     }
00058     
00059         void operator()( int ) const
00060         {
00061                 T t;
00062                 CheckInvariant(t);
00063         }
00064 };
00065 
00066 template <class T>
00067 struct test_construct_n
00068 {
00069         test_construct_n( size_t _n ) : n(_n+1)
00070         {
00071         gTestController.SetCurrentTestName("n-size constructor");
00072     }
00073         
00074         void operator()( int ) const
00075         {
00076                 T t(n);
00077                 CheckInvariant(t);
00078         }
00079         
00080         size_t n;
00081 };
00082 
00083 template <class T>
00084 struct test_construct_n_instance
00085 {
00086         test_construct_n_instance( size_t _n )
00087                 : n(_n+1)
00088         {
00089             gTestController.SetCurrentTestName("n-size with instance constructor");
00090         }
00091         
00092         void operator()( int ) const
00093         {
00094         typedef typename T::value_type Value_type;
00095                 Value_type Val = 0;
00096                 T t( n, Val );
00097                 CheckInvariant(t);
00098         }
00099         
00100         size_t n;
00101 };
00102 
00103 template <class T>
00104 struct test_construct_pointer_range
00105 {
00106         test_construct_pointer_range( const typename T::value_type *first, 
00107                                   const typename T::value_type* last )
00108                 : fItems( first ), fEnd( last )
00109     {
00110         gTestController.SetCurrentTestName("pointer range constructor");
00111     }
00112         
00113         void operator()( int ) const
00114         {
00115                 T t( fItems, fEnd );
00116                 // Prevent simulated failures during verification
00117         gTestController.CancelFailureCountdown();
00118                 CheckInvariant(t);
00119         }
00120         
00121         const typename T::value_type* fItems, *fEnd;
00122 };
00123 
00124 template <class T>
00125 struct test_construct_iter_range
00126 {
00127         test_construct_iter_range( const T& src ) : fItems( src )
00128         {
00129         gTestController.SetCurrentTestName("iterator range constructor");
00130     }
00131         
00132         void operator()( int ) const
00133         {
00134                 T t( fItems.begin(), fItems.end() );
00135                 // Prevent simulated failures during verification
00136         gTestController.CancelFailureCountdown();
00137                 EH_ASSERT( t == fItems );
00138                 CheckInvariant(t);
00139         }
00140         
00141         const T& fItems;
00142 };
00143 
00144 #endif // test_construct_H_
00145 

Generated on Mon Jun 5 10:20:48 2006 for Intelligence.kdevelop by  doxygen 1.4.6