From a11d3273185f46a6ee666521f47fbe870a9efbb5 Mon Sep 17 00:00:00 2001 From: mat007 Date: Thu, 19 Nov 2009 13:27:21 +0000 Subject: [PATCH] Fix git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@64 860be788-9bd5-4423-9f1e-828f051e677b --- src/libraries/turtle/node.hpp | 7 +++---- src/libraries/turtle/object.hpp | 10 ++++++++++ src/tests/turtle_test/object_test.cpp | 9 +++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/libraries/turtle/node.hpp b/src/libraries/turtle/node.hpp index 1d88477..317dbb0 100644 --- a/src/libraries/turtle/node.hpp +++ b/src/libraries/turtle/node.hpp @@ -10,7 +10,6 @@ #define MOCK_NODE_HPP_INCLUDED #include "verifiable.hpp" -#include #include #include #include @@ -19,7 +18,7 @@ namespace mock { - class node : private boost::noncopyable + class node : protected verifiable { public: void add( verifiable& e ) @@ -31,7 +30,7 @@ namespace mock v_.erase( std::remove( v_.begin(), v_.end(), &e ), v_.end() ); } - bool verify() const + virtual bool verify() const { bool valid = true; for( verifiables_cit it = v_.begin(); it != v_.end(); ++it ) @@ -39,7 +38,7 @@ namespace mock valid = false; return valid; } - void reset() + virtual void reset() { std::for_each( v_.begin(), v_.end(), std::mem_fun( &verifiable::reset ) ); diff --git a/src/libraries/turtle/object.hpp b/src/libraries/turtle/object.hpp index 94c3725..b524526 100644 --- a/src/libraries/turtle/object.hpp +++ b/src/libraries/turtle/object.hpp @@ -10,6 +10,7 @@ #define MOCK_OBJECT_HPP_INCLUDED #include "node.hpp" +#include "root.hpp" #include #include #include @@ -51,6 +52,15 @@ namespace mock class object_impl : public node { public: + object_impl() + { + root.add( *this ); + } + virtual ~object_impl() + { + root.remove( *this ); + } + std::string name_; private: diff --git a/src/tests/turtle_test/object_test.cpp b/src/tests/turtle_test/object_test.cpp index 291836d..847b339 100644 --- a/src/tests/turtle_test/object_test.cpp +++ b/src/tests/turtle_test/object_test.cpp @@ -41,6 +41,15 @@ BOOST_AUTO_TEST_CASE( verifying_an_object_containing_a_failing_expectation_fails 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 ) { mock::object o;