OSDN Git Service

added the English explanation to some sections.
authortsntsumi <tsntsumi@users.sourceforge.jp>
Sun, 22 Aug 2010 13:09:30 +0000 (13:09 +0000)
committertsntsumi <tsntsumi@users.sourceforge.jp>
Sun, 22 Aug 2010 13:09:30 +0000 (13:09 +0000)
doc/cookbook.dox

index 9afadbf..3241aa6 100644 (file)
@@ -310,7 +310,7 @@ To compile and run, do the following:
 @endif
 
 @code
-$ gcc -I. -o runTestCaseRunner runTestCaseRunner.c testComplex.c complex.c -lccunit
+$ gcc -o runTestCaseRunner runTestCaseRunner.c testComplex.c complex.c -lccunit
 $ ./runTestCaseRunner
 ..
 Time: 0.000027 sec
@@ -380,7 +380,7 @@ void test_complex_equals ()
 @endcode
 
 @code
-$ gcc -I. -o runTestCaseRunner runTestCaseRunner.c testComplex.c complex.c -lccunit
+$ gcc -o runTestCaseRunner runTestCaseRunner.c testComplex.c complex.c -lccunit
 $ ./runTestRunner
 ..F
 Time: 0.000036 sec
@@ -439,46 +439,54 @@ digraph TestCase {
   edge [ fontsize=9, dir=back, arrowtail=vee ]
   gv [ label="Global Variables", shape=box ]
   { rank=same;
-    tc1 [ label="Test case 1" ];
-    tc2 [ label="Test case 2" ];
-    tcn [ label="Test case n" ];
+    tc1 [ label="Test Case 1" ];
+    tc2 [ label="Test Case 2" ];
+    tcn [ label="Test Case n" ];
   }
   gv -> tc1;
   gv -> tc2 [ weight=8 ];
   gv -> tcn;
-  tc2 -> tcn [ label="...", dir=none, color=white ];
+  tc2 -> tcn [ label="...", fontname=Helvetica, dir=none, color=white ];
 }
 @enddot
 
 @english
 Tests need to run against the background of a known set of
-objects. This set of objects is called a test fixture. When
+data.
 you are writing tests you will often find that you spend
-more time writing the code to set up the fixture than you do
+more time writing the code to set up the data than you do
 in actually testing values.
 @japanese
 ¥Æ¥¹¥È¤ÏÃæ¿È¤Î¤ï¤«¤Ã¤Æ¤¤¤ë¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤òÁ°Äó¤È¤·¤Æ¼Â¹Ô¤µ¤ì¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
 ¥Æ¥¹¥È¤ò½ñ¤¤¤Æ¤¤¤ë¤È¡¢
-¼ÂºÝ¤Ë¥Æ¥¹¥È¤¹¤ëÃͤò¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¥³¡¼¥É¤ò½ñ¤¯Êý¤Ë¡¢
-¤è¤ê»þ´Ö¤ò¤«¤±¤Æ¤¤¤ë¤³¤È¤Ëµ¤¤Å¤¯¤³¤È¤¬¤è¤¯¤¢¤ê¤Þ¤¹¡£
+¼ÂºÝ¤Ë¥Æ¥¹¥È¤¹¤ë¥³¡¼¥É¤è¤ê¤â¡¢
+Ãͤò¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¥³¡¼¥É¤ò½ñ¤¯Êý¤Ë¡¢
+¤è¤ê»þ´Ö¤ò¤«¤±¤Æ¤¤¤ë¤³¤È¤¬¤è¤¯¤¢¤ê¤Þ¤¹¡£
 @endif
 
 @english
+In the sample code of the previous section,
+some complex numbers are allocated,
+and it is deleted.
 @japanese
 Î㤨¤ÐÁ°Àá¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ç¤Ï¡¢
 ¤¤¤¯¤Ä¤«¤ÎÊ£ÁÇ¿ô¤ò³ä¤êÅö¤Æ¤¿¤ê²òÊü¤·¤¿¤ê¤·¤Æ¤¤¤Þ¤¹¡£
 @endif
 
 @english
-Often, you will be able to use the same fixture for several
-different tests. Each case will send slightly different
-messages or parameters to the fixture and will check for
+Often, you will be able to use the same data for several
+different tests. Each case will assign slightly different
+values to the data and will check for
 different results.
