OSDN Git Service

Revised the contents of the section setUp_and_tearDown
authortsntsumi <tsntsumi@users.sourceforge.jp>
Fri, 20 Aug 2010 22:49:11 +0000 (22:49 +0000)
committertsntsumi <tsntsumi@users.sourceforge.jp>
Fri, 20 Aug 2010 22:49:11 +0000 (22:49 +0000)
doc/cookbook.dox

index a988a1b..be1c9f2 100644 (file)
@@ -61,30 +61,31 @@ To make a simple test, here is what you do:
 @~
 
 <ol>
-<li> @~english Create a test function
-     @~japanese ¥Æ¥¹¥È´Ø¿ô¤òºî¤ê¤Þ¤¹¡£
-     @~
+<li> @english Create a test function
+     @japanese ¥Æ¥¹¥È´Ø¿ô¤òºî¤ê¤Þ¤¹¡£
+     @endif
 </li>
-<li> @~english When you want to check a value, call
+<li> @english When you want to check a value, call
      @link CCUNIT_ASSERT() CCUNIT_ASSERT(bool) @endlink
      and pass a bool that is true if the test succeeds
-     @~japanese Ãͤò¥Á¥§¥Ã¥¯¤·¤¿¤¤¾ì¹ç¤Ï¡¢
+
+     ASSERT macro is listed in others as well in
+     @link Assertions Making assertions @endlink.
+     @japanese
+     Ãͤò¥Á¥§¥Ã¥¯¤·¤¿¤¤¾ì¹ç¤Ï¡¢
      @link CCUNIT_ASSERT() CCUNIT_ASSERT(bool) @endlink
      ¤ò¸Æ¤Ó½Ð¤·¤Æ¡¢
      ¥Æ¥¹¥È¤¬À®¸ù¤¹¤ë¤Ê¤é¿¿¤òÊÖ¤¹¤è¤¦¤Ê¿¿µ¶ÃͤòÅϤ·¤Þ¤¹¡£
-     @~
 
-     @~english ASSERT macro is listed in others as well in
-     @link Assertions Making assertions @endlink.
-     @~japanese ASSERT ´Ø·¸¤Î¥Þ¥¯¥í¤Ï¾¤Ë¤â
-     @link Assertions Making assertions @endlink
+     ASSERT ´Ø·¸¤Î¥Þ¥¯¥í¤Ï¾¤Ë¤â
+     @link Assertions ¥¢¥µ¡¼¥È¤ÎÀë¸À @endlink
      ¤Ë¥ê¥¹¥È¤·¤Æ¤¢¤ê¤Þ¤¹¡£
-     @~
+     @endif
 </li>
 </ol>
 
 @~english
-!!!For example, to test that the sum of two complex number
+For example, to test that the sum of two complex number
 which is the sum of the values of two complex numbers,
 write (This sample program is in the @c examples/complex directory):
 @~japanese
@@ -153,20 +154,19 @@ $ echo $?
 @~english
 That was a very simple test. Ordinarily, you'll have many
 little test cases that you'll want to run on the same set of
-objects. To do this, use a fixture.
+objects. To do this, use global variables.
 @~japanese
 ¤³¤ì¤ÏÂçÊÑñ½ã¤Ê¥Æ¥¹¥È¤Ç¤¹¡£
 Ä̾
 ¤¿¤¯¤µ¤ó¤Î¾®¤µ¤Ê¥Æ¥¹¥È´Ø¿ô¤òºî¤Ã¤Æ¡¢
 Æ±¤¸¤è¤¦¤Ê¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤ò»È¤Ã¤Æ¥Æ¥¹¥È¤ò¹Ô¤¦¤³¤È¤Ë¤Ê¤ë¤Ç¤·¤ç¤¦¡£
 ¤Ä¤Þ¤ê³Æ¥Æ¥¹¥È´Ø¿ô¶¦Ä̤Υ°¥í¡¼¥Ð¥ëÊÑ¿ô¤ò»È¤¦¤ÈÊØÍø¤Ç¤¹¡£
