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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
// (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/logged_expectations.hpp>
#include <boost/test/mock_object.hpp>
using namespace boost::itest;
// Boost
#include <boost/bind.hpp>
//____________________________________________________________________________//
// Collaborators interfaces
class Stove {
public:
virtual void light() = 0;
virtual void set_temperature( int temp ) = 0;
virtual void set_cook_time( int time_in_sec ) = 0;
virtual void auto_clean() = 0;
};
class Microwave {
public:
virtual int get_max_power() = 0;
virtual void set_power_level( int l ) = 0;
virtual void set_time( int time_in_sec ) = 0;
virtual void start() = 0;
};
class Timer {
public:
virtual void wait( int wait_time ) = 0;
};
//____________________________________________________________________________//
// Collaborators mocks
class MockStove : public ::boost::itest::mock_object<0,Stove> {
public:
virtual void light()
{
BOOST_ITEST_SCOPE( Stove::light );
}
virtual void set_temperature( int temp )
{
BOOST_ITEST_SCOPE( Stove::set_temperature );
BOOST_ITEST_DATA_FLOW( temp );
}
virtual void set_cook_time( int time_in_sec )
{
BOOST_ITEST_SCOPE( Stove::set_cook_time );
BOOST_ITEST_DATA_FLOW( time_in_sec );
}
virtual void auto_clean()
{
BOOST_ITEST_SCOPE( Stove::auto_clean );
}
};
class MockMicrowave : public ::boost::itest::mock_object<0,Microwave> {
public:
virtual int get_max_power()
{
BOOST_ITEST_SCOPE( Microwave::get_max_power );
return BOOST_ITEST_RETURN( int, 1000 );
}
virtual void set_power_level( int l )
{
BOOST_ITEST_SCOPE( Microwave::set_power_level );
BOOST_ITEST_DATA_FLOW( l );
}
virtual void set_time( int time_in_sec )
{
BOOST_ITEST_SCOPE( Microwave::set_time );
BOOST_ITEST_DATA_FLOW( time_in_sec );
}
virtual void start()
{
BOOST_ITEST_SCOPE( Microwave::start );
}
};
class MockTimer : public ::boost::itest::mock_object<0,Timer> {
public:
virtual void wait( int wait_time )
{
BOOST_ITEST_SCOPE( Timer::wait );
BOOST_ITEST_DATA_FLOW( wait_time );
}
};
//____________________________________________________________________________//
// Class under test
class kitchen_robot {
public:
void make_grilled_chicken( Timer& t, Stove& s, Microwave& m )
{
m.set_power_level( 600 / (m.get_max_power()/5) + 1 );
m.set_time( 15 * 60 ); // 15 min
m.start(); // defrost
t.wait( 15 * 60 );
s.set_cook_time( 2 * 60 * 60 ); // 2 hours
s.light();
s.set_temperature( 450 );
t.wait( 15 * 60 ); // 15 min - preheat
s.set_temperature( 400 );
t.wait( 90 * 60 ); // 1 hour 30 min - cook
s.set_temperature( 250 );
t.wait( 90 * 60 ); // 15 min - almost done
s.auto_clean(); // done
}
};
//____________________________________________________________________________//
BOOST_TEST_LOGGED_EXPECTATIONS( test_grilled_chiken_recept )
{
kitchen_robot kr;
MockTimer t;
MockStove s;
MockMicrowave m;
kr.make_grilled_chicken( t, s, m );
}
//____________________________________________________________________________//
// EOF
|