[Mockpp-commits] homepage index-en.gtml,1.10,1.11
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-11-20 10:03:38
|
Update of /cvsroot/mockpp/homepage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16342 Modified Files: index-en.gtml Log Message: update Index: index-en.gtml =================================================================== RCS file: /cvsroot/mockpp/homepage/index-en.gtml,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- index-en.gtml 6 May 2005 12:43:56 -0000 1.10 +++ index-en.gtml 20 Nov 2005 10:03:27 -0000 1.11 @@ -77,10 +77,13 @@ </p> <p> - Originally I started with a port of MockObjects to C++ and wanted to keep the same interfaces. But + Originally I started with a port of <a href="http://www.mockobjects.com/">Mock Objects</a> + to C++ and wanted to keep the same interfaces. But in the meanwhile I found out more about Java and it's differencens to C++ (it's funny reflection api for example ) and so I had to change a bunch of details. Additionally I included the - working method of EasyMock. From my limited understanding of Java there seems to be something + working methods of + <a href="http://www.easymock.org/">EasyMock</a> and <a href="http://www.jmock.org/">jMock</a>. + From my limited understanding of Java there seems to be something similar in MockObjects but I guess EasyMock is easier to use and certainly was easier to port to C++. </p> @@ -95,7 +98,7 @@ </p> <p> - Mockpp contains a number of classes, templates and macros which I divide into + Mockpp contains a number of classes, templates (and macros) which I divide into <a href="#basic"><em>Basic Expectations</em></a> and <a href="#advanced"><em>Advanced Expectations</em></a>. @@ -205,7 +208,8 @@ </p> <p> - To easily feed the parameters into your calls you need a <em>controller</em> for your mock object. + To easily feed the expected parameters into your calls you need a mock method + for your mock object. </p> #compress OFF @@ -217,41 +221,48 @@ public: MyVisitableMockObject(const String &name) - : VisitableMockObject(name, 0), - - // creates internal objects for visitable() method below - MOCKPP_CONSTRUCT_MEMBERS_FOR_METHOD1(visitable) + : VisitableMockObject(name, 0) + // constructs an internal mock method + , visitable_mocker("visitable") this) {} - // creates: int visitable(unsigned); - MOCKPP_VISITABLE1(MyVisitableMockObject, int, visitable, unsigned); + // forwards the actual call to the mock method + int visitable(unsigned u) + { + return visitable_mocker.forward(u); + } + + // creates a mock method for: int visitable(unsigned); + VisitableMockMethod<int, unsigned> visitable_mocker; }; .... - MyVisitableMockObject mvo(MOCKPP_PCHAR("mvo")); - MOCKPP_CONTROLLER_FOR(MyVisitableMockObject, visitable) ctr (&mvo); + MyVisitableMockObject mvo("mvo"); + + // create a short hand reference to the mock method + VisitableMockMethod<int, unsigned> &visitor (mvo.visit_mocker); // we are in record mode now: - ctr.addReturnValue(1); // return "1" the first time - ctr.addReturnValue(11); // return "11" the second time - ctr.setDefaultReturnValue(123); // return "123" all the other calls + visitor.addReturnValue(1); // return "1" the first time + visitor.addReturnValue(11); // return "11" the second time + visitor.setDefaultReturnValue(123); // return "123" all the other calls - ctr.addResponseValue(0, 1); // return "0" when passed "1" - ctr.addResponseValue(1, 0); // return "1" when passed "0" + visitor.addResponseValue(0, 1); // return "0" when passed "1" + visitor.addResponseValue(1, 0); // return "1" when passed "0" - ctr.addResponseThrowable(make_throwable(int(1), 1); // throw when passed "1" - ctr.addResponseThrowable(make_throwable(int(0), 0); // throw when passed "0" + visitor.addResponseThrowable(make_throwable(int(1), 1); // throw when passed "1" + visitor.addResponseThrowable(make_throwable(int(0), 0); // throw when passed "0" // throw std::string("string 1") when called the first time - ctr.addThrowable(make_throwable(std::string("string 1"))); + visitor.addThrowable(make_throwable(std::string("string 1"))); // throw std::string("string 2") the next three times - ctr.addThrowable(std::string("string 2"), 3); + visitor.addThrowable(std::string("string 2"), 3); // throw int(123) the rest of the time - ctr.setDefaultThrowable(make_throwable(int(123))); + visitor.setDefaultThrowable(make_throwable(int(123))); mvo.visitable(1); // require "1" as parameter the first time mvo.visitable(2); // require "2" as parameter the second time @@ -298,7 +309,6 @@ <table border="1"><tr><td bgcolor="white"> <pre> - MOCKPP_CHAINER_FOR (MyClass, MyMethod) chainer (&myobject); chainer.expects(once()) .after("other-ident") .with(new IsEqual<int>(321)) |