OSDN Git Service

add japanese documents
[ccunit/ccunit.git] / doc / cookbook.dox
1 /* -*- Indented-Text -*- */
2 /* $Id$ */
3 /**
4 @english
5 @page cookbook CCUnit Cookbook
6 @endif
7 @japanese
8 @page cookbook CCUnit ¥¯¥Ã¥¯¥Ö¥Ã¥¯
9 @endif
10
11 @~english
12 Here is a short cookbook to help you get started.
13 @~japanese
14 ¤³¤ì¤Ï CCUnit ¤ò»È¤¤»Ï¤á¤ë¤Ë¤¢¤¿¤Ã¤Æ¡¢
15 Íý²ò¤Î½õ¤±¤È¤Ê¤ë¤è¤¦¤Êû¤¤¥¯¥Ã¥¯¥Ö¥Ã¥¯¤Ç¤¹¡£
16 @~
17 @english
18 [see also <a href="../ja/cookbook.html">Japanese</a> documents]
19 @endif
20 @japanese
21 [see also <a href="../../cookbook.html">English</a> documents]
22 @endif
23
24 @english
25 @section simple_test_case Simple Test Case
26 @endif
27 @japanese
28 @section simple_test_case ¥·¥ó¥×¥ë¤Ê¥Æ¥¹¥È¥±¡¼¥¹
29 @endif
30
31 @~english
32 Tests in <b>CCUnit</b> can be run automatically.  They are
33 easy to set up and once you have written them, they are
34 always there to help you keep confidence in the quality of
35 your code.
36 @~japanese
37 CCUnit¤ò»È¤Ã¤¿¥Æ¥¹¥È¤Ï¼«Æ°Åª¤Ë¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
38 CCUnit ¤Î¥Æ¥¹¥È¤Ï´Êñ¤Ë¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¤³¤È¤¬¤Ç¤­¡¢
39 °ìÅ٥ƥ¹¥È¤ò½ñ¤¤¤Æ¤·¤Þ¤¨¤Ð¡¢
40 ¤¤¤Ä¤Ç¤â¥×¥í¥°¥é¥à¤ÎÉʼÁ¤ò¿®Íê¤Ç¤­¤ë¤â¤Î¤ËÊݤĤ³¤È¤¬¤Ç¤­¤ë¤Ç¤·¤ç¤¦¡£
41 @~
42
43 @~english
44 To make a simple test, here is what you do:
45 @~japanese
46 ñ½ã¤Ê¥Æ¥¹¥È¤òºî¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
47 @~
48
49 <ol>
50 <li> @~english Create a test function
51      @~japanese ¥Æ¥¹¥È´Ø¿ô¤òºî¤ë</li>
52 <li> @~english When you want to check a value, call
53      @~japanese Ãͤò¥Á¥§¥Ã¥¯¤·¤¿¤¤¾ì¹ç¤Ï¡¢@~
54      @link CCUNIT_ASSERT() CCUNIT_ASSERT(bool) @endlink
55      @~english and pass a bool that is true if the test succeeds
56      @~japanese ¤ò¸Æ¤Ó½Ð¤·¤Æ¡¢
57      ¤â¤·¥Æ¥¹¥È¤¬À®¸ù¤¹¤ë¤Î¤Ç¤¢¤ì¤Ð¿¿¤òÊÖ¤¹¤è¤¦¤Ê¿¿µ¶ÃͤòÅϤ·¤Þ¤¹</li>
58 </ol>
59
60 @~english
61 For example, to test that the sum of two complex number
62 which is the sum of the values of two complex numbers,
63 write:
64 @~japanese
65 Î㤨¤Ð¡¢Æó¤Ä¤ÎÊ£ÁÇ¿ô¤Î¹ç·×¤¬¡¢
66 Æó¤Ä¤ÎÊ£ÁÇ¿ô¤ÎÃͤò²Ã»»¤·¤¿ÃͤÈƱ¤¸¤Ç¤¢¤ë¤³¤È¤ò¥Æ¥¹¥È¤¹¤ë¤È¤·¤Þ¤¹¡£
67 @~
68
69 @code
70 void test_complex_add ()
71 {
72   complex_t c10_1 = { 10.0, 1.0 };
73   complex_t c1_1 = { 1.0, 1.0 };
74   complex_t result;
75   complex_t c11_2 = { 11.0, 2.0 };
76   CCUNIT_ASSERT (complex_equals (&c11_2, complex_add (&result, c10_1, c1_1)));
77 }
78 @endcode
79
80 @~english
81 That was a very simple test. Ordinarily, you'll have many
82 little test cases that you'll want to run on the same set of
83 objects. To do this, use a fixture.
84 @~japanese
85 ¤³¤ì¤ÏÂçÊÑñ½ã¤Ê¥Æ¥¹¥È¤Ç¤¹¡£
86 Ä̾Ʊ¤¸¥Ç¡¼¥¿¤Î¥»¥Ã¥È¤ÇÁö¤é¤»¤ë¤¿¤á¤Ë¡¢
87 ¤¿¤¯¤µ¤ó¤Î¾®¤µ¤Ê¥Æ¥¹¥È¥±¡¼¥¹¤òºî¤é¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤Ç¤·¤ç¤¦¡£
88 ¤½¤¦¤¹¤ë¤Ë¤Ï¥Õ¥£¥¯¥¹¥Á¥ã¡ÊÈ÷Éʡˤò»È¤¤¤Þ¤¹¡£
89 @~
90
91 @english
92 @section fixture Fixture
93 @endif
94 @japanese
95 @section fixture ¥Õ¥£¥¯¥¹¥Á¥ã
96 @endif
97
98 @~english
99 What if you have two or more tests that operate on the same
100 similar set of objects?
101 @~japanese
102 ¤â¤·Æó¤Ä°Ê¾å¤Î¥Æ¥¹¥È¤¬¤¢¤ë¤Ê¤é¡¢
103 Ʊ¤¸Îà»÷¤Î¥Ç¡¼¥¿¤Î¥»¥Ã¥È¤ÇÁàºî¤¹¤ë¤Î¤Ç¤Ï¤Ê¤¤¤Ç¤·¤ç¤¦¤«¡£
104 @~
105
106 @~english
107 Tests need to run against the background of a known set of
108 objects. This set of objects is called a test fixture. When
109 you are writing tests you will often find that you spend
110 more time writing the code to set up the fixture than you do
111 in actually testing values.
112 @~japanese
113 ¥Æ¥¹¥È¤Ï¼þÃΤΥǡ¼¥¿¤Î¥»¥Ã¥È¤òÇطʤˤ·¤Æ¼Â¹Ô¤µ¤ì¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
114 ¤³¤Î¥Ç¡¼¥¿¤Î¥»¥Ã¥È¤ò¥Õ¥£¥¯¥¹¥Á¥ã¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹¡£
115 ¥Æ¥¹¥È¤ò½ñ¤¤¤Æ¤¤¤ë¤È¡¢
116 ¼ÂºÝ¤Î¥Æ¥¹¥È¤¹¤ëÃͤò¥Õ¥£¥¯¥¹¥Á¥ã¤Ë¥»¥Ã¥È¥¢¥Ã¥×¤¹¤ë¥³¡¼¥É¤ò½ñ¤¯Êý¤Ë¡¢
117 ¤â¤Ã¤È»þ´Ö¤ò¤«¤±¤Æ¤¤¤ë¤³¤È¤Ëµ¤¤Å¤¯¤³¤È¤¬¤è¤¯¤¢¤ê¤Þ¤¹¡£
118 @~
119
120 @~english
121 Often, you will be able to use the same fixture for several
122 different tests. Each case will send slightly different
123 messages or parameters to the fixture and will check for
124 different results.
125 @~japanese
126 ¿¤¯¤Î¾ì¹ç¡¢¤¤¤¯¤Ä¤«¤Î°Û¤Ê¤Ã¤¿¥Æ¥¹¥È¤Î¤¿¤á¤ËƱ¤¸¥Õ¥£¥¯¥¹¥Á¥ã¤ò»È¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
127 ¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ï¾¯¤·°Û¤Ê¤Ã¤¿¥á¥Ã¥»¡¼¥¸¡¢
128 ¤¢¤ë¤¤¤Ï¥Ñ¥é¥á¡¼¥¿¤ò¥Õ¥£¥¯¥¹¥Á¥ã¤ËÁ÷¤ê¡¢
129 °Û¤Ê¤ë·ë²Ì¤òÄ´¤Ù¤Þ¤¹¡£
130 @~
131
132 @~english
133 When you have a common fixture, here is what you do:
134 @~japanese
135 ¤â¤·¶¦Ä̤¹¤ë¥Õ¥£¥¯¥¹¥Á¥ã¤¬¤¢¤ì¤Ð¡¢¤³¤ó¤Ê¤Õ¤¦¤Ë¤¹¤ë¤³¤È¤Ë¤Ê¤ê
136 ¤Þ¤¹¡£
137 @~
138
139 <ol>
140 <li>@~english
141     Create a @link CCUnitTestCase TestCase @endlink object
142     @~japanese
143     @link CCUnitTestCase TestCase @endlink ¹½Â¤ÂΤ˥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹
144     ¡Ê°Ê¹ß¡¢¹½Â¤ÂΤ˳ä¤êÅö¤Æ¤¿¥á¥â¥ê¤ò¡¢¥ª¥Ö¥¸¥§¥¯¥È¤È¸Æ¤Ö¤³¤È¤Ë¤·¤Þ¤¹¡Ë
145 </li>
146 <li>@~english
147     Add an global variable for each part of the fixture
148     @~japanese
149     ¥Õ¥£¥¯¥¹¥Á¥ã¤Î¤½¤ì¤¾¤ì¤ÎÉôʬ¤ËÂç°èÊÑ¿ô¤òÄɲä·¤Þ¤¹
150 </li>
151 <li>@~english
152     Write <code>setUp()</code> function to initialize the valiables
153     @~japanese
154     <code>setUp()</code> ´Ø¿ô¤ò½ñ¤¤¤ÆÊÑ¿ô¤ò½é´ü²½¤·¤Þ¤¹
155 </li>
156 <li>@~english
157     Write <code>tearDown()</code> to release any permanent
158     resources you allocated in <code>setUp</code>
159     @~japanese
160     <code>tearDown()</code> ´Ø¿ô¤ò½ñ¤¤¤Æ<code>setUp</code>
161     ¤Ç³ä¤êÅö¤Æ¤¿±Ê³Ū¥ê¥½¡¼¥¹¤ò²òÊü¤·¤Þ¤¹
162 </li>
163 <li>@~english
164     Create a @link CCUnitTestFixture TestFixture @endlink object
165     @~japanese
166     @link CCUnitTestFixture CCUnitTestFixture @endlink
167     ¹½Â¤ÂΤ˥á¥â¥ê¤ò³ä¤êÅö¤Æ¤Þ¤¹
168 </li>
169 <li>@~english
170     Add @link GGUnitTestCase TestCase @endlink objects to fixture object
171     @~japanese
172     @link CCUnitTestCase TestCase @endlink
173     ¥ª¥Ö¥¸¥§¥¯¥È¤ò@link CCUnitTestFixture TestFixture @endlink
174     ¥Õ¥£¥¯¥¹¥Á¥ã¥ª¥Ö¥¸¥§¥¯¥È¤ËÅÐÏ¿¤·¤Þ¤¹¡£
175 </li>
176 </ol>
177
178 @~english
179 For example, to write several test cases, first create a
180 fixture:
181 @~japanese
182 Î㤨¤Ð¡¢¤¤¤¯¤Ä¤«¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¯¾ì¹ç¡¢
183 ºÇ½é¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤òºîÀ®¤·¤Þ¤¹¡£
184 @~
185
186 @code
187 //** TEST CASE: complex number test *\/
188
189 #include "complex.h"
190
191 static complex_t* s10_1;
192 static complex_t* s1_1;
193 static complex_t* s11_2;
194
195 void setUp_ComplexTest ()
196 {
197   s10_1 = complex_new (10, 1);
198   s1_1 = complex_new (1, 1);
199   s11_2 = complex_new (11, 2);
200 }
201
202 void tearDown_ComplexTest ()
203 {
204   complex_delete (s10_1);
205   complex_delete (s1_1);
206   complex_delete (s11_2);
207 }
208
209 ...
210
211   CCUnitTestFixture* fixture;
212   fixture = ccunit_newTestFixture ("ComplexTest",
213                                    CCUNIT_NEWTESTFUNC(setUp_ComplexTest),
214                                    CCUNIT_NEWTESTFUNC(tearDown_ComplexTest));
215 @endcode
216
217 @~english
218 Once you have the Fixture in place, you can write as complex
219 Test Cases as you'd like.
220 @~japanese
221 °ìÅÙ·è¤Þ¤Ã¤¿¤È¤³¤í¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤ò½ñ¤¤¤Æ¤·¤Þ¤¨¤Ð¡¢
222 ¤¢¤Ê¤¿¤¬¹¥¤­¤Ê¤è¤¦¤ËÊ£ÁÇ¿ô¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¯¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
223 @~
224
225 @english
226 @section test_case Test Case
227 @endif
228 @japanese
229 @section test_case ¥Æ¥¹¥È¥±¡¼¥¹
230 @endif
231
232 @~english
233 How do you write and invoke an individual test case when you
234 have a Fixture?
235 @~japanese
236 ¥Õ¥£¥¯¥¹¥Á¥ã¤ò°ì¤Ä½ñ¤¤¤¿¤È¤·¤Æ¡¢
237 ¤É¤¦¤ä¤Ã¤Æ¸Ä¡¹¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò½ñ¤¤¤Æ¼Â¹Ô¤¹¤ì¤ÐÎɤ¤¤Ç¤·¤ç¤¦¤«¡£
238 @~
239
240 @~english
241 For example, to test the equality of two complex number,
242 write:
243 @~japanese
244 Î㤨¤Ð¡¢Æó¤Ä¤ÎÊ£ÁÇ¿ô¤¬Åù¤·¤¤¡Ê¤Þ¤¿¤ÏÅù¤·¤¯¤Ê¤¤¡Ë¤³¤È¤ò¥Æ¥¹¥È¤¹¤ë¤Ë¤Ï¡¢
245 ¼¡¤Î¤è¤¦¤Ë½ñ¤­¤Þ¤¹¡£
246 @~
247
248 @code
249 void test_complex_equals ()
250 {
251   CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s10_1, complex_to_string);
252   CCUNIT_ASSERT_TEST_OBJ (s10_1, !complex_equals, s1_1, complex_to_string);
253 }
254
255 ...
256
257   ccunit_addNewTestCase (fixture,
258                          "test_complex_equals",
259                          "complex equals test",
260                          test_complex_equals);
261 @endcode
262
263 @~english
264 One may create and run objects for each test case like this:
265 @~japanese
266 °ì¤Ä¤Ë¤Ï¼¡¤Î¤è¤¦¤Ë¡¢
267 ¥Õ¥£¥¯¥¹¥Á¥ã¤òºîÀ®¤·¤Æ¤½¤ì¤¾¤ì¤Î¥Æ¥¹¥È¥±¡¼¥¹¤ò¼Â¹Ô¤µ¤»¤ë¤³¤È
268 ¤¬¤Ç¤­¤Þ¤¹¡£
269 @~
270
271 @code
272   CCUnitTestResult* result;
273   result = ccunit_runTestFixture (fixture);
274 @endcode
275
276 @~english
277 When the test fixture is run, that specific test functions
278 will be run.  This is not a useful thing to do, however, as
279 no diagnostics will be displayed.  One will normally use a
280 @link ExecutingTest TestRunner @endlink (see below) to
281 display the results.
282 @~japanese
283 ¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤¬¼Â¹Ô¤µ¤ì¤ë¤È¡¢
284 ÆÃÄê¤Î¥Æ¥¹¥È´Ø¿ô¤¬¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£
285 ¤³¤ì¤Ï¤¢¤Þ¤êÊØÍø¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡¢
286 ¤Ê¤¼¤Ê¤é¡¢¿ÇÃǤ¬É½¼¨¤µ¤ì¤Ê¤¤¤«¤é¤Ç¤¹¡£
287 Ä̾ï¤Ï @link ExecutingTest TestRunner @endlink
288 (@ref test_runner ¸å½Ò)
289 ¤Ç·ë²Ì¤òɽ¼¨¤·¤Þ¤¹¡£
290 @~
291
292 @~english
293 Once you have several tests, organize them into a suite.
294 @~japanese
295 °ìÅÙ¤¤¤¯¤Ä¤«¤Î¥Æ¥¹¥È¤òºî¤Ã¤¿¤é¡¢
296 ¤½¤ì¤é¤ò¥¹¥¤¡¼¥È¤ËÀ°Íý¤·¤Þ¤¹¡£
297 @~
298
299 @english
300 @section suite Suite
301 @endif
302 @japanese
303 @section suite ¥¹¥¤¡¼¥È
304 @endif
305
306 @~english
307 How do you set up your tests so that you can run them all at once?
308 @~japanese
309 ¤É¤Î¤è¤¦¤Ë¤·¤Æ¡¢°ìÅ٤˥ƥ¹¥È¤ò¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¡¢
310 ½àÈ÷¤·¤¿¤é¤¤¤¤¤Ç¤·¤ç¤¦¤«¡©
311 @~
312
313 @~english
314 %CCUnit provides a @link CCUnitTestSuite TestSuite @endlink
315 module that runs any number of TestCases together.
316 @~japanese
317 CCUnit ¤Ï¤¤¤¯¤Ä¤â¤Î @link CCUnitTestCase TestCases @endlink
318 ¤ò°ì½ï¤Ë¼Â¹Ô¤¹¤ë
319 @link CCUnitTestSuite TestSuite @endlink ¥â¥¸¥å¡¼¥ë¤òÄ󶡤·¤Þ¤¹¡£
320 @~
321
322 @~english
323 You saw, above, how to run test fixture.
324 @~japanese
325 ¥Æ¥¹¥È¥Õ¥£¥¯¥¹¥Á¥ã¤ò¼Â¹Ô¤¹¤ëÊýË¡¤Ï¾å½Ò¤·¤Þ¤·¤¿¡£
326 @~
327
328 @~english
329 To create a suite of two or more tests, you do the following:
330 @~japanese
331 Æó¤Ä°Ê¾å¤Î¥Æ¥¹¥È¤ò´Þ¤à°ì¤Ä¤Î¥¹¥¤¡¼¥È¤òºî¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡£
332 @~
333
334 @code
335 CCUnitTestSuite* suite;
336 CCUnitTestFixture* fixture;
337 CCUnitTestResult* result;
338 suite = ccunit_newTestSuite ("Complex test suite");
339 fixture = ccunit_newTestFixture ("Complex Tests",
340                                  CCUNIT_NEWTESTFUNC(setUp_complex_test),
341                                  CCUNIT_NEWTESTFUNC(tearDown_complex_test));
342 ccunit_addNewTestCase (fixture, "test_complex_equals", "complex equals test",
343                        test_complex_equals);
344 ccunit_addNewTestCase (fixture, "test_complex_add", "complex add test",
345                        test_complex_add);
346 ccunit_addNewTestCase (fixture, "test_complex_sub", "complex sub test",
347                        test_complex_sub);
348 ccunit_addTestFixture (suite, fixtuer);
349 result = ccunit_runTestSuite (suite, NULL);
350 @endcode
351
352 @~english
353 @link CCUnitTestSuite TestSuites @endlink don't only have to
354 contain @link CCUnitTestFixture TestFixtures @endlink.  They
355 can contain any object that implements the @link CCUnitTest
356 Test @endlink interface.  For example, you can create a
357 @link CCUnitTestSuite TestSuite @endlink in your code and I
358 can create one in mine, and we can run them together by
359 creating a @link CCUnitTestSuite TestSuite @endlink that
360 contains both:
361 @~japanese
362 @link CCUnitTestSuite TestSuites @endlink ¤Ï
363 @link CCUnitTestFixture TestFixtures @endlink
364 ¤ò´Þ¤à¤À¤±¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£
365 ¤½¤ì¤é¤Ï @link CCUnitTest Test @endlink
366 ¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤¹¤ë¤É¤ó¤Ê¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤â´Þ¤á¤é¤ì¤Þ¤¹¡£
367 Î㤨¤Ð¡¢¤¢¤Ê¤¿¤Ï¤¢¤Ê¤¿¤Î¥³¡¼¥É¤Ë@link CCUnitTestSuite TestSuite @endlink
368 ¤òºî¤ë¤³¤È¤¬¤Ç¤­¡¢¤½¤·¤Æ»ä¤Ï»ä¤Î¥¹¥¤¡¼¥È¤òºî¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¢
369 ¤½¤·¤Æ»äã¤ÏξÊý¤È¤â¤ò´Þ¤ó¤Ç¤¤¤ë @link CCUnitTestSuite TestSuite @endlink
370 ¤òºî¤Ã¤Æ°ì½ï¤Ë¸Ä¡¹¤Î¥¹¥¤¡¼¥È¤òÆ°¤«¤¹¤³¤È¤¬¤Ç¤­¤ë¤Î¤Ç¤¹¡£
371 @~
372
373 @code
374 CCUnitTestSuite* suite;
375 CCUnitTestResult* result;
376 suite = ccunit_newTestSuite ("suite");
377 ccunit_addTestSuite (suite, complex_add_sub_suite ());
378 ccunit_addTestSuite (suite, complex_mul_div_suite ());
379 result = ccunit_runTestSuite(suite, NULL);
380 @endcode
381
382
383 @english
384 @section test_runner TestRunner
385 @endif
386 @japanese
387 @section test_runner ¥Æ¥¹¥È¥é¥ó¥Ê¡¼
388 @endif
389
390 @~english
391 How do you run your tests and collect their results?
392 @~japanese
393 ¤É¤¦¤ä¤Ã¤Æ¥Æ¥¹¥È¤ò¼Â¹Ô¤·¡¢¤½¤Î·ë²Ì¤ò½¸¤á¤¿¤éÎɤ¤¤Ç¤·¤ç¤¦¤«¡£
394 @~
395
396 @~english
397 Once you have a test suite, you'll want to run it. %CCUnit
398 provides tools to define the suite to be run and to display
399 its results.  You make your suite accessible to a @link
400 CreatingTestSuite ccunit_makeSuite @endlink tool that generate a
401 creating test suite code.
402 @~japanese
403 °ì¤Ä¥Æ¥¹¥È¥¹¥¤¡¼¥È¤ò½ñ¤¤¤¿¤é¡¢
404 ¤½¤ì¤ò¼Â¹Ô¤·¤¿¤¤¤Ç¤·¤ç¤¦¡£
405 CCUnit ¤Ï¥¹¥¤¡¼¥È¤ò¼Â¹Ô¤¹¤ë¤¿¤á¤ËÄêµÁ¤·¡¢
406 ·ë²Ì¤òɽ¼¨¤¹¤ë¤¿¤á¤Î¥Ä¡¼¥ë¤òÄ󶡤·¤Þ¤¹¡£
407 ¥¹¡¼¥Ä¤ò@link CreatingTestSuite ccunit_makeSuite @endlink
408 ¥Ä¡¼¥ë¤ËÆþÎϤǤ­¤ë¤è¤¦¤Ê·Á¼°¤Ç½ñ¤¯¤³¤È¤Ç¡¢
409 ¥Æ¥¹¥È¥¹¡¼¥Ä¤òºîÀ®¤¹¤ë¥³¡¼¥É¤ò¼«Æ°Åª¤ËÀ¸À®¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
410 @~
411
412 @~english
413 For example, to make a ComplexTest suite available to a
414 @link CreatingTestSuite ccunit_makeSuite @endlink,
415 excute the following tool to
416 ComplexTest.c:
417 @~japanese
418 Î㤨¤Ð¡¢ComplexTest ¥¹¥¤¡¼¥È¤ò
419 @link CreatingTestSuite ccunit_makeSuite @endlink
420 ¤ò»È¤Ã¤Æ»ÈÍѤǤ­¤ë¤è¤¦¤Ë¤¹¤ë¤Ë¤Ï¡¢
421 °Ê²¼¤Î¥Ä¡¼¥ë¤ò ComplexTest.c ¤Ë¼Â¹Ô¤·¤Þ¤¹¡£
422 @~
423
424 @code
425 $ ccunit_makeSuite -f complex_suite -o suiteComplex.c ComplexTest.c
426 @endcode
427
428 @anchor test_runner_code
429 @~english
430 To use the TestRunner, include the header files for the tests in Main.c:
431 @~japanese
432 TestRunner ¤ò»ÈÍѤ¹¤ë¤Ë¤Ï¡¢
433 Main.c¤Ç¥Æ¥¹¥È¤Î¤¿¤á¤Î¥Õ¥¡¥¤¥ë¤Î¥Ø¥Ã¥À¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Þ¤¹¡£
434 @~
435
436 @code
437 #include <ccunit/CCUnitTestRunner.h>
438 #include <ccunit/CCUnitTestSuite.h>
439 @endcode
440
441 @~english
442 And call to
443 @link ccunit_runTestRunner()
444 ccunit_runTestRunner (CCUnitTestRunner*, CCUnitTestSuite *) @endlink
445 in the <code>main()</code> function:
446 @~japanese
447 ¤½¤·¤Æ@link ccunit_runTestRunner()
448 ccunit_runTestRunner (CCUnitTestRunner*, CCUnitTestSuite *) @endlink
449 ¤ò<code>main()</code>´Ø¿ô¤Ç¼Â¹Ô¤·¤Þ¤¹¡£
450 @~
451
452 @code
453 extern CCUnitTestSuite* complex_suite(const char* name);
454
455 int main( int argc, char **argv)
456 {
457   CCUnitTestRunner* runner;
458   CCUnitTestSuite* suite;
459   runner = ccunit_newTestRunner (stdout);
460   suite = complex_suite ("complex test suite");
461   return ccunit_runTestRunner (runner, suite);
462 }
463 @endcode
464
465 @~english
466 The @link ExecutingTest TestRunner @endlink will run the tests.
467 If all the tests pass, you'll get an informative message.
468 If any fail, you'll get the following information:
469 @~japanese
470 @link ExecutingTest TestRunner @endlink ¤Ï¥Æ¥¹¥È¤ò¼Â¹Ô¤·¤Þ¤¹¡£
471 ¤â¤·¤¹¤Ù¤Æ¤Î¥Æ¥¹¥È¤¬¥Ñ¥¹¤¹¤ì¤Ð¡¢¤½¤Î¾ðÊó¤Î¥á¥Ã¥»¡¼¥¸¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
472 ¤â¤·¤É¤ì¤«¤¬¼ºÇÔ¤¹¤ì¤Ð¡¢¤½¤ì¤Ë¤Ä¤¤¤Æ°Ê²¼¤Î¤è¤¦¤Ê¾ðÊó¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
473 @~
474
475 <ul>
476 <li>@~english
477     The name of the source file that contains the test
478     @~japanese
479     ¥Æ¥¹¥È¤ò´Þ¤ó¤Ç¤¤¤ë¥½¡¼¥¹¥Õ¥¡¥¤¥ë̾
480 </li>
481 <li>@~english
482     The line number where the failure occurred
483     @~japanese
484     ¼ºÇÔ¤¬Åܤ俹ÔÈÖ¹æ
485 </li>
486 <li>@~english
487     The name of the test case that failed
488     @~japanese
489     ¼ºÇÔ¤·¤¿¥Æ¥¹¥È¥±¡¼¥¹¤Î̾Á°
490 </li>
491 <li>@~english
492     All of the text inside the call to
493     <code>CCUNIT_ASSERT ()</code> which detected the failure
494     @~japanese
495     ¼ºÇÔ¤ò¸¡ÃΤ·¤¿<code>CCUNIT_ASSERT ()</code>¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿»þ¤Î¾ò·ï¤Îʸ»úÎó¡£
496 </li>
497 </ul>
498
499 @english
500 @section helper_macros Helper Tool
501 @endif
502 @japanese
503 @section helper_macros ¥Ø¥ë¥Ñ¡¼¥Ä¡¼¥ë
504 @endif
505
506 @~english
507 As you might have noticed, implementing the <code>suite
508 ()</code> function of fixture is a repetitive and error
509 prone task. A @ref CreatingTestSuite set of functions and
510 command have been created to automatically implements the
511 <code>suite()</code> function.
512 @~japanese
513 ¤ªµ¤¤Å¤­¤Î¤è¤¦¤Ë¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤Î <code>suite ()</code>´Ø¿ô¤ò¼ÂÁõ¤¹¤ë¤Î¤Ï¡¢
514 È¿ÉüŪ¤Ç´Ö°ã¤¤¤ä¤¹¤¤ºî¶È¤Ç¤¹¡£
515 @ref CreatingTestSuite ¤Î´Ø¿ô¤Î¥»¥Ã¥È¤È¥³¥Þ¥ó¥É¤Ï<code>suite ()</code>
516 ´Ø¿ô¤Î¼ÂÁõ¤ò¼«Æ°Åª¤ËºîÀ®¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
517 @~
518
519 @dontinclude complex/testComplex.c
520
521 @~english
522 The following code is a rewrite of ComplexTest using those command:
523 @~japanese
524 °Ê²¼¤Î¥³¡¼¥É¤Ï¤½¤ì¤é¤Î¥³¥Þ¥ó¥É¤¬»È¤¦¤è¤¦¤ËComplexTest¤ò½ñ´¹¤¨¤¿¤â¤Î¤Ç¤¹¡£
525 @~
526
527 @code
528 #include <cppunit/CCUnitAssert.h>
529 @endcode
530
531 @~english
532 First, you declare the fixture, passing the test fixture
533 name to the javaDoc style comment, which consist of a
534 C-style comment block starting with two <tt>*</tt>'s:
535 @~japanese
536 ºÇ½é¤Ë¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤òÀë¸À¤·¤Þ¤¹¡£
537 ¤³¤ì¤ÏjavaDoc¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥ÈÆâ¤Ë¥Õ¥£¥¯¥¹¥Á¥ã¤Î̾Á°¤òµ­½Ò¤·¤Þ¤¹¡£
538 javaDoc¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥È¤È¤Ï C ¥¹¥¿¥¤¥ë¤Î¥³¥á¥ó¥È¥Ö¥í¥Ã¥¯¤Î³«»Ï¤¬
539 Æó¤Ä¤Î¥¢¥¹¥¿¥ê¥¹¥¯<tt>*</tt>¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤â¤Î¤Ç¤¹¡£
540 @~
541
542 @code
543 //** test case: complex number test *\/
544 @endcode
545
546 @~english
547 The function to make @link CCUnitTestSuite TestSuite
548 @endlink is <code>ccunit_suite</code>.
549 But, it can be changed to another
550 name by the <code>-f</code> option of the
551 <code>ccunit_makeSuite</code> command, too.
552 Then, you define each test case of the fixture with prefix
553 <code>test</code>, <code>setUp</code>,
554 <code>tearDown</code>:
555
556 @~japanese
557 @link CCUnitTestSuite TestSuite @endlink
558 ¤òºîÀ®¤¹¤ë´Ø¿ô¤Ï <code>ccunit_suite</code> ¤Ç¤¹¡¢
559 ¤·¤«¤· <code>ccunit_makeSuite</code> ¥³¥Þ¥ó¥É¤Î
560 <code>-f</code> ¥ª¥×¥·¥ç¥ó¤ÇÊ̤Î̾Á°¤ËÊѤ¨¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£
561 ¤½¤·¤Æ¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤Î¥Æ¥¹¥È¥±¡¼¥¹¤Ë¤Ï¤½¤ì¤¾¤ì̾Á°¤ÎÀèƬ¤Ë¡¢
562 <code>test</code>, <code>setUp</code>,
563 <code>tearDown</code> ¤ò¤Ä¤±¤Æ¤¯¤À¤µ¤¤¡£
564 @~
565
566 @code
567 #include <complex.h>
568
569 static complex_t* s10_1;
570 static complex_t* s1_1;
571 static complex_t* s11_2;
572
573 void setUp_complex_test ()
574 {
575   s10_1 = complex_new (10, 1);
576   s1_1 = complex_new (1, 1);
577   s11_2 = complex_new (11, 2);
578 }
579
580 void tearDown_complex_test ()
581 {
582   complex_delete (s10_1);
583   complex_delete (s1_1);
584   complex_delete (s11_2);
585 }
586
587 //** test equals *\/
588 void test_complex_equals ()
589 {
590   CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s10_1, complex_to_string);
591   CCUNIT_ASSERT_TEST_OBJ (s10_1, !complex_equals, s1_1, complex_to_string);
592 }
593
594 //** test add *\/
595 void test_complex_add ()
596 {
597   complex_t c10_1 = { 10.0, 1.0 };
598   complex_t c1_1 = { 1.0, 1.0 };
599   complex_t result;
600   complex_t c11_2 = { 11.0, 2.0 };
601   CCUNIT_ASSERT (complex_equals (&c11_2, complex_add (&result, &c10_1, &c1_1)));
602 }
603
604 //** test sub *\/
605 void test_complex_sub ()
606 {
607   complex_t c9_0 = { 9, 0 };
608   complex_t result;
609   CCUNIT_ASSERT_TEST_OBJ (&c9_0, complex_equals,
610                           complex_sub (&result, s10_1, s1_1),
611                           complex_to_string);
612 }
613 @endcode
614
615 @~english
616 Finally, you end the fixture declaration:
617 @~japanese
618 ºÇ¸å¤Ë¡¢¥Õ¥£¥¯¥¹¥Á¥ã¤Î½ª¤ê¤òÀë¸À¤·¤Þ¤¹¡£
619 @~
620
621 @code
622 //** end test case *\/
623 @endcode
624
625 @~english
626 To generate creating suite function code, run
627 <code>ccunit_makeSuite</code> tool.
628 @~japanese
629 ¥¹¥¤¡¼¥ÈºîÀ®´Ø¿ô¤Î¥³¡¼¥É¤òÀ¸À®¤¹¤ë¤Ë¤Ï¡¢
630 <code>ccunit_makeSuite</code>¥Ä¡¼¥ë¤ò¼Â¹Ô¤·¤Þ¤¹¡£
631 @~
632
633 @code
634 $ ccunit_makeSuite -f complex_suite -o suiteComplex.c testComplex.c
635 $ cat suiteComplex.c
636
637 #include <ccunit/CCUnitTestSuite.h>
638 #include <ccunit/CCUnitTestFixture.h>
639 #include <ccunit/CCUnitTestCase.h>
640
641 //* test fixture: complex number test *\/
642 //* setUp_complex_test *\/
643 extern void setUp_complex_test ();
644 //* tearDown_complex_test *\/
645 extern void tearDown_complex_test ();
646 //* test_complex_equals *\/
647 extern void test_complex_equals ();
648 //* test_complex_add *\/
649 extern void test_complex_add ();
650 //* test_complex_sub *\/
651 extern void test_complex_sub ();
652
653 static CCUnitTestFunc fx_001_cases[] = {
654   {
655     "test_complex_equals",
656     "test equals",
657     test_complex_equals
658   },
659   {
660     "test_complex_add",
661     "test add",
662     test_complex_add
663   },
664   {
665     "test_complex_sub",
666     "test sub",
667     test_complex_sub
668   },
669   {
670     NULL, NULL, NULL
671   },
672 };
673
674 static CCUnitTestFixtureDfn fx_001 = {
675   { ccunitTypeFixture },
676   "complex number test",
677   {
678     "setUp_complex_test",
679     "setUp_complex_test",
680     setUp_complex_test
681   },
682   {
683     "tearDown_complex_test",
684     "tearDown_complex_test",
685     tearDown_complex_test
686   },
687   fx_001_cases,
688 };
689
690 static CCUnitTestDfn* suite_001_test[] = {
691     &fx_001.test,
692     NULL,
693 };
694
695 static CCUnitTestSuiteDfn suite_001 = {
696   { ccunitTypeSuite },
697   "",
698   suite_001_test
699 };
700
701
702 CCUnitTestSuite* complex_suite (const char* name)
703 {
704   if (!suite_001.name[0])
705     suite_001.name = name;
706   return ccunit_newTestSuiteFromDfn (&suite_001);
707 }
708 $
709 @endcode
710
711 @english
712 @section post_build_check Post-build check
713 @endif
714 @japanese
715 @section post_build_check ¥Ó¥ë¥É¸å¤Î¥Á¥§¥Ã¥¯
716 @endif
717
718 @~english
719 Now that we have our unit tests running, how about
720 integrating unit testing to our build process ?
721 @~japanese
722 ¤µ¤¢¥æ¥Ë¥Ã¥È¥Æ¥¹¥È¤ò¼Â¹Ô¤¹¤ë½àÈ÷¤¬¤Ç¤­¤Þ¤·¤¿¡£
723 ¤Ç¤Ï¥Ó¥ë¥É¥×¥í¥»¥¹¤Ë¥æ¥Ë¥Ã¥È¥Æ¥¹¥È¤òÅý¹ç¤¹¤ë¤Ë¤Ï¤É¤¦¤·¤¿¤é¤¤
724 ¤¤¤Ç¤·¤ç¤¦¡£
725 @~
726
727 @~english
728 To do that, the application must returns a value different than 0 to indicate that
729 there was an error.
730 @~japanese
731 ¤½¤¦¤¹¤ë¤Ë¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¡¢¥¨¥é¡¼¤¬È¯À¸¤·¤¿¤³¤È¤ò¼¨¤¹
732 £°°Ê³°¤ÎÃͤòÊÖ¤µ¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£
733 @~
734
735 @~english
736 @link ccunit_runTestRunner() ccunit_runTestRunner() @endlink returns
737 a integer indicating if the run was successful.
738 @~japanese
739 @link ccunit_runTestRunner() ccunit_runTestRunner() @endlink
740 ¤Ï¡¢¼Â¹Ô¤¬À®¸ù¤·¤¿¤«¤É¤¦¤«¤ò¼¨¤¹À°¿ô¤òÊÖ¤·¤Þ¤¹¡£
741 @~
742
743 @~english
744 Updating our main programm, we obtains:
745 @~japanese
746 ¼¡¤Î¤è¤¦¤Ë¥á¥¤¥ó¥×¥í¥°¥é¥à¤ò¹¹¿·¤·¤Þ¤¹¡£
747 @~
748
749 @code
750 #include <ccunit/CCUnitTestRunner.h>
751
752 int main (int argc, char** argv)
753 {
754   CCUnitTestRunner* runner;
755   CCUnitTestSuite* suite;
756   int wasSucessful;
757   runner = ccunit_newTestRunner (stdout);
758   suite = ccunit_suite ();
759   wasSucessful = ccunit_runTestRunner (runner, suite);
760   return wasSucessful;
761 }
762 @endcode
763
764 @~english
765 Now, you need to run your application after compilation.
766 The sample program made in the above is in the example/complex directory.
767 @~japanese
768 ¤½¤ì¤Ç¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ò¥³¥ó¥Ñ¥¤¥ë¤·¤¿¸å¤Ë¼Â¹Ô¤·¤Æ¤ß¤Þ¤·¤ç
769 ¤¦¡£
770 °Ê¾å¤ÇºîÀ®¤·¤¿¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ï example/complex ¥Ç¥£¥ì¥¯
771 ¥È¥ê¤Ë¤¢¤ê¤Þ¤¹¡£
772 @~
773
774 */