git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@64 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2009-11-19 13:27:21 +00:00
parent b3ece38963
commit a11d327318
3 changed files with 22 additions and 4 deletions

View file

@ -10,7 +10,6 @@
#define MOCK_NODE_HPP_INCLUDED #define MOCK_NODE_HPP_INCLUDED
#include "verifiable.hpp" #include "verifiable.hpp"
#include <boost/noncopyable.hpp>
#include <functional> #include <functional>
#include <algorithm> #include <algorithm>
#include <ostream> #include <ostream>
@ -19,7 +18,7 @@
namespace mock namespace mock
{ {
class node : private boost::noncopyable class node : protected verifiable
{ {
public: public:
void add( verifiable& e ) void add( verifiable& e )
@ -31,7 +30,7 @@ namespace mock
v_.erase( std::remove( v_.begin(), v_.end(), &e ), v_.end() ); v_.erase( std::remove( v_.begin(), v_.end(), &e ), v_.end() );
} }
bool verify() const virtual bool verify() const
{ {
bool valid = true; bool valid = true;
for( verifiables_cit it = v_.begin(); it != v_.end(); ++it ) for( verifiables_cit it = v_.begin(); it != v_.end(); ++it )
@ -39,7 +38,7 @@ namespace mock
valid = false; valid = false;
return valid; return valid;
} }
void reset() virtual void reset()
{ {
std::for_each( v_.begin(), v_.end(), std::for_each( v_.begin(), v_.end(),
std::mem_fun( &verifiable::reset ) ); std::mem_fun( &verifiable::reset ) );

View file

@ -10,6 +10,7 @@
#define MOCK_OBJECT_HPP_INCLUDED #define MOCK_OBJECT_HPP_INCLUDED
#include "node.hpp" #include "node.hpp"
#include "root.hpp"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <ostream> #include <ostream>
#include <string> #include <string>
@ -51,6 +52,15 @@ namespace mock
class object_impl : public node class object_impl : public node
{ {
public: public:
object_impl()
{
root.add( *this );
}
virtual ~object_impl()
{
root.remove( *this );
}
std::string name_; std::string name_;
private: private:

View file

@ -41,6 +41,15 @@ BOOST_AUTO_TEST_CASE( verifying_an_object_containing_a_failing_expectation_fails
BOOST_CHECK( ! o.verify() ); BOOST_CHECK( ! o.verify() );
} }
BOOST_AUTO_TEST_CASE( verifying_all_objects_with_one_of_them_containing_a_failing_expectation_fails )
{
mock::object o;
mock::expectation< void(), silent_error > e;
o.set_parent( e );
e.expect().once();
BOOST_CHECK( ! mock::verify() );
}
BOOST_AUTO_TEST_CASE( resetting_an_object_containing_a_failing_expectation_and_verifying_it_succeeds ) BOOST_AUTO_TEST_CASE( resetting_an_object_containing_a_failing_expectation_and_verifying_it_succeeds )
{ {
mock::object o; mock::object o;