Thread: [Mockpp-commits] mockpp/mockpp/tests IncCounter.h,NONE,1.1 ChainableMockMethod_1_test.cpp,1.2,1.3 Ch
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-10-03 09:55:03
|
Update of /cvsroot/mockpp/mockpp/mockpp/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20688/mockpp/tests Modified Files: ChainableMockMethod_1_test.cpp ChainableMockMethod_2_test.cpp Makefile.am Added Files: IncCounter.h Log Message: more tests and fixes Index: Makefile.am =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/tests/Makefile.am,v retrieving revision 1.83 retrieving revision 1.84 diff -u -d -r1.83 -r1.84 --- Makefile.am 2 Oct 2005 18:51:33 -0000 1.83 +++ Makefile.am 3 Oct 2005 09:54:39 -0000 1.84 @@ -83,7 +83,7 @@ check_inst_SOURCES = check_inst.cpp -noinst_HEADERS = classes_ABCDE.h MyBuilderNamespace.h MyMatchBuilder.h +noinst_HEADERS = classes_ABCDE.h MyBuilderNamespace.h MyMatchBuilder.h IncCounter.h ########################################################################### Index: ChainableMockMethod_1_test.cpp =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/tests/ChainableMockMethod_1_test.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ChainableMockMethod_1_test.cpp 2 Oct 2005 18:51:33 -0000 1.2 +++ ChainableMockMethod_1_test.cpp 3 Oct 2005 09:54:39 -0000 1.3 @@ -44,8 +44,11 @@ #include <mockpp/constraint/OutBound.h> +#include "IncCounter.h" + #include <cppunit/extensions/HelperMacros.h> + namespace { // anon @@ -56,12 +59,14 @@ CPPUNIT_TEST_SUITE( ChainableMockMethod_1_test ); CPPUNIT_TEST( test_parameter_1 ); + CPPUNIT_TEST( test_parameter_1v ); CPPUNIT_TEST_SUITE_END(); public: void test_parameter_1(); + void test_parameter_1v(); }; @@ -75,6 +80,7 @@ MyChainableMockObject_1(const mockpp::String &name) : mockpp::ChainableMockObject(name, 0) , chainable_mocker(MOCKPP_PCHAR("chainable"), this) + , chainablev_mocker(MOCKPP_PCHAR("chainablev"), this) {} int chainable(unsigned i) @@ -82,7 +88,13 @@ return chainable_mocker.forward(i); } - mockpp::ChainableMockMethod1<int, unsigned> chainable_mocker; + void chainablev(unsigned i) + { + chainablev_mocker.forward(i); + } + + mockpp::ChainableMockMethod1<int, unsigned> chainable_mocker; + mockpp::ChainableMockMethod1<void, unsigned> chainablev_mocker; }; @@ -97,7 +109,7 @@ .will(new mockpp::ReturnStub<int>(21)); chain.stubs(mockpp::once()) - .with(mockpp::eq((unsigned int) 34)) // @todoc pitfall + .with(mockpp::eq((unsigned int) 34)) .will(new mockpp::ReturnStub<int>(43)); CPPUNIT_ASSERT(mcm.chainable(12) == 21); @@ -117,6 +129,40 @@ } +void ChainableMockMethod_1_test::test_parameter_1v() +{ + MyChainableMockObject_1 mcm(MOCKPP_PCHAR("chainable-object")); + + mockpp::ChainableMockMethod1<void, unsigned>::ChainerFor chain(mcm, mcm.chainablev_mocker); + unsigned counter = 0; + + chain.stubs(mockpp::once()) + .with(mockpp::eq((unsigned int) 12)) + .will(new IncCounter<unsigned>(counter)); +// @todo CPPUNIT_ASSERT_EQUAL(1u, counter); + + chain.stubs(mockpp::once()) + .with(mockpp::eq((unsigned int) 34)) + .will(new IncCounter<unsigned>(counter)); +// @todo CPPUNIT_ASSERT_EQUAL(2u, counter); + + mcm.chainablev(12); + mcm.chainablev(34); + + try + { + mcm.chainablev(56); + CPPUNIT_ASSERT_MESSAGE("should have thrown", false); + } + catch(mockpp::AssertionFailedError &ex) + { + CPPUNIT_ASSERT(ex.getMessage().find(MOCKPP_PCHAR("unexpected invocation")) != mockpp::String::npos); + } + + mcm.verify(); +} + + } // anon ns --- NEW FILE: IncCounter.h --- /*************************************************************************** IncCounter.cpp - Increments a counter value for testing purposes ------------------- begin : Thu Oct 2 2005 copyright : (C) 2002-2005 by Ewald Arnold email : mockpp at ewald-arnold dot de $Id: IncCounter.h,v 1.1 2005/10/03 09:54:39 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** begin : Thu Oct 3 2005 copyright : (C) 2002-2005 by Ewald Arnold email : mockpp at ewald-arnold dot de 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. */ #ifndef MOCKPP_IncCounter_H #define MOCKPP_IncCounter_H #include <mockpp/mockpp.h> // always first #include <mockpp/stub/TypelessStub.h> #include <iostream> // @todo template <typename T> class IncCounter : public mockpp::TypelessStub<void> { public: IncCounter( T &arg ) : back_ref(arg) { } virtual ~IncCounter() {} virtual void typelessInvoke() { std::cout << "inccounter\n"; back_ref++; } virtual mockpp::String describeTo( mockpp::String &buffer ) const { mockpp::String fmt = MOCKPP_PCHAR("inc counter %1"); buffer += fmt; return buffer; } private: T& back_ref; }; #endif // MOCKPP_IncCounter_H Index: ChainableMockMethod_2_test.cpp =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/tests/ChainableMockMethod_2_test.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ChainableMockMethod_2_test.cpp 2 Oct 2005 18:51:33 -0000 1.1 +++ ChainableMockMethod_2_test.cpp 3 Oct 2005 09:54:39 -0000 1.2 @@ -44,6 +44,8 @@ #include <mockpp/constraint/OutBound.h> +#include "IncCounter.h" + #include <cppunit/extensions/HelperMacros.h> namespace { // anon @@ -56,12 +58,14 @@ CPPUNIT_TEST_SUITE( ChainableMockMethod_2_test ); CPPUNIT_TEST( test_parameter_2 ); + CPPUNIT_TEST( test_parameter_2v ); CPPUNIT_TEST_SUITE_END(); public: void test_parameter_2(); + void test_parameter_2v(); }; @@ -75,6 +79,7 @@ MyChainableMockObject_2(const mockpp::String &name) : mockpp::ChainableMockObject(name, 0) , chainable_mocker(MOCKPP_PCHAR("chainable"), this) + , chainablev_mocker(MOCKPP_PCHAR("chainablev"), this) {} int chainable(unsigned i, long l) @@ -82,7 +87,13 @@ return chainable_mocker.forward(i, l); } - mockpp::ChainableMockMethod2<int, unsigned, long> chainable_mocker; + void chainablev(unsigned i, long l) + { + chainablev_mocker.forward(i, l); + } + + mockpp::ChainableMockMethod2<int, unsigned, long> chainable_mocker; + mockpp::ChainableMockMethod2<void, unsigned, long> chainablev_mocker; }; @@ -119,6 +130,42 @@ } +void ChainableMockMethod_2_test::test_parameter_2v() +{ + MyChainableMockObject_2 mcm(MOCKPP_PCHAR("chainable-object")); + + mockpp::ChainableMockMethod2<void, unsigned, long>::ChainerFor chain(mcm, mcm.chainablev_mocker); + unsigned counter = 0; + + chain.stubs(mockpp::once()) + .with(mockpp::eq<unsigned>(12u), + mockpp::eq<long>(23)) + .will(new IncCounter<unsigned>(counter)); +// @todo CPPUNIT_ASSERT_EQUAL(1u, counter); + + chain.stubs(mockpp::once()) + .with(mockpp::eq<unsigned>(34), + mockpp::eq<long>(45)) + .will(new IncCounter<unsigned>(counter)); +// @todo CPPUNIT_ASSERT_EQUAL(2u, counter); + + mcm.chainablev(12, 23); + mcm.chainablev(34, 45); + + try + { + mcm.chainablev(56, 67); + CPPUNIT_ASSERT_MESSAGE("should have thrown", false); + } + catch(mockpp::AssertionFailedError &ex) + { + CPPUNIT_ASSERT(ex.getMessage().find(MOCKPP_PCHAR("unexpected invocation")) != mockpp::String::npos); + } + + mcm.verify(); +} + + } // anon ns |