-¤³¤Î¤è¤¦¤Ê¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤ò¥Õ¥£¥¯¥¹¥Á¥ã (È÷ÉÊ) ¤È¸À¤¤¤Þ¤¹¡£
 @~
 
 @english
-@section fixture Fixture
+@section setUp_and_tearDown setUp and tearDown
 @japanese
-@section fixture ¥Õ¥£¥¯¥¹¥Á¥ã
+@section setUp_and_tearDown setUp ¤È tearDown
 @endif
 
 @~english
@@ -181,7 +181,7 @@ similar set of objects?
 digraph TestCase {
   node [ fontsize=9, fontname=Helvetica ]
   edge [ fontsize=9, dir=back, arrowtail=vee ]
-  gv [ label="Fixture\n(Global variables)", shape=box ]
+  gv [ label="Global Variables", shape=box ]
   { rank=same;
     tc1 [ label="Test case 1" ];
     tcn [ label="Test case n" ];
@@ -200,23 +200,27 @@ more time writing the code to set up the fixture than you do
 in actually testing values.
 @~japanese
 ¥Æ¥¹¥È¤ÏÃæ¿È¤Î¤ï¤«¤Ã¤Æ¤¤¤ë¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤òÁ°Äó¤È¤·¤Æ¼Â¹Ô¤µ¤ì¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
-¤½¤Î¤è¤¦¤Ê¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤ò¥Õ¥£¥¯¥¹¥Á¥ã¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹¡£
 ¥Æ¥¹¥È¤ò½ñ¤¤¤Æ¤¤¤ë¤È¡¢
-¼ÂºÝ¤Ë¥Æ¥¹¥È¤¹¤ëÃͤò¥Õ¥£¥¯¥¹¥Á¥ã¤Ë¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¥³¡¼¥É¤ò½ñ¤¯Êý¤Ë¡¢
+¼ÂºÝ¤Ë¥Æ¥¹¥È¤¹¤ëÃͤò¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¥³¡¼¥É¤ò½ñ¤¯Êý¤Ë¡¢
 ¤è¤ê»þ´Ö¤ò¤«¤±¤Æ¤¤¤ë¤³¤È¤Ëµ¤¤Å¤¯¤³¤È¤¬¤è¤¯¤¢¤ê¤Þ¤¹¡£
 @~
 
+@english
+@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
 different results.
 @~japanese
-¿¤¯¤Î¾ì¹ç¡¢¤¤¤¯¤Ä¤«¤Î°Û¤Ê¤Ã¤¿¥Æ¥¹¥È¤Î¤¿¤á¤ËƱ¤¸¥Õ¥£¥¯¥¹¥Á¥ã¤ò»È¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
-¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ï¾¯¤·°Û¤Ê¤Ã¤¿Ãͤǥե£¥¯¥¹¥Á¥ã¤ò½é´ü²½¤·¡¢
-°Û¤Ê¤ë·ë²Ì¤òÄ´¤Ù¤ë¤³¤È¤Ë¤Ê¤ë¤Ç¤·¤ç¤¦¡£
-¤½¤·¤Æ¥Æ¥¹¥È¤¬½ª¤ï¤Ã¤¿¤é¡¢
-¥Õ¥£¥¯¥¹¥Á¥ã¤ò¸å»ÏËö¤¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
+¿¤¯¤Î¾ì¹ç¡¢¤¤¤¯¤Ä¤«¤Î°Û¤Ê¤Ã¤¿¥Æ¥¹¥È¤Î¤¿¤á¤ËƱ¤¸¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤ò»È¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
+¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È´Ø¿ô¤ò¼Â¹Ô¤¹¤ëÁ°¤ËÊÑ¿ô¤ò½é´ü²½¤·¡¢
+ÃͤòÄ´¤Ù¤ë¤³¤È¤Ë¤Ê¤ë¤Ç¤·¤ç¤¦¡£
+¤½¤·¤Æ¥Æ¥¹¥È¤¬½ª¤ï¤Ã¤¿¤é¸å»ÏËö¤¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
 @~
 
 @dot
@@ -224,186 +228,120 @@ digraph TestFixture {
   node [ fontsize=9, fontname=Helvetica ]
   edge [ fontsize=9, dir=back, arrowtail=vee ]
   rankdir=TB;
-  gv [ label="Fixture\n(Data)", shape=box ]
+  gv [ label="Global Variables", shape=box ]
   { rank=same;
     su [ label="setUp" ];
-    tc [ label="TestCases" ];
+    tc [ label="TestCase" ];
     td [ label="tearDown" ];
   }
-  gv -> su [ label="initialize\neach test" ];
+  gv -> su [ label="initialize" ];
   gv -> tc [ label="access" ];
-  gv -> td [ label="clean-up\neach test" ];
+  gv -> td [ label="clean-up" ];
 }
 @enddot
 
 @~english
 When you have a common fixture, here is what you do:
 @~japanese
-¤â¤·³Æ¥Æ¥¹¥È¤Ë¶¦Ä̤Υե£¥¯¥¹¥Á¥ã¤¬¤¢¤ì¤Ð¡¢
+¤â¤·³Æ¥Æ¥¹¥È¤Ë¶¦Ä̤Υ°¥í¡¼¥Ð¥ëÊÑ¿ô¤¬¤¢¤ì¤Ð¡¢
 ¼¡¤Î¤è¤¦¤Ë¤¹¤ë¤³¤È¤Ç¤·¤ç¤¦¡£
 @~
 
 <ol>
-<li>@~english
-    Create a @link CCUnitTestFunc TestFunc @endlink object
-    @~japanese
-    @link CCUnitTestFunc TestFunc @endlink ¹½Â¤ÂΤ˥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹
-    ¡Ê°Ê¹ß¡¢¹½Â¤ÂΤ˳ä¤êÅö¤Æ¤¿¥á¥â¥ê¤ò¡¢¥ª¥Ö¥¸¥§¥¯¥È¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹¡Ë
-    @~
+<li>@english
+    Create a @link CCUnitTestCase TestCase @endlink object
+    @japanese
+    @link CCUnitTestCase TestCase @endlink ¤òºîÀ®¤·¤Þ¤¹
+    @endif
 </li>
-<li>@~english
+<li>@english
     Add an global variable for each part of the case
-    @~japanese
-    ¥Õ¥£¥¯¥¹¥Á¥ã¤Î¥¹¥³¡¼¥×Æâ¤ËÂç°èÊÑ¿ô¤òÄêµÁ¤·¤Þ¤¹
-    @~
+    @japanese
+    TestCase ¤Î¥¹¥³¡¼¥×Æâ¤Ë¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤òÄêµÁ¤·¤Þ¤¹
+    @endif
 </li>
-<li>@~english
-    Write @c setup_setUp(), @c setUp() function to initialize the valiables
-    @~japanese
-    ÊÑ¿ô¤ò½é´ü²½¤¹¤ë @c setup_setUp(), @c setUp() ´Ø¿ô¤ò½ñ¤­¤Þ¤¹
-    @~
+<li>@english
+    Write @c setUp() function to initialize the valiables
+    @japanese
+    ¥Õ¥£¥¯¥¹¥Á¥ã¤ò½é´ü²½¤¹¤ë @c setUp() ´Ø¿ô¤ò½ñ¤­¤Þ¤¹
+    @endif
 </li>
 <li>@english
-    Write @c tearDown(), @c setup_tearDown() to release any permanent
+    Write @c tearDown() to release any permanent
     resources you allocated in @c setUp
     @japanese
-    @c setup_setUp(), @c setUp() ¤Ç³ä¤êÅö¤Æ¤¿±Ê³Ū¥ê¥½¡¼¥¹¤ò²òÊü¤¹¤ë¤¿¤á¤Î
-    @c tearDown(), @c setup_tearDown() ´Ø¿ô¤ò½ñ¤­¤Þ¤¹
+    @c setUp() ¤Ç³ä¤êÅö¤Æ¤¿±Ê³Ū¥ê¥½¡¼¥¹¤ò²òÊü¤¹¤ë¤¿¤á¤Î
+    @c tearDown() ´Ø¿ô¤ò½ñ¤­¤Þ¤¹
     @endif
 </li>
-<li>@~english
-    Create a @link CCUnitTestCase TestCase @endlink object
-    @~japanese
-    @link CCUnitTestCase TestCase @endlink
-    ¹½Â¤ÂΤ˥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹
-    @~
+<li>@english Write TestFunc.
+    @japanese
+    ¥Æ¥¹¥È´Ø¿ô (TestFunc) ¤ò½ñ¤­¤Þ¤¹¡£
+    @endif
 </li>
-<li>@~english
+<li>@english
     Add @link CCUnitTestFunc TestFunc @endlink objects to case object
-    @~japanese
-    @link CCUnitTestFunc TestFunc @endlink ¥ª¥Ö¥¸¥§¥¯¥È¤ò
-    @link CCUnitTestCase TestCase @endlink
-    ¥ª¥Ö¥¸¥§¥¯¥È¤ËÅÐÏ¿¤·¤Þ¤¹¡£
-    @~
+    @japanese
+    @link CCUnitTestFunc TestFunc @endlink ¤ò
+    @link CCUnitTestCase TestCase @endlink ¤ËÅÐÏ¿¤·¤Þ¤¹¡£
+    @endif
 </li>
 </ol>
 
-@~english
+@english
 For example, to write several test cases, first create a
-case:
-@~japanese
-Î㤨¤Ð¡¢¤¤¤¯¤Ä¤«¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¯¾ì¹ç¡¢
-ºÇ½é¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤òºîÀ®¤·¤Þ¤¹¡£
-@~
-
-@code
-//** TEST CASE: complex number test *\/
-
-#include "complex.h"
+fixture:
+@japanese
+@endif
 
-static complex_t* s10_1;
-static complex_t* s1_1;
-static complex_t* s11_2;
-static complex_t* sc;
+@dontinclude complex/testComplexSetup.c
 
-void setup_setUp_complex_test ()
-{
-  sc = complex_new (1, 1);
-}
+@skipline complex.h
+@until end test case
 
-void setup_tearDown_complex_test ()
-{
-  complex_delete (sc);
-}
+@dontinclude complex/runTestCaseSetup.c
 
-void setUp_complex_test ()
-{
-  s10_1 = complex_new (10, 1);
-  s1_1 = complex_new (1, 1);
-  s11_2 = complex_new (11, 2);
-  complex_add (&sc, &sc, &c1_1);
-}
+@skip int main
+@until setUp_test_complex);
+@until tearDown_test_complex);
 
