[Mockpp-commits] mockpp/mockpp/docs/en Makefile.am,1.21,1.22 appendix.docbook,1.7,1.8 dev_advanced_e
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-05-05 21:02:10
|
Update of /cvsroot/mockpp/mockpp/mockpp/docs/en In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15246/mockpp/docs/en Modified Files: Makefile.am appendix.docbook dev_advanced_easymock.docbook dev_production.docbook Log Message: docs extended and overworked Index: appendix.docbook =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/docs/en/appendix.docbook,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- appendix.docbook 21 Nov 2004 19:32:39 -0000 1.7 +++ appendix.docbook 5 May 2005 21:01:59 -0000 1.8 @@ -18,7 +18,7 @@ <title>Requirements</title> <para> -In order to fully benefit from &mockpp;, you need +In order to fully benefit from &mockpp;, you need <ulink url="http://cppunit.sf.net">CppUnit</ulink>, a framework for unit tests with C++.</para> @@ -27,7 +27,7 @@ <sect1 id="compilation"> <title>Compilation and Installation</title> -<sect2> +<sect2 id="installing-autoconf"> <title>Installing on systems using autoconf and friends</title> <para>In order to compile and install mockpp on your system, type the following in the base @@ -43,21 +43,21 @@ There are some options for <userinput>configure</userinput> you might be interested in: <variablelist> - + <varlistentry> <term>--enable-unicode</term> - <listitem>By default &mockpp; uses standard 8bit wide strings (<token>std::string</token> + <listitem>By default &mockpp; uses standard 8bit wide strings (<token>std::string</token> and <token>const char*</token> to be more precise). If you need basic support for <ulink url="http://www.unicode.org">Unicode</ulink> and it's 16bit or 32bit wide characters - you must add this parameter when invoking <userinput>configure</userinput>. + you must add this parameter when invoking <userinput>configure</userinput>. </listitem> </varlistentry> - + </variablelist> - - + + <para>Since mockpp uses autoconf and automake you should have no trouble compiling it. -Should you run into problems please report them to the +Should you run into problems please report them to the <ulink url="http://sourceforge.net/bugs/?group_id=69135">Bug Tracker</ulink>.</para> <para>Once you have compiled the sources you should run the built in checks @@ -71,14 +71,14 @@ </sect2> -<sect2> +<sect2 id="installing-others"> <title>Installing on other systems</title> <para> If you are using a compiler on a platform not directly supported you must setup you -own project files for your compiler. All adjustments are done in +own project files for your compiler. All adjustments are done in <filename class='headerfile'>mockpp.h</filename>. To benefit from updates it is of -course better to move your own settings to a configuration file and include it. +course better to move your own settings to a configuration file and include it. <para> </para> Index: dev_advanced_easymock.docbook =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/docs/en/dev_advanced_easymock.docbook,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- dev_advanced_easymock.docbook 4 Mar 2005 23:37:00 -0000 1.7 +++ dev_advanced_easymock.docbook 5 May 2005 21:01:59 -0000 1.8 @@ -1,4 +1,4 @@ -<!-- Advanced mock objects - the easymock approach + <!-- Advanced mock objects - the easymock approach $Id$ --> Index: dev_production.docbook =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/docs/en/dev_production.docbook,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- dev_production.docbook 30 Apr 2005 21:14:41 -0000 1.1 +++ dev_production.docbook 5 May 2005 21:01:59 -0000 1.2 @@ -1,26 +1,137 @@ +<?xml version="1.0" encoding="UTF-8"?> <!-- Support for Production Code $Id$ --> - <sect1 id="production"> -<title>Support for Production Code</title> + <title>Support for Production Code</title> -<para>To effectively benefit from unit tests it is frequently necessary to optimize -production code. The following sections show some of the possibilities. The common -pattern is as usual to delegate the detailed work to a helper class which is -approriately instantiated. + <para>To effectively benefit from unit tests it is frequently necessary to + optimize production code. The following sections show some of the + possibilities. The common pattern is as usual to delegate the detailed work + to a helper class which is approriately instantiated.</para> -</para> + <para>Some of the following approaches have the drawback to weaken the + protection of your class mebers. You have to decide yourself if this is + acceptable for you.</para> -<sect2> -<title>Reproducible Time Values</title> + <para>But you should keep in mind that mechanisms like + <keysym>protected</keysym> or <keysym>private</keysym> only defend from + Murphy (unintentional usage) and not from Machiavelli (evil abuse). A + potential attacker can simply copy a class declaration, remove all + <keysym>private</keysym> and <keysym>protected</keysym> keywords and then + access everything by doing a simple typecast.</para> -<para>Sometimes you need defined time values. Either you want to reduce timeouts -or times to wait + <sect2 id="reproducible-time-values"> + <title>Reproducible Time Values</title> -</para> + <para>Sometimes you need predictible time values. Either you want to + minimize the impact of timeouts in error conditions or prevent idle times. + <application>mockpp</application> contains a sample imlementation of how + to handle calls to <methodname>std::time()</methodname>.</para> -</sect2> + <para><programlisting>// prototype for method under test: + void myTimedMethod(TimeServer *time); -</sect1> +// in production code: + myTimedMethod(getRealTimeServer()); + +// in test code: + getMockTimeServer()->addUnixTime(0x123456); + myTimedMethod(getMockTimeServer()); + +</programlisting></para> + </sect2> + + <sect2 id="accessing-protected-elements"> + <title>Accessing protected elements</title> + + <para>Usually you will protect internal members in your classes. Variables + should almost always be <keysym>private</keysym>, in rare cases + <keysym>protected</keysym>. So they are out of reach for your testing + code. Methods on the other hand may</para> + + <sect3> + <title>Lifting class members</title> + + <para>One of the simplest methods to get access to interesting methods + is to use a <keysym>using</keysym> declaration in a simple derived class + to lift the member into <keysym>public</keysym> area. Of course this is + only possible for <keysym>protected</keysym> methods and not for + <keysym>private</keysym> ones. But testing <keysym>private</keysym> + methods usually makes little sense anyway as they cover internal + details.</para> + + <para>On the other hand it may be a nice compromise to make a + <keysym>private</keysym> method more general and more robust in order to + make it <keysym>protected</keysym> and test it this way.</para> + + <para><programlisting>class Sample +{ + Sample(); + + protected: + + void interesting_internal_method(); +}; + + +class TestSample : public Sample +{ + + public: + + using Sample::interesting_internal_method; +}; + + TestSample sample; + sample.interesting_internal_method(); + +</programlisting></para> + </sect3> + + <sect3> + <title>Inserting a Mock Object</title> + + <para>Another possibility is to implement access to internal variables + via getter and setter methods. If you make such methods + <keysym>private</keysym> and <keysym>virtual</keysym> you prevent its + direct use but still have the chance to overload the getter method in + the tests. This way it is possible to insert mock objects for internal + variables.</para> + + <para><programlisting>class Sample +{ + private: + + virtual Complicated *getVariable() + { + return &variable; + } + + Complicated variable; +}; + + +class MockComplicated : public Complicated +{ +}; + + +class DerivedSample : public Sample +{ + private: + + virtual Complicated *getVariable() + { + return &mock; + } + + public: + + MockingComplicated mock; +}; +</programlisting></para> + </sect3> + </sect2> +</sect1> \ No newline at end of file Index: Makefile.am =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/docs/en/Makefile.am,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- Makefile.am 4 May 2005 20:44:53 -0000 1.21 +++ Makefile.am 5 May 2005 21:01:59 -0000 1.22 @@ -41,6 +41,10 @@ xsltproc --output var/mockpp.fo /usr/share/xml/docbook/stylesheet/nwalsh/current/fo/docbook.xsl $(srcdir)/index.docbook fop var/myfile.fo var/mockpp.pdf +svg-files: + xsltproc --output var/mockpp.fo /usr/share/xml/docbook/stylesheet/nwalsh/current/fo/docbook.xsl $(srcdir)/index.docbook + fop var/myfile.fo -svg var/mockpp.svg + .PHONY: html-files pdf-files doc-dist remote-install EXTRA_DIST=appendix.docbook bookinfo.docbook credits.docbook customize.xsl \ |