+Then, if the test is finished, clean-up the data.
+The function @c setUp and @c tearDown are used at such time.
 @japanese
 Â¿¤¯¤Î¾ì¹ç¡¢¤¤¤¯¤Ä¤«¤Î°Û¤Ê¤Ã¤¿¥Æ¥¹¥È¤Î¤¿¤á¤ËƱ¤¸¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤ò»È¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
 ¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È´Ø¿ô¤ò¼Â¹Ô¤¹¤ëÁ°¤ËÊÑ¿ô¤ò½é´ü²½¤·¡¢
 ÃͤòÄ´¤Ù¤ë¤³¤È¤Ë¤Ê¤ë¤Ç¤·¤ç¤¦¡£
 ¤½¤·¤Æ¥Æ¥¹¥È¤¬½ª¤ï¤Ã¤¿¤é¸å»ÏËö¤¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
+
+@c setUp ¤È @c tearDown ´Ø¿ô¤Ï¤½¤ó¤Ê»þ¤Ë»ÈÍѤ¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
 @endif
 
 @dot
@@ -499,48 +507,55 @@ digraph TestFixture {
 @enddot
 
 @english
-When you have a common fixture, here is what you do:
+When you have a common global variables, here is what you do:
 @japanese
 ¤â¤·³Æ¥Æ¥¹¥È¤Ë¶¦Ä̤Υ°¥í¡¼¥Ð¥ëÊÑ¿ô¤¬¤¢¤ì¤Ð¡¢
 ¼¡¤Î¤è¤¦¤Ë¤¹¤ë¤³¤È¤Ç¤·¤ç¤¦¡£
 @endif
 
+@dontinclude complex/testComplexSetup.c
+
 @english
-For example, to write several test cases, first create a
-fixture:
+Define the global variable.
 @japanese
+¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤òÄêµÁ¤·¤Þ¤¹¡£
 @endif
 
-@dontinclude complex/testComplexSetup.c
-
 @skipline complex.h
 @until c10_1;
 
 @english
+Write the function @c setUp to allocate the complex.
 @japanese
-¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤òÄêµÁ¤·¤Þ¤¹¡£
+Ê£ÁÇ¿ô¤ò³ä¤êÅö¤Æ¤ë @c setUp ´Ø¿ô¤ò½ñ¤­¤Þ¤¹¡£
 @endif
 
 @until }
 
 @english
+Write the function @c tearDown to delete the memory of that complex.
 @japanese
-Ê£ÁÇ¿ô¤ò³ä¤êÅö¤Æ¤ë @c setUp ´Ø¿ô¤ò½ñ¤­¤Þ¤¹¡£
+³ä¤êÅö¤Æ¤¿¥á¥â¥ê¤ò²òÊü¤¹¤ë @c tearDown ´Ø¿ô¤ò½ñ¤­¤Þ¤¹¡£
 @endif
 
 @until }
 
 @english
+Write the test function.
 @japanese
-³ä¤êÅö¤Æ¤¿¥á¥â¥ê¤ò²òÊü¤¹¤ë @c tearDown ´Ø¿ô¤ò½ñ¤­¤Þ¤¹¡£
+¥Æ¥¹¥È´Ø¿ô¤ò½ñ¤­¤Þ¤¹¡£
 @endif
 
 @until test_complex_equals
 @until }
 
 @english
+Register the function @c setUp and @c tearDown.
+At this time, the name of the function must have begun with
+@c "setUp" or @c "tearDown".
 @japanese
-¥Æ¥¹¥È´Ø¿ô¤ò½ñ¤­¤Þ¤¹¡£
+@c setUp ¤È @c tearDown ¤òÅÐÏ¿¤·¤Þ¤¹¡£
+¤³¤Î»þ¡¢´Ø¿ô¤Î̾Á°¤¬ @c setUp/tearDown ¤Ç»Ï¤Þ¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£
 @endif
 
 @dontinclude complex/runTestCaseSetup.c
@@ -549,22 +564,19 @@ fixture:
 @until tearDown_test_complex);
 
 @english
-@japanese
-@c setUp() ¤È @c tearDown() ¤òÅÐÏ¿¤·¤Þ¤¹¡£
-¤³¤Î»þ¡¢´Ø¿ô¤Î̾Á°¤¬ @c setUp/tearDown ¤Ç»Ï¤Þ¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£
-@endif
-
-@until }
-
-@english
+Run the test case, and return the result.
 @japanese
 ¥Æ¥¹¥È¥±¡¼¥¹¤ò¼Â¹Ô¤·¡¢
 ·ë²Ì¤òÊÖ¤·¤Þ¤¹¡£
 @endif
 
