[Cppunit-devel] documentation fixes
Brought to you by:
blep
From: Steve M. R. <ste...@vi...> - 2001-05-23 13:26:50
|
Hi, Here is an updated version of the documentation patch I once sent. -Steve P.S. In the unix community, the file named ChangeLog has adopted a very standardized format. Changelog entries must be of the form "<TAB>* filename: text ..." if the entry pertains to the whole file, or "<TAB>* filename (id1, id2,...): text ..." if the entry pertains to certain functions or variables named "id1", "id2", etc. Several tools (notably the emacs editor) understand this format and will highlight it. It would be greatly appreciated if this format is maintained for ChangeLog entries. See <http://www.red-bean.com/cvs2cl/changelogs.html> for more detailed suggestions on how and what to log. 2001-05-22 Steve M. Robbins <st...@ny...> * examples/hierarchy/main.cpp: Remove extraneous #includes. * doc/other_documentation.dox: Don't try to include CppUnit in <a> tag text; Doxygen screws this up. * doc/cookbook.html: Fix example code. Index: examples/hierarchy/main.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit/examples/hierarchy/main.cpp,v retrieving revision 1.8 diff -u -b -B -r1.8 main.cpp --- examples/hierarchy/main.cpp 2001/04/23 22:19:10 1.8 +++ examples/hierarchy/main.cpp 2001/05/23 13:04:40 @@ -1,7 +1,5 @@ -#include "cppunit/TestRegistry.h" #include "cppunit/TextTestResult.h" #include "cppunit/TestSuite.h" -#include "cppunit/Test.h" #include "BoardGame.h" #include "Chess.h" Index: doc/cookbook.html =================================================================== RCS file: /cvsroot/cppunit/cppunit/doc/cookbook.html,v retrieving revision 1.1.1.1 diff -u -b -B -r1.1.1.1 cookbook.html --- doc/cookbook.html 2000/10/05 18:37:28 1.1.1.1 +++ doc/cookbook.html 2001/05/23 13:04:40 @@ -8,7 +8,12 @@ <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> </P> <H1>CppUnit Cookbook</H1> - <P>Here is a short cookbook to help you get started. </P> + <P> + Here is a short cookbook to help you get started. + Note that all CppUnit types are defined in the CppUnit + namespace. For brevity, the prefix <b>CppUnit::</b> + is omitted in the following examples. + </P> <H2>Simple Test Case</H2> <P> You want to know whether your code is working. @@ -90,9 +95,7 @@ friend bool operator== (const Complex& a, const Complex& b); double real, imaginary; public: - Complex () { - real = imaginary = 0.0; - } + Complex ( double r, double i = 0 ) : real(r),imaginary(i) {} }; bool operator== (const Complex& a, const Complex& b) @@ -153,7 +156,7 @@ <TT><PRE>	class ComplexNumberTest : public TestCase { 	private: Complex 	*m_10_1, *m_1_1; *m_11_2; -	protected: +	public: 	void		setUp () { 			 m_10_1 = new Complex (10, 1); 			 m_1_1 = new Complex (1, 1); @@ -170,31 +173,33 @@ 			 assert (*m_10_1 + *m_1_1 == *m_11_2); 	} 	};</PRE> -</TT><P>Create and run instances for each test case like this:</P> -<TT><PRE>	test = new TestCaller<ComplexNumberTest>("testEquality", ComplexNumberTest::testEquality); - test->run (); </PRE> -</TT><P>The second argument to the test caller constructor is the address of a method on ComplexNumberTest. When the test caller is run, that specific method will be run.</P> -<P>Once you have several tests, organize them into a suite.</P> +</TT><P>One may create and run instances for each test case like this:</P> +<TT><PRE>	TestCaller<ComplexNumberTest> test("testEquality", &ComplexNumberTest::testEquality); + test.run (); </PRE> +</TT><P>The second argument to the test caller constructor is the address of a method on ComplexNumberTest. When the test caller is run, that specific method will be run. This is not a useful thing to do, however, as no diagnostics will be + displayed. One will normally use a TestRunner (see below) to display + the results. + </P> + + <P>Once you have several tests, organize them into a suite.</P> <P> </P> <H2>Suite</H2> <P>How do you set up your tests so that you can run them all at once?<BR> <BR> -CppUnit provides a TestSuite class that runs any number of TestCases together. For example, to run a single test case, you execute:</P> -<TT><PRE>	TestResult result; -	TestCaller<ComplexNumberTest> test ("testAddition", ComplexNumberTest::testAddition); -	Test.run (&result);</PRE> -</TT><P> </P> -<P>To create a suite of two or more tests, you do the following:</P> +CppUnit provides a TestSuite class that runs any number of TestCases together. + We saw, above, how to run a single test case. +To create a suite of two or more tests, you do the following:</P> <TT><PRE>	TestSuite suite; 	TestResult result; -	suite.addTest (new TestCaller<ComplexNumberTest>("testEquality", ComplexNumberTest::testEquality)); -	suite.addTest (new TestCaller<ComplexNumberTest>("testAddition", ComplexNumberTest::testAddition)); +	suite.addTest (new TestCaller<ComplexNumberTest>("testEquality", &ComplexNumberTest::testEquality)); +	suite.addTest (new TestCaller<ComplexNumberTest>("testAddition", &ComplexNumberTest::testAddition)); 	suite.run (&result); </PRE> </TT><P>TestSuites don't only have to contain callers for TestCases. They can contain any object that implements the Test interface. For example, you can create a TestSuite in your code and I can create one in mine, and we can run them together by creating a TestSuite that contains both: </P> <TT><PRE>	TestSuite suite; -	suite.addTest (ComplexNumberTest.suite ()); -	suite.addTest (SurrealNumberTest.suite ()); +	TestResult result; +	suite.addTest (ComplexNumberTest::suite ()); +	suite.addTest (SurrealNumberTest::suite ()); 	suite.run (&result);</PRE> </TT><P> </P> <H2>TestRunner</H2> Index: doc/other_documentation.dox =================================================================== RCS file: /cvsroot/cppunit/cppunit/doc/other_documentation.dox,v retrieving revision 1.2 diff -u -b -B -r1.2 other_documentation.dox --- doc/other_documentation.dox 2001/04/14 00:51:17 1.2 +++ doc/other_documentation.dox 2001/05/23 13:04:40 @@ -16,7 +16,7 @@ \section _usage Usage Take a look into - <a href="../cookbook.html">the CppUnit cookbook</a>. + the CppUnit <a href="../cookbook.html">cookbook</a>. It gives a quick start into using this testing framework. For a discussion on CppUnit, check -- by Rocket to the Moon, by Airplane to the Rocket, by Taxi to the Airport, by Frontdoor to the Taxi, by throwing back the blanket and laying down the legs ... - They Might Be Giants |