OSDN Git Service

modify the explanation of the sample file.
[ccunit/ccunit.git] / doc / cookbook.dox
1 /* -*- Indented-Text -*- */
2 /* Copyright (C) 2003, 2010 TSUTSUMI Kikuo.
3    This file is part of the CCUnit Library.
4
5    The CCUnit Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public License
7    as published by the Free Software Foundation; either version 2.1 of
8    the License, or (at your option) any later version.
9
10    The CCUnit Library is distributed in the hope that it will be
11    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the CCUnit Library; see the file COPYING.LESSER.
17    If not, see <http://www.gnu.org/licenses/>
18 */
19 /* $Id$ */
20 /**
21 @english
22 @page cookbook CCUnit Cookbook
23 @japanese
24 @page cookbook CCUnit ¥¯¥Ã¥¯¥Ö¥Ã¥¯
25 @endif
26
27 @~english
28 Here is a short cookbook to help you get started.
29 @~japanese
30 ¤³¤ì¤Ï CCUnit ¤ò»È¤¤»Ï¤á¤ë¤Ë¤¢¤¿¤Ã¤Æ¡¢
31 Íý²ò¤Î½õ¤±¤È¤Ê¤ë¤è¤¦¤Êû¤¤¥¯¥Ã¥¯¥Ö¥Ã¥¯¤Ç¤¹¡£
32 @~
33 @english
34 [see also <a href="../ja/cookbook.html">Japanese</a> documents]
35 @japanese
36 [see also <a href="../../cookbook.html">English</a> documents]
37 @endif
38
39 @english
40 @section simple_test_case Simple Test Case
41 @japanese
42 @section simple_test_case ¥·¥ó¥×¥ë¤Ê¥Æ¥¹¥È¥±¡¼¥¹
43 @endif
44
45 @~english
46 Tests in <b>CCUnit</b> can be run automatically.  They are
47 easy to set up and once you have written them, they are
48 always there to help you keep confidence in the quality of
49 your code.
50 @~japanese
51 CCUnit¤ò»È¤Ã¤¿¥Æ¥¹¥È¤Ï¼«Æ°Åª¤Ë¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
52 CCUnit ¤Î¥Æ¥¹¥È¤Ï´Êñ¤Ë¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¤³¤È¤¬¤Ç¤­¡¢
53 °ìÅ٥ƥ¹¥È¤ò½ñ¤¤¤Æ¤·¤Þ¤¨¤Ð¡¢
54 ¤¤¤Ä¤Ç¤â¥×¥í¥°¥é¥à¤ÎÉʼÁ¤ò¿®Íê¤Ç¤­¤ë¤â¤Î¤ËÊݤĤ³¤È¤¬¤Ç¤­¤ë¤Ç¤·¤ç¤¦¡£
55 @~
56
57 @~english
58 To make a simple test, here is what you do:
59 @~japanese
60 ñ½ã¤Ê¥Æ¥¹¥È¤òºî¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
61 @~
62
63 <ol>
64 <li> @~english Create a test function
65      @~japanese ¥Æ¥¹¥È´Ø¿ô¤òºî¤ë
66      @~
67 </li>
68 <li> @~english When you want to check a value, call
69      @~japanese Ãͤò¥Á¥§¥Ã¥¯¤·¤¿¤¤¾ì¹ç¤Ï¡¢@~
70      @link CCUNIT_ASSERT() CCUNIT_ASSERT(bool) @endlink
71      @~english and pass a bool that is true if the test succeeds
72      @~japanese ¤ò¸Æ¤Ó½Ð¤·¤Æ¡¢
73      ¤â¤·¥Æ¥¹¥È¤¬À®¸ù¤¹¤ë¤Ê¤é¿¿¤òÊÖ¤¹¤è¤¦¤Ê¿¿µ¶ÃͤòÅϤ·¤Þ¤¹@~
74
75      @~english ASSERT macro is listed in others as well in
76      @link Assertions Making assertions @endlink.
77      @~japanese ASSERT ´Ø·¸¤Î¥Þ¥¯¥í¤Ï¾¤Ë¤â
78      @link Assertions Making assertions @endlink
79      ¤Ë¥ê¥¹¥È¤·¤Æ¤¢¤ê¤Þ¤¹¡£
80      @~
81 </li>
82 </ol>
83
84 @~english
85 For example, to test that the sum of two complex number
86 which is the sum of the values of two complex numbers,
87 write:
88 @~japanese
89 Î㤨¤Ð¡¢Æó¤Ä¤ÎÊ£ÁÇ¿ô¤Î¹ç·×¤¬¡¢
90 Æó¤Ä¤ÎÊ£ÁÇ¿ô¤ÎÃͤò²Ã»»¤·¤¿ÃͤÈƱ¤¸¤Ç¤¢¤ë¤³¤È¤ò¥Æ¥¹¥È¤¹¤ë¤È¤·¤Þ¤¹¡£
91 ¡Ê¤³¤³¤Ç»ÈÍѤ¹¤ë¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ï
92 examples/complex ¥Ç¥£¥ì¥¯¥È¥ê¤Ë¤¢¤ê¤Þ¤¹¡£¡Ë
93 @~
94
95 @~english
96 This sample program is in the examples/complex directory.
97 @~
98
99 @code
100 void test_complex_add ()
101 {
102   complex_t c10_1 = { 10.0, 1.0 };
103   complex_t c1_1 = { 1.0, 1.0 };
104   complex_t result;
105   complex_t c11_2 = { 11.0, 2.0 };
106   CCUNIT_ASSERT (complex_equals (&c11_2, complex_add (&result, &c10_1, &c1_1)));
107 }
108 @endcode
109
110 @~english
111 That was a very simple test. Ordinarily, you'll have many
112 little test cases that you'll want to run on the same set of
113 objects. To do this, use a fixture.
114 @~japanese
115 ¤³¤ì¤ÏÂçÊÑñ½ã¤Ê¥Æ¥¹¥È¤Ç¤¹¡£
116 Ä̾Ʊ¤¸¥Ç¡¼¥¿¤Î¥»¥Ã¥È¤ÇÁö¤é¤»¤ë¤¿¤á¤Ë¡¢
117 ¤¿¤¯¤µ¤ó¤Î¾®¤µ¤Ê¥Æ¥¹¥È¥±¡¼¥¹¤òºî¤é¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤Ç¤·¤ç¤¦¡£
118 ¤½¤³¤Ç¥Õ¥£¥¯¥¹¥Á¥ã¡ÊÈ÷Éʡˤò»È¤¤¤Þ¤¹¡£
119 @~
120
121 @english
122 @section fixture Fixture
123 @japanese
124 @section fixture ¥Õ¥£¥¯¥¹¥Á¥ã
125 @endif
126
127 @~english
128 What if you have two or more tests that operate on the same
129 similar set of objects?
130 @~japanese
131 ¤â¤·Æó¤Ä°Ê¾å¤Î¥Æ¥¹¥È¤¬¤¢¤ë¤Ê¤é¡¢
132 Ʊ¤¸Îà»÷¤Î¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤ò»È¤¦¤Î¤Ç¤Ï¤Ê¤¤¤Ç¤·¤ç¤¦¤«¡£
133 @~
134
135 @dot
136 digraph TestCase {
137   node [ fontsize=9, fontname=Helvetica ]
138   edge [ fontsize=9, dir=back, arrowtail=vee ]
139   gv [ label="Data\n(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
150 @~english
151 Tests need to run against the background of a known set of
152 objects. This set of objects is called a test fixture. When
153 you are writing tests you will often find that you spend
154 more time writing the code to set up the fixture than you do
155 in actually testing values.
156 @~japanese
157 ¥Æ¥¹¥È¤ÏÃæ¿È¤Î¤ï¤«¤Ã¤Æ¤¤¤ë¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤òÁ°Äó¤È¤·¤Æ¼Â¹Ô¤µ¤ì¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
158 ¤½¤Î¤è¤¦¤Ê¥Ç¡¼¥¿¤Î½¸¤Þ¤ê¤ò¥Õ¥£¥¯¥¹¥Á¥ã¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹¡£
159 ¥Æ¥¹¥È¤ò½ñ¤¤¤Æ¤¤¤ë¤È¡¢
160 ¼ÂºÝ¤Ë¥Æ¥¹¥È¤¹¤ëÃͤò¥Õ¥£¥¯¥¹¥Á¥ã¤Ë¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¥³¡¼¥É¤ò½ñ¤¯Êý¤Ë¡¢
161 ¤è¤ê»þ´Ö¤ò¤«¤±¤Æ¤¤¤ë¤³¤È¤Ëµ¤¤Å¤¯¤³¤È¤¬¤è¤¯¤¢¤ê¤Þ¤¹¡£
162 @~
163
164 @~english
165 Often, you will be able to use the same fixture for several
166 different tests. Each case will send slightly different
167 messages or parameters to the fixture and will check for
168 different results.
169 @~japanese
170 ¿¤¯¤Î¾ì¹ç¡¢¤¤¤¯¤Ä¤«¤Î°Û¤Ê¤Ã¤¿¥Æ¥¹¥È¤Î¤¿¤á¤ËƱ¤¸¥Õ¥£¥¯¥¹¥Á¥ã¤ò»È¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
171 ¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ï¾¯¤·°Û¤Ê¤Ã¤¿Ãͤǥե£¥¯¥¹¥Á¥ã¤ò½é´ü²½¤·¡¢
172 °Û¤Ê¤ë·ë²Ì¤òÄ´¤Ù¤ë¤³¤È¤Ë¤Ê¤ë¤Ç¤·¤ç¤¦¡£
173 ¤½¤·¤Æ¥Æ¥¹¥È¤¬½ª¤ï¤Ã¤¿¤é¡¢
174 ¥Õ¥£¥¯¥¹¥Á¥ã¤ò¸å»ÏËö¤¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
175 ¤³¤ì¤é¤Î¥Õ¥£¥¯¥¹¥Á¥ã¤È¡¢
176 ¥Õ¥£¥¯¥¹¥Á¥ã¤ò½é´ü²½¡¦ÍøÍÑ¡¦¸å»ÏËö¤¹¤ë¥Æ¥¹¥È´Ø¿ô¤Î½¸¤Þ¤ê¤ò¡¢
177 ¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹
178 (¤â¤·¤¯¤Ïά¤·¤Æñ¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤È¸Æ¤Ó¤Þ¤¹¡£)
179 @~
180
181 @dot
182 digraph TestFixture {
183   node [ fontsize=9, fontname=Helvetica ]
184   edge [ fontsize=9, dir=back, arrowtail=vee ]
185   rankdir=TB;
186   subgraph cluster_fixture {
187     fontsize=9;
188     label="Test Fixture";
189     gv [ label="Fixture\n(Data)", shape=box ]
190     { rank=same;
191       ssu [ label="setup_setUp" ];
192       su [ label="setUp" ];
193       tc [ label="TestCases" ];
194       td [ label="tearDown" ];
195       std [ label="setup_tearDown" ];
196     }
197     gv -> ssu [ label="initialize" ];
198     gv -> su [ label="initialize\neach test" ];
199     gv -> tc [ label="access" ];
200     gv -> td [ label="clean-up\neach test" ];
201     gv -> std [ label="clean-up" ];
202   }
203 }
204 @enddot
205
206 @~english
207 When you have a common fixture, here is what you do:
208 @~japanese
209 ¤â¤·³Æ¥Æ¥¹¥È¤Ë¶¦Ä̤¹¤ë¥Ç¡¼¥¿¤¬¤¢¤ì¤Ð¡¢
210 °Ê²¼¤Î¤è¤¦¤Ë¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤òºî¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
211 @~
212
213 <ol>
214 <li>@~english
215     Create a @link CCUnitTestCase TestCase @endlink object
216     @~japanese
217     @link CCUnitTestCase TestCase @endlink ¹½Â¤ÂΤ˥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹
218     ¡Ê°Ê¹ß¡¢¹½Â¤ÂΤ˳ä¤êÅö¤Æ¤¿¥á¥â¥ê¤ò¡¢¥ª¥Ö¥¸¥§¥¯¥È¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹¡Ë
219     @~
220 </li>
221 <li>@~english
222     Add an global variable for each part of the fixture
223     @~japanese
224     ¥Õ¥£¥¯¥¹¥Á¥ã¤Î¥¹¥³¡¼¥×Æâ¤ËÂç°èÊÑ¿ô¤òÄêµÁ¤·¤Þ¤¹
225     @~
226 </li>
227 <li>@~english
228     Write @c setup_setUp(), @c setUp() function to initialize the valiables
229     @~japanese
230     ÊÑ¿ô¤ò½é´ü²½¤¹¤ë @c setup_setUp(), @c setUp() ´Ø¿ô¤ò½ñ¤­¤Þ¤¹
231     @~
232 </li>
233 <li>@english
234     Write @c tearDown(), @c setup_tearDown() to release any permanent
235     resources you allocated in @c setUp
236     @japanese
237     @c setup_setUp(), @c setUp() ¤Ç³ä¤êÅö¤Æ¤¿±Ê³Ū¥ê¥½¡¼¥¹¤ò²òÊü¤¹¤ë¤¿¤á¤Î
238     @c tearDown(), @c setup_tearDown() ´Ø¿ô¤ò½ñ¤­¤Þ¤¹
239     @endif
240 </li>
241 <li>@~english
242     Create a @link CCUnitTestFixture TestFixture @endlink object
243     @~japanese
244     @link CCUnitTestFixture TestFixture @endlink
245     ¹½Â¤ÂΤ˥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹
246     @~
247 </li>
248 <li>@~english
249     Add @link CCUnitTestCase TestCase @endlink objects to fixture object
250     @~japanese
251     @link CCUnitTestCase TestCase @endlink ¥ª¥Ö¥¸¥§¥¯¥È¤ò
252     @link CCUnitTestFixture TestFixture @endlink
253     ¥ª¥Ö¥¸¥§¥¯¥È¤ËÅÐÏ¿¤·¤Þ¤¹¡£
254     @~
255 </li>
256 </ol>
257
258 @~english
259 For example, to write several test cases, first create a
260 fixture:
261 @~japanese
262 Î㤨¤Ð¡¢¤¤¤¯¤Ä¤«¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¯¾ì¹ç¡¢
263 ºÇ½é¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤òºîÀ®¤·¤Þ¤¹¡£
264 @~
265
266 @code
267 //** TEST CASE: complex number test *\/
268
269 #include "complex.h"
270
271 static complex_t* s10_1;
272 static complex_t* s1_1;
273 static complex_t* s11_2;
274 static complex_t* sc;
275
276 void setup_setUp_complex_test ()
277 {
278   sc = complex_new (1, 1);
279 }
280
281 void setup_tearDown_complex_test ()
282 {
283   complex_delete (sc);
284 }
285
286 void setUp_complex_test ()
287 {
288   s10_1 = complex_new (10, 1);
289   s1_1 = complex_new (1, 1);
290   s11_2 = complex_new (11, 2);
291   complex_add (&sc, &sc, &c1_1);
292 }
293
294 void tearDown_complex_test ()
295 {
296   complex_delete (s10_1);
297   complex_delete (s1_1);
298   complex_delete (s11_2);
299 }
300
301 int main ()
302 {
303   CCUnitTestFixture* fixture;
304   fixture = ccunit_newTestFixture ("complex test",
305                                    CCUNIT_NEWTESTFUNC(setUp_complex_test),
306                                    CCUNIT_NEWTESTFUNC(tearDown_complex_test));
307   ccunit_setTestFixturSetup (fixture,
308                              CCUNIT_NEWTESTFUNCTION(setup_setUp_complex_test),
309                              CCUNIT_NEWTESTFUNCTION(setup_tearDown_complex_test));
310 @endcode
311
312 @~english
313 Once you have the Fixture in place, you can write as complex
314 Test Cases as you'd like.
315 @~japanese
316 °ìÅÙ·è¤Þ¤Ã¤¿¤È¤³¤í¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤ò½ñ¤¤¤Æ¤·¤Þ¤¨¤Ð¡¢
317 ¤¢¤Ê¤¿¤¬¹¥¤­¤Ê¤è¤¦¤ËÊ£ÁÇ¿ô¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¯¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
318 @~
319
320 @english
321 @section test_case Test Case
322 @japanese
323 @section test_case ¥Æ¥¹¥È¥±¡¼¥¹
324 @endif
325
326 @~english
327 How do you write and invoke an individual test case when you
328 have a Fixture?
329 @~japanese
330 ¥Õ¥£¥¯¥¹¥Á¥ã¤ò°ì¤Ä½ñ¤¤¤¿¤È¤·¤Æ¡¢
331 ¤É¤¦¤ä¤Ã¤Æ¸Ä¡¹¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¤¤Æ¼Â¹Ô¤¹¤ì¤ÐÎɤ¤¤Ç¤·¤ç¤¦¤«¡£
332 @~
333
334 @~english
335 For example, to test the equality of two complex number,
336 write:
337 @~japanese
338 Î㤨¤Ð¡¢Æó¤Ä¤ÎÊ£ÁÇ¿ô¤¬Åù¤·¤¤¡Ê¤Þ¤¿¤ÏÅù¤·¤¯¤Ê¤¤¡Ë¤³¤È¤ò¥Æ¥¹¥È¤¹¤ë¤Ë¤Ï¡¢
339 ¼¡¤Î¤è¤¦¤Ë½ñ¤­¤Þ¤¹¡£
340 @~
341
342 @code
343 void test_complex_equals ()
344 {
345   CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s10_1, complex_to_string);
346   CCUNIT_ASSERT_TEST_OBJ (s10_1, !complex_equals, s1_1, complex_to_string);
347 }
348
349 ...
350
351 int main ()
352 {
353   ...
354
355   ccunit_addNewTestCase (fixture,
356                          "test_complex_equals",
357                          "complex equals test",
358                          test_complex_equals);
359 @endcode
360
361 @~english
362 One may create and run objects for each test case like this:
363 @~japanese
364 ¤½¤·¤Æ¼¡¤Î¤è¤¦¤Ë¡¢
365 ¥Õ¥£¥¯¥¹¥Á¥ã¤òºîÀ®¤·¤Æ¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò¼Â¹Ô¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
366 @~
367
368 @code
369   CCUnitTestResult* result;
370   result = ccunit_runTestFixture (fixture);
371   return 0;
372 }
373 @endcode
374
375 @english
376 Calling sequence of test cases in a fixture is following:
377 @japanese
378 ¤Ò¤È¤Ä¤Î¥Õ¥£¥¯¥¹¥Á¥ã¤ÎÃæ¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Î¼Â¹Ô¥·¡¼¥±¥ó¥¹¤Ï¼¡¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
379 @endif
380
381 @dot
382 digraph FixtureCallingSequence {
383   node [ fontsize=9, fontname=Helvetica ]
384   edge [ fontsize=9 ]
385   rankdir = LR;
386   { rank=same;
387     setUp;
388     setUp2 [ label="setUp" ];
389   }
390   setup_setUp -> setUp [ weight=8 ];
391   setup_setUp -> setUp2 [ style=invis ];
392   setUp -> "TestCase 1" [ weight=8 ];
393   "TestCase 1" -> tearDown [ weight=8 ];
394   setUp2 -> "TestCase n" [ weight=8 ];
395   tearDown2 [ label="tearDown" ];
396   "TestCase n" -> tearDown2;
397   tearDown2 -> setup_tearDown;
398   tearDown -> setUp2;
399 }
400 @enddot
401
402 @english
403 The sample code made in the above is in the directory <code>examples/complex</code>,
404 the files <code>testComplex.c</code> and <code>runTestFixture.c</code>.
405 @japanese
406 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢<code>examples/complex</code> ¥Ç¥£¥ì¥¯¥È¥ê¤Î
407 <code>testComplex.c, runTestFixture.c</code> ¤Ë¤¢¤ê¤Þ¤¹¡£
408
409 ¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
410 @endif
411
412 @code
413 $ gcc -I. -o runTestFixture runTestFixture.c testComplex.c complex.c -lccunit
414 $ ./runTestFixture
415 @endcode
416
417 @~english
418 When the test fixture is run, that specific test functions
419 will be run.  This is not a useful thing to do, however, as
420 no diagnostics will be displayed.  One will normally use a
421 @link ExecutingTest TestRunner @endlink (see below) to
422 display the results.
423 @~japanese
424 ¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤¬¼Â¹Ô¤µ¤ì¤ë¤È¡¢
425 »ØÄꤷ¤¿¥Æ¥¹¥È´Ø¿ô¤¬¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£
426 ¤³¤ì¤Ï¤Þ¤À¤¢¤Þ¤êÊØÍø¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡¢
427 ¤Ê¤¼¤Ê¤é¡¢¿ÇÃǤ¬É½¼¨¤µ¤ì¤Ê¤¤¤«¤é¤Ç¤¹¡£
428 Ä̾ï¤Ï @link ExecutingTest TestRunner @endlink
429 (@ref test_runner ¸å½Ò)
430 ¤Ç·ë²Ì¤òɽ¼¨¤·¤Þ¤¹¡£
431 @~
432
433 @~english
434 Once you have several tests, organize them into a suite.
435 @~japanese
436 °ìÅÙ¤¤¤¯¤Ä¤«¤Î¥Æ¥¹¥È¤òºî¤Ã¤¿¤é¡¢
437 ¤½¤ì¤é¤ò¥¹¡¼¥Ä¤ËÀ°Íý¤·¤Þ¤¹¡£
438 @~
439
440 @english
441 @section suite Suite
442 @japanese
443 @section suite ¥¹¡¼¥Ä
444 @endif
445
446 @dot
447 digraph TestStructure {
448   node [ fontsize=9, fontname=Helvetica ];
449   edge [ dir=back, fontsize=9 ];
450   TestSuite -> TestSuite [ label="1..n" ];
451   TestFixture;
452   TestSuite -> TestFixture [ label="1..n" ];
453   TestFixture -> setup_setUp [ label="0..1" ];
454   TestFixture -> setUp [ label="0..1" ];
455   TestCase;
456   TestFixture -> TestCase [ label="1..n" ];
457   TestFixture -> tearDown [ label="0..1" ];
458   TestFixture -> setup_tearDown [ label="0..1" ];
459 }
460 @enddot
461
462 @~english
463 How do you set up your tests so that you can run them all at once?
464 @~japanese
465 °ìÅ٤˥ƥ¹¥È¤ò¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë½àÈ÷¤¹¤ë¤Ë¤Ï¡¢
466 ¤É¤Î¤è¤¦¤Ë¤·¤¿¤é¤¤¤¤¤Ç¤·¤ç¤¦¤«¡©
467 @~
468
469 @~english
470 CCUnit provides a @link CCUnitTestSuite TestSuite @endlink
471 module that runs any number of TestCases together.
472 @~japanese
473 CCUnit ¤Ï¤¤¤¯¤Ä¤â¤Î @link CCUnitTestCase TestCases @endlink
474 ¤ò°ì½ï¤Ë¼Â¹Ô¤¹¤ë
475 @link CCUnitTestSuite TestSuite @endlink ¥â¥¸¥å¡¼¥ë¤òÄ󶡤·¤Þ¤¹¡£
476 @~
477
478 @~english
479 You saw, above, how to run test fixture.
480 @~japanese
481 ¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤ò¼Â¹Ô¤¹¤ëÊýË¡¤Ï¾å½Ò¤·¤Þ¤·¤¿¡£
482 @~
483
484 @~english
485 To create a suite of two or more tests, you do the following:
486 @~japanese
487 Æó¤Ä°Ê¾å¤Î¥Æ¥¹¥È¤ò´Þ¤à°ì¤Ä¤Î¥¹¡¼¥Ä¤òºî¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
488 @~
489
490 @code
491 int main ()
492 {
493   CCUnitTestSuite* suite;
494   CCUnitTestFixture* fixture;
495   CCUnitTestResult* result;
496   suite = ccunit_newTestSuite ("Complex test suite");
497   fixture = ccunit_newTestFixture ("Complex Tests",
498                                    CCUNIT_NEWTESTFUNC(setUp_complex_test),
499                                    CCUNIT_NEWTESTFUNC(tearDown_complex_test));
500   ccunit_addNewTestCase (fixture, "test_complex_equals", "complex equals test",
501                          test_complex_equals);
502   ccunit_addNewTestCase (fixture, "test_complex_add", "complex add test",
503                          test_complex_add);
504   ccunit_addNewTestCase (fixture, "test_complex_sub", "complex sub test",
505                          test_complex_sub);
506   ccunit_addTestFixture (suite, fixtuer);
507   result = ccunit_runTestSuite (suite, NULL);
508   return 0;
509 }
510 @endcode
511
512 @~english
513 @link CCUnitTestSuite TestSuites @endlink don't only have to
514 contain @link CCUnitTestFixture TestFixtures @endlink.  They
515 can contain any object that implements the @link CCUnitTest
516 Test @endlink interface.  For example, you can create a
517 @link CCUnitTestSuite TestSuite @endlink
518 (<code>complex_add_sub_suite ()</code>) in your code and I
519 can create one in mine
520 (<code>complex_mul_div_suite ()</code>), and we can run them together by
521 creating a @link CCUnitTestSuite TestSuite @endlink that
522 contains both:
523 @~japanese
524 @link CCUnitTestSuite TestSuites @endlink ¤Ï
525 @link CCUnitTestFixture TestFixtures @endlink
526 ¤ò´Þ¤à¤À¤±¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£
527 @link CCUnitTestSuite TestSuites @endlink ¼«¿È¤ò´Þ¤à¤³¤È¤â¤Ç¤­¤Þ¤¹¡£
528 <!--
529 ¤½¤ì¤é¤Ï @link CCUnitTest Test @endlink
530 ¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤¹¤ë¤É¤ó¤Ê¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤â´Þ¤á¤é¤ì¤Þ¤¹¡£
531 -->
532 Î㤨¤Ð¡¢¤¢¤Ê¤¿¤Ï¤¢¤Ê¤¿¤Î¥³¡¼¥É¤Ë @link CCUnitTestSuite TestSuite @endlink
533 (<code>complex_add_sub_suite ()</code>)
534 ¤òºî¤ë¤³¤È¤¬¤Ç¤­¡¢
535 ¤½¤·¤Æ»ä¤Ï»ä¤Î¥¹¡¼¥Ä
536 (<code>complex_mul_div_suite ()</code>)
537 ¤òºî¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¢
538 ¤½¤·¤Æ»äã¤ÏξÊý¤È¤â¤ò´Þ¤ó¤Ç¤¤¤ë @link CCUnitTestSuite TestSuite @endlink
539 ¤òºî¤Ã¤Æ°ì½ï¤Ë¤½¤ì¤¾¤ì¤Î¥¹¡¼¥Ä¤òÆ°¤«¤¹¤³¤È¤¬¤Ç¤­¤ë¤Î¤Ç¤¹¡£
540 @~
541
542 @code
543   CCUnitTestSuite* suite;
544   CCUnitTestResult* result;
545   suite = ccunit_newTestSuite ("Complex add/sub/mul/div test suite");
546   ccunit_addTestSuite (suite, complex_add_sub_suite ());
547   ccunit_addTestSuite (suite, complex_mul_div_suite ());
548   result = ccunit_runTestSuite(suite, NULL);
549 @endcode
550
551 @english
552 The sample code made in the above is in the directory <code>examples/complex</code>,
553 the files <code>testComplex.c</code>, <code>testComplexMulDiv.c</code>,
554 <code>complexTestSuite.c</code> and <code>runTestSuite.c</code>.
555 @japanese
556 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢<code>examples/complex</code> ¥Ç¥£¥ì¥¯¥È¥ê¤Î
557 <code>testComplex.c, testComplexMulDiv.c, complexTestSuite.c, runTestSuite.c</code>
558 ¤Ë¤¢¤ê¤Þ¤¹¡£
559
560 ¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
561 @endif
562
563 @code
564 $ gcc -I. -o runTestSuite runTestSuite.c testComplex.c testComplexMulDiv.c complexTestSuite.c complex.c -lccunit
565 $ ./runTestSuite
566 @endcode
567
568 @english
569 @section test_runner TestRunner
570 @japanese
571 @section test_runner ¥Æ¥¹¥È¥é¥ó¥Ê¡¼
572 @endif
573
574 @~english
575 How do you run your tests and collect their results?
576 The fixtures store result of own tests into
577 the @link CCUnitTestResult TestResult @endlink.
578 @~japanese
579 ¤É¤¦¤ä¤Ã¤Æ¥Æ¥¹¥È¤ò¼Â¹Ô¤·¡¢¤½¤Î·ë²Ì¤ò½¸¤á¤¿¤éÎɤ¤¤Ç¤·¤ç¤¦¤«¡£
580 ¥Õ¥£¥¯¥¹¥Á¥ã¤Ï¥Æ¥¹¥È¥±¡¼¥¹¤Î¼Â¹Ô·ë²Ì¤ò
581 @link CCUnitTestResult TestResult @endlink ¤Ë³ÊǼ¤·¤Þ¤¹¡£
582 @~
583
584 @dot
585 digraph TestResult {
586   node [ fontsize=9, fontname=Helvetica ]
587   { rank=same;
588     edge [ fontsize=9, fontname=Courier ]
589     TestFixture -> TestResult [ label="TestFailure", style=dotted, arrowhead=vee ];
590   }
591   edge [ fontsize=9, dir=back ]
592   TestFixture -> setUp;
593   TestFixture -> "TestCase 1..n";
594   TestFixture -> tearDown;
595   TestResult -> "TestFailure 0..m";
596 }
597 @enddot
598
599 @~english
600 Once you have a test suite, you'll want to run it. %CCUnit
601 provides @link ExecutingTest TestRunner @endlink
602 to define the suite to be run and to display
603 its results.
604 @~japanese
605 °ì¤Ä¥Æ¥¹¥È¥¹¡¼¥Ä¤ò½ñ¤¤¤¿¤é¡¢
606 ¤½¤ì¤ò¼Â¹Ô¤·¤¿¤¤¤Ç¤·¤ç¤¦¡£
607 CCUnit ¤Ï¥¹¡¼¥Ä¤ò¼Â¹Ô¤¹¤ë¤¿¤á¤ËÄêµÁ¤·¡¢
608 ·ë²Ì¤òɽ¼¨¤¹¤ë¤¿¤á¤Î @link ExecutingTest TestRunner @endlink ¤òÄ󶡤·¤Þ¤¹¡£
609 @~
610
611 @~english
612 To use the @link CCUnitTestRunner TestRunner @endlink,
613 include the header files for the tests in runTestRunner.c:
614 @~japanese
615 @link CCUnitTestRunner TestRunner @endlink ¤ò»ÈÍѤ¹¤ë¤Ë¤Ï¡¢
616 Î㤨¤Ð runTestRunner.c ¤Ç¥Æ¥¹¥È¤Î¤¿¤á¤Î¥Õ¥¡¥¤¥ë¤Î¥Ø¥Ã¥À¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Þ¤¹¡£
617 @~
618
619 @code
620 #include <ccunit/CCUnitTestRunner.h>
621 #include <ccunit/CCUnitTestSuite.h>
622 @endcode
623
624 @~english
625 And call to
626 @link ccunit_runTestRunner()
627 ccunit_runTestRunner (CCUnitTestRunner*, CCUnitTestSuite *) @endlink
628 in the <code>main()</code> function:
629 @~japanese
630 ¤½¤·¤Æ@link ccunit_runTestRunner()
631 ccunit_runTestRunner (CCUnitTestRunner*, CCUnitTestSuite *) @endlink
632 ¤ò<code>main()</code>´Ø¿ô¤Ç¼Â¹Ô¤·¤Þ¤¹¡£
633 @~
634
635 @code
636 extern CCUnitTestSuite* complex_add_sub_suite ();
637 extern CCUnitTestSuite* complex_mul_div_suite ();
638
639 int main( int argc, char **argv)
640 {
641   CCUnitTestRunner* runner;
642   CCUnitTestSuite* suite;
643   suite = ccunit_newTestSuite ("complex test suite");
644   ccunit_addTestSuite (suite, complex_add_sub_suite ());
645   ccunit_addTestSuite (suite, complex_mul_div_suite ());
646   runner = ccunit_newTestRunner (stdout);
647   return ccunit_runTestRunner (runner, suite);
648 }
649 @endcode
650
651 @english
652 The sample code made in the above is in the directory <code>examples/complex</code>,
653 the files <code>testComplex.c, complexTestSuite.c</code> and <code>runTestRunner.c</code>.
654 @japanese
655 ¤³¤³¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï¡¢<code>examples/complex</code> ¥Ç¥£¥ì¥¯¥È¥ê¤Î
656 <code>testComplex.c, complexTestSuite.c, runTestRunner.c</code>
657 ¤Ë¤¢¤ê¤Þ¤¹¡£
658
659 ¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó¼Â¹Ô¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
660 @endif
661
662 @code
663 $ gcc -I. -o runTestRunner runTestRunner.c testComplex.c testComplexMulDiv.c complexTestSuite.c complex.c -lccunit
664 $ ./runTestRunner
665 .....
666 Time: 0.000066 sec
667
668 OK (5 tests)
669 @endcode
670
671 @~english
672 The @link ExecutingTest TestRunner @endlink will run the tests.
673 If all the tests pass, you'll get an informative message.
674 If any fail, you'll get the following information:
675 @~japanese
676 @link ExecutingTest TestRunner @endlink ¤Ï¥Æ¥¹¥È¤ò¼Â¹Ô¤·¤Þ¤¹¡£
677 ¤â¤·¤¹¤Ù¤Æ¤Î¥Æ¥¹¥È¤¬¥Ñ¥¹¤¹¤ì¤Ð¡¢¤½¤Î¾ðÊó¤Î¥á¥Ã¥»¡¼¥¸¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
678 ¾å¤ÎÎã¤Ç¤Ï¡¢ºÇ½é¤Î¡Ö<code>.....</code>¡×¤Ï¼Â¹Ô¤·¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Ç¤¹¡£
679 ¼Â¹Ô¤¹¤ëľÁ°¤Ë¡Ö<code>.</code>¡×¤¬½ÐÎϤµ¤ì¤Þ¤¹¡£
680 Á´¤Æ¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Î¼Â¹Ô¤¬½ªÎ»¤¹¤ë¤È¡¢
681 ¼Â¹Ô¤Ë¤«¤«¤Ã¤¿»þ´Ö¤È¼Â¹Ô¤·¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Î¿ô¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
682
683 ¤É¤ì¤«¤¬¼ºÇÔ¤¹¤ì¤Ð¡¢¤½¤ì¤Ë¤Ä¤¤¤Æ°Ê²¼¤Î¤è¤¦¤Ê¾ðÊó¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
684 @~
685
686 <ul>
687 <li>@~english
688     The name of the source file that contains the test
689     @~japanese
690     ¥Æ¥¹¥È¤ò´Þ¤ó¤Ç¤¤¤ë¥½¡¼¥¹¥Õ¥¡¥¤¥ë̾
691     @~
692 </li>
693 <li>@~english
694     The line number where the failure occurred
695     @~japanese
696     ¼ºÇÔ¤¬µ¯¤³¤Ã¤¿¹ÔÈÖ¹æ
697     @~
698 </li>
699 <li>@~english
700     The name of the test case that failed
701     @~japanese
702     ¼ºÇÔ¤·¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Î̾Á°
703     @~
704 </li>
705 <li>@~english
706     All of the text inside the call to
707     <code>CCUNIT_ASSERT ()</code> which detected the failure
708     @~japanese
709     ¼ºÇÔ¤ò¸¡ÃΤ·¤¿<code>CCUNIT_ASSERT ()</code>¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿»þ¤Î¾ò·ï¤Îʸ»úÎó¡£
710     @~
711 </li>
712 </ul>
713
714 @english
715 @japanese
716 »î¤·¤Ë @c testComplex.c ¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ç¤ï¤¶¤È´Ö°ã¤¨¤Æ¤ß¤Þ¤·¤ç¤¦¡£
717 <code>!complex_equals</code> ¤Î <code>!</code> ¤ò¤È¤Ã¤Æ¤ß¤Þ¤¹¡£
718 @endif
719
720 @code
721 //* testComplex.c *\/
722 //** test equals *\/
723 void test_complex_equals ()
724 {
725   CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s10_1, complex_to_string);
726 //*CCUNIT_ASSERT_TEST_OBJ (s10_1, !complex_equals, s1_1, complex_to_string);*\/
727   CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s1_1, complex_to_string);
728 }
729 @endcode
730
731 @code
732 $ gcc -I. -o runTestRunner runTestRunner.c testComplex.c testComplexMulDiv.c complexTestSuite.c complex.c -lccunit
733 $ ./runTestRunner
734 .F....
735 Time: 0.000059 sec
736
737 FAILURES!!!
738 Test Results: 
739 Run 5, Failures 1
740 There was 1 failure:
741 testComplex.c:53: complex equals test:
742         complex_equals (s10_1, s1_1)
743         expect: 10+1i
744         actual: 1+1i
745 @endcode
746
747 @english
748 @japanese
749 ¤³¤ÎÎã¤Ç¤Ï¥Æ¥¹¥È¥±¡¼¥¹¤ò 5 ¸Ä¼Â¹Ô¤·¤Æ¡¢
750 ¤Ò¤È¤Ä¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ç¼ºÇÔ¤·¤Æ¤¤¤ë¤³¤È¤¬¤ï¤«¤ê¤Þ¤¹¡£
751 ºÇ½é¤Î¡Ö<code>.F....</code>¡×¤Ç¤Ï¡¢
752 ¤Ò¤È¤ÄÌܤΥƥ¹¥È¥±¡¼¥¹¤¬¼ºÇÔ¤·¤Æ¤¤¤ë¤³¤È¤ò¤¢¤é¤ï¤·¤Æ¤¤¤Þ¤¹¡£
753
754 ¤Þ¤¿¾å½Ò¤Î¤è¤¦¤Ë¡¢
755 ¼ºÇÔ¤·¤¿¥Õ¥¡¥¤¥ë̾¡¢¹ÔÈֹ桢¥Æ¥¹¥È¥±¡¼¥¹¤Î̾Á° (<code>complex equals test</code>)¡¢
756 ɽÌÀ¤·¤¿¾ò·ï¤Îʸ»úÎó (<code>complex_equals (s10_1, s1_1)</code>)¡¢
757 ´üÂÔ¤·¤¿ÃÍ (<code>10+1i</code>)¡¢
758 ¼ÂºÝ¤ÎÃÍ (<code>1+1i</code>)
759 ¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
760 @endif
761
762 @english
763 @section helper_macros Helper Tool
764 @japanese
765 @section helper_macros ¥Ø¥ë¥Ñ¡¼¥Ä¡¼¥ë
766 @endif
767
768 @~english
769 As you might have noticed, implementing the <code>suite
770 ()</code> function of fixture is a repetitive and error
771 prone task. A @ref CreatingTestSuite set of functions and
772 command have been created to automatically implements the
773 <code>suite()</code> function.
774 @~japanese
775 ¤ªµ¤¤Å¤­¤Î¤è¤¦¤Ë¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤Î <code>suite ()</code>´Ø¿ô¤ò¼ÂÁõ¤¹¤ë¤Î¤Ï¡¢
776 È¿ÉüŪ¤Ç´Ö°ã¤¤¤ä¤¹¤¤ºî¶È¤Ç¤¹¡£
777 @ref CreatingTestSuite ¤Î´Ø¿ô¤Î½¸¤Þ¤ê¤È¥³¥Þ¥ó¥É¤Ï<code>suite ()</code>
778 ´Ø¿ô¤Î¼ÂÁõ¤ò¼«Æ°Åª¤ËºîÀ®¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
779 @~
780
781 @dontinclude complex/testComplex.c
782
783 @~english
784 The following code is a rewrite of ComplexTest using those command:
785 @~japanese
786 °Ê²¼¤Î¥³¡¼¥É¤Ï¤½¤ì¤é¤Î¥³¥Þ¥ó¥É¤¬»È¤¦¤è¤¦¤Ë testComplex.c ¤ò½ñ´¹¤¨¤¿¤â¤Î¤Ç¤¹¡£
787 @~
788
789 @~english
790 First, you declare the fixture, passing the test fixture
791 name to the javaDoc style comment, which consist of a
792 C-style comment block starting with two <tt>*</tt>'s:
793 @~japanese
794 ºÇ½é¤Ë¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤òÀë¸À¤·¤Þ¤¹¡£
795 ¤³¤ì¤ÏjavaDoc¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥ÈÆâ¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤Î̾Á°¤òµ­½Ò¤·¤Þ¤¹¡£
796 javaDoc¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥È¤È¤Ï C ¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥È¥Ö¥í¥Ã¥¯¤Î³«»Ï¤¬
797 Æó¤Ä¤Î¥¢¥¹¥¿¥ê¥¹¥¯ <tt>**</tt> ¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤â¤Î¤Ç¤¹¡£
798 @~
799
800 @code
801 #include <ccunit/CCUnitAssert.h>
802
803 //** test case: complex number test *\/
804 @endcode
805
806 @~english
807 The function to make @link CCUnitTestSuite TestSuite
808 @endlink is <code>ccunit_suite</code>.
809 But, it can be changed to another
810 name by the <code>-f</code> option of the
811 <code>ccunit_makeSuite</code> command, too.
812 Then, you define each test case of the fixture with prefix
813 <code>test</code>, <code>setUp</code>,
814 <code>tearDown</code>:
815 @~japanese
816 @link CCUnitTestSuite TestSuite @endlink
817 ¤òºîÀ®¤¹¤ë´Ø¿ô¤Ï <code>ccunit_suite</code> ¤Ç¤¹¡¢
818 ¤·¤«¤· <code>ccunit_makeSuite</code> ¥³¥Þ¥ó¥É¤Î
819 <code>-f</code> ¥ª¥×¥·¥ç¥ó¤ÇÊ̤Î̾Á°¤ËÊѤ¨¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£
820 ¤½¤·¤Æ¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ë¤Ï¤½¤ì¤¾¤ì̾Á°¤ÎÀèƬ¤Ë¡¢
821 <code>test</code>, <code>setUp</code>,
822 <code>tearDown</code> ¤ò¤Ä¤±¤Æ¤¯¤À¤µ¤¤¡£
823 @~
824
825 @code
826 #include <complex.h>
827
828 static complex_t* s10_1;
829 static complex_t* s1_1;
830 static complex_t* s11_2;
831 static complex_t* sc;
832
833 void setup_setUp_complex_test ()
834 {
835   sc = complex_new (1, 1);
836 }
837
838 void setup_tearDown_complex_test ()
839 {
840   complex_delete (sc);
841 }
842
843 void setUp_complex_test ()
844 {
845   s10_1 = complex_new (10, 1);
846   s1_1 = complex_new (1, 1);
847   s11_2 = complex_new (11, 2);
848 }
849
850 void tearDown_complex_test ()
851 {
852   complex_delete (s10_1);
853   complex_delete (s1_1);
854   complex_delete (s11_2);
855 }
856
857 //** test equals *\/
858 void test_complex_equals ()
859 {
860   CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s10_1, complex_to_string);
861   CCUNIT_ASSERT_TEST_OBJ (s10_1, !complex_equals, s1_1, complex_to_string);
862 }
863
864 //** test add *\/
865 void test_complex_add ()
866 {
867   complex_t c10_1 = { 10.0, 1.0 };
868   complex_t c1_1 = { 1.0, 1.0 };
869   complex_t result;
870   complex_t c11_2 = { 11.0, 2.0 };
871   CCUNIT_ASSERT (complex_equals (&c11_2, complex_add (&result, &c10_1, &c1_1)));
872 }
873
874 //** test sub *\/
875 void test_complex_sub ()
876 {
877   complex_t c9_0 = { 9, 0 };
878   complex_t result;
879   CCUNIT_ASSERT_TEST_OBJ (&c9_0, complex_equals,
880                           complex_sub (&result, s10_1, s1_1),
881                           complex_to_string);
882 }
883 @endcode
884
885 @~english
886 Finally, you end the fixture declaration:
887 @~japanese
888 ºÇ¸å¤Ë¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤Î½ª¤ê¤òÀë¸À¤·¤Þ¤¹¡£
889 @~
890
891 @code
892 //** end test case *\/
893 @endcode
894
895 @english
896 @japanese
897 ¤Ò¤È¤Ä¤Î¥Õ¥¡¥¤¥ë¤ÎÃæ¤ËÊ£¿ô¤Î¥Õ¥£¥¯¥¹¥Á¥ã¤òÄêµÁ¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£
898 ¤½¤Î¾ì¹ç¤Ï¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤Î½ª¤ï¤ê¤ÎÀë¸À¤Î¸å¤Ë³¤±¤Æ¥Õ¥£¥¯¥¹¥Á¥ã¤òÄêµÁ¤·¤Æ¤¯¤À¤µ¤¤¡£
899 @endif
900
901 @~english
902 To generate creating suite function code, run
903 <code>ccunit_makeSuite</code> tool.
904 @~japanese
905 ¥¹¡¼¥ÄºîÀ®´Ø¿ô¤Î¥³¡¼¥É¤òÀ¸À®¤¹¤ë¤Ë¤Ï¡¢
906 <code>ccunit_makeSuite</code>¥Ä¡¼¥ë¤ò¼Â¹Ô¤·¤Þ¤¹¡£
907 @~
908
909 @code
910 $ ccunit_makeSuite -f complex_suite -o suiteComplex.c testComplex.c
911 $ cat suiteComplex.c
912
913 #include <ccunit/CCUnitTestSuite.h>
914 #include <ccunit/CCUnitTestFixture.h>
915 #include <ccunit/CCUnitTestCase.h>
916
917 //* test fixture: complex number test *\/
918 //* setUp_complex_test *\/
919 extern void setUp_complex_test ();
920 //* tearDown_complex_test *\/
921 extern void tearDown_complex_test ();
922 //* test_complex_equals *\/
923 extern void test_complex_equals ();
924 //* test_complex_add *\/
925 extern void test_complex_add ();
926 //* test_complex_sub *\/
927 extern void test_complex_sub ();
928
929 static CCUnitTestFunc fx_001_cases[] = {
930   {
931     "test_complex_equals",
932     "test equals",
933     test_complex_equals
934   },
935   {
936     "test_complex_add",
937     "test add",
938     test_complex_add
939   },
940   {
941     "test_complex_sub",
942     "test sub",
943     test_complex_sub
944   },
945   {
946     NULL, NULL, NULL
947   },
948 };
949
950 static CCUnitTestFixtureDfn fx_001 = {
951   { ccunitTypeFixture },
952   "complex number test",
953   {
954     "setup_setUp_complex_test",
955     "setup_setUp_complex_test",
956     setup_setUp_complex_test
957   },
958   {
959     "setup_tearDown_complex_test",
960     "setup_tearDown_complex_test",
961     setup_tearDown_complex_test
962   },
963   {
964     "setUp_complex_test",
965     "setUp_complex_test",
966     setUp_complex_test
967   },
968   {
969     "tearDown_complex_test",
970     "tearDown_complex_test",
971     tearDown_complex_test
972   },
973   fx_001_cases,
974 };
975
976 static CCUnitTestDfn* suite_001_test[] = {
977     &fx_001.test,
978     NULL,
979 };
980
981 static CCUnitTestSuiteDfn suite_001 = {
982   { ccunitTypeSuite },
983   "",
984   suite_001_test
985 };
986
987
988 CCUnitTestSuite* complex_suite (const char* name)
989 {
990   if (!suite_001.name[0])
991     suite_001.name = name;
992   return ccunit_newTestSuiteFromDfn (&suite_001);
993 }
994 $
995 @endcode
996
997 @english
998 Fixtures can be packaged into test suite.
999 You declare the suite before fixtures.
1000 @japanese
1001 ¤Ê¤ª¡¢¤¤¤¯¤Ä¤«¤Î¥Õ¥£¥¯¥¹¥Á¥ã¤ò¥Æ¥¹¥È¥¹¡¼¥Ä¤Ë¤Þ¤È¤á¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£
1002 ¤½¤Î¤¿¤á¤Ë¤Ï¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤ÎÄêµÁ¤ÎÁ°¤Ë¥Æ¥¹¥È¥¹¡¼¥Ä¤òÀë¸À¤·¤Þ¤¹¡£
1003 @endif
1004
1005 @code
1006 //** test suite: complex number test suite *\/
1007 //** test case: complex number equality test *\/
1008 ...
1009 //** test case: complex number compute test *\/
1010 ...
1011 @endcode
1012
1013 @copydetails CCUnitMakeSuite
1014
1015 @english
1016 @section post_build_check Post-build check
1017 @japanese
1018 @section post_build_check ¥Ó¥ë¥É¸å¤Î¥Á¥§¥Ã¥¯
1019 @endif
1020
1021 @~english
1022 Now that we have our unit tests running, how about
1023 integrating unit testing to our build process ?
1024 @~japanese
1025 ¤µ¤¢¥æ¥Ë¥Ã¥È¥Æ¥¹¥È¤ò¼Â¹Ô¤¹¤ë½àÈ÷¤¬¤Ç¤­¤Þ¤·¤¿¡£
1026 ¤Ç¤Ï¥Ó¥ë¥É¥×¥í¥»¥¹¤Ë¥æ¥Ë¥Ã¥È¥Æ¥¹¥È¤òÅý¹ç¤¹¤ë¤Ë¤Ï¤É¤¦¤·¤¿¤é¤¤¤¤¤Ç¤·¤ç¤¦¡£
1027 @~
1028
1029 @~english
1030 To do that, the application must returns a value different than 0 to indicate that
1031 there was an error.
1032 @~japanese
1033 ¤½¤¦¤¹¤ë¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¡¢¥¨¥é¡¼¤¬È¯À¸¤·¤¿¤³¤È¤ò¼¨¤¹
1034 0 °Ê³°¤ÎÃͤòÊÖ¤µ¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£
1035 @~
1036
1037 @~english
1038 @link ccunit_runTestRunner() ccunit_runTestRunner() @endlink returns
1039 a integer indicating if the run was successful.
1040 @~japanese
1041 @link ccunit_runTestRunner() ccunit_runTestRunner() @endlink
1042 ¤Ï¡¢¼Â¹Ô¤¬À®¸ù¤·¤¿¤«¤É¤¦¤«¤ò¼¨¤¹À°¿ô¤òÊÖ¤·¤Þ¤¹¡£
1043 @~
1044
1045 @~english
1046 Updating our main programm, we obtains:
1047 @~japanese
1048 ¼¡¤Î¤è¤¦¤Ë¥á¥¤¥ó¥×¥í¥°¥é¥à¤ò¹¹¿·¤·¤Þ¤¹¡£
1049 @~
1050
1051 @code
1052 #include <ccunit/CCUnitTestRunner.h>
1053
1054 extern CCUnitTestSuite* complex_suite(const char* name);
1055
1056 int main (int argc, char** argv)
1057 {
1058   CCUnitTestRunner* runner;
1059   CCUnitTestSuite* suite;
1060   int wasSucessful;
1061   runner = ccunit_newTestRunner (stdout);
1062   suite = complex_suite ("complex test suite");
1063   wasSucessful = ccunit_runTestRunner (runner, suite);
1064   return wasSucessful;
1065 }
1066 @endcode
1067
1068 @~english
1069 Now, you need to run your application after compilation.
1070 @~japanese
1071 ¤½¤ì¤Ç¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ò¥³¥ó¥Ñ¥¤¥ë¤·¤¿¸å¤Ë¼Â¹Ô¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£
1072 @~
1073
1074 @code
1075 $ gcc -I. -o runTest runTest.c testComplex.c suiteComplex.c complex.c -lccunit
1076 $ ./runTest
1077 ...
1078 Time: 0.000032 sec
1079
1080 OK (3 tests)
1081 @endcode
1082
1083 @code
1084 $ ccunit_makeSuite -f complex_suite -o suiteComplex.c testComplex.c testComplexMulDiv.c
1085 $ gcc -I. -o runTest runTest.c testComplex.c testComplexMulDiv.c suiteComplex.c complex.c -lccunit
1086 $ ./runTest
1087 .....
1088 Time: 0.000045 sec
1089
1090 OK (5 tests)
1091 @endcode
1092
1093 @~english
1094 The sample program made in the above is in the @c examples/complex directory.
1095 @~japanese
1096 °Ê¾å¤ÇºîÀ®¤·¤¿¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ï @c examples/complex ¥Ç¥£¥ì¥¯¥È¥ê¤Ë¤¢¤ê¤Þ¤¹¡£
1097 @~
1098
1099 - complex - @~english some complex number library test cases
1100   @~japanese Ê£ÁÇ¿ô¤ò·×»»¤¹¤ë¥é¥¤¥Ö¥é¥ê¤È¤½¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Î¥µ¥ó¥×¥ë¤Ç¤¹¡£@~
1101   - libcomplex.a - complex number library
1102     - complex.c
1103     - complex.h
1104   - runTestFixture @~japanese - ¤â¤Ã¤È¤âñ½ã¤Ê¥Æ¥¹¥È¥±¡¼¥¹¤ò¼Â¹Ô¤¹¤ë¥µ¥ó¥×¥ë¤Ç¤¹¡£@~
1105     - runTestFixture.c - main program
1106     - testComplex.c - test cases
1107   - runTestSuite @~japanese - ¥Æ¥¹¥È¥¹¡¼¥Ä¤Î¥µ¥ó¥×¥ë¤Ç¤¹¡£@~
1108     - runTestSuite.c - main program
1109     - testComplex.c - test cases
1110     - testComplexMulDiv.c - test cases
1111     - complexTestSuite.c - create test suite function
1112   - runTestRunner @~japanese - ¥Æ¥¹¥È¥¹¡¼¥Ä¤ò¥Æ¥¹¥È¥é¥ó¥Ê¡¼¤Ç¼Â¹Ô¤¹¤ë¥µ¥ó¥×¥ë¤Ç¤¹¡£@~
1113     - runTestRunner.c - main program
1114     - testComplex.c - test cases
1115     - testComplexMulDiv.c - test cases
1116     - complexTestSuite.c - create test suite function
1117   - runTest @~japanese - ¥Æ¥¹¥È¥¹¡¼¥Ä¤ò¼«Æ°À¸À®¤¹¤ë¥µ¥ó¥×¥ë¤Ç¤¹¡£@~
1118     - runTest.c - main program
1119     - testComplex.c - test cases
1120     - suiteComplex.c - auto generated test suite from testComplex.c
1121
1122 */