[Mockpp-commits] mockpp/mockpp/docs/en Makefile.am,1.36,1.37 dev_advanced_easymock.docbook,1.8,1.9 d
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-11-17 21:09:02
|
Update of /cvsroot/mockpp/mockpp/mockpp/docs/en In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11881/mockpp/docs/en Modified Files: Makefile.am dev_advanced_easymock.docbook dev_advanced_jmock.docbook Log Message: update Index: dev_advanced_jmock.docbook =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/docs/en/dev_advanced_jmock.docbook,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- dev_advanced_jmock.docbook 28 Oct 2005 20:35:14 -0000 1.14 +++ dev_advanced_jmock.docbook 17 Nov 2005 21:08:52 -0000 1.15 @@ -37,7 +37,6 @@ <programlisting> - MOCKPP_CHAINER_FOR (MyClass, MyMethod) chainer (&myobject); chainer.expects(once()) .after("other-ident") .with(new IsEqual<int>(321)) @@ -234,7 +233,7 @@ <programlisting> - mockpp::IsSame<std::string> same ("string"); + IsSame<std::string> same ("string"); </programlisting> @@ -244,7 +243,7 @@ <programlisting> std::string str ("string"); - mockpp::IsSame<std::string> same (str); + IsSame<std::string> same (str); </programlisting> @@ -287,7 +286,7 @@ </sect3> <sect3> -<title>Some Examples</title> +<title>Create a Chainer Object Using Macros</title> <para> To get a chainable mock object you must: @@ -306,8 +305,8 @@ { public: - virtual int access(unsigned &index) = 0; - } + virtual int access(unsigned index) = 0; + }; class MyChainableMockObject : public ChainableMockObject, <co id="chainable-class-co" linkends="chainable-class" /> public MyInterfaceClass @@ -325,10 +324,18 @@ MOCKPP_CHAINER_FOR(MyChainableMockObject, access) chainer (&mco); <co id="jmock-chainer-co" linkends="jmock-controller" /> - chainer.setDefaultStub(new ThrowStub(std::string("throw-default"))); <co id="jmock-feed1-co" linkends="jmock-feed1" /> - chainer.stubs().with(1).will(new ReturnStub(13)); <co id="jmock-feed2-co" linkends="jmock-feed2" /> - chainer.expects(once()).with((2).id("called-with-2"); <co id="jmock-feed3-co" linkends="jmock-feed3" /> - chainer.stubs().after(otherObject, "some-label").will(new ReturnStub(2222)); <co id="jmock-feed4-co" linkends="jmock-feed4" /> + chainer.setDefaultStub(new ThrowStub<int>(make_throwable(1))); <co id="jmock-feed1-co" linkends="jmock-feed1" /> + chainer.stubs() + .with(eq(1)) + .will(new ReturnStub<int>(13)); <co id="jmock-feed2-co" linkends="jmock-feed2" /> + + chainer.expects(once()) + .with((eq(2))) + .id("called-with-2"); <co id="jmock-feed3-co" linkends="jmock-feed3" /> + + chainer.stubs() + .after(otherObject, "some-label") + .will(new ReturnStub<int>(2222)); <co id="jmock-feed4-co" linkends="jmock-feed4" /> // use the object @@ -394,4 +401,75 @@ </sect3> +<sect3> +<title>Using a Mock Method Chainer</title> + +The second approach with mock method templates is almost the same as before. The difference +is to replace the macros and the resulting chainer object with the method object +and forward the call to it. + +<programlisting> + + class MyChainableMockObject : public ChainableMockObject, + public MyInterfaceClass + { + public: + MyChainableMockObject(const String &name) + : ChainableMockObject(name, 0) + , access_mocker("access", this) <co id="chainmeth-cons-co" linkends="chainmeth-cons" /> + {} + + virtual int access(unsigned index) <co id="chainmeth-fwd-co" linkends="chainmeth-fwd" /> + { + return access_mocker.forward(index); + } + + ChainableMockMethod1<int, unsigned> access_mocker; <co id="chainmeth-var-co" linkends="chainmeth-var" /> + }; + + MyChainableMockObject mco("mco"); + + ChainableMockMethod1<int, unsigned> &chainer (mco.access_mocker); <co id="chainmeth-ref-co" linkends="chainmeth-ref" /> + + chainer.setDefaultStub(new ThrowStub<int>(make_throwable(1))); + chainer.stubs() + .with(eq(12u)) + .will(new ReturnStub<int>(13)); <co id="chainmeth-setup-co" linkends="chainmeth-setup" /> + + // use the object + + mco.verify(); + +</programlisting> + +<calloutlist> + + <callout arearefs="chainmeth-cons-co" id="chainmeth-cons" > + <para>Construct the mock method helper object.</para> + </callout> + + <callout arearefs="chainmeth-fwd-co" id="chainmeth-fwd" > + <para>Provide the method as entry point and forward the call to + the method which does the actual work.</para> + </callout> + + <callout arearefs="chainmeth-var-co" id="chainmeth-var" > + <para>Instantiate a mock method variable. Select the class according + to the parameters the method takes. There also a template without a trailing + number which handles an arbitrary parameter count.</para> + </callout> + + <callout arearefs="chainmeth-ref-co" id="chainmeth-ref" > + <para>For convenience create a reference to the mock method helper.</para> + </callout> + + <callout arearefs="chainmeth-setup-co" id="chainmeth-setup" > + <para>Set up the mock objects behaviour in the same manner as + described above using the macros.</para> + </callout> + +</calloutlist> + +</sect3> + </sect2> Index: dev_advanced_easymock.docbook =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/docs/en/dev_advanced_easymock.docbook,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- dev_advanced_easymock.docbook 5 May 2005 21:01:59 -0000 1.8 +++ dev_advanced_easymock.docbook 17 Nov 2005 21:08:52 -0000 1.9 @@ -10,13 +10,17 @@ To obtain a visitable mock object you must: <itemizedlist> <listitem>Derive and define your object with the methods you need</listitem> - <listitem>Create a controller for each method and set up the behaviour</listitem> + <listitem>Create a helper object for each method and set up the behaviour</listitem> <listitem>Activate and use the object</listitem> </itemizedlist> </para> +<sect3 id="visit-macros"> +<title>Using Macros</title> + <para> -The following listing contains a short example and explains the basic features. +The following listing contains a short example and explains the basic features +when using macros. <programlisting> @@ -25,7 +29,7 @@ public: virtual int access(unsigned &index) = 0; - } + }; class MyVisitableMockObject : public VisitableMockObject, <co id="visitable-class-co" linkends="visitable-class" /> public MyInterfaceClass @@ -47,11 +51,11 @@ access_ctr.addThrowable(std::string("throw"), 2); <co id="mock-feed1-co" linkends="mock-feed1" /> access_ctr.addResponseValue(1, 13); <co id="mock-feed2-co" linkends="mock-feed2" /> access_ctr.addResponseValue(2, 37); - access_ctr.addResponseValue(3, gt<unsigned>(50)); <co id="mock-gt-co" linkends="mock-gt" /> + access_ctr.addResponseValue(3, lt(50u)); <co id="mock-gt-co" linkends="mock-gt" /> mvo.access(1); <co id="mock-feed3-co" linkends="mock-feed3" /> mvo.access(13); - mvo.access(lt<unsigned>(123)); <co id="mock-feed4-co" linkends="mock-feed4" /> + mvo.access(lt(123u)); <co id="mock-feed4-co" linkends="mock-feed4" /> mvo.activate(); <co id="mock-activate-co" linkends="mock-activate" /> @@ -112,7 +116,8 @@ </callout> <callout arearefs="mock-feed4-co" id="mock-feed4" > - <para>Demands that the parameter value is less than 123.</para> + <para>Demands that the parameter value is less than 123 by using an + appropriate <link linkend="parameter-constraint">constraint object</link>.</para> </callout> <callout arearefs="mock-activate-co" id="mock-activate" > @@ -132,6 +137,100 @@ the api documentation of <classname>VisitableMockObject::Controller</classname>. </para> +</sect3> + + +<sect3 id="visit-template"> +<title>Using Mock Method Templates</title> + +The second approach with mock method templates is almost the same as before. The difference +is to replace the macros and the resulting controller object with the method object +and forward the call to it. + +<programlisting> + + class MyVisitableMockObject : public VisitableMockObject, + public MyInterfaceClass + { + public: + + MyVisitableMockObject(const String &name) + : VisitableMockObject(name, 0) + , access_mocker("access", this) <co id="mockmeth-cons-co" linkends="mockmeth-cons" /> + {} + + virtual int access(unsigned index) <co id="mockmeth-fwd-co" linkends="mockmeth-fwd" /> + { + return access_mocker.forward(index); + } + + virtual void access(const ConstraintHolder<unsigned> &p) const <co id="mockmeth-fwd-constraint-co" linkends="mockmeth-fwd-constraint" /> + { + return access_mocker.forward(p); + } + + VisitableMockMethod1<int, unsigned> access_mocker; <co id="mockmeth-var-co" linkends="mockmeth-var" /> + }; + + MyVisitableMockObject mvmo("mvmo"); + + VisitableMockMethod1<int, unsigned> &access_ctr (mvmo.access_mocker); <co id="mockmeth-ref-co" linkends="mockmeth-ref" /> + + access_ctr.addThrowable(std::string("throw"), 2); + access_ctr.addResponseValue(1, 13); + access_ctr.addResponseValue(2, 37); + access_ctr.addResponseValue(3, eq(50u)); <co id="mockmeth-setup-co" linkends="mockmeth-setup" /> + + mvmo.access(1); + mvmo.access(13); + mvmo.access(eq(123)); + + mvmo.activate(); + + // use the object + + mvmo.verify(); + +</programlisting> + +<calloutlist> + + <callout arearefs="mockmeth-cons-co" id="mockmeth-cons" > + <para>Construct the mock method helper object.</para> + </callout> + + <callout arearefs="mockmeth-fwd-co" id="mockmeth-fwd" > + <para>Provide the method as entry point and forward the call to + the method which does the actual work.</para> + </callout> + + <callout arearefs="mockmeth-fwd-constraint-co" id="mockmeth-fwd-constraint" > + <para>If you want to benefit from <link linkend="parameter-constraint">constraints</link> + you have to provide an overloaded method which forwards the + constraint holder. This method has always return type <token>void</token> + and should be <token>const</token>. Of course you can call this method only + in record mode.</para> + </callout> + + <callout arearefs="mockmeth-var-co" id="mockmeth-var" > + <para>Instantiate a mock method variable. Select the class according + to the parameters the method takes. There also a template without a trailing + number which handles an arbitrary parameter count.</para> + </callout> + + <callout arearefs="mockmeth-ref-co" id="mockmeth-ref" > + <para>For convenience create a reference to the mock method helper.</para> + </callout> + + <callout arearefs="mockmeth-setup-co" id="mockmeth-setup" > + <para>Set up the mock objects behaviour in the same manner as + described above using the macros.</para> + </callout> + +</calloutlist> + +</sect3> + <sect3 id="visit-order"> <title>Dispatching Order</title> Index: Makefile.am =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/docs/en/Makefile.am,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- Makefile.am 14 Nov 2005 19:42:14 -0000 1.36 +++ Makefile.am 17 Nov 2005 21:08:52 -0000 1.37 @@ -29,10 +29,9 @@ ln -s ../../examples/tutorial/html tutorial -test -L api-doc && rm api-doc ln -s ../../docs/api/html api-doc - mkdir -pv var - -rm -rf ./var -rm -rf ./var/common -rm -rf ./var/images + mkdir -pv var cp -R $(srcdir)/common var cp -R $(srcdir)/images var xsltproc --nonet -o var/ $(srcdir)/customize-chunked.xsl $(srcdir)/index.docbook |