1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_construct.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,125 @@
1.4 +/***********************************************************************************
1.5 + test_construct.h
1.6 +
1.7 + * Copyright (c) 1997
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 +***********************************************************************************/
1.19 +#ifndef test_construct_H_
1.20 +#define test_construct_H_
1.21 +
1.22 +#include "Prefix.h"
1.23 +#if defined (EH_NEW_HEADERS)
1.24 +# include <algorithm>
1.25 +# include <cassert>
1.26 +# include <cstdlib>
1.27 +#else
1.28 +# include <algo.h>
1.29 +# include <assert.h>
1.30 +# include <stdlib.h>
1.31 +#endif
1.32 +
1.33 +USING_CSTD_NAME(size_t)
1.34 +
1.35 +template <class T>
1.36 +struct test_copy_construct {
1.37 + test_copy_construct() {
1.38 + gTestController.SetCurrentTestName("copy constructor");
1.39 + }
1.40 +
1.41 + void operator()( const T& t ) const {
1.42 + T aCopy( t );
1.43 + // Prevent simulated failures during verification
1.44 + gTestController.CancelFailureCountdown();
1.45 + //EH_ASSERT( aCopy == t );
1.46 + CheckInvariant(t);
1.47 + }
1.48 +};
1.49 +
1.50 +template <class T>
1.51 +struct test_default_construct {
1.52 + test_default_construct() {
1.53 + gTestController.SetCurrentTestName("default constructor");
1.54 + }
1.55 +
1.56 + void operator()( int ) const {
1.57 + T t;
1.58 + CheckInvariant(t);
1.59 + }
1.60 +};
1.61 +
1.62 +template <class T>
1.63 +struct test_construct_n {
1.64 + test_construct_n( size_t _n ) : n(_n+1) {
1.65 + gTestController.SetCurrentTestName("n-size constructor");
1.66 + }
1.67 +
1.68 + void operator()( int ) const {
1.69 + T t(n);
1.70 + CheckInvariant(t);
1.71 + }
1.72 +
1.73 + size_t n;
1.74 +};
1.75 +
1.76 +template <class T>
1.77 +struct test_construct_n_instance {
1.78 + test_construct_n_instance( size_t _n ) : n(_n+1) {
1.79 + gTestController.SetCurrentTestName("n-size with instance constructor");
1.80 + }
1.81 +
1.82 + void operator()( int ) const {
1.83 + typedef typename T::value_type Value_type;
1.84 + Value_type Val = 0;
1.85 + T t( n, Val );
1.86 + CheckInvariant(t);
1.87 + }
1.88 +
1.89 + size_t n;
1.90 +};
1.91 +
1.92 +template <class T>
1.93 +struct test_construct_pointer_range {
1.94 + test_construct_pointer_range( const typename T::value_type *first,
1.95 + const typename T::value_type* last )
1.96 + : fItems( first ), fEnd( last ) {
1.97 + gTestController.SetCurrentTestName("pointer range constructor");
1.98 + }
1.99 +
1.100 + void operator()( int ) const {
1.101 + T t( fItems, fEnd );
1.102 + // Prevent simulated failures during verification
1.103 + gTestController.CancelFailureCountdown();
1.104 + CheckInvariant(t);
1.105 + }
1.106 +
1.107 + const typename T::value_type* fItems, *fEnd;
1.108 +};
1.109 +
1.110 +template <class T>
1.111 +struct test_construct_iter_range {
1.112 +
1.113 + test_construct_iter_range( const T& src ) : fItems( src ) {
1.114 + gTestController.SetCurrentTestName("iterator range constructor");
1.115 + }
1.116 +
1.117 + void operator()( int ) const {
1.118 + T t( fItems.begin(), fItems.end() );
1.119 + // Prevent simulated failures during verification
1.120 + gTestController.CancelFailureCountdown();
1.121 + EH_ASSERT( t == fItems );
1.122 + CheckInvariant(t);
1.123 + }
1.124 +
1.125 + const T& fItems;
1.126 +};
1.127 +
1.128 +#endif // test_construct_H_