+@until }
+
 @english
 The sample code made in the above is in the directory <code>examples/complex</code>,
 the files are @c testComplexSetup.c and <code>runTestCaseSetup.c</code>.
+
+To compile and run, do the following:
 @japanese
 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢@c examples/complex ¥Ç¥£¥ì¥¯¥È¥ê¤Î
 <code>testComplexSetup.c, runTestCaseSetup.c</code> ¤Ë¤¢¤ê¤Þ¤¹¡£
@@ -588,14 +600,24 @@ OK (2 tests)
 @endif
 
 @english
+In the previous section,
+the initialization was done in every test every time.
+But we do the initialization only once,
+and we may run the multiple test.
+Then, only when all the tests are finished,
+it may seem to carry out the code for the settlement.
+
+You register the @c setUp and @c tearDown function in the test case for that.
+Then, the test functions are run in the following order:
 @japanese
 Á°¤ÎÀá¤Ç¤Ï¥Æ¥¹¥È¤´¤È¤ËËè²ó½é´ü²½¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤·¤¿¡£
+¤·¤«¤·¡¢
 °ì²ó¤À¤±½é´ü²½¤ò¹Ô¤Ã¤Æ¡¢
 Ê£¿ô¤Î¥Æ¥¹¥È¤ò¼Â¹Ô¤·¤¿¤¤¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¡£
 ¤½¤·¤Æ¥Æ¥¹¥È¤¬Á´¤Æ½ª¤ï¤Ã¤¿¤È¤­¤À¤±¸å»ÏËö¤Î¥³¡¼¥É¤ò¼Â¹Ô¤¹¤ë¤è¤¦¤Ê¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¡£
 
 ¤½¤Î¤¿¤á¤Ë¤Ï¥Æ¥¹¥È¥±¡¼¥¹¤Ë
-@c setup_setUp/setup_tearDown ´Ø¿ô¤òÅÐÏ¿¤·¤Þ¤¹¡£
+@c setup_setUp, @c setup_tearDown ´Ø¿ô¤òÅÐÏ¿¤·¤Þ¤¹¡£
 ¤¹¤ë¤È¼¡¤Î¤è¤¦¤Ê½ç½ø¤Ç¥Æ¥¹¥È´Ø¿ô¤¬¼Â¹Ô¤µ¤ì¤Þ¤¹¡£
 @endif
 
@@ -616,7 +638,7 @@ digraph TestCaseCallingSequence {
   tearDown2 [ label="tearDown" ];
   "TestFunc n" -> tearDown2;
   tearDown2 -> setup_tearDown;
-  tearDown -> setUp2;
+  tearDown -> setUp2 [ style=dotted ];
 }
 @enddot
 
@@ -638,18 +660,35 @@ Once you have several tests, organize them into a suite.
 @endif
 
 @dot
-digraph TestStructure {
+digraph StructureCollaboration {
   node [ fontsize=9, fontname=Helvetica ];
   edge [ dir=back, fontsize=9 ];
+  subgraph cluster1 {
+    fontsize=9;
+    fontname=FreeSans
+    label="Test Functions"; labelloc=t; labeljust=l;
+    style=dashed;
+    rank=same;
+    setup_setUp;
+    setUp;
+    TestFunc;
+    tearDown;
+    setup_tearDown;
+  }
+  TestSuite [ URL="@ref CCUnitTestSuite" ];
+  TestCase [ URL="@ref CCUnitTestCase" ];
+  TestFunc [ URL="@ref CCUnitTestFunc" ];
+  setup_setUp [ URL="@ref CCUnitTestFunc" ];
+  setUp [ URL="@ref CCUnitTestFunc" ];
+  tearDown [ URL="@ref CCUnitTestFunc" ];
+  setup_tearDown [ URL="@ref CCUnitTestFunc" ];
   TestSuite -> TestSuite [ label="1..n" ];
-  TestCase;
-  TestSuite -> TestCase [ label="1..n" ];
-  TestCase -> setup_setUp [ label="0..1" ];
-  TestCase -> setUp [ label="0..1" ];
-  TestFunc;
-  TestCase -> TestFunc [ label="1..n" ];
-  TestCase -> tearDown [ label="0..1" ];
-  TestCase -> setup_tearDown [ label="0..1" ];
+  TestSuite -> TestCase [ headlabel="1..n", labeldistance=1, labelangle=-45 ];
+  TestCase -> setup_setUp [ headlabel="0..1", labelangle=45 ];
+  TestCase -> setUp [ headlabel="0..1", labelangle=45 ];
+  TestCase -> TestFunc [ headlabel="1..n", labelangle=-45 ];
+  TestCase -> tearDown [ headlabel="0..1", labelangle=-45 ];
+  TestCase -> setup_tearDown [ headlabel="0..1", labelangle=-45 ];
 }
 @enddot
 
@@ -672,33 +711,39 @@ To create a suite of two or more tests, you do the following:
 
 @dontinclude complex/runTestSuite.c
 
-@skip main
-@until test_complex_div);
-
 @english
