Update of /cvsroot/mockpp/mockpp/mockpp/tests
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27160/mockpp/tests
Added Files:
ChainableMockMethod_1_test.cpp
Log Message:
draft
--- NEW FILE: ChainableMockMethod_1_test.cpp ---
/***************************************************************************
ChainableMockMethod_1_test.cpp
-
unit tests for ChainableMockObject class and 1 parameter methods
-------------------
begin : Thu Sep 28 2004
copyright : (C) 2002-2005 by Ewald Arnold
email : mockpp at ewald-arnold dot de
$Id: ChainableMockMethod_1_test.cpp,v 1.1 2005/10/02 10:55:47 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.
*
***************************************************************************/
#include <mockpp/mockpp.h> // always first
#ifndef HAVE_CPPUNIT
# warning CppUnit not available at compile time
#else
#include <mockpp/chaining/ChainableMockMethod.h>
#include <mockpp/chaining/ChainingMockObjectSupport.h>
#include <mockpp/chaining/Invocation.h>
#include <mockpp/constraint/OutBound.h>
#include <cppunit/extensions/HelperMacros.h>
namespace { // anon
class ChainableMockMethod_1_test : public CppUnit::TestFixture
{
public:
CPPUNIT_TEST_SUITE( ChainableMockMethod_1_test );
CPPUNIT_TEST(test_outbound);
CPPUNIT_TEST( test_parameter_1 );
CPPUNIT_TEST_SUITE_END();
public:
void test_outbound();
void test_parameter_1();
};
CPPUNIT_TEST_SUITE_REGISTRATION(ChainableMockMethod_1_test);
class MyChainableMockObject_1 : public mockpp::ChainableMockObject
{
public:
MyChainableMockObject_1(const mockpp::String &name)
: mockpp::ChainableMockObject(name, 0)
, chainable_mocker(MOCKPP_PCHAR("chainable"), this)
{}
int chainable(unsigned i)
{
return chainable_mocker.forward(i);
}
mockpp::ChainableMockMethod<int, unsigned> chainable_mocker;
};
void ChainableMockMethod_1_test::test_parameter_1()
{
MyChainableMockObject_1 mcm(MOCKPP_PCHAR("chainable-object"));
mockpp::ChainerFor<mockpp::ChainableMockMethod<int, unsigned> > chain(mcm, mcm.chainable_mocker);
chain.stubs(mockpp::once())
.with(mockpp::eq((unsigned int) 12))
.will(new mockpp::ReturnStub<int>(21));
chain.stubs(mockpp::once())
.with(mockpp::eq((unsigned int) 34)) // @todoc pitfall
.will(new mockpp::ReturnStub<int>(43));
CPPUNIT_ASSERT(mcm.chainable(12) == 21);
CPPUNIT_ASSERT(mcm.chainable(34) == 43);
try
{
mcm.chainable(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();
}
void ChainableMockMethod_1_test::test_outbound()
{
MyChainableMockObject_1 mcm(MOCKPP_PCHAR("chainable-object"));
/*
MOCKPP_CHAINER_FOR_EXT(MyChainableMockObject_1ex, outbound, Ext) chain(&mcm);
chain.stubs(mockpp::once())
.with(mockpp::outBound( (unsigned int) 123));
chain.stubs(mockpp::once())
.with(mockpp::outBound( (unsigned int) 456));
unsigned val = 0;
mcm.outbound(val);
CPPUNIT_ASSERT_EQUAL((unsigned)123, val);
mcm.outbound(val);
CPPUNIT_ASSERT_EQUAL((unsigned)456, val);
*/
}
} // anon ns
#endif // HAVE_CPPUNIT
|