[857] | 1 | // (C) Copyright Gennadiy Rozental 2005.
|
---|
| 2 | // Distributed under the Boost Software License, Version 1.0.
|
---|
| 3 | // (See accompanying file LICENSE_1_0.txt or copy at
|
---|
| 4 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
| 5 |
|
---|
| 6 | // See http://www.boost.org/libs/test for the library home page.
|
---|
| 7 | //
|
---|
| 8 | // File : $RCSfile: unit_test_suite.ipp,v $
|
---|
| 9 | //
|
---|
| 10 | // Version : $Revision: 1.10 $
|
---|
| 11 | //
|
---|
| 12 | // Description : privide core implementation for Unit Test Framework.
|
---|
| 13 | // Extensions could be provided in separate files
|
---|
| 14 | // ***************************************************************************
|
---|
| 15 |
|
---|
| 16 | #ifndef BOOST_TEST_UNIT_TEST_SUITE_IPP_012205GER
|
---|
| 17 | #define BOOST_TEST_UNIT_TEST_SUITE_IPP_012205GER
|
---|
| 18 |
|
---|
| 19 | // Boost.Test
|
---|
| 20 | #include <boost/detail/workaround.hpp>
|
---|
| 21 | #include <boost/test/unit_test_suite.hpp>
|
---|
| 22 | #include <boost/test/framework.hpp>
|
---|
| 23 | #include <boost/test/utils/foreach.hpp>
|
---|
| 24 | #include <boost/test/results_collector.hpp>
|
---|
| 25 | #include <boost/test/detail/unit_test_parameters.hpp>
|
---|
| 26 |
|
---|
| 27 | // Boost
|
---|
| 28 | #include <boost/timer.hpp>
|
---|
| 29 |
|
---|
| 30 | // STL
|
---|
| 31 | #include <algorithm>
|
---|
| 32 | #include <vector>
|
---|
| 33 |
|
---|
| 34 | #include <boost/test/detail/suppress_warnings.hpp>
|
---|
| 35 |
|
---|
| 36 | #if BOOST_WORKAROUND(__BORLANDC__, < 0x600) && \
|
---|
| 37 | BOOST_WORKAROUND(_STLPORT_VERSION, <= 0x450) \
|
---|
| 38 | /**/
|
---|
| 39 | using std::rand; // rand is in std and random_shuffle is in _STL
|
---|
| 40 | #endif
|
---|
| 41 |
|
---|
| 42 | //____________________________________________________________________________//
|
---|
| 43 |
|
---|
| 44 | namespace boost {
|
---|
| 45 |
|
---|
| 46 | namespace unit_test {
|
---|
| 47 |
|
---|
| 48 | // ************************************************************************** //
|
---|
| 49 | // ************** test_unit ************** //
|
---|
| 50 | // ************************************************************************** //
|
---|
| 51 |
|
---|
| 52 | test_unit::test_unit( const_string name, test_unit_type t )
|
---|
| 53 | : p_type( t )
|
---|
| 54 | , p_type_name( t == tut_case ? "case" : "suite" )
|
---|
| 55 | , p_id( INV_TEST_UNIT_ID )
|
---|
| 56 | , p_name( std::string( name.begin(), name.size() ) )
|
---|
| 57 | {
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | //____________________________________________________________________________//
|
---|
| 61 |
|
---|
| 62 | void
|
---|
| 63 | test_unit::depends_on( test_unit* tu )
|
---|
| 64 | {
|
---|
| 65 | m_dependencies.push_back( tu->p_id );
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | //____________________________________________________________________________//
|
---|
| 69 |
|
---|
| 70 | bool
|
---|
| 71 | test_unit::check_dependencies() const
|
---|
| 72 | {
|
---|
| 73 | #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x530) )
|
---|
| 74 | BOOST_TEST_FOREACH( test_unit_id, tu_id, const_cast<test_unit*>(this)->m_dependencies ) {
|
---|
| 75 | #else
|
---|
| 76 | BOOST_TEST_FOREACH( test_unit_id, tu_id, m_dependencies ) {
|
---|
| 77 | #endif
|
---|
| 78 | if( !unit_test::results_collector.results( tu_id ).passed() )
|
---|
| 79 | return false;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | return true;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | //____________________________________________________________________________//
|
---|
| 86 |
|
---|
| 87 | // ************************************************************************** //
|
---|
| 88 | // ************** test_case ************** //
|
---|
| 89 | // ************************************************************************** //
|
---|
| 90 |
|
---|
| 91 | test_case::test_case( const_string name, callback0<> const& test_func )
|
---|
| 92 | : test_unit( name, (test_unit_type)type )
|
---|
| 93 | , m_test_func( test_func )
|
---|
| 94 | {
|
---|
| 95 | // !! weirdest MSVC BUG; try to remove this statement; looks like it eats first token of next statement
|
---|
| 96 | #if BOOST_WORKAROUND(BOOST_MSVC,<1300)
|
---|
| 97 | 0;
|
---|
| 98 | #endif
|
---|
| 99 |
|
---|
| 100 | framework::register_test_unit( this );
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | //____________________________________________________________________________//
|
---|
| 104 |
|
---|
| 105 | // ************************************************************************** //
|
---|
| 106 | // ************** test_suite ************** //
|
---|
| 107 | // ************************************************************************** //
|
---|
| 108 |
|
---|
| 109 | //____________________________________________________________________________//
|
---|
| 110 |
|
---|
| 111 | test_suite::test_suite( const_string name )
|
---|
| 112 | : test_unit( name, (test_unit_type)type )
|
---|
| 113 | {
|
---|
| 114 | framework::register_test_unit( this );
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | //____________________________________________________________________________//
|
---|
| 118 |
|
---|
| 119 | // !! need to prevent modifing test unit once it is added to tree
|
---|
| 120 |
|
---|
| 121 | void
|
---|
| 122 | test_suite::add( test_unit* tu, counter_t expected_failures, unsigned timeout )
|
---|
| 123 | {
|
---|
| 124 | if( expected_failures != 0 )
|
---|
| 125 | tu->p_expected_failures.value = expected_failures;
|
---|
| 126 |
|
---|
| 127 | p_expected_failures.value += tu->p_expected_failures;
|
---|
| 128 |
|
---|
| 129 | if( timeout != 0 )
|
---|
| 130 | tu->p_timeout.value = timeout;
|
---|
| 131 |
|
---|
| 132 | m_members.push_back( tu->p_id );
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | //____________________________________________________________________________//
|
---|
| 136 |
|
---|
| 137 | void
|
---|
| 138 | test_suite::add( test_unit_generator const& gen, unsigned timeout )
|
---|
| 139 | {
|
---|
| 140 | test_unit* tu;
|
---|
| 141 | while((tu = gen.next(), tu))
|
---|
| 142 | add( tu, 0, timeout );
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | //____________________________________________________________________________//
|
---|
| 146 |
|
---|
| 147 | // ************************************************************************** //
|
---|
| 148 | // ************** traverse_test_tree ************** //
|
---|
| 149 | // ************************************************************************** //
|
---|
| 150 |
|
---|
| 151 | void
|
---|
| 152 | traverse_test_tree( test_case const& tc, test_tree_visitor& V )
|
---|
| 153 | {
|
---|
| 154 | V.visit( tc );
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | //____________________________________________________________________________//
|
---|
| 158 |
|
---|
| 159 | void traverse_test_tree( test_suite const& suite, test_tree_visitor& V )
|
---|
| 160 | {
|
---|
| 161 | if( !V.test_suite_start( suite ) )
|
---|
| 162 | return;
|
---|
| 163 |
|
---|
| 164 | try {
|
---|
| 165 | if( runtime_config::random_seed() == 0 ) {
|
---|
| 166 | BOOST_TEST_FOREACH( test_unit_id, id, suite.m_members )
|
---|
| 167 | traverse_test_tree( id, V );
|
---|
| 168 | }
|
---|
| 169 | else {
|
---|
| 170 | std::vector<test_unit_id> members( suite.m_members );
|
---|
| 171 | //#if !defined(__BORLANDC__) || !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
|
---|
| 172 | std::random_shuffle( members.begin(), members.end() );
|
---|
| 173 | //#else
|
---|
| 174 | // bool random_test_order_not_supported_on_borland = false;
|
---|
| 175 | // assert(random_test_order_not_supported_on_borland);
|
---|
| 176 | //#endif
|
---|
| 177 | BOOST_TEST_FOREACH( test_unit_id, id, members )
|
---|
| 178 | traverse_test_tree( id, V );
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | } catch( test_aborted const& ) {
|
---|
| 182 | V.test_suite_finish( suite );
|
---|
| 183 |
|
---|
| 184 | throw;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | V.test_suite_finish( suite );
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | //____________________________________________________________________________//
|
---|
| 191 |
|
---|
| 192 | void
|
---|
| 193 | traverse_test_tree( test_unit_id id, test_tree_visitor& V )
|
---|
| 194 | {
|
---|
| 195 | if( test_id_2_unit_type( id ) == tut_case )
|
---|
| 196 | traverse_test_tree( framework::get<test_case>( id ), V );
|
---|
| 197 | else
|
---|
| 198 | traverse_test_tree( framework::get<test_suite>( id ), V );
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | //____________________________________________________________________________//
|
---|
| 202 |
|
---|
| 203 | // ************************************************************************** //
|
---|
| 204 | // ************** object generators ************** //
|
---|
| 205 | // ************************************************************************** //
|
---|
| 206 |
|
---|
| 207 | namespace ut_detail {
|
---|
| 208 |
|
---|
| 209 | std::string
|
---|
| 210 | normalize_test_case_name( const_string name )
|
---|
| 211 | {
|
---|
| 212 | return ( name[0] == '&'
|
---|
| 213 | ? std::string( name.begin()+1, name.size()-1 )
|
---|
| 214 | : std::string( name.begin(), name.size() ) );
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | //____________________________________________________________________________//
|
---|
| 218 |
|
---|
| 219 | } // namespace ut_detail
|
---|
| 220 |
|
---|
| 221 | } // namespace unit_test
|
---|
| 222 |
|
---|
| 223 | } // namespace boost
|
---|
| 224 |
|
---|
| 225 | //____________________________________________________________________________//
|
---|
| 226 |
|
---|
| 227 | #include <boost/test/detail/enable_warnings.hpp>
|
---|
| 228 |
|
---|
| 229 | // ***************************************************************************
|
---|
| 230 | // Revision History :
|
---|
| 231 | //
|
---|
| 232 | // $Log: unit_test_suite.ipp,v $
|
---|
| 233 | // Revision 1.10 2005/04/18 04:55:36 rogeeff
|
---|
| 234 | // test unit name made read/write
|
---|
| 235 | //
|
---|
| 236 | // Revision 1.9 2005/03/23 21:02:25 rogeeff
|
---|
| 237 | // Sunpro CC 5.3 fixes
|
---|
| 238 | //
|
---|
| 239 | // Revision 1.8 2005/03/21 15:33:15 rogeeff
|
---|
| 240 | // check reworked
|
---|
| 241 | //
|
---|
| 242 | // Revision 1.7 2005/02/25 21:27:44 turkanis
|
---|
| 243 | // fix for random_shuffle on Borland 5.x w/ STLPort
|
---|
| 244 | //
|
---|
| 245 | // Revision 1.6 2005/02/21 10:12:24 rogeeff
|
---|
| 246 | // Support for random order of test cases implemented
|
---|
| 247 | //
|
---|
| 248 | // Revision 1.5 2005/02/20 08:27:07 rogeeff
|
---|
| 249 | // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
|
---|
| 250 | //
|
---|
| 251 | // ***************************************************************************
|
---|
| 252 |
|
---|
| 253 | #endif // BOOST_TEST_UNIT_TEST_SUITE_IPP_012205GER
|
---|