Développer et télécharger des logiciels Open Source

Montrer la différence incrémentale des versions sélectionnées de クックブック.

Catégorie (Tag) arbre

déposer de l'information

Catégorie (Tag)
root
nom de fichier
Cookbook
dernière mise à jour
2003-10-24 00:10
type
HTML
Editeur
TSUTSUMI Kikuo
description
CCUnitをつかってテストを実装するためのクックブック
langue
Anglais
Japonais
Traduire
--- /tmp/DOCMAN2xrOQI4	2025-02-15 00:19:02.619221249 +0900
+++ /tmp/DOCMAN2ykSsqs	2025-02-15 00:19:02.619221249 +0900
@@ -1,361 +1 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html>
-<head>
-<title>
-CCUnit - The Unit Testing Library for C language
-</title>
-<link href="doxygen.css" rel="stylesheet" type="text/css">
-</head>
-
-<body bgcolor="#ffffff">
-<table width="100%">
-  <tr>
-    <td width="40%" align="left" valign="center">
-      <a href="http://sourceforge.jp/projects/ccunit">
-      CCUnit project page
-      </a>
-    </td>
-    <td>
-      <!-- a href="FAQ">FAQ</a -->
-    </td>
-    <td width="40%" align="right" valign="center">
-      <a href="http://ccunit.sourceforge.jp">CCUnit home page</a>
-    </td>
-  </tr>
-</table>
-
-<hr>
-<!-- Generated by Doxygen 1.3.3 -->
-<div class="qindex"><a class="qindex" href="index.html">Main?Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data?Structures</a> | <a class="qindex" href="files.html">File?List</a> | <a class="qindex" href="functions.html">Data?Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related?Pages</a></div>
-<h1><a name="cookbook_ja">CCUnit Cookbook (ja)</a>
-</h1> CCUnit  <h2><a name="simple_test_case_ja"></a>
-</h2>
-CCUnit CCUnit   <p>
-<p>
-<ol>
-<li>
- </li>
-<li>
- <a class="el" href="group__Assertions.html#a2">CCUNIT_ASSERT(bool) </a>   </li>
-</ol>
-<p>
- <p>
-<div class="fragment"><pre><span class="keywordtype">void</span> 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 };
-  <a class="code" href="group__Assertions.html#a2">CCUNIT_ASSERT</a> (complex_equals (&c11_2, complex_add (&result, c10_1, c1_1)));
-}
-</pre></div><p>
-   <h2><a name="fixture_ja"></a>
-</h2>
- <p>
-    <p>
- <p>
-<ol>
-<li>
-<a class="el" href="group__CCUnitTestCase.html">CCUnitTestCase </a>    </li>
-<li>
- </li>
-<li>
-<code>setUp()</code>  </li>
-<li>
-<code>tearDown()</code> <code>setUp</code>  </li>
-<li>
-<a class="el" href="group__CCUnitTestFixture.html">CCUnitTestFixture </a>  </li>
-<li>
- </li>
-</ol>
-<p>
- <p>
-<div class="fragment"><pre><span class="comment">/** TEST CASE:  */</span>
-
-<span class="preprocessor">#include "complex.h"</span>
-
-<span class="keyword">static</span> complex_t* s10_1;
-<span class="keyword">static</span> complex_t* s1_1;
-<span class="keyword">static</span> complex_t* s11_2;
-
-<span class="keywordtype">void</span> setUp_ComplexTest ()
-{
-  s10_1 = complex_new (10, 1);
-  s1_1 = complex_new (1, 1);
-  s11_2 = complex_new (11, 2);
-}
-
-<span class="keywordtype">void</span> tearDown_ComplexTest ()
-{
-  complex_delete (s10_1);
-  complex_delete (s1_1);
-  complex_delete (s11_2);
-}
-
-...
-
-  <a class="code" href="structCCUnitTestFixture.html">CCUnitTestFixture</a>* fixture;
-  fixture = <a class="code" href="group__CCUnitTestFixture.html#a1">ccunit_newTestFixture</a> (<span class="stringliteral">"ComplexTest"</span>,
-                                   <a class="code" href="group__CCUnitTestCase.html#a5">CCUNIT_NEWTESTFUNC</a>(setUp_ComplexTest),
-                                   <a class="code" href="group__CCUnitTestCase.html#a5">CCUNIT_NEWTESTFUNC</a>(tearDown_ComplexTest));
-</pre></div><p>
- <h2><a name="test_case_ja"></a>
-</h2>
- <p>
- <p>
-<div class="fragment"><pre><span class="keywordtype">void</span> test_complex_equals ()
-{
-  <a class="code" href="group__Assertions.html#a18">CCUNIT_ASSERT_TEST_OBJ</a> (s10_1, complex_equals, s10_1, complex_to_string);
-  <a class="code" href="group__Assertions.html#a18">CCUNIT_ASSERT_TEST_OBJ</a> (s10_1, !complex_equals, s1_1, complex_to_string);
-}
-
-...
-
-  <a class="code" href="group__CCUnitTestFixture.html#a3">ccunit_addNewTestCase</a> (fixture,
-                         <span class="stringliteral">"test_complex_equals"</span>,
-                         <span class="stringliteral">""</span>,
-                         test_complex_equals);
-  <a class="code" href="group__CCUnitTestFixture.html#a3">ccunit_addNewTestCase</a> (fixture,
-                         <span class="stringliteral">"test_complex_add"</span>,
-                         <span class="stringliteral">""</span>,
-                         test_complex_add);
-</pre></div><p>
-  <p>
-<div class="fragment"><pre>  <a class="code" href="structCCUnitTestResult.html">CCUnitTestResult</a>* result;
-  result = <a class="code" href="group__CCUnitTestFixture.html#a4">ccunit_runTestFixture</a> (fixture);
-</pre></div><p>
-     <a class="el" href="group__ExecutingTest.html">TestRunner </a> () <p>
- <h2><a name="suite_ja"></a>
-</h2>
- <p>
-CCUnit  TestCases  <a class="el" href="group__CCUnitTestSuite.html">TestSuite </a> <p>
- <p>
-<div class="fragment"><pre><a class="code" href="structCCUnitTestSuite.html">CCUnitTestSuite</a>* suite;
-<a class="code" href="structCCUnitTestFixture.html">CCUnitTestFixture</a>* fixture;
-<a class="code" href="structCCUnitTestResult.html">CCUnitTestResult</a>* result;
-suite = <a class="code" href="group__CCUnitTestSuite.html#a3">ccunit_newTestSuite</a> (<span class="stringliteral">""</span>);
-fixture = <a class="code" href="group__CCUnitTestFixture.html#a1">ccunit_newTestFixture</a> (<span class="stringliteral">""</span>,
-                                 <a class="code" href="group__CCUnitTestCase.html#a5">CCUNIT_NEWTESTFUNC</a>(setUp_complex_test),
-                                 <a class="code" href="group__CCUnitTestCase.html#a5">CCUNIT_NEWTESTFUNC</a>(tearDown_complex_test));
-<a class="code" href="group__CCUnitTestFixture.html#a3">ccunit_addNewTestCase</a> (fixture, <span class="stringliteral">"test_complex_equals"</span>, <span class="stringliteral">""</span>,
-                       test_complex_equals);
-<a class="code" href="group__CCUnitTestFixture.html#a3">ccunit_addNewTestCase</a> (fixture, <span class="stringliteral">"test_complex_add"</span>, <span class="stringliteral">""</span>,
-                       test_complex_add);
-<a class="code" href="group__CCUnitTestFixture.html#a3">ccunit_addNewTestCase</a> (fixture, <span class="stringliteral">"test_complex_sub"</span>, <span class="stringliteral">""</span>,
-                       test_complex_sub);
-<a class="code" href="group__CCUnitTestSuite.html#a8">ccunit_addTestFixture</a> (suite, fixtuer);
-result = <a class="code" href="group__CCUnitTestSuite.html#a9">ccunit_runTestSuite</a> (suite, NULL);
-</pre></div><p>
-<a class="el" href="group__CCUnitTestSuite.html">TestSuites </a>  <a class="el" href="group__CCUnitTestFixture.html">TestFixtures </a> <p>
- <a class="el" href="group__CCUnitTest.html">Test </a>  <a class="el" href="group__CCUnitTestSuite.html">TestSuite </a>   <a class="el" href="group__CCUnitTestSuite.html">TestSuite </a> <p>
-<div class="fragment"><pre><a class="code" href="structCCUnitTestSuite.html">CCUnitTestSuite</a>* suite;
-<a class="code" href="structCCUnitTestResult.html">CCUnitTestResult</a>* result;
-suite = <a class="code" href="group__CCUnitTestSuite.html#a3">ccunit_newTestSuite</a> (<span class="stringliteral">"suite"</span>);
-<a class="code" href="group__CCUnitTestSuite.html#a7">ccunit_addTestSuite</a> (suite, complex_add_sub_suite ()); <span class="comment">/*  */</span>
-<a class="code" href="group__CCUnitTestSuite.html#a7">ccunit_addTestSuite</a> (suite, complex_mul_div_suite ()); <span class="comment">/*  */</span>
-result = <a class="code" href="group__CCUnitTestSuite.html#a9">ccunit_runTestSuite</a>(suite, NULL);
-</pre></div><h2><a name="test_runner_ja"></a>
-TestRunner</h2>
-How do you run your tests and collect their results?<p>
-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 <a class="el" href="group__CreatingTestSuite.html">ccunit_makeSuite </a> tool that generate a creating test suite code.<p>
-For example, to make a ComplexTest suite available to a <a class="el" href="group__CreatingTestSuite.html">ccunit_makeSuite </a>, excute the following tool to ComplexTest.c:<p>
-<div class="fragment"><pre>$ <a class="code" href="group__CCUnitMakeSuite.html#a1">ccunit_makeSuite</a> -f complex_suite -o suiteComplex.c ComplexTest.c
-</pre></div><p>
-<a name="test_runner_code"/></a> To use the TestRunner, include the header files for the tests in Main.c:<p>
-<div class="fragment"><pre><span class="preprocessor">#include <<a class="code" href="CCUnitTestRunner_8h.html">ccunit/CCUnitTestRunner.h</a>></span>
-<span class="preprocessor">#include <<a class="code" href="CCUnitTestSuite_8h.html">ccunit/CCUnitTestSuite.h</a>></span>
-</pre></div><p>
-And call to <a class="el" href="group__CCUnitTestRunner.html#a9">ccunit_runTestRunner (CCUnitTestRunner*, CCUnitTestSuite *) </a> in the <code><a class="el" href="group__CreatingTestSuite.html#a9">main()</a></code> function:<p>
-<div class="fragment"><pre><span class="keyword">extern</span> <a class="code" href="structCCUnitTestSuite.html">CCUnitTestSuite</a>* complex_suite(<span class="keyword">const</span> <span class="keywordtype">char</span>* name);
-
-<span class="keywordtype">int</span> <a class="code" href="group__CreatingTestSuite.html#a9">main</a>( <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
-{
-  <a class="code" href="structCCUnitTestRunner.html">CCUnitTestRunner</a>* runner;
-  <a class="code" href="structCCUnitTestSuite.html">CCUnitTestSuite</a>* suite;
-  runner = <a class="code" href="group__CCUnitTestRunner.html#a7">ccunit_newTestRunner</a> (stdout);
-  suite = complex_suite (<span class="stringliteral">"complex test suite"</span>);
-  <span class="keywordflow">return</span> <a class="code" href="group__CCUnitTestRunner.html#a9">ccunit_runTestRunner</a> (runner, suite);
-}
-</pre></div><p>
-The <a class="el" href="group__ExecutingTest.html">TestRunner </a> will run the tests. If all the tests pass, you'll get an informative message. If any fail, you'll get the following information:<p>
-<ul>
-<li>
-The name of the source file that contains the test </li>
-<li>
-The line number where the failure occurred </li>
-<li>
-The name of the test case that failed </li>
-<li>
-All of the text inside the call to <code>CCUNIT_ASSERT ()</code> which detected the failure </li>
-</ul>
-<h2><a name="helper_macros_ja"></a>
-Helper Tool</h2>
-As you might have noticed, implementing the fixture <code>suite ()</code> function is a repetitive and error prone task. A <a class="el" href="group__CreatingTestSuite.html">Creating TestSuite</a> set of functions and command have been created to automatically implements the <code>suite()</code> method.<p>
-The following code is a rewrite of ComplexTest using those command:<p>
-<div class="fragment"><pre><span class="preprocessor">#include <cppunit/CCUnitAssert.h></span>
-</pre></div><p>
-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 <code>*</code>'s:<p>
-<div class="fragment"><pre><span class="comment">/** test case: complex number test */</span>
-</pre></div><p>
-The suite created by the <code><a class="el" href="group__CreatingTestSuite.html#a8">ccunit_suite()</a></code> function is specified <code>-f</code> option of command <code>ccunit_makeSuite</code>. Then, you define each test case of the fixture with prefix <code>test</code>, <code>setUp</code>, <code>tearDown</code>:<p>
-<div class="fragment"><pre><span class="preprocessor">#include <complex.h></span>
-
-<span class="keyword">static</span> complex_t* s10_1;
-<span class="keyword">static</span> complex_t* s1_1;
-<span class="keyword">static</span> complex_t* s11_2;
-
-<span class="keywordtype">void</span> setUp_complex_test ()
-{
-  s10_1 = complex_new (10, 1);
-  s1_1 = complex_new (1, 1);
-  s11_2 = complex_new (11, 2);
-}
-
-<span class="keywordtype">void</span> tearDown_complex_test ()
-{
-  complex_delete (s10_1);
-  complex_delete (s1_1);
-  complex_delete (s11_2);
-}
-
-<span class="comment">/** test equals */</span>
-<span class="keywordtype">void</span> test_complex_equals ()
-{
-  <a class="code" href="group__Assertions.html#a18">CCUNIT_ASSERT_TEST_OBJ</a> (s10_1, complex_equals, s10_1, complex_to_string);
-  <a class="code" href="group__Assertions.html#a18">CCUNIT_ASSERT_TEST_OBJ</a> (s10_1, !complex_equals, s1_1, complex_to_string);
-}
-
-<span class="comment">/** test add */</span>
-<span class="keywordtype">void</span> 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 };
-  <a class="code" href="group__Assertions.html#a2">CCUNIT_ASSERT</a> (complex_equals (&c11_2, complex_add (&result, &c10_1, &c1_1)));
-}
-
-<span class="comment">/** test sub */</span>
-<span class="keywordtype">void</span> test_complex_sub ()
-{
-  complex_t c9_0 = { 9, 0 };
-  complex_t result;
-  <a class="code" href="group__Assertions.html#a18">CCUNIT_ASSERT_TEST_OBJ</a> (&c9_0, complex_equals,
-                          complex_sub (&result, s10_1, s1_1),
-                          complex_to_string);
-}
-</pre></div><p>
-Finally, you end the fixture declaration:<p>
-<div class="fragment"><pre><span class="comment">/** end test case */</span>
-</pre></div><p>
-To generate creating suite function code, run <code>ccunit_makeSuite</code> tool.<p>
-<div class="fragment"><pre>$ <a class="code" href="group__CCUnitMakeSuite.html#a1">ccunit_makeSuite</a> testComplex.c
-
-<span class="preprocessor">#include <<a class="code" href="CCUnitTestSuite_8h.html">ccunit/CCUnitTestSuite.h</a>></span>
-<span class="preprocessor">#include <<a class="code" href="CCUnitTestFixture_8h.html">ccunit/CCUnitTestFixture.h</a>></span>
-<span class="preprocessor">#include <<a class="code" href="CCUnitTestCase_8h.html">ccunit/CCUnitTestCase.h</a>></span>
-
-<span class="comment">/* test fixture: complex number test */</span>
-<span class="comment">/* setUp_complex_test */</span>
-<span class="keyword">extern</span> <span class="keywordtype">void</span> setUp_complex_test ();
-<span class="comment">/* tearDown_complex_test */</span>
-<span class="keyword">extern</span> <span class="keywordtype">void</span> tearDown_complex_test ();
-<span class="comment">/* test_complex_equals */</span>
-<span class="keyword">extern</span> <span class="keywordtype">void</span> test_complex_equals ();
-<span class="comment">/* test_complex_add */</span>
-<span class="keyword">extern</span> <span class="keywordtype">void</span> test_complex_add ();
-<span class="comment">/* test_complex_sub */</span>
-<span class="keyword">extern</span> <span class="keywordtype">void</span> test_complex_sub ();
-
-
-<span class="keyword">static</span> <a class="code" href="structCCUnitTestFixtureDfn.html">CCUnitTestFixtureDfn</a> fx_001 = {
-  { <a class="code" href="CCUnitTest_8h.html#a10a5">ccunitTypeFixture</a> },
-  <span class="stringliteral">"complex number test"</span>,
-  {
-    <span class="stringliteral">"setUp_complex_test"</span>,
-    <span class="stringliteral">"setUp_complex_test"</span>,
-    setUp_complex_test
-  },
-  {
-    <span class="stringliteral">"tearDown_complex_test"</span>,
-    <span class="stringliteral">"tearDown_complex_test"</span>,
-    tearDown_complex_test
-  },
-  {
-    {
-      <span class="stringliteral">"test_complex_equals"</span>,
-      <span class="stringliteral">"test equals"</span>,
-      test_complex_equals
-    },
-    {
-      <span class="stringliteral">"test_complex_add"</span>,
-      <span class="stringliteral">"test add"</span>,
-      test_complex_add
-    },
-    {
-      <span class="stringliteral">"test_complex_sub"</span>,
-      <span class="stringliteral">"test sub"</span>,
-      test_complex_sub
-    },
-    {
-      NULL, NULL, NULL
-    },
-  }
-};
-
-<span class="keyword">static</span> <a class="code" href="structCCUnitTestSuiteDfn.html">CCUnitTestSuiteDfn</a> suite_001 = {
-  { <a class="code" href="CCUnitTest_8h.html#a10a4">ccunitTypeSuite</a> },
-  <span class="stringliteral">""</span>,
-  {
-    &suite_002.test,
-    NULL,
-  },
-};
-
-<a class="code" href="structCCUnitTestSuite.html">CCUnitTestSuite</a>* <a class="code" href="group__CreatingTestSuite.html#a8">ccunit_suite</a> (<span class="keyword">const</span> <span class="keywordtype">char</span>* name)
-{
-  <span class="keywordflow">if</span> (!suite_001.<a class="code" href="structCCUnitTestSuiteDfn.html#o1">name</a>[0])
-    suite_001.<a class="code" href="structCCUnitTestSuiteDfn.html#o1">name</a> = name;
-  <span class="keywordflow">return</span> <a class="code" href="group__CCUnitTestSuite.html#a4">ccunit_newTestSuiteFromDfn</a> (&suite_001);
-}
-$
-</pre></div><h2><a name="post_build_check_ja"></a>
-Post-build check</h2>
-Now that we have our unit tests running, how about integrating unit testing to our build process ?<p>
-To do that, the application must returns a value different than 0 to indicate that there was an error.<p>
-<a class="el" href="group__CCUnitTestRunner.html#a9">ccunit_runTestRunner() </a> returns a integer indicating if the run was successful.<p>
-Updating our main programm, we obtains: <div class="fragment"><pre><span class="preprocessor">#include <<a class="code" href="CCUnitTestRunner_8h.html">ccunit/CCUnitTestRunner.h</a>></span>
-
-<span class="keywordtype">int</span> <a class="code" href="group__CreatingTestSuite.html#a9">main</a> (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)
-{
-  <a class="code" href="structCCUnitTestRunner.html">CCUnitTestRunner</a>* runner;
-  <a class="code" href="structCCUnitTestSuite.html">CCUnitTestSuite</a>* suite;
-  <span class="keywordtype">int</span> wasSucessful;
-  runner = <a class="code" href="group__CCUnitTestRunner.html#a7">ccunit_newTestRunner</a> (stdout);
-  suite = <a class="code" href="group__CreatingTestSuite.html#a8">ccunit_suite</a> ();
-  wasSucessful = <a class="code" href="group__CCUnitTestRunner.html#a9">ccunit_runTestRunner</a> (runner, suite);
-  <span class="keywordflow">return</span> wasSucessful;
-}
-</pre></div><p>
-Now, you need to run your application after compilation. <hr>
-<table width="100%">
-  <tr>
-    <td width="10%" align="left" valign="center">
-	<a href="http://sourceforge.jp/">
-	<img src="http://sourceforge.jp/sflogo.php?group_id=760"
-	 width="96" height="31" border="0" alt="SourceForge.jp"></a>
-    </td>
-    <td width="20%" align="left" valign="center">
-      hosts this site.
-    </td>
-    <td>
-    </td>
-    <td align="right" valign="center">
-      Send comments to:<br>
-      <a href="mailto:tsutsumi@users.sourceforge.jp">CCUnit Developer</a>
-    </td>
-  </tr>
-</table>
-
-</body>
-</html>
+<a href="http://ccunit.sourceforge.jp/jp/index.html>CCUnit japanese documentation</a>