OSDN Git Service

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