A C Unit Test Library for C language.
Revision | d894e8d05a0a32b9238f22037bfff5ab2c139709 (tree) |
---|---|
Time | 2010-08-19 20:44:17 |
Author | tsntsumi <> |
Commiter | tsntsumi <> |
This commit was manufactured by cvs2svn to create tag 'rel-1_2'.
Sprout from master 2010-08-18 04:20:08 UTC tsutsumi 'revert some macros'
Cherrypick from master 2010-08-19 11:44:16 UTC tsutsumi 'specify whether setUp/tearDown isn't necessarily needed.':
@@ -129,9 +129,24 @@ What if you have two or more tests that operate on the same | ||
129 | 129 | similar set of objects? |
130 | 130 | @~japanese |
131 | 131 | もし二つ以上のテストがあるなら、 |
132 | -同じ類似のデータのセットで操作するのではないでしょうか。 | |
132 | +同じ類似のデータの集まりで操作するのではないでしょうか。 | |
133 | 133 | @~ |
134 | 134 | |
135 | +@dot | |
136 | +digraph TestCase { | |
137 | + node [ fontsize=9, fontname=Helvetica ] | |
138 | + edge [ fontsize=9, dir=back, arrowtail=vee ] | |
139 | + gv [ label="Global variables", shape=box ] | |
140 | + { rank=same; | |
141 | + tc1 [ label="Test case 1" ]; | |
142 | + tcn [ label="Test case n" ]; | |
143 | + } | |
144 | + gv -> tc1; | |
145 | + gv -> tcn; | |
146 | + tc1 -> tcn [ style=dotted, arrowtail=none ]; | |
147 | +} | |
148 | +@enddot | |
149 | + | |
135 | 150 | @~english |
136 | 151 | Tests need to run against the background of a known set of |
137 | 152 | objects. This set of objects is called a test fixture. When |
@@ -139,7 +154,7 @@ you are writing tests you will often find that you spend | ||
139 | 154 | more time writing the code to set up the fixture than you do |
140 | 155 | in actually testing values. |
141 | 156 | @~japanese |
142 | -テストは周知のデータのセットを背景にして実行される必要があります。 | |
157 | +テストは周知のデータの集まりを背景にして実行される必要があります。 | |
143 | 158 | このデータのセットをフィクスチャと呼ぶことにします。 |
144 | 159 | テストを書いていると、 |
145 | 160 | 実際のテストする値をフィクスチャにセットアップするコードを書く方に、 |
@@ -155,9 +170,25 @@ different results. | ||
155 | 170 | 多くの場合、いくつかの異なったテストのために同じフィクスチャを使うことができます。 |
156 | 171 | それぞれのテストケースは少し異なったメッセージ、 |
157 | 172 | あるいはパラメータをフィクスチャに送り、 |
158 | -異なる結果を調べます。 | |
173 | +異なる結果を調べることになるでしょう。 | |
159 | 174 | @~ |
160 | 175 | |
176 | +@dot | |
177 | +digraph TestFixture { | |
178 | + node [ fontsize=9, fontname=Helvetica ] | |
179 | + edge [ fontsize=9, dir=back, arrowtail=vee ] | |
180 | + gv [ label="Global variables", shape=box ] | |
181 | + { rank=same; | |
182 | + su [ label="setUp ()" ]; | |
183 | + tc [ label="TestCase" ]; | |
184 | + td [ label="tearDown ()" ]; | |
185 | + } | |
186 | + gv -> su [ label="initialize" ]; | |
187 | + gv -> tc [ label="access" ]; | |
188 | + gv -> td [ label="clean-up" ]; | |
189 | +} | |
190 | +@enddot | |
191 | + | |
161 | 192 | @~english |
162 | 193 | When you have a common fixture, here is what you do: |
163 | 194 | @~japanese |
@@ -195,7 +226,7 @@ When you have a common fixture, here is what you do: | ||
195 | 226 | <li>@~english |
196 | 227 | Create a @link CCUnitTestFixture TestFixture @endlink object |
197 | 228 | @~japanese |
198 | - @link CCUnitTestFixture CCUnitTestFixture @endlink | |
229 | + @link CCUnitTestFixture TestFixture @endlink | |
199 | 230 | 構造体にメモリを割り当てます |
200 | 231 | @~ |
201 | 232 | </li> |
@@ -204,7 +235,7 @@ When you have a common fixture, here is what you do: | ||
204 | 235 | @~japanese |
205 | 236 | @link CCUnitTestCase TestCase @endlink オブジェクトを |
206 | 237 | @link CCUnitTestFixture TestFixture @endlink |
207 | - フィクスチャオブジェクトに登録します。 | |
238 | + オブジェクトに登録します。 | |
208 | 239 | @~ |
209 | 240 | </li> |
210 | 241 | </ol> |
@@ -240,8 +271,8 @@ void tearDown_complex_test () | ||
240 | 271 | complex_delete (s11_2); |
241 | 272 | } |
242 | 273 | |
243 | -... | |
244 | - | |
274 | +int main () | |
275 | +{ | |
245 | 276 | CCUnitTestFixture* fixture; |
246 | 277 | fixture = ccunit_newTestFixture ("complex test", |
247 | 278 | CCUNIT_NEWTESTFUNC(setUp_complex_test), |
@@ -287,6 +318,10 @@ void test_complex_equals () | ||
287 | 318 | |
288 | 319 | ... |
289 | 320 | |
321 | +int main () | |
322 | +{ | |
323 | + ... | |
324 | + | |
290 | 325 | ccunit_addNewTestCase (fixture, |
291 | 326 | "test_complex_equals", |
292 | 327 | "complex equals test", |
@@ -303,6 +338,42 @@ One may create and run objects for each test case like this: | ||
303 | 338 | @code |
304 | 339 | CCUnitTestResult* result; |
305 | 340 | result = ccunit_runTestFixture (fixture); |
341 | + return 0; | |
342 | +} | |
343 | +@endcode | |
344 | + | |
345 | +@english | |
346 | +Calling sequence of test cases in a fixture is following: | |
347 | +@japanese | |
348 | +ひとつのフィクスチャの中のテストケースの実行シーケンスは次のようになります。 | |
349 | +@endif | |
350 | + | |
351 | +@dot | |
352 | +digraph FixtureCallingSequence { | |
353 | + node [ fontsize=9, fontname=Helvetica ] | |
354 | + edge [ fontsize=9 ] | |
355 | + rankdir = LR; | |
356 | + setUp -> "TestCase 1" -> tearDown; | |
357 | + setUp2 [ label="setUp" ]; | |
358 | + tearDown2 [ label="tearDown" ]; | |
359 | + setUp2 -> "TestCase n" -> tearDown2; | |
360 | + tearDown -> setUp2 [ style=dotted ]; | |
361 | +} | |
362 | +@enddot | |
363 | + | |
364 | +@english | |
365 | +The sample code made in the above is in the directory <code>examples/complex</code>, | |
366 | +the files <code>testComplex.c</code> and <code>runTestFixture.c</code>. | |
367 | +@japanese | |
368 | +ここまでのサンプルコードは、<code>examples/complex</code> ディレクトリの | |
369 | +<code>testComplex.c, runTestFixture.c</code> にあります。 | |
370 | + | |
371 | +コンパイルおよび実行するには、次のようにします。 | |
372 | +@endif | |
373 | + | |
374 | +@code | |
375 | +$ gcc -I. -o runTestFixture runTestFixture.c testComplex.c complex.c -lccunit | |
376 | +$ ./runTestFixture | |
306 | 377 | @endcode |
307 | 378 | |
308 | 379 | @~english |
@@ -313,8 +384,8 @@ no diagnostics will be displayed. One will normally use a | ||
313 | 384 | display the results. |
314 | 385 | @~japanese |
315 | 386 | テストフィクスチャが実行されると、 |
316 | -特定のテスト関数が呼び出されます。 | |
317 | -これはあまり便利ではありません、 | |
387 | +指定したテスト関数が呼び出されます。 | |
388 | +これはまだあまり便利ではありません、 | |
318 | 389 | なぜなら、診断が表示されないからです。 |
319 | 390 | 通常は @link ExecutingTest TestRunner @endlink |
320 | 391 | (@ref test_runner 後述) |
@@ -334,6 +405,20 @@ Once you have several tests, organize them into a suite. | ||
334 | 405 | @section suite スーツ |
335 | 406 | @endif |
336 | 407 | |
408 | +@dot | |
409 | +digraph TestStructure { | |
410 | + node [ fontsize=9, fontname=Helvetica ]; | |
411 | + edge [ dir=back, fontsize=9 ]; | |
412 | + TestSuite -> TestSuite [ label="1..n" ]; | |
413 | + TestFixture; | |
414 | + TestSuite -> TestFixture [ label="1..n" ]; | |
415 | + TestFixture -> setUp [ label="0..1" ]; | |
416 | + TestCase; | |
417 | + TestFixture -> TestCase [ label="1..n" ]; | |
418 | + TestFixture -> tearDown [ label="0..1" ]; | |
419 | +} | |
420 | +@enddot | |
421 | + | |
337 | 422 | @~english |
338 | 423 | How do you set up your tests so that you can run them all at once? |
339 | 424 | @~japanese |
@@ -363,21 +448,25 @@ To create a suite of two or more tests, you do the following: | ||
363 | 448 | @~ |
364 | 449 | |
365 | 450 | @code |
366 | -CCUnitTestSuite* suite; | |
367 | -CCUnitTestFixture* fixture; | |
368 | -CCUnitTestResult* result; | |
369 | -suite = ccunit_newTestSuite ("Complex test suite"); | |
370 | -fixture = ccunit_newTestFixture ("Complex Tests", | |
371 | - CCUNIT_NEWTESTFUNC(setUp_complex_test), | |
372 | - CCUNIT_NEWTESTFUNC(tearDown_complex_test)); | |
373 | -ccunit_addNewTestCase (fixture, "test_complex_equals", "complex equals test", | |
374 | - test_complex_equals); | |
375 | -ccunit_addNewTestCase (fixture, "test_complex_add", "complex add test", | |
376 | - test_complex_add); | |
377 | -ccunit_addNewTestCase (fixture, "test_complex_sub", "complex sub test", | |
378 | - test_complex_sub); | |
379 | -ccunit_addTestFixture (suite, fixtuer); | |
380 | -result = ccunit_runTestSuite (suite, NULL); | |
451 | +int main () | |
452 | +{ | |
453 | + CCUnitTestSuite* suite; | |
454 | + CCUnitTestFixture* fixture; | |
455 | + CCUnitTestResult* result; | |
456 | + suite = ccunit_newTestSuite ("Complex test suite"); | |
457 | + fixture = ccunit_newTestFixture ("Complex Tests", | |
458 | + CCUNIT_NEWTESTFUNC(setUp_complex_test), | |
459 | + CCUNIT_NEWTESTFUNC(tearDown_complex_test)); | |
460 | + ccunit_addNewTestCase (fixture, "test_complex_equals", "complex equals test", | |
461 | + test_complex_equals); | |
462 | + ccunit_addNewTestCase (fixture, "test_complex_add", "complex add test", | |
463 | + test_complex_add); | |
464 | + ccunit_addNewTestCase (fixture, "test_complex_sub", "complex sub test", | |
465 | + test_complex_sub); | |
466 | + ccunit_addTestFixture (suite, fixtuer); | |
467 | + result = ccunit_runTestSuite (suite, NULL); | |
468 | + return 0; | |
469 | +} | |
381 | 470 | @endcode |
382 | 471 | |
383 | 472 | @~english |
@@ -411,14 +500,30 @@ contains both: | ||
411 | 500 | @~ |
412 | 501 | |
413 | 502 | @code |
414 | -CCUnitTestSuite* suite; | |
415 | -CCUnitTestResult* result; | |
416 | -suite = ccunit_newTestSuite ("Complex add/sub/mul/div test suite"); | |
417 | -ccunit_addTestSuite (suite, complex_add_sub_suite ()); | |
418 | -ccunit_addTestSuite (suite, complex_mul_div_suite ()); | |
419 | -result = ccunit_runTestSuite(suite, NULL); | |
503 | + CCUnitTestSuite* suite; | |
504 | + CCUnitTestResult* result; | |
505 | + suite = ccunit_newTestSuite ("Complex add/sub/mul/div test suite"); | |
506 | + ccunit_addTestSuite (suite, complex_add_sub_suite ()); | |
507 | + ccunit_addTestSuite (suite, complex_mul_div_suite ()); | |
508 | + result = ccunit_runTestSuite(suite, NULL); | |
420 | 509 | @endcode |
421 | 510 | |
511 | +@english | |
512 | +The sample code made in the above is in the directory <code>examples/complex</code>, | |
513 | +the files <code>testComplex.c</code>, <code>testComplexMulDiv.c</code>, | |
514 | +<code>complexTestSuite.c</code> and <code>runTestSuite.c</code>. | |
515 | +@japanese | |
516 | +ここまでのサンプルコードは、<code>examples/complex</code> ディレクトリの | |
517 | +<code>testComplex.c, testComplexMulDiv.c, complexTestSuite.c, runTestSuite.c</code> | |
518 | +にあります。 | |
519 | + | |
520 | +コンパイルおよび実行するには、次のようにします。 | |
521 | +@endif | |
522 | + | |
523 | +@code | |
524 | +$ gcc -I. -o runTestSuite runTestSuite.c testComplex.c testComplexMulDiv.c complexTestSuite.c complex.c -lccunit | |
525 | +$ ./runTestSuite | |
526 | +@endcode | |
422 | 527 | |
423 | 528 | @english |
424 | 529 | @section test_runner TestRunner |
@@ -428,54 +533,47 @@ result = ccunit_runTestSuite(suite, NULL); | ||
428 | 533 | |
429 | 534 | @~english |
430 | 535 | How do you run your tests and collect their results? |
536 | +The fixtures store result of own tests into | |
537 | +the @link CCUnitTestResult TestResult @endlink. | |
431 | 538 | @~japanese |
432 | 539 | どうやってテストを実行し、その結果を集めたら良いでしょうか。 |
540 | +フィクスチャはテストケースの実行結果を | |
541 | +@link CCUnitTestResult TestResult @endlink に格納します。 | |
433 | 542 | @~ |
434 | 543 | |
544 | +@dot | |
545 | +digraph TestResult { | |
546 | + node [ fontsize=9, fontname=Helvetica ] | |
547 | + { rank=same; | |
548 | + edge [ fontsize=9, fontname=Courier ] | |
549 | + TestFixture -> TestResult [ label="TestFailure", style=dotted, arrowhead=vee ]; | |
550 | + } | |
551 | + edge [ fontsize=9, dir=back ] | |
552 | + TestFixture -> setUp; | |
553 | + TestFixture -> "TestCase 1..n"; | |
554 | + TestFixture -> tearDown; | |
555 | + TestResult -> "TestFailure 0..m"; | |
556 | +} | |
557 | +@enddot | |
558 | + | |
435 | 559 | @~english |
436 | 560 | Once you have a test suite, you'll want to run it. %CCUnit |
437 | -provides tools to define the suite to be run and to display | |
438 | -its results. You make your suite accessible to a @link | |
439 | -CreatingTestSuite ccunit_makeSuite @endlink tool that generate a | |
440 | -creating test suite code. | |
561 | +provides @link ExecutingTest TestRunner @endlink | |
562 | +to define the suite to be run and to display | |
563 | +its results. | |
441 | 564 | @~japanese |
442 | 565 | 一つテストスーツを書いたら、 |
443 | 566 | それを実行したいでしょう。 |
444 | 567 | CCUnit はスーツを実行するために定義し、 |
445 | -結果を表示するためのツールを提供します。 | |
446 | -スーツを @link CreatingTestSuite ccunit_makeSuite @endlink | |
447 | -ツールに入力できるような形式で書くことで、 | |
448 | -テストスーツを作成するコードを自動的に生成することができます。 | |
449 | -@~ | |
450 | - | |
451 | -@~english | |
452 | -For example, to make a ComplexTest suite available to a | |
453 | -@link CreatingTestSuite ccunit_makeSuite @endlink, | |
454 | -excute the following tool to | |
455 | -testComplex.c: | |
456 | -@~japanese | |
457 | -例えば、ComplexTest スーツを | |
458 | -@link CreatingTestSuite ccunit_makeSuite @endlink | |
459 | -を使って使用できるようにするには、 | |
460 | -以下のツールを testComplex.c に実行します。 | |
461 | -@~ | |
462 | - | |
463 | -@code | |
464 | -$ ccunit_makeSuite -f complex_suite -o suiteComplex.c testComplex.c | |
465 | -@endcode | |
466 | - | |
467 | -@anchor test_runner_code | |
468 | -@~english | |
469 | -@~japanese | |
470 | -<code>complex_suite</code> という関数が定義された、 | |
471 | -<code>suiteComplex.c</code> というファイルが作成されます。 | |
568 | +結果を表示するための @link ExecutingTest TestRunner @endlink を提供します。 | |
472 | 569 | @~ |
473 | 570 | |
474 | 571 | @~english |
475 | -To use the TestRunner, include the header files for the tests in runTest.c: | |
572 | +To use the @link CCUnitTestRunner TestRunner @endlink, | |
573 | +include the header files for the tests in runTestRunner.c: | |
476 | 574 | @~japanese |
477 | -TestRunner を使用するには、 | |
478 | -例えば runTest.c でテストのためのファイルのヘッダをインクルードします。 | |
575 | +@link CCUnitTestRunner TestRunner @endlink を使用するには、 | |
576 | +例えば runTestRunner.c でテストのためのファイルのヘッダをインクルードします。 | |
479 | 577 | @~ |
480 | 578 | |
481 | 579 | @code |
@@ -495,18 +593,41 @@ ccunit_runTestRunner (CCUnitTestRunner*, CCUnitTestSuite *) @endlink | ||
495 | 593 | @~ |
496 | 594 | |
497 | 595 | @code |
498 | -extern CCUnitTestSuite* complex_suite(const char* name); | |
596 | +extern CCUnitTestSuite* complex_add_sub_suite (); | |
597 | +extern CCUnitTestSuite* complex_mul_div_suite (); | |
499 | 598 | |
500 | 599 | int main( int argc, char **argv) |
501 | 600 | { |
502 | 601 | CCUnitTestRunner* runner; |
503 | 602 | CCUnitTestSuite* suite; |
603 | + suite = ccunit_newTestSuite ("complex test suite"); | |
604 | + ccunit_addTestSuite (suite, complex_add_sub_suite ()); | |
605 | + ccunit_addTestSuite (suite, complex_mul_div_suite ()); | |
504 | 606 | runner = ccunit_newTestRunner (stdout); |
505 | - suite = complex_suite ("complex test suite"); | |
506 | 607 | return ccunit_runTestRunner (runner, suite); |
507 | 608 | } |
508 | 609 | @endcode |
509 | 610 | |
611 | +@english | |
612 | +The sample code made in the above is in the directory <code>examples/complex</code>, | |
613 | +the files <code>testComplex.c, complexTestSuite.c</code> and <code>runTestRunner.c</code>. | |
614 | +@japanese | |
615 | +ここまでのサンプルコードは、<code>examples/complex</code> ディレクトリの | |
616 | +<code>testComplex.c, complexTestSuite.c, runTestRunner.c</code> | |
617 | +にあります。 | |
618 | + | |
619 | +コンパイルおよび実行するには、次のようにします。 | |
620 | +@endif | |
621 | + | |
622 | +@code | |
623 | +$ gcc -I. -o runTestRunner runTestRunner.c testComplex.c testComplexMulDiv.c complexTestSuite.c complex.c -lccunit | |
624 | +$ ./runTestRunner | |
625 | +..... | |
626 | +Time: 0.000066 sec | |
627 | + | |
628 | +OK (5 tests) | |
629 | +@endcode | |
630 | + | |
510 | 631 | @~english |
511 | 632 | The @link ExecutingTest TestRunner @endlink will run the tests. |
512 | 633 | If all the tests pass, you'll get an informative message. |
@@ -514,7 +635,12 @@ If any fail, you'll get the following information: | ||
514 | 635 | @~japanese |
515 | 636 | @link ExecutingTest TestRunner @endlink はテストを実行します。 |
516 | 637 | もしすべてのテストがパスすれば、その情報のメッセージが表示されます。 |
517 | -もしどれかが失敗すれば、それについて以下のような情報が表示されます。 | |
638 | +上の例では、最初の「<code>.....</code>」は実行したテストケースです。 | |
639 | +実行する直前に「<code>.</code>」が出力されます。 | |
640 | +全てのテストケースの実行が終了すると、 | |
641 | +実行にかかった時間と実行したテストケースの数が表示されます。 | |
642 | + | |
643 | +どれかが失敗すれば、それについて以下のような情報が表示されます。 | |
518 | 644 | @~ |
519 | 645 | |
520 | 646 | <ul> |
@@ -546,6 +672,54 @@ If any fail, you'll get the following information: | ||
546 | 672 | </ul> |
547 | 673 | |
548 | 674 | @english |
675 | +@japanese | |
676 | +試しに @c testComplex.c のテストケースでわざと間違えてみましょう。 | |
677 | +<code>!complex_equals</code> の <code>!</code> をとってみます。 | |
678 | +@endif | |
679 | + | |
680 | +@code | |
681 | +//* testComplex.c *\/ | |
682 | +//** test equals *\/ | |
683 | +void test_complex_equals () | |
684 | +{ | |
685 | + CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s10_1, complex_to_string); | |
686 | +//*CCUNIT_ASSERT_TEST_OBJ (s10_1, !complex_equals, s1_1, complex_to_string);*\/ | |
687 | + CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s1_1, complex_to_string); | |
688 | +} | |
689 | +@endcode | |
690 | + | |
691 | +@code | |
692 | +$ gcc -I. -o runTestRunner runTestRunner.c testComplex.c testComplexMulDiv.c complexTestSuite.c complex.c -lccunit | |
693 | +$ ./runTestRunner | |
694 | +.F.... | |
695 | +Time: 0.000059 sec | |
696 | + | |
697 | +FAILURES!!! | |
698 | +Test Results: | |
699 | +Run 5, Failures 1 | |
700 | +There was 1 failure: | |
701 | +testComplex.c:53: complex equals test: | |
702 | + complex_equals (s10_1, s1_1) | |
703 | + expect: 10+1i | |
704 | + actual: 1+1i | |
705 | +@endcode | |
706 | + | |
707 | +@english | |
708 | +@japanese | |
709 | +この例ではテストケースを 5 個実行して、 | |
710 | +ひとつのテストケースで失敗していることがわかります。 | |
711 | +最初の「<code>.F....</code>」では、 | |
712 | +ひとつ目のテストケースが失敗していることをあらわしています。 | |
713 | + | |
714 | +また上述のように、 | |
715 | +失敗したファイル名、行番号、テストケースの名前 (<code>complex equals test</code>)、 | |
716 | +表明した条件の文字列 (<code>complex_equals (s10_1, s1_1)</code>)、 | |
717 | +期待した値 (<code>10+1i</code>)、 | |
718 | +実際の値 (<code>1+1i</code>) | |
719 | +が表示されます。 | |
720 | +@endif | |
721 | + | |
722 | +@english | |
549 | 723 | @section helper_macros Helper Tool |
550 | 724 | @japanese |
551 | 725 | @section helper_macros ヘルパーツール |
@@ -560,7 +734,7 @@ command have been created to automatically implements the | ||
560 | 734 | @~japanese |
561 | 735 | お気づきのように、フィクスチャの <code>suite ()</code>関数を実装するのは、 |
562 | 736 | 反復的で間違いやすい作業です。 |
563 | -@ref CreatingTestSuite の関数のセットとコマンドは<code>suite ()</code> | |
737 | +@ref CreatingTestSuite の関数の集まりとコマンドは<code>suite ()</code> | |
564 | 738 | 関数の実装を自動的に作成することができます。 |
565 | 739 | @~ |
566 | 740 |
@@ -569,13 +743,9 @@ command have been created to automatically implements the | ||
569 | 743 | @~english |
570 | 744 | The following code is a rewrite of ComplexTest using those command: |
571 | 745 | @~japanese |
572 | -以下のコードはそれらのコマンドが使うようにComplexTestを書換えたものです。 | |
746 | +以下のコードはそれらのコマンドが使うように testComplex.c を書換えたものです。 | |
573 | 747 | @~ |
574 | 748 | |
575 | -@code | |
576 | -#include <ccunit/CCUnitAssert.h> | |
577 | -@endcode | |
578 | - | |
579 | 749 | @~english |
580 | 750 | First, you declare the fixture, passing the test fixture |
581 | 751 | name to the javaDoc style comment, which consist of a |
@@ -588,6 +758,8 @@ javaDoc | ||
588 | 758 | @~ |
589 | 759 | |
590 | 760 | @code |
761 | +#include <ccunit/CCUnitAssert.h> | |
762 | + | |
591 | 763 | //** test case: complex number test *\/ |
592 | 764 | @endcode |
593 | 765 |
@@ -600,7 +772,6 @@ name by the <code>-f</code> option of the | ||
600 | 772 | Then, you define each test case of the fixture with prefix |
601 | 773 | <code>test</code>, <code>setUp</code>, |
602 | 774 | <code>tearDown</code>: |
603 | - | |
604 | 775 | @~japanese |
605 | 776 | @link CCUnitTestSuite TestSuite @endlink |
606 | 777 | を作成する関数は <code>ccunit_suite</code> です、 |
@@ -670,6 +841,12 @@ Finally, you end the fixture declaration: | ||
670 | 841 | //** end test case *\/ |
671 | 842 | @endcode |
672 | 843 | |
844 | +@english | |
845 | +@japanese | |
846 | +ひとつのファイルの中に複数のフィクスチャを定義することもできます。 | |
847 | +その場合は、フィクスチャの終わりの宣言の後に続けてフィクスチャを定義してください。 | |
848 | +@endif | |
849 | + | |
673 | 850 | @~english |
674 | 851 | To generate creating suite function code, run |
675 | 852 | <code>ccunit_makeSuite</code> tool. |
@@ -757,6 +934,24 @@ $ | ||
757 | 934 | @endcode |
758 | 935 | |
759 | 936 | @english |
937 | +Fixtures can be packaged into test suite. | |
938 | +You declare the suite before fixtures. | |
939 | +@japanese | |
940 | +なお、いくつかのフィクスチャをテストスーツにまとめることもできます。 | |
941 | +そのためには、フィクスチャの定義の前にテストスーツを宣言します。 | |
942 | +@endif | |
943 | + | |
944 | +@code | |
945 | +//** test suite: complex number test suite *\/ | |
946 | +//** test case: complex number equality test *\/ | |
947 | +... | |
948 | +//** test case: complex number compute test *\/ | |
949 | +... | |
950 | +@endcode | |
951 | + | |
952 | +@copydetails CCUnitMakeSuite | |
953 | + | |
954 | +@english | |
760 | 955 | @section post_build_check Post-build check |
761 | 956 | @japanese |
762 | 957 | @section post_build_check ビルド後のチェック |
@@ -767,8 +962,7 @@ Now that we have our unit tests running, how about | ||
767 | 962 | integrating unit testing to our build process ? |
768 | 963 | @~japanese |
769 | 964 | さあユニットテストを実行する準備ができました。 |
770 | -ではビルドプロセスにユニットテストを統合するにはどうしたらい | |
771 | -いでしょう。 | |
965 | +ではビルドプロセスにユニットテストを統合するにはどうしたらいいでしょう。 | |
772 | 966 | @~ |
773 | 967 | |
774 | 968 | @~english |
@@ -776,7 +970,7 @@ To do that, the application must returns a value different than 0 to indicate th | ||
776 | 970 | there was an error. |
777 | 971 | @~japanese |
778 | 972 | そうするには、アプリケーションは、エラーが発生したことを示す |
779 | -0以外の値を返さなければなりません。 | |
973 | +0 以外の値を返さなければなりません。 | |
780 | 974 | @~ |
781 | 975 | |
782 | 976 | @~english |
@@ -796,13 +990,15 @@ Updating our main programm, we obtains: | ||
796 | 990 | @code |
797 | 991 | #include <ccunit/CCUnitTestRunner.h> |
798 | 992 | |
993 | +extern CCUnitTestSuite* complex_suite(const char* name); | |
994 | + | |
799 | 995 | int main (int argc, char** argv) |
800 | 996 | { |
801 | 997 | CCUnitTestRunner* runner; |
802 | 998 | CCUnitTestSuite* suite; |
803 | 999 | int wasSucessful; |
804 | 1000 | runner = ccunit_newTestRunner (stdout); |
805 | - suite = ccunit_suite (); | |
1001 | + suite = complex_suite ("complex test suite"); | |
806 | 1002 | wasSucessful = ccunit_runTestRunner (runner, suite); |
807 | 1003 | return wasSucessful; |
808 | 1004 | } |
@@ -810,10 +1006,56 @@ int main (int argc, char** argv) | ||
810 | 1006 | |
811 | 1007 | @~english |
812 | 1008 | Now, you need to run your application after compilation. |
813 | -The sample program made in the above is in the examples/complex directory. | |
814 | 1009 | @~japanese |
815 | 1010 | それではアプリケーションをコンパイルした後に実行してみましょう。 |
816 | -以上で作成したサンプルプログラムは examples/complex ディレクトリにあります。 | |
817 | 1011 | @~ |
818 | 1012 | |
1013 | +@code | |
1014 | +$ gcc -I. -o runTest runTest.c testComplex.c suiteComplex.c complex.c -lccunit | |
1015 | +$ ./runTest | |
1016 | +... | |
1017 | +Time: 0.000032 sec | |
1018 | + | |
1019 | +OK (3 tests) | |
1020 | +@endcode | |
1021 | + | |
1022 | +@code | |
1023 | +$ ccunit_makeSuite -f complex_suite -o suiteComplex.c testComplex.c testComplexMulDiv.c | |
1024 | +$ gcc -I. -o runTest runTest.c testComplex.c testComplexMulDiv.c suiteComplex.c complex.c -lccunit | |
1025 | +$ ./runTest | |
1026 | +..... | |
1027 | +Time: 0.000045 sec | |
1028 | + | |
1029 | +OK (5 tests) | |
1030 | +@endcode | |
1031 | + | |
1032 | +@~english | |
1033 | +The sample program made in the above is in the @c examples/complex directory. | |
1034 | +@~japanese | |
1035 | +以上で作成したサンプルプログラムは @c examples/complex ディレクトリにあります。 | |
1036 | +@~ | |
1037 | + | |
1038 | +- complex - @~english some complex number library test cases | |
1039 | + @~japanese 複素数を計算するライブラリとそのテストケースのサンプルです。@~ | |
1040 | + - libcomplex.a - complex number library | |
1041 | + - complex.c | |
1042 | + - complex.h | |
1043 | + - runTestFixture @~japanese - もっとも単純なテストケースを実行するサンプルです。@~ | |
1044 | + - runTestFixture.c - main program | |
1045 | + - testComplex.c - test cases | |
1046 | + - runTestSuite @~japanese - テストスーツのサンプルです。@~ | |
1047 | + - runTestSuite.c - main program | |
1048 | + - testComplex.c - test cases | |
1049 | + - testComplexMulDiv.c - test cases | |
1050 | + - complexTestSuite.c - create test suite function | |
1051 | + - runTestRunner @~japanese - テストスーツをテストランナーで実行するサンプルです。@~ | |
1052 | + - runTestRunner.c - main program | |
1053 | + - testComplex.c - test cases | |
1054 | + - testComplexMulDiv.c - test cases | |
1055 | + - complexTestSuite.c - create test suite function | |
1056 | + - runTest @~japanese - テストスーツを自動生成するサンプルです。@~ | |
1057 | + - runTest.c - main program | |
1058 | + - testComplex.c - test cases | |
1059 | + - suiteComplex.c - auto generated test suite from testComplex.c | |
1060 | + | |
819 | 1061 | */ |
@@ -197,24 +197,105 @@ This library is released under the GNU | ||
197 | 197 | |
198 | 198 | */ |
199 | 199 | |
200 | -/** @defgroup WritingTestFixture Writing test fixture | |
200 | +/** | |
201 | + * @english | |
202 | + * @defgroup Construction | |
203 | + * CCUnit manages test suites, test fixtures, test cases. | |
204 | + * @japanese | |
205 | + * @defgroup Construction 構成 | |
206 | + * CCUnit はテストスーツ、テストフィクスチャ、テストケースを管理します。 | |
207 | + * @endif | |
208 | + * @dot | |
209 | +digraph CCUnitTestStructure { | |
210 | + node [ fontsize=9, fontname=Helvetica ]; | |
211 | + edge [ dir=back, fontsize=9 ]; | |
212 | + TestSuite -> TestSuite [ label="1..n" ]; | |
213 | + TestSuite -> TestFixture [ label="1..n" ]; | |
214 | + TestFixture -> setUp [ label="0..1" ]; | |
215 | + TestFixture -> TestCase [ label="1..n" ]; | |
216 | + TestFixture -> tearDown [ label="0..1" ]; | |
217 | +} | |
218 | + * @enddot | |
219 | + * | |
220 | + * @english | |
221 | + * Test cases are packaged into a fixture. Fixtures packaged | |
222 | + * into a suite. And suites are packaged into a suite. | |
223 | + * Fixtures can have @c setUp and @c tearDown functions | |
224 | + * which are called before and after running the test cases. | |
225 | + * @japanese | |
226 | + * いくつかのテストケースはテストフィクスチャにまとめられ、 | |
227 | + * またいくつかのテストフィクスチャはテストスーツにまとめられます。 | |
228 | + * そしてテストスーツもまたテストスーツにまとめられます。 | |
229 | + * テストスーツを実行すると、それにまとめられているテストスーツ、 | |
230 | + * テストフィクスチャが順番に実行されます。 | |
231 | + * テストフィクスチャには @c setUp と @c tearDown 関数を登録することができ、 | |
232 | + * テストフィクスチャが実行される際には、 | |
233 | + * それぞれのテストケースを実行する前と後に、 | |
234 | + * @c setUp と @c teaDown が自動的に実行されます。 | |
235 | + * @ endif | |
201 | 236 | */ |
202 | 237 | |
203 | -/** @defgroup Assertions Making assertions | |
238 | +/** | |
239 | + * @english | |
240 | + * @defgroup Assertions Making assertions | |
241 | + * @japanese | |
242 | + * @defgroup Assertions アサートの宣言 | |
243 | + * テストケースで使用するアサートマクロです。 | |
244 | + * @endif | |
204 | 245 | */ |
205 | 246 | |
206 | -/** @defgroup CreatingTestSuite Creating TestSuite | |
247 | +/** | |
248 | + * @english | |
249 | + * @defgroup WritingTestFixture Writing test fixture | |
250 | + * @japanese | |
251 | + * @defgroup WritingTestFixture テストフィクスチャを書く | |
252 | + * 一連のテストケースを、 | |
253 | + * 準備をする関数と後処理をする関数でまとめたものをフィクスチャと呼びます。 | |
254 | + * @endif | |
255 | + */ | |
256 | + | |
257 | +/** | |
258 | + * @english | |
259 | + * @defgroup CreatingTestSuite Creating TestSuite | |
260 | + * @japanese | |
261 | + * @defgroup CreatingTestSuite テストスーツの生成 | |
262 | + * いくつかのテストフィクスチャやテストスーツをまとめて、 | |
263 | + * ひとつのテストスーツにします。 | |
264 | + * @endif | |
207 | 265 | * @sa CCUnitMakeSuite |
208 | 266 | */ |
209 | 267 | |
210 | -/** @defgroup ExecutingTest Executing test | |
268 | +/** | |
269 | + * @english | |
270 | + * @defgroup ExecutingTest Executing test | |
271 | + * @japanese | |
272 | + * @defgroup ExecutingTest テストの実行 | |
273 | + * テストスーツを実行します。 | |
274 | + * @endif | |
211 | 275 | */ |
212 | 276 | |
213 | -/** @defgroup TrackingTestExecution Tracking test execution | |
277 | +/** | |
278 | + * @english | |
279 | + * @defgroup TrackingTestExecution Tracking test execution | |
280 | + * @japanese | |
281 | + * @defgroup TrackingTestExecution テストの実行の追跡 | |
282 | + * テストの実行を追跡します。 | |
283 | + * @endif | |
214 | 284 | */ |
215 | 285 | |
216 | -/** @defgroup BrowsingCollectedTestResult Browsing collected test result | |
286 | +/** | |
287 | + * @english | |
288 | + * @defgroup BrowsingCollectedTestResult Browsing collected test result | |
289 | + * @japanese | |
290 | + * @defgroup BrowsingCollectedTestResult テスト結果の参照 | |
291 | + * テスト結果を参照します。 | |
292 | + * @endif | |
217 | 293 | */ |
218 | 294 | |
219 | -/** @defgroup ModuleHierarchy Module hierarchy | |
295 | +/** | |
296 | + * @english | |
297 | + * @defgroup ModuleHierarchy Module hierarchy | |
298 | + * @japanese | |
299 | + * @defgroup ModuleHierarchy モジュール階層 | |
300 | + * @endif | |
220 | 301 | */ |