Home | History | Annotate | Download | only in eh
      1 /***********************************************************************************
      2   test_construct.h
      3 
      4  * Copyright (c) 1997
      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 ***********************************************************************************/
     16 #ifndef test_construct_H_
     17 #define test_construct_H_
     18 
     19 #include "Prefix.h"
     20 #if defined (EH_NEW_HEADERS)
     21 #  include <algorithm>
     22 #  include <cassert>
     23 #  include <cstdlib>
     24 #else
     25 #  include <algo.h>
     26 #  include <assert.h>
     27 #  include <stdlib.h>
     28 #endif
     29 
     30 USING_CSTD_NAME(size_t)
     31 
     32 template <class T>
     33 struct test_copy_construct {
     34   test_copy_construct() {
     35     gTestController.SetCurrentTestName("copy constructor");
     36   }
     37 
     38   void operator()( const T& t ) const {
     39     T aCopy( t );
     40     // Prevent simulated failures during verification
     41     gTestController.CancelFailureCountdown();
     42     //EH_ASSERT( aCopy == t );
     43     CheckInvariant(t);
     44   }
     45 };
     46 
     47 template <class T>
     48 struct test_default_construct {
     49   test_default_construct() {
     50     gTestController.SetCurrentTestName("default constructor");
     51   }
     52 
     53   void operator()( int ) const {
     54     T t;
     55     CheckInvariant(t);
     56   }
     57 };
     58 
     59 template <class T>
     60 struct test_construct_n {
     61   test_construct_n( size_t _n ) : n(_n+1) {
     62     gTestController.SetCurrentTestName("n-size constructor");
     63   }
     64 
     65   void operator()( int ) const {
     66     T t(n);
     67     CheckInvariant(t);
     68   }
     69 
     70   size_t n;
     71 };
     72 
     73 template <class T>
     74 struct test_construct_n_instance {
     75   test_construct_n_instance( size_t _n ) : n(_n+1) {
     76     gTestController.SetCurrentTestName("n-size with instance constructor");
     77   }
     78 
     79   void operator()( int ) const {
     80     typedef typename T::value_type Value_type;
     81     Value_type Val = 0;
     82     T t( n, Val );
     83     CheckInvariant(t);
     84   }
     85 
     86   size_t n;
     87 };
     88 
     89 template <class T>
     90 struct test_construct_pointer_range {
     91   test_construct_pointer_range( const typename T::value_type *first,
     92                                 const typename T::value_type* last )
     93     : fItems( first ), fEnd( last ) {
     94     gTestController.SetCurrentTestName("pointer range constructor");
     95   }
     96 
     97   void operator()( int ) const {
     98     T t( fItems, fEnd );
     99     // Prevent simulated failures during verification
    100     gTestController.CancelFailureCountdown();
    101     CheckInvariant(t);
    102   }
    103 
    104   const typename T::value_type* fItems, *fEnd;
    105 };
    106 
    107 template <class T>
    108 struct test_construct_iter_range {
    109 
    110   test_construct_iter_range( const T& src ) : fItems( src ) {
    111     gTestController.SetCurrentTestName("iterator range constructor");
    112   }
    113 
    114   void operator()( int ) const {
    115     T t( fItems.begin(), fItems.end() );
    116     // Prevent simulated failures during verification
    117     gTestController.CancelFailureCountdown();
    118     EH_ASSERT( t == fItems );
    119     CheckInvariant(t);
    120   }
    121 
    122   const T& fItems;
    123 };
    124 
    125 #endif // test_construct_H_
    126