-void tearDown_complex_test ()
-{
-  complex_delete (s10_1);
-  complex_delete (s1_1);
-  complex_delete (s11_2);
-}
-
-int main ()
-{
-  CCUnitTestCase* testCase;
-  testCase = ccunit_newTestCase ("complex test",
-                                   CCUNIT_NEWTESTFUNC(setUp_complex_test),
-                                   CCUNIT_NEWTESTFUNC(tearDown_complex_test));
-  ccunit_setTestFixturSetup (testCase,
-                             CCUNIT_NEWTESTFUNCTION(setup_setUp_complex_test),
-                             CCUNIT_NEWTESTFUNCTION(setup_tearDown_complex_test));
-@endcode
+@english
+@japanese
+@c setUp() ¤È @c tearDown() ¤òÅÐÏ¿¤·¤Þ¤¹¡£
+¤³¤Î»þ¡¢´Ø¿ô¤Î̾Á°¤¬ @c setUp/tearDown ¤Ç»Ï¤Þ¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£
+@endif
 
-@~english
-Once you have the TestCase in place, you can write as complex
-Test Cases as you'd like.
-@~japanese
-°ìÅÙ·è¤Þ¤Ã¤¿¤È¤³¤í¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤ò½ñ¤¤¤Æ¤·¤Þ¤¨¤Ð¡¢
-¤¢¤Ê¤¿¤¬¹¥¤­¤Ê¤è¤¦¤ËÊ£ÁÇ¿ô¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¯¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
-@~
+@until }
 
 @english
