From 7f5c99f619a8721f48ce5313e6104d8059cd19ff Mon Sep 17 00:00:00 2001 From: tsutsumi <> Date: Thu, 23 Oct 2003 19:35:23 +0000 Subject: [PATCH] merge cookbook.dox --- doc/cookbook.ja.dox | 451 ---------------------------------------------------- 1 file changed, 451 deletions(-) delete mode 100644 doc/cookbook.ja.dox diff --git a/doc/cookbook.ja.dox b/doc/cookbook.ja.dox deleted file mode 100644 index d4f04bc..0000000 --- a/doc/cookbook.ja.dox +++ /dev/null @@ -1,451 +0,0 @@ -/* -*- Indented-Text -*- */ -/* $Id$ */ -/** @page cookbook_ja CCUnit Cookbook (ja) - -¤³¤ì¤Ï CCUnit ¤ò»È¤¤»Ï¤á¤ë¤Ë¤¢¤¿¤Ã¤Æ¡¢Íý²ò¤Î½õ¤±¤È¤Ê¤ë¤è¤¦¤Ê -û¤¤¥¯¥Ã¥¯¥Ö¥Ã¥¯¤Ç¤¹¡£ - -@section simple_test_case_ja ¥·¥ó¥×¥ë¤Ê¥Æ¥¹¥È¥±¡¼¥¹ - -CCUnit¤ò»È¤Ã¤¿¥Æ¥¹¥È¤Ï¼«Æ°Åª¤Ë¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£ -CCUnit ¤Î¥Æ¥¹¥È¤Ï´Êñ¤Ë¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¤³¤È¤¬¤Ç¤­¤Æ°ìÅ٥ƥ¹¥È -¤ò½ñ¤¤¤Æ¤·¤Þ¤¨¤Ð¡¢¤¤¤Ä¤Ç¤â¥×¥í¥°¥é¥à¤ÎÉʼÁ¤ò¿®Íê¤Ç¤­¤ë¤â¤Î¤Ë -ÊݤĤ³¤È¤¬¤Ç¤­¤ë¤Ç¤·¤ç¤¦¡£ - -ñ½ã¤Ê¥Æ¥¹¥È¤òºî¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£ - -
    -
  1. ¥Æ¥¹¥È´Ø¿ô¤òºî¤ë
  2. -
  3. Ãͤò¥Á¥§¥Ã¥¯¤·¤¿¤¤¾ì¹ç¤Ï¡¢ - @link CCUNIT_ASSERT() CCUNIT_ASSERT(bool) @endlink - ¤ò¸Æ¤Ó½Ð¤·¤Æ¡¢¤â¤·¥Æ¥¹¥È¤¬À®¸ù¤¹¤ë¤Î¤Ç¤¢¤ì¤Ð¿¿¤òÊÖ¤¹¤è - ¤¦¤Ê¿¿µ¶ÃͤòÅϤ·¤Þ¤¹¡£
  4. -
- -Î㤨¤Ð¡¢Æó¤Ä¤ÎÊ£ÁÇ¿ô¤Î¹ç·×¤¬¡¢Æó¤Ä¤ÎÊ£ÁÇ¿ô¤ÎÃͤò²Ã»»¤·¤¿¤â¤Î -¤Ç¤¢¤ë¤³¤È¤ò¥Æ¥¹¥È¤¹¤ë¤È¤·¤Þ¤¹¡£ - -@code -void test_complex_add () -{ - complex_t c10_1 = { 10.0, 1.0 }; - complex_t c1_1 = { 1.0, 1.0 }; - complex_t result; - complex_t c11_2 = { 11.0, 2.0 }; - CCUNIT_ASSERT (complex_equals (&c11_2, complex_add (&result, c10_1, c1_1))); -} -@endcode - -¤³¤ì¤ÏÂçÊÑñ½ã¤Ê¥Æ¥¹¥È¤Ç¤¹¡£ -Ä̾Ʊ¤¸¥Ç¡¼¥¿¤Î¥»¥Ã¥È¤ÇÁö¤é¤»¤ë¤¿¤á¤Ë¡¢ -¤¿¤¯¤µ¤ó¤Î¾®¤µ¤Ê¥Æ¥¹¥È¥±¡¼¥¹¤òºî¤é¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤Ç¤·¤ç¤¦¡£ -¤½¤¦¤¹¤ë¤Ë¤Ï¥Õ¥£¥¯¥¹¥Á¥ã¡ÊÈ÷Éʡˤò»È¤¤¤Þ¤¹¡£ - -@section fixture_ja ¥Õ¥£¥¯¥¹¥Á¥ã - -¤â¤·Æó¤Ä°Ê¾å¤Î¥Æ¥¹¥È¤¬¤¢¤ë¤Ê¤é¡¢ -Ʊ¤¸Îà»÷¤Î¥Ç¡¼¥¿¤Î¥»¥Ã¥È¤ÇÁàºî¤¹¤ë¤Î¤Ç¤Ï¤Ê¤¤¤Ç¤·¤ç¤¦¤«¡£ - -¥Æ¥¹¥È¤Ï¼þÃΤΥǡ¼¥¿¤Î¥»¥Ã¥È¤òÇطʤˤ·¤Æ¼Â¹Ô¤µ¤ì¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£ -¤³¤Î¥Ç¡¼¥¿¤Î¥»¥Ã¥È¤ò¥Õ¥£¥¯¥¹¥Á¥ã¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹¡£ -¥Æ¥¹¥È¤ò½ñ¤¤¤Æ¤¤¤ë¤È¡¢ -¼ÂºÝ¤Î¥Æ¥¹¥È¤¹¤ëÃͤò¥Õ¥£¥¯¥¹¥Á¥ã¤Ë¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¥³¡¼¥É¤ò½ñ¤¯Êý¤Ë¡¢ -¤â¤Ã¤È»þ´Ö¤ò¤«¤±¤Æ¤¤¤ë¤³¤È¤Ëµ¤¤Å¤¯¤³¤È¤¬¤è¤¯¤¢¤ê¤Þ¤¹¡£ - -¤â¤·¶¦Ä̤¹¤ë¥Õ¥£¥¯¥¹¥Á¥ã¤¬¤¢¤ì¤Ð¡¢¤³¤ó¤Ê¤Õ¤¦¤Ë¤¹¤ë¤³¤È¤Ë¤Ê¤ê -¤Þ¤¹¡£ - -
    -
  1. @link CCUnitTestCase CCUnitTestCase @endlink -¹½Â¤ÂΤ˥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹ -¡Ê°Ê¹ß¡¢¹½Â¤ÂΤ˳ä¤êÅö¤Æ¤¿¥á¥â¥ê¤ò¡¢¥ª¥Ö¥¸¥§¥¯¥È¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹¡Ë -
  2. -
  3. ¥Õ¥£¥¯¥¹¥Á¥ã¤Î¤½¤ì¤¾¤ì¤ÎÉôʬ¤ËÂç°èÊÑ¿ô¤òÄɲä·¤Þ¤¹
  4. -
  5. setUp() ´Ø¿ô¤ò½ñ¤¤¤ÆÊÑ¿ô¤ò½é´ü²½¤·¤Þ¤¹
  6. -
  7. tearDown() ´Ø¿ô¤ò½ñ¤¤¤ÆsetUp -¤Ç³ä¤êÅö¤Æ¤¿±Ê³Ū¥ê¥½¡¼¥¹¤ò²òÊü¤·¤Þ¤¹
  8. -
  9. @link CCUnitTestFixture CCUnitTestFixture @endlink -¹½Â¤ÂΤ˥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹
  10. -
  11. ¥Æ¥¹¥È¥±¡¼¥¹¥ª¥Ö¥¸¥§¥¯¥È¤ò¥Õ¥£¥¯¥¹¥Á¥ã¥ª¥Ö¥¸¥§¥¯¥È¤ËÄɲä·¤Þ¤¹
  12. -
- -Î㤨¤Ð¡¢¤¤¤¯¤Ä¤«¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¯¾ì¹ç¡¢ -ºÇ½é¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤òºîÀ®¤·¤Þ¤·¤ç¤¦¡£ - -@code -//** TEST CASE: Ê£ÁÇ¿ô¥é¥¤¥Ö¥é¥ê¥Æ¥¹¥È *\/ - -#include "complex.h" - -static complex_t* s10_1; -static complex_t* s1_1; -static complex_t* s11_2; - -void setUp_ComplexTest () -{ - s10_1 = complex_new (10, 1); - s1_1 = complex_new (1, 1); - s11_2 = complex_new (11, 2); -} - -void tearDown_ComplexTest () -{ - complex_delete (s10_1); - complex_delete (s1_1); - complex_delete (s11_2); -} - -... - - CCUnitTestFixture* fixture; - fixture = ccunit_newTestFixture ("ComplexTest", - CCUNIT_NEWTESTFUNC(setUp_ComplexTest), - CCUNIT_NEWTESTFUNC(tearDown_ComplexTest)); -@endcode - -°ìÅÙ·è¤Þ¤Ã¤¿¤È¤³¤í¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤ò½ñ¤¤¤Æ¤·¤Þ¤¨¤Ð¡¢ -¤¢¤Ê¤¿¤¬¹¥¤­¤Ê¤è¤¦¤ËÊ£ÁÇ¿ô¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¯¤³¤È¤¬¤Ç¤­¤ë¤Ç¤·¤ç¤¦¡£ - -@section test_case_ja ¥Æ¥¹¥È¥±¡¼¥¹ - -¥Õ¥£¥¯¥¹¥Á¥ã¤ò°ì¤Ä½ñ¤¤¤¿¤È¤·¤Æ¡¢ -¤É¤¦¤ä¤Ã¤Æ¸Ä¡¹¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¤¤Æ¼Â¹Ô¤¹¤ì¤ÐÎɤ¤¤Ç¤·¤ç¤¦¤«¡£ - -Î㤨¤Ð¡¢Æó¤Ä¤ÎÊ£ÁÇ¿ô¤¬Åù¤·¤¤¡Ê¤Þ¤¿¤ÏÅù¤·¤¯¤Ê¤¤¡Ë¤³¤È¤ò¥Æ¥¹¥È¤¹¤ë¤Ë¤Ï¡¢ -¼¡¤Î¤è¤¦¤Ë½ñ¤­¤Þ¤¹¡£ - -@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); -} - -... - - ccunit_addNewTestCase (fixture, - "test_complex_equals", - "Ê£ÁÇ¿ôÅùÃͥƥ¹¥È", - test_complex_equals); - ccunit_addNewTestCase (fixture, - "test_complex_add", - "Ê£ÁÇ¿ô²Ã»»¥Æ¥¹¥È", - test_complex_add); -@endcode - -°ì¤Ä¤Ë¤Ï¼¡¤Î¤è¤¦¤Ë¡¢ -¥Õ¥£¥¯¥¹¥Á¥ã¤òºîÀ®¤·¤Æ¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò¼Â¹Ô¤µ¤»¤ë¤³¤È -¤¬¤Ç¤­¤Þ¤¹¡£ - -@code - CCUnitTestResult* result; - result = ccunit_runTestFixture (fixture); -@endcode - -¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤¬¼Â¹Ô¤µ¤ì¤ë¤È¡¢ -ÆÃÄê¤Î¥Æ¥¹¥È´Ø¿ô¤¬¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£ -¤³¤ì¤Ï¤¢¤Þ¤êÊØÍø¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡¢ -¤Ê¤¼¤Ê¤é¡¢¿ÇÃǤ¬É½¼¨¤µ¤ì¤Ê¤¤¤«¤é¤Ç¤¹¡£ -Ä̾ï¤Ï @link ExecutingTest TestRunner @endlink (¸å½Ò) -¤Ç·ë²Ì¤òɽ¼¨¤·¤Þ¤¹¡£ - -°ìÅÙ¤¤¤¯¤Ä¤«¤Î¥Æ¥¹¥È¤òºî¤Ã¤¿¤é¡¢ -¤½¤ì¤é¤ò¥¹¥¤¡¼¥È¤ËÀ°Íý¤·¤Þ¤¹¡£ - -@section suite_ja ¥¹¥¤¡¼¥È - -¤É¤Î¤è¤¦¤Ë¤·¤Æ¡¢°ìÅ٤˥ƥ¹¥È¤ò¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¡¢ -½àÈ÷¤·¤·¤¿¤é¤¤¤¤¤Ç¤·¤ç¤¦¤«¡© - -CCUnit ¤Ï¤¤¤¯¤Ä¤â¤Î @link CCUnitTestCase TestCases @endlink -¤ò°ì½ï¤Ë¼Â¹Ô¤¹¤ë -@link CCUnitTestSuite TestSuite @endlink ¥â¥¸¥å¡¼¥ë¤òÄ󶡤·¤Þ¤¹¡£ - -¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤ò¼Â¹Ô¤¹¤ëÊýË¡¤Ï¾å½Ò¤·¤Þ¤·¤¿¡£ -Æó¤Ä°Ê¾å¤Î¥Æ¥¹¥È¤ò´Þ¤à°ì¤Ä¤Î¥¹¥¤¡¼¥È¤òºî¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£ - -@code -CCUnitTestSuite* suite; -CCUnitTestFixture* fixture; -CCUnitTestResult* result; -suite = ccunit_newTestSuite ("Ê£ÁÇ¿ô¥Æ¥¹¥È¥¹¥¤¡¼¥È"); -fixture = ccunit_newTestFixture ("Ê£ÁÇ¿ô¥Æ¥¹¥È", - CCUNIT_NEWTESTFUNC(setUp_complex_test), - CCUNIT_NEWTESTFUNC(tearDown_complex_test)); -ccunit_addNewTestCase (fixture, "test_complex_equals", "Ê£ÁÇ¿ôÅùÃͥƥ¹¥È", - test_complex_equals); -ccunit_addNewTestCase (fixture, "test_complex_add", "Ê£ÁÇ¿ô²Ã»»¥Æ¥¹¥È", - test_complex_add); -ccunit_addNewTestCase (fixture, "test_complex_sub", "Ê£ÁÇ¿ô¸º»»¥Æ¥¹¥È", - test_complex_sub); -ccunit_addTestFixture (suite, fixtuer); -result = ccunit_runTestSuite (suite, NULL); -@endcode - -@link CCUnitTestSuite TestSuites @endlink ¤Ï -@link CCUnitTestFixture TestFixtures @endlink -¤ò´Þ¤à¤À¤±¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£ - -¤½¤ì¤é¤Ï @link CCUnitTest Test @endlink -¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤¹¤ë¤É¤ó¤Ê¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤â´Þ¤á¤é¤ì¤Þ¤¹¡£ -Î㤨¤Ð¡¢¤¢¤Ê¤¿¤Ï¤¢¤Ê¤¿¤Î¥³¡¼¥É¤Ë@link CCUnitTestSuite TestSuite @endlink -¤òºî¤ë¤³¤È¤¬¤Ç¤­¡¢¤½¤·¤Æ»ä¤Ï»ä¤Î¥¹¥¤¡¼¥È¤òºî¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¢ -¤½¤·¤Æ»äã¤ÏξÊý¤È¤â¤ò´Þ¤ó¤Ç¤¤¤ë @link CCUnitTestSuite TestSuite @endlink -¤òºî¤Ã¤Æ°ì½ï¤Ë¸Ä¡¹¤Î¥¹¥¤¡¼¥È¤òÆ°¤«¤¹¤³¤È¤¬¤Ç¤­¤ë¤Î¤Ç¤¹¡£ - -@code -CCUnitTestSuite* suite; -CCUnitTestResult* result; -suite = ccunit_newTestSuite ("suite"); -ccunit_addTestSuite (suite, complex_add_sub_suite ()); //* ¤¢¤Ê¤¿¤Î¥¹¥¤¡¼¥È *\/ -ccunit_addTestSuite (suite, complex_mul_div_suite ()); //* ¤ï¤¿¤·¤Î¥¹¥¤¡¼¥È *\/ -result = ccunit_runTestSuite(suite, NULL); -@endcode - - -@section test_runner_ja TestRunner - -How do you run your tests and collect their results? - -Once you have a test suite, you'll want to run it. %CCUnit -provides tools to define the suite to be run and to display -its results. You make your suite accessible to a @link -CreatingTestSuite ccunit_makeSuite @endlink tool that generate a -creating test suite code. - -For example, to make a ComplexTest suite available to a -@link CreatingTestSuite ccunit_makeSuite @endlink, -excute the following tool to -ComplexTest.c: - -@code -$ ccunit_makeSuite -f complex_suite -o suiteComplex.c ComplexTest.c -@endcode - -@anchor test_runner_code -To use the TestRunner, include the header files for the tests in Main.c: - -@code -#include -#include -@endcode - -And call to -@link ccunit_runTestRunner() -ccunit_runTestRunner (CCUnitTestRunner*, CCUnitTestSuite *) @endlink -in the main() function: - -@code -extern CCUnitTestSuite* complex_suite(const char* name); - -int main( int argc, char **argv) -{ - CCUnitTestRunner* runner; - CCUnitTestSuite* suite; - runner = ccunit_newTestRunner (stdout); - suite = complex_suite ("complex test suite"); - return ccunit_runTestRunner (runner, suite); -} -@endcode - -The @link ExecutingTest TestRunner @endlink will run the tests. -If all the tests pass, you'll get an informative message. -If any fail, you'll get the following information: - - - -@section helper_macros_ja Helper Tool - -As you might have noticed, implementing the fixture -suite () function is a repetitive and error -prone task. A @ref CreatingTestSuite set of functions and -command have been created to automatically implements the -suite() method. - -The following code is a rewrite of ComplexTest using those command: - -@code -#include -@endcode - -First, you declare the fixture, passing the test fixture -name to the javaDoc style comment, which consist of a -C-style comment block starting with two *'s: - -@code -//** test case: complex number test *\/ -@endcode - -The suite created by the ccunit_suite() -function is specified -f option of command -ccunit_makeSuite. Then, you define each test -case of the fixture with prefix test, -setUp, tearDown: - -@code -#include - -static complex_t* s10_1; -static complex_t* s1_1; -static complex_t* s11_2; - -void setUp_complex_test () -{ - s10_1 = complex_new (10, 1); - s1_1 = complex_new (1, 1); - s11_2 = complex_new (11, 2); -} - -void tearDown_complex_test () -{ - complex_delete (s10_1); - complex_delete (s1_1); - complex_delete (s11_2); -} - -//** test equals *\/ -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); -} - -//** test add *\/ -void test_complex_add () -{ - complex_t c10_1 = { 10.0, 1.0 }; - complex_t c1_1 = { 1.0, 1.0 }; - complex_t result; - complex_t c11_2 = { 11.0, 2.0 }; - CCUNIT_ASSERT (complex_equals (&c11_2, complex_add (&result, &c10_1, &c1_1))); -} - -//** test sub *\/ -void test_complex_sub () -{ - complex_t c9_0 = { 9, 0 }; - complex_t result; - CCUNIT_ASSERT_TEST_OBJ (&c9_0, complex_equals, - complex_sub (&result, s10_1, s1_1), - complex_to_string); -} -@endcode - -Finally, you end the fixture declaration: - -@code -//** end test case *\/ -@endcode - -To generate creating suite function code, run -ccunit_makeSuite tool. - -@code -$ ccunit_makeSuite testComplex.c - -#include -#include -#include - -//* test fixture: complex number test *\/ -//* setUp_complex_test *\/ -extern void setUp_complex_test (); -//* tearDown_complex_test *\/ -extern void tearDown_complex_test (); -//* test_complex_equals *\/ -extern void test_complex_equals (); -//* test_complex_add *\/ -extern void test_complex_add (); -//* test_complex_sub *\/ -extern void test_complex_sub (); - - -static CCUnitTestFixtureDfn fx_001 = { - { ccunitTypeFixture }, - "complex number test", - { - "setUp_complex_test", - "setUp_complex_test", - setUp_complex_test - }, - { - "tearDown_complex_test", - "tearDown_complex_test", - tearDown_complex_test - }, - { - { - "test_complex_equals", - "test equals", - test_complex_equals - }, - { - "test_complex_add", - "test add", - test_complex_add - }, - { - "test_complex_sub", - "test sub", - test_complex_sub - }, - { - NULL, NULL, NULL - }, - } -}; - -static CCUnitTestSuiteDfn suite_001 = { - { ccunitTypeSuite }, - "", - { - &suite_002.test, - NULL, - }, -}; - -CCUnitTestSuite* ccunit_suite (const char* name) -{ - if (!suite_001.name[0]) - suite_001.name = name; - return ccunit_newTestSuiteFromDfn (&suite_001); -} -$ -@endcode - -@section post_build_check_ja Post-build check - -Now that we have our unit tests running, how about -integrating unit testing to our build process ? - -To do that, the application must returns a value different than 0 to indicate that -there was an error. - -@link ccunit_runTestRunner() ccunit_runTestRunner() @endlink returns -a integer indicating if the run was successful. - -Updating our main programm, we obtains: -@code -#include - -int main (int argc, char** argv) -{ - CCUnitTestRunner* runner; - CCUnitTestSuite* suite; - int wasSucessful; - runner = ccunit_newTestRunner (stdout); - suite = ccunit_suite (); - wasSucessful = ccunit_runTestRunner (runner, suite); - return wasSucessful; -} -@endcode - -Now, you need to run your application after compilation. - -*/ -- 2.11.0