+Create two test cases, and register test functions to each cases.
 @japanese
 ¥Æ¥¹¥È¥±¡¼¥¹¤òÆó¤ÄÀ¸À®¤·¡¢¤½¤ì¤¾¤ì¤Ë¥Æ¥¹¥È´Ø¿ô¤òÅÐÏ¿¤·¤Þ¤¹¡£
 @endif
 
-@until testArith);
+@skip main
+@until test_complex_div);
 
 @english
+Create a test suite,
+then register that two test cases to it.
 @japanese
 ¥Æ¥¹¥È¥¹¡¼¥Ä¤òÀ¸À®¤·¡¢
 ¥Æ¥¹¥È¥±¡¼¥¹¤òÅÐÏ¿¤·¤Þ¤¹¡£
 @endif
 
-@until }
+@until testArith);
 
 @english
+Create test runner and run the tests.
 @japanese
 ¥Æ¥¹¥È¥é¥ó¥Ê¡¼¤òÀ¸À®¤·¥Æ¥¹¥È¤ò¼Â¹Ô¤·¤Þ¤¹¡£
 @endif
 
+@until }
+
 @english
 The sample code made in the above is in the directory <code>examples/complex</code>,
 the files are <code>runTestSuite.c</code>, <code>testComplexSetup.c</code>
 and <code>testComplexArith.c</code>.
+
+To compile and run, do the following:
 @japanese
 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢<code>examples/complex</code> ¥Ç¥£¥ì¥¯¥È¥ê¤Î
 <code>runTestSuite.c, testComplexSetup.c, testComplexArith.c</code>
@@ -708,7 +753,7 @@ and <code>testComplexArith.c</code>.
 @endif
 
 @code
-$ gcc -I. -o runTestSuite runTestSuite.c testComplexSetup.c testComplexArith.c complex.c -lccunit
+$ gcc -o runTestSuite runTestSuite.c testComplexSetup.c testComplexArith.c complex.c -lccunit
 $ ./runTestSuite
 ......
 Time: 0.000061 sec
@@ -719,8 +764,8 @@ OK (6 tests)
 @english
 @link CCUnitTestSuite TestSuites @endlink don't only have to
 contain @link CCUnitTestCase TestCases @endlink.  They
-can contain any object that implements the @link CCUnitTest
-Test @endlink interface.  For example, you can create a
+can also contain @link CCUnitTestSuite TestSuites@endlink.
+For example, you can create a
 @link CCUnitTestSuite TestSuite @endlink
 in your code and I
 can create one in mine, and we can run them together by
@@ -737,7 +782,7 @@ contains both:
 ¤òºî¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¢
 ¤½¤·¤Æ»äã¤ÏξÊý¤È¤â¤ò´Þ¤ó¤Ç¤¤¤ë @link CCUnitTestSuite TestSuite @endlink
 ¤òºî¤Ã¤Æ¡¢
-°ì½ï¤Ë¤½¤ì¤¾¤ì¤Î¥¹¡¼¥Ä¤òÆ°¤«¤¹¤³¤È¤¬¤Ç¤­¤ë¤Î¤Ç¤¹¡£
+°ì½ï¤Ë¤½¤ì¤¾¤ì¤Î¥¹¡¼¥Ä¤ò¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¤Î¤Ç¤¹¡£
 @endif
 
 @code
@@ -917,7 +962,7 @@ and <code>testComplexArith.c</code>.
 
 @code
 $ ccunit_makeSuite -f suite_test_complex -o suiteTestComplex.c testComplexSetup.c testComplexArith.c
-$ gcc -I. -o runTestSuiteAuto runTestSuiteAuto.c testComplexSetup.c testComplexArith.c suiteTestComplex.c complex.c -lccunit
+$ gcc -o runTestSuiteAuto runTestSuiteAuto.c testComplexSetup.c testComplexArith.c suiteTestComplex.c complex.c -lccunit
 $ ./runTestSuiteAuto
 .......
 Time: 0.000060 sec