-@section test_case Test Case
 @japanese
-@section test_case ¥Æ¥¹¥È¥±¡¼¥¹
+¥Æ¥¹¥È¥±¡¼¥¹¤ò¼Â¹Ô¤·¡¢
+·ë²Ì¤òÊÖ¤·¤Þ¤¹¡£
 @endif
 
-@~english
-How do you write and invoke an individual test case when you
-have a Fixture?
-@~japanese
-¥Õ¥£¥¯¥¹¥Á¥ã¤ò°ì¤Ä½ñ¤¤¤¿¤È¤·¤Æ¡¢
-¤É¤¦¤ä¤Ã¤Æ¸Ä¡¹¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¤¤Æ¼Â¹Ô¤¹¤ì¤ÐÎɤ¤¤Ç¤·¤ç¤¦¤«¡£
-@~
+@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>.
+@japanese
+¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢@c examples/complex ¥Ç¥£¥ì¥¯¥È¥ê¤Î
+<code>testComplexSetup.c, runTestCaseSetup.c</code> ¤Ë¤¢¤ê¤Þ¤¹¡£
 
-@~english
-For example, to test the equality of two complex number,
-write:
-@~japanese
-Î㤨¤Ð¡¢Æó¤Ä¤ÎÊ£ÁÇ¿ô¤¬Åù¤·¤¤¡Ê¤Þ¤¿¤ÏÅù¤·¤¯¤Ê¤¤¡Ë¤³¤È¤ò¥Æ¥¹¥È¤¹¤ë¤Ë¤Ï¡¢
-¼¡¤Î¤è¤¦¤Ë½ñ¤­¤Þ¤¹¡£
-@~
+¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
+@endif
 
 @code
