1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
// (C) Copyright Gennadiy Rozental 2005-2006.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
// Boost.Test
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/test/exception_safety.hpp>
#include <boost/test/mock_object.hpp>
using namespace boost::itest;
// Boost
#include <boost/bind.hpp>
//____________________________________________________________________________//
// Here is the function we are going to use to see all execution path variants
template<typename Employee,typename Ostr>
typename Employee::string_type
validate_and_return_salary( Employee const& e, Ostr& os )
{
if( e.Title() == "CEO" || e.Salary() > 100000 )
os << e.First() << " " << e.Last() << " is overpaid";
return e.First() + " " + e.Last();
}
//____________________________________________________________________________//
// Mock object we are going to use for this test
struct EmpMock : mock_object<> {
typedef mock_object<> mo_type;
typedef mo_type string_type;
string_type const& Title() const { BOOST_ITEST_MOCK_FUNC( EmpMock::Title ); }
string_type const& First() const { BOOST_ITEST_MOCK_FUNC( EmpMock::First ); }
string_type const& Last() const { BOOST_ITEST_MOCK_FUNC( EmpMock::Last ); }
mo_type const& Salary() const { BOOST_ITEST_MOCK_FUNC( EmpMock::Salary ); }
};
//____________________________________________________________________________//
BOOST_TEST_EXCEPTION_SAFETY( test_all_exec_path )
{
validate_and_return_salary( EmpMock(), mock_object<>::prototype() );
}
//____________________________________________________________________________//
// EOF
|