home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stl453up.zip / stl453fx / test / eh / test_construct.h < prev    next >
C/C++ Source or Header  |  2002-04-29  |  3KB  |  146 lines

  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.  
  31. USING_CSTD_NAME(size_t)
  32.  
  33. template <class T>
  34. struct test_copy_construct
  35. {
  36.     test_copy_construct()
  37.     {
  38.         gTestController.SetCurrentTestName("copy constructor");
  39.     }
  40.     
  41.     void operator()( const T& t ) const
  42.     {
  43.         T aCopy( t );
  44.         // Prevent simulated failures during verification
  45.         gTestController.CancelFailureCountdown();
  46.         EH_ASSERT( aCopy == t );
  47.         CheckInvariant(t);
  48.     }
  49. };
  50.  
  51. template <class T>
  52. struct test_default_construct
  53. {
  54.     test_default_construct()
  55.     {
  56.         gTestController.SetCurrentTestName("default constructor");
  57.     }
  58.     
  59.     void operator()( int ) const
  60.     {
  61.         T t;
  62.         CheckInvariant(t);
  63.     }
  64. };
  65.  
  66. template <class T>
  67. struct test_construct_n
  68. {
  69.     test_construct_n( size_t _n ) : n(_n+1)
  70.     {
  71.         gTestController.SetCurrentTestName("n-size constructor");
  72.     }
  73.     
  74.     void operator()( int ) const
  75.     {
  76.         T t(n);
  77.         CheckInvariant(t);
  78.     }
  79.     
  80.     size_t n;
  81. };
  82.  
  83. template <class T>
  84. struct test_construct_n_instance
  85. {
  86.     test_construct_n_instance( size_t _n )
  87.         : n(_n+1)
  88.     {
  89.         gTestController.SetCurrentTestName("n-size with instance constructor");
  90.     }
  91.     
  92.     void operator()( int ) const
  93.     {
  94.         typedef typename T::value_type Value_type;
  95.         Value_type Val = 0;
  96.         T t( n, Val );
  97.         CheckInvariant(t);
  98.     }
  99.     
  100.     size_t n;
  101. };
  102.  
  103. template <class T>
  104. struct test_construct_pointer_range
  105. {
  106.     test_construct_pointer_range( const typename T::value_type *first, 
  107.                                   const typename T::value_type* last )
  108.         : fItems( first ), fEnd( last )
  109.     {
  110.         gTestController.SetCurrentTestName("pointer range constructor");
  111.     }
  112.     
  113.     void operator()( int ) const
  114.     {
  115.         T t( fItems, fEnd );
  116.         // Prevent simulated failures during verification
  117.         gTestController.CancelFailureCountdown();
  118.         CheckInvariant(t);
  119.     }
  120.     
  121.     const typename T::value_type* fItems, *fEnd;
  122. };
  123.  
  124. template <class T>
  125. struct test_construct_iter_range
  126. {
  127.     test_construct_iter_range( const T& src ) : fItems( src )
  128.     {
  129.         gTestController.SetCurrentTestName("iterator range constructor");
  130.     }
  131.     
  132.     void operator()( int ) const
  133.     {
  134.         T t( fItems.begin(), fItems.end() );
  135.         // Prevent simulated failures during verification
  136.         gTestController.CancelFailureCountdown();
  137.         EH_ASSERT( t == fItems );
  138.         CheckInvariant(t);
  139.     }
  140.     
  141.     const T& fItems;
  142. };
  143.  
  144. #endif // test_construct_H_
  145.  
  146.