-void test_complex_equals ()
-{
-  CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s10_1, complex_to_string);
-  CCUNIT_ASSERT_TEST_OBJ (s10_1, !complex_equals, s1_1, complex_to_string);
-}
-
-...
-
-int main ()
-{
-  ...
-
-  ccunit_addNewTestFunc (testCase,
-                         "test_complex_equals",
-                         "complex equals test",
-                         test_complex_equals);
+$ gcc -o runTestCaseSetup runTestCaseSetup.c testComplexSetup.c complex.c -lccunit
+$ ./runTestCase
+$ echo $?
+0
 @endcode
 
-@~english
-One may create and run objects for each test case like this:
-@~japanese
-¤½¤·¤Æ¼¡¤Î¤è¤¦¤Ë¡¢
-¥Õ¥£¥¯¥¹¥Á¥ã¤òºîÀ®¤·¤Æ¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò¼Â¹Ô¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
-@~
+@english
+@section one_time_setUp_tearDown setUp/tearDown of only one time
+@japanese
+@section one_time_setUp_tearDown °ì²ó¤À¤±¤Î setUp/tearDown
+@endif
 
-@code
-  CCUnitTestResult* result;
-  result = ccunit_runTestCase (testCase);
-  return 0;
-}
-@endcode
 
 @english
 Calling sequence of test cases in a fixture is following:
@@ -448,22 +386,6 @@ $ ./runTestCase
 @endcode
 
 @~english
-When the test testCase is run, that specific test functions
-will be run.  This is not a useful thing to do, however, as
-no diagnostics will be displayed.  One will normally use a
-@link ExecutingTest TestRunner @endlink (see below) to
-display the results.
-@~japanese
-¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤¬¼Â¹Ô¤µ¤ì¤ë¤È¡¢
-»ØÄꤷ¤¿¥Æ¥¹¥È´Ø¿ô¤¬¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£
-¤³¤ì¤Ï¤Þ¤À¤¢¤Þ¤êÊØÍø¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡¢
-¤Ê¤¼¤Ê¤é¡¢¿ÇÃǤ¬É½¼¨¤µ¤ì¤Ê¤¤¤«¤é¤Ç¤¹¡£
-Ä̾ï¤Ï @link ExecutingTest TestRunner @endlink
-(@ref test_runner ¸å½Ò)
-¤Ç·ë²Ì¤òɽ¼¨¤·¤Þ¤¹¡£
-@~
-
-@~english
 Once you have several tests, organize them into a suite.
 @~japanese
 °ìÅÙ¤¤¤¯¤Ä¤«¤Î¥Æ¥¹¥È¤òºî¤Ã¤¿¤é¡¢