os/ossrv/ossrv_pub/boost_apis/boost/test/interaction_based.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/test/interaction_based.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,277 @@
     1.4 +//  (C) Copyright Gennadiy Rozental 2005.
     1.5 +//  Distributed under the Boost Software License, Version 1.0.
     1.6 +//  (See accompanying file LICENSE_1_0.txt or copy at 
     1.7 +//  http://www.boost.org/LICENSE_1_0.txt)
     1.8 +
     1.9 +//  See http://www.boost.org/libs/test for the library home page.
    1.10 +//
    1.11 +//  File        : $RCSfile: interaction_based.hpp,v $
    1.12 +//
    1.13 +//  Version     : $Revision: 1.3 $
    1.14 +//
    1.15 +//  Description : Facilities to perform interaction-based testing
    1.16 +// ***************************************************************************
    1.17 +
    1.18 +#ifndef BOOST_TEST_INTERACTION_BASED_HPP_112105GER
    1.19 +#define BOOST_TEST_INTERACTION_BASED_HPP_112105GER
    1.20 +
    1.21 +// Boost.Test
    1.22 +#include <boost/test/detail/config.hpp>
    1.23 +#include <boost/test/detail/global_typedef.hpp>
    1.24 +
    1.25 +#include <boost/test/utils/wrap_stringstream.hpp>
    1.26 +
    1.27 +#include <boost/test/detail/suppress_warnings.hpp>
    1.28 +
    1.29 +// Boost
    1.30 +#include <boost/lexical_cast.hpp>
    1.31 +
    1.32 +//____________________________________________________________________________//
    1.33 +
    1.34 +// ************************************************************************** //
    1.35 +// **************               BOOST_ITEST_EPOINT             ************** //
    1.36 +// ************************************************************************** //
    1.37 +
    1.38 +#define BOOST_ITEST_EPOINT( description ) \
    1.39 +    ::boost::itest::manager::instance().exception_point( BOOST_TEST_L(__FILE__), __LINE__, description )
    1.40 +/**/
    1.41 +
    1.42 +// ************************************************************************** //
    1.43 +// **************               BOOST_ITEST_DPOINT             ************** //
    1.44 +// ************************************************************************** //
    1.45 +
    1.46 +#define BOOST_ITEST_DPOINT() \
    1.47 +    ::boost::itest::manager::instance().decision_point( BOOST_TEST_L(__FILE__), __LINE__ )
    1.48 +/**/
    1.49 +
    1.50 +// ************************************************************************** //
    1.51 +// **************                BOOST_ITEST_SCOPE             ************** //
    1.52 +// ************************************************************************** //
    1.53 +
    1.54 +#define BOOST_ITEST_SCOPE( scope_name ) \
    1.55 +    ::boost::itest::scope_guard itest_scope_guard ## __LINE__( BOOST_TEST_L(__FILE__), __LINE__, BOOST_STRINGIZE(scope_name) )
    1.56 +/**/
    1.57 +
    1.58 +// ************************************************************************** //
    1.59 +// **************                 BOOST_ITEST_NEW              ************** //
    1.60 +// ************************************************************************** //
    1.61 +
    1.62 +#define BOOST_ITEST_NEW( type_name ) \
    1.63 +    new ( ::boost::itest::location( BOOST_TEST_L(__FILE__), __LINE__ ) ) type_name
    1.64 +/**/
    1.65 +
    1.66 +// ************************************************************************** //
    1.67 +// **************              BOOST_ITEST_DATA_FLOW           ************** //
    1.68 +// ************************************************************************** //
    1.69 +
    1.70 +#define BOOST_ITEST_DATA_FLOW( v ) \
    1.71 +    ::boost::itest::manager::instance().generic_data_flow( v )
    1.72 +/**/
    1.73 +
    1.74 +// ************************************************************************** //
    1.75 +// **************               BOOST_ITEST_RETURN             ************** //
    1.76 +// ************************************************************************** //
    1.77 +
    1.78 +#define BOOST_ITEST_RETURN( type, default_value ) \
    1.79 +    ::boost::itest::manager::instance().generic_return<type>( default_value )
    1.80 +/**/
    1.81 +
    1.82 +// ************************************************************************** //
    1.83 +// **************              BOOST_ITEST_MOCK_FUNC           ************** //
    1.84 +// ************************************************************************** //
    1.85 +
    1.86 +#define BOOST_ITEST_MOCK_FUNC( function_name )          \
    1.87 +    BOOST_ITEST_SCOPE( function_name );                 \
    1.88 +    BOOST_ITEST_EPOINT( 0 );                            \
    1.89 +    return ::boost::itest::mock_object<>::prototype();  \
    1.90 +/**/
    1.91 +
    1.92 +namespace boost {
    1.93 +
    1.94 +namespace itest { // interaction-based testing
    1.95 +
    1.96 +using unit_test::const_string;
    1.97 +
    1.98 +// ************************************************************************** //
    1.99 +// **************                    manager                   ************** //
   1.100 +// ************************************************************************** //
   1.101 +
   1.102 +class BOOST_TEST_DECL manager {
   1.103 +public:
   1.104 +    // instance access
   1.105 +    static manager&     instance() { return *instance_ptr(); }
   1.106 +
   1.107 +    // Mock objects interface hooks
   1.108 +    virtual void        exception_point( const_string /*file*/, 
   1.109 +                                         std::size_t /*line_num*/, 
   1.110 +                                         const_string /*descr*/ ){}
   1.111 +    virtual bool        decision_point( const_string /*file*/, 
   1.112 +                                        std::size_t /*line_num*/ )          { return true; }
   1.113 +    virtual unsigned    enter_scope( const_string /*file*/, 
   1.114 +                                     std::size_t /*line_num*/,
   1.115 +                                     const_string /*scope_name*/){ return 0; }
   1.116 +    virtual void        leave_scope( unsigned )                             {}
   1.117 +    virtual void        allocated( const_string /*file*/, 
   1.118 +                                   std::size_t /*line_num*/, 
   1.119 +                                   void* /*p*/, std::size_t /*s*/ )         {}
   1.120 +    virtual void        freed( void* /*p*/ )                                {}
   1.121 +    virtual void        data_flow( const_string d )                         {}
   1.122 +    virtual std::string return_value( const_string default_value )          { return ""; }
   1.123 +
   1.124 +    template<typename T>
   1.125 +    void                generic_data_flow( T const& t )
   1.126 +    {
   1.127 +        wrap_stringstream ws;
   1.128 +
   1.129 +        data_flow( (ws << t).str() );
   1.130 +    }
   1.131 +    template<typename T, typename DefaultValueType>
   1.132 +    T                   generic_return( DefaultValueType const& dv )
   1.133 +    {
   1.134 +        wrap_stringstream ws;
   1.135 +
   1.136 +        std::string const& res = return_value( (ws << dv).str() );
   1.137 +
   1.138 +        if( res.empty() )
   1.139 +            return dv;
   1.140 +
   1.141 +        return lexical_cast<T>( res );
   1.142 +    }
   1.143 +
   1.144 +protected:
   1.145 +    manager();
   1.146 +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) 
   1.147 +public:
   1.148 +#endif
   1.149 +    BOOST_TEST_PROTECTED_VIRTUAL ~manager();
   1.150 +
   1.151 +private:
   1.152 +    struct dummy_constr{};
   1.153 +    explicit manager( dummy_constr* ) {}
   1.154 +
   1.155 +    static manager*     instance_ptr( bool reset = false, manager* ptr = 0 );
   1.156 +}; // manager
   1.157 +
   1.158 +// ************************************************************************** //
   1.159 +// **************                  scope_guard                 ************** //
   1.160 +// ************************************************************************** //
   1.161 +
   1.162 +class scope_guard {
   1.163 +public:
   1.164 +    // Constructor
   1.165 +    scope_guard( const_string file, std::size_t line_num, const_string scope_name )
   1.166 +    {
   1.167 +        m_scope_index = manager::instance().enter_scope( file, line_num, scope_name );
   1.168 +    }
   1.169 +    ~scope_guard()
   1.170 +    {
   1.171 +        manager::instance().leave_scope( m_scope_index );
   1.172 +    }
   1.173 +
   1.174 +    unsigned m_scope_index;
   1.175 +};
   1.176 +
   1.177 +// ************************************************************************** //
   1.178 +// **************                    location                  ************** //
   1.179 +// ************************************************************************** //
   1.180 +
   1.181 +struct location {
   1.182 +    location( const_string file, std::size_t line ) 
   1.183 +    : m_file_name( file )
   1.184 +    , m_line_num( line )
   1.185 +    {}
   1.186 +
   1.187 +    const_string    m_file_name;
   1.188 +    std::size_t     m_line_num;
   1.189 +};
   1.190 +
   1.191 +}  // namespace itest
   1.192 +
   1.193 +} // namespace boost
   1.194 +
   1.195 +// ************************************************************************** //
   1.196 +// **************              operator new overload           ************** //
   1.197 +// ************************************************************************** //
   1.198 +
   1.199 +#if !defined(BOOST_ITEST_NO_NEW_OVERLOADS)
   1.200 +
   1.201 +// STL
   1.202 +#include <cstdlib>
   1.203 +
   1.204 +# ifdef BOOST_NO_STDC_NAMESPACE
   1.205 +namespace std { using ::malloc; using ::free; }
   1.206 +# endif
   1.207 +
   1.208 +inline void*
   1.209 +operator new( std::size_t s, ::boost::itest::location const& l )
   1.210 +{
   1.211 +    void* res = std::malloc(s ? s : 1);
   1.212 +
   1.213 +    if( res )
   1.214 +        ::boost::itest::manager::instance().allocated( l.m_file_name, l.m_line_num, res, s );
   1.215 +    else
   1.216 +        throw std::bad_alloc();
   1.217 +        
   1.218 +    return res;
   1.219 +}
   1.220 +
   1.221 +//____________________________________________________________________________//
   1.222 +
   1.223 +inline void*
   1.224 +operator new[]( std::size_t s, ::boost::itest::location const& l )
   1.225 +{
   1.226 +    void* res = std::malloc(s ? s : 1);
   1.227 +
   1.228 +    if( res )
   1.229 +        ::boost::itest::manager::instance().allocated( l.m_file_name, l.m_line_num, res, s );
   1.230 +    else
   1.231 +        throw std::bad_alloc();
   1.232 +        
   1.233 +    return res;
   1.234 +}
   1.235 +
   1.236 +//____________________________________________________________________________//
   1.237 +
   1.238 +inline void
   1.239 +operator delete( void* p, ::boost::itest::location const& )
   1.240 +{
   1.241 +    ::boost::itest::manager::instance().freed( p );
   1.242 +
   1.243 +    std::free( p );
   1.244 +}
   1.245 +
   1.246 +//____________________________________________________________________________//
   1.247 +
   1.248 +inline void
   1.249 +operator delete[]( void* p, ::boost::itest::location const& )
   1.250 +{
   1.251 +    ::boost::itest::manager::instance().freed( p );
   1.252 +
   1.253 +    std::free( p );
   1.254 +}
   1.255 +
   1.256 +//____________________________________________________________________________//
   1.257 +
   1.258 +#endif
   1.259 +
   1.260 +#include <boost/test/detail/enable_warnings.hpp>
   1.261 +
   1.262 +// ***************************************************************************
   1.263 +//  Revision History :
   1.264 +//  
   1.265 +//  $Log: interaction_based.hpp,v $
   1.266 +//  Revision 1.3  2006/01/28 08:52:35  rogeeff
   1.267 +//  operator new overloads made inline to:
   1.268 +//  1. prevent issues with export them from DLL
   1.269 +//  2. release link issue fixed
   1.270 +//
   1.271 +//  Revision 1.2  2006/01/15 11:14:38  rogeeff
   1.272 +//  simpl_mock -> mock_object<>::prototype()
   1.273 +//  operator new need to be rethinked
   1.274 +//
   1.275 +//  Revision 1.1  2005/12/14 05:09:21  rogeeff
   1.276 +//  interraction based testing is introdused
   1.277 +//
   1.278 +// ***************************************************************************
   1.279 +
   1.280 +#endif // BOOST_TEST_INTERACTION_BASED_HPP_112105GER