Thread: [Mockpp-commits] mockpp/mockpp/tests ChainableMockObjectPolymorphism_test.cpp,NONE,1.1 ChainingMockO
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-09-22 18:34:27
|
Update of /cvsroot/mockpp/mockpp/mockpp/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9065/mockpp/tests Modified Files: ChainingMockObjectSupport_test.cpp IsSame_test.cpp Makefile.am Added Files: ChainableMockObjectPolymorphism_test.cpp Log Message: make IsSame compare by reference --- NEW FILE: ChainableMockObjectPolymorphism_test.cpp --- /*************************************************************************** ChainableMockObjectPolymorphism_test.cpp - unit tests for MockVisitor class and polymorphic parameter methods ------------------- begin : Tue Sep 20 2004 copyright : (C) 2005 contributed by Mathieu Champlon email : mockpp at ewald-arnold dot de $Id: ChainableMockObjectPolymorphism_test.cpp,v 1.1 2005/09/22 18:34:19 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * ***************************************************************************/ #define MOCKPP_ENABLE_DEFAULT_FORMATTER #include <mockpp/mockpp.h> // always first #ifndef HAVE_CPPUNIT # warning CppUnit not available at compile time #else #include <mockpp/ChainableMockObject.h> #include <mockpp/chaining/ChainingMockObjectSupport.h> #include <mockpp/chaining/Invocation.h> #include <mockpp/constraint/OutBound.h> #include <cppunit/extensions/HelperMacros.h> class MockVisitorPolymorphism_test : public CppUnit::TestFixture { public: CPPUNIT_TEST_SUITE( MockVisitorPolymorphism_test ); CPPUNIT_TEST(test_visitor_retrieves_parameter1); CPPUNIT_TEST(test_visitor_retrieves_parameter2); CPPUNIT_TEST_SUITE_END(); public: void test_visitor_retrieves_parameter1(); void test_visitor_retrieves_parameter2(); }; CPPUNIT_TEST_SUITE_REGISTRATION(MockVisitorPolymorphism_test); // let's suppose we have an interface defined like this : class Parameter { public: // this method won't be part of the test // it's only to show that this class is not a simple value object virtual void doSomething() = 0; }; // this interface will be mocked for the test class Visitor { public: virtual void visit( const Parameter & ) = 0; }; // this is the class under test class UnderTest { public: // it takes a Parameter as a configuration component UnderTest( const Parameter ¶meter ) : parameter_( parameter ) {} // this is the method we are about to test void accept( Visitor &visitor ) { visitor.visit( parameter_ ); } private: const Parameter& parameter_; }; // we need a mock for the Parameter in order to build an UnderTest instance class MockParameter1 : public mockpp::ChainableMockObject, public Parameter { public: MockParameter1(const mockpp::String &name) : mockpp::ChainableMockObject(name, 0) , MOCKPP_CONSTRUCT_MEMBERS_FOR_CHAINABLE0(doSomething) {} MOCKPP_VOID_CHAINABLE0(MockParameter1, doSomething); }; // we need a mock for the Parameter in order to build an UnderTest instance class MockParameter2 : public mockpp::ChainableMockObject, public Parameter { public: MockParameter2(const mockpp::String &name) : mockpp::ChainableMockObject(name, 0) , MOCKPP_CONSTRUCT_MEMBERS_FOR_CHAINABLE0(doSomething) {} bool operator==(const MockParameter2 &rhs) const { return this == &rhs; } MOCKPP_VOID_CHAINABLE0(MockParameter2, doSomething); }; // we mock the Visitor in order to call the apply method of UnderTest with it class MockVisitor1 : public mockpp::ChainableMockObject, public Visitor { public: MockVisitor1(const mockpp::String &name) : mockpp::ChainableMockObject(name, 0) , MOCKPP_CONSTRUCT_MEMBERS_FOR_CHAINABLE1(visit) {} // here is the first problem as Parameter is just an interface MOCKPP_VOID_CHAINABLE_EXT1(MockVisitor1, visit, const Parameter &, , Parameter); }; // we mock the Visitor in order to call the apply method of UnderTest with it class MockVisitor2 : public mockpp::ChainableMockObject, public Visitor { public: MockVisitor2(const mockpp::String &name) : mockpp::ChainableMockObject(name, 0) , MOCKPP_CONSTRUCT_MEMBERS_FOR_CHAINABLE1(visit) {} // here is the first problem as Parameter is just an interface MOCKPP_VOID_CHAINABLE_EXT1(MockVisitor2, visit, const Parameter &, , MockParameter2); }; bool operator==(const Parameter &p1, const Parameter &p2) { return &p1 == &p2; } void MockVisitorPolymorphism_test::test_visitor_retrieves_parameter1() { // we create our class under test MockParameter1 mp1(MOCKPP_PCHAR("mock-parameter1")); UnderTest ut1(mp1); // we program the mock visitor as we expect MockVisitor1 mv(MOCKPP_PCHAR("mock-visitor")); MOCKPP_CHAINER_FOR(MockVisitor1, visit) chain(&mv); // here is the second problem as we would like to verify that the // call is made with precisely 'mp' and nothing else chain.stubs(mockpp::once()) .with(mockpp::same<Parameter>(mp1)); // we trigger the tested method ut1.accept(mv); // and finally verify the expectation mv.verify(); } void MockVisitorPolymorphism_test::test_visitor_retrieves_parameter2() { // we create our class under test MockParameter2 mp2(MOCKPP_PCHAR("mock-parameter2")); UnderTest ut2(mp2); // we program the mock visitor as we expect MockVisitor2 mv(MOCKPP_PCHAR("mock-visitor")); MOCKPP_CHAINER_FOR(MockVisitor2, visit) chain(&mv); // here is the second problem as we would like to verify that the // call is made with precisely 'mp' and nothing else chain.stubs(mockpp::once()) .with(mockpp::same(mp2)); // we trigger the tested method ut2.accept(mv); // and finally verify the expectation mv.verify(); } #endif // HAVE_CPPUNIT Index: ChainingMockObjectSupport_test.cpp =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/tests/ChainingMockObjectSupport_test.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- ChainingMockObjectSupport_test.cpp 3 Apr 2005 18:32:54 -0000 1.28 +++ ChainingMockObjectSupport_test.cpp 22 Sep 2005 18:34:19 -0000 1.29 @@ -273,7 +273,8 @@ void ChainingMockObjectSupport_test::test_same_func() { - mockpp::Constraint<std::string>::AP same = mockpp::same( std::string( "string" ) ); + std::string str( "string" ); + mockpp::Constraint<std::string>::AP same = mockpp::same( str ); CPPUNIT_ASSERT( same->eval( "string" ) == true ); CPPUNIT_ASSERT( same->eval( "not-string" ) == false ); } Index: Makefile.am =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/tests/Makefile.am,v retrieving revision 1.79 retrieving revision 1.80 diff -u -d -r1.79 -r1.80 --- Makefile.am 19 Sep 2005 18:36:28 -0000 1.79 +++ Makefile.am 22 Sep 2005 18:34:19 -0000 1.80 @@ -56,26 +56,26 @@ VerifyingTestCaller_test.cpp TrackingCounter_test.cpp MixedMockObject_5_test.cpp TimeServer_test.cpp jmock_test_SOURCES = And_test.cpp IsAnything_test.cpp IsCloseTo_test.cpp \ - IsEqual_test.cpp IsGreaterOrEqual_test.cpp IsGreaterThan_test.cpp IsInstanceOf_test.cpp \ - IsLessOrEqual_test.cpp IsLessThan_test.cpp IsNot_test.cpp IsNothing_test.cpp IsSame_test.cpp \ - Or_test.cpp ReturnStub_test.cpp StringContains_test.cpp StubSequence_test.cpp \ - TestFailureStub_test.cpp ThrowStub_test.cpp VoidStub_test.cpp ChainingMockObjectSupport_test.cpp \ - CustomStub_test.cpp DefaultResultStub_test.cpp mock_test.cpp Invocation_test.cpp \ - AnyArgumentsMatcher_test.cpp InvokedRecorder_test.cpp InvokeAtLeastOnceMatcher_test.cpp \ - InvokeOnceMatcher_test.cpp InvokeCountMatcher_test.cpp InvokedAfterMatcher_test.cpp \ - TestFailureMatcher_test.cpp NoArgumentsMatcher_test.cpp ArgumentsMatcher_test.cpp \ - ConstraintSet_test.cpp ArgumentsMatchBuilder_test.cpp InvocationMockerBuilder_test.cpp \ - AbstractDynamicChainingMock_test.cpp AbstractInvocationDispatcher_test.cpp ChainingMockBuilder_test.cpp \ - CoreMock_test.cpp DynamicChainingMockError_test.cpp FIFOInvocationDispatcher_test.cpp \ - InvocationMocker_test.cpp LIFOInvocationDispatcher_test.cpp InvokeAtMostMatcher_test.cpp \ - InvokedBeforeMatcher_test.cpp StubBuilder_test.cpp MatchBuilder_test.cpp \ - InvokeAtLeastMatcher_test.cpp classes_ABCDE.cpp ChainableMockObject_1_test.cpp \ - ChainableMockObject_1_void_test.cpp ChainableMockObject_2_test.cpp ChainableMockObject_2_void_test.cpp \ - ChainableMockObject_3_test.cpp ChainableMockObject_3_void_test.cpp ChainableMockObject_4_test.cpp \ - ChainableMockObject_4_void_test.cpp ChainableMockObject_5_test.cpp ChainableMockObject_5_void_test.cpp \ - ChainableMockObject_test.cpp ChainableMockObject_void_test.cpp TypelessStubSequence_test.cpp \ - StringEndsWith_test.cpp StringStartsWith_test.cpp UnlimitedMatcher_test.cpp mockpp_pti_test.cpp \ - OutBound_test.cpp + IsEqual_test.cpp IsGreaterOrEqual_test.cpp IsGreaterThan_test.cpp IsInstanceOf_test.cpp \ + IsLessOrEqual_test.cpp IsLessThan_test.cpp IsNot_test.cpp IsNothing_test.cpp IsSame_test.cpp \ + Or_test.cpp ReturnStub_test.cpp StringContains_test.cpp StubSequence_test.cpp \ + TestFailureStub_test.cpp ThrowStub_test.cpp VoidStub_test.cpp ChainingMockObjectSupport_test.cpp \ + CustomStub_test.cpp DefaultResultStub_test.cpp mock_test.cpp Invocation_test.cpp \ + AnyArgumentsMatcher_test.cpp InvokedRecorder_test.cpp InvokeAtLeastOnceMatcher_test.cpp \ + InvokeOnceMatcher_test.cpp InvokeCountMatcher_test.cpp InvokedAfterMatcher_test.cpp \ + TestFailureMatcher_test.cpp NoArgumentsMatcher_test.cpp ArgumentsMatcher_test.cpp \ + ConstraintSet_test.cpp ArgumentsMatchBuilder_test.cpp InvocationMockerBuilder_test.cpp \ + AbstractDynamicChainingMock_test.cpp AbstractInvocationDispatcher_test.cpp ChainingMockBuilder_test.cpp \ + CoreMock_test.cpp DynamicChainingMockError_test.cpp FIFOInvocationDispatcher_test.cpp \ + InvocationMocker_test.cpp LIFOInvocationDispatcher_test.cpp InvokeAtMostMatcher_test.cpp \ + InvokedBeforeMatcher_test.cpp StubBuilder_test.cpp MatchBuilder_test.cpp \ + InvokeAtLeastMatcher_test.cpp classes_ABCDE.cpp ChainableMockObject_1_test.cpp \ + ChainableMockObject_1_void_test.cpp ChainableMockObject_2_test.cpp ChainableMockObject_2_void_test.cpp \ + ChainableMockObject_3_test.cpp ChainableMockObject_3_void_test.cpp ChainableMockObject_4_test.cpp \ + ChainableMockObject_4_void_test.cpp ChainableMockObject_5_test.cpp ChainableMockObject_5_void_test.cpp \ + ChainableMockObject_test.cpp ChainableMockObject_void_test.cpp TypelessStubSequence_test.cpp \ + StringEndsWith_test.cpp StringStartsWith_test.cpp UnlimitedMatcher_test.cpp mockpp_pti_test.cpp \ + OutBound_test.cpp ChainableMockObjectPolymorphism_test.cpp readability_test_SOURCES = readability_test.cpp classes_ABCDE.cpp Index: IsSame_test.cpp =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/tests/IsSame_test.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- IsSame_test.cpp 30 Dec 2004 20:54:06 -0000 1.6 +++ IsSame_test.cpp 22 Sep 2005 18:34:19 -0000 1.7 @@ -71,7 +71,8 @@ void IsSame_test::test_invoke() { - mockpp::IsSame<std::string> same ("string"); + std::string str = "string"; + mockpp::IsSame<std::string> same (str); CPPUNIT_ASSERT(same.eval("string") == true); CPPUNIT_ASSERT(same.eval("not-string") == false); } |