os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_construct.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/***********************************************************************************
sl@0
     2
  test_construct.h
sl@0
     3
sl@0
     4
 * Copyright (c) 1997
sl@0
     5
 * Mark of the Unicorn, Inc.
sl@0
     6
 *
sl@0
     7
 * Permission to use, copy, modify, distribute and sell this software
sl@0
     8
 * and its documentation for any purpose is hereby granted without fee,
sl@0
     9
 * provided that the above copyright notice appear in all copies and
sl@0
    10
 * that both that copyright notice and this permission notice appear
sl@0
    11
 * in supporting documentation.  Mark of the Unicorn makes no
sl@0
    12
 * representations about the suitability of this software for any
sl@0
    13
 * purpose.  It is provided "as is" without express or implied warranty.
sl@0
    14
sl@0
    15
***********************************************************************************/
sl@0
    16
#ifndef test_construct_H_
sl@0
    17
#define test_construct_H_
sl@0
    18
sl@0
    19
#include "Prefix.h"
sl@0
    20
#if defined (EH_NEW_HEADERS)
sl@0
    21
#  include <algorithm>
sl@0
    22
#  include <cassert>
sl@0
    23
#  include <cstdlib>
sl@0
    24
#else
sl@0
    25
#  include <algo.h>
sl@0
    26
#  include <assert.h>
sl@0
    27
#  include <stdlib.h>
sl@0
    28
#endif
sl@0
    29
sl@0
    30
USING_CSTD_NAME(size_t)
sl@0
    31
sl@0
    32
template <class T>
sl@0
    33
struct test_copy_construct {
sl@0
    34
  test_copy_construct() {
sl@0
    35
    gTestController.SetCurrentTestName("copy constructor");
sl@0
    36
  }
sl@0
    37
sl@0
    38
  void operator()( const T& t ) const {
sl@0
    39
    T aCopy( t );
sl@0
    40
    // Prevent simulated failures during verification
sl@0
    41
    gTestController.CancelFailureCountdown();
sl@0
    42
    //EH_ASSERT( aCopy == t );
sl@0
    43
    CheckInvariant(t);
sl@0
    44
  }
sl@0
    45
};
sl@0
    46
sl@0
    47
template <class T>
sl@0
    48
struct test_default_construct {
sl@0
    49
  test_default_construct() {
sl@0
    50
    gTestController.SetCurrentTestName("default constructor");
sl@0
    51
  }
sl@0
    52
sl@0
    53
  void operator()( int ) const {
sl@0
    54
    T t;
sl@0
    55
    CheckInvariant(t);
sl@0
    56
  }
sl@0
    57
};
sl@0
    58
sl@0
    59
template <class T>
sl@0
    60
struct test_construct_n {
sl@0
    61
  test_construct_n( size_t _n ) : n(_n+1) {
sl@0
    62
    gTestController.SetCurrentTestName("n-size constructor");
sl@0
    63
  }
sl@0
    64
sl@0
    65
  void operator()( int ) const {
sl@0
    66
    T t(n);
sl@0
    67
    CheckInvariant(t);
sl@0
    68
  }
sl@0
    69
sl@0
    70
  size_t n;
sl@0
    71
};
sl@0
    72
sl@0
    73
template <class T>
sl@0
    74
struct test_construct_n_instance {
sl@0
    75
  test_construct_n_instance( size_t _n ) : n(_n+1) {
sl@0
    76
    gTestController.SetCurrentTestName("n-size with instance constructor");
sl@0
    77
  }
sl@0
    78
sl@0
    79
  void operator()( int ) const {
sl@0
    80
    typedef typename T::value_type Value_type;
sl@0
    81
    Value_type Val = 0;
sl@0
    82
    T t( n, Val );
sl@0
    83
    CheckInvariant(t);
sl@0
    84
  }
sl@0
    85
sl@0
    86
  size_t n;
sl@0
    87
};
sl@0
    88
sl@0
    89
template <class T>
sl@0
    90
struct test_construct_pointer_range {
sl@0
    91
  test_construct_pointer_range( const typename T::value_type *first,
sl@0
    92
                                const typename T::value_type* last )
sl@0
    93
    : fItems( first ), fEnd( last ) {
sl@0
    94
    gTestController.SetCurrentTestName("pointer range constructor");
sl@0
    95
  }
sl@0
    96
sl@0
    97
  void operator()( int ) const {
sl@0
    98
    T t( fItems, fEnd );
sl@0
    99
    // Prevent simulated failures during verification
sl@0
   100
    gTestController.CancelFailureCountdown();
sl@0
   101
    CheckInvariant(t);
sl@0
   102
  }
sl@0
   103
sl@0
   104
  const typename T::value_type* fItems, *fEnd;
sl@0
   105
};
sl@0
   106
sl@0
   107
template <class T>
sl@0
   108
struct test_construct_iter_range {
sl@0
   109
sl@0
   110
  test_construct_iter_range( const T& src ) : fItems( src ) {
sl@0
   111
    gTestController.SetCurrentTestName("iterator range constructor");
sl@0
   112
  }
sl@0
   113
sl@0
   114
  void operator()( int ) const {
sl@0
   115
    T t( fItems.begin(), fItems.end() );
sl@0
   116
    // Prevent simulated failures during verification
sl@0
   117
    gTestController.CancelFailureCountdown();
sl@0
   118
    EH_ASSERT( t == fItems );
sl@0
   119
    CheckInvariant(t);
sl@0
   120
  }
sl@0
   121
sl@0
   122
  const T& fItems;
sl@0
   123
};
sl@0
   124
sl@0
   125
#endif // test_construct_H_