OSDN Git Service

(no commit message)
[ccunit/ccunit.git] / src / ccunit / CCUnitTestSuite.c
1 /* Copyright (C) 2003 TSUTSUMI Kikuo.
2    This file is part of the CCUnit Library.
3
4    The CCUnit Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public License
6    as published by the Free Software Foundation; either version 2.1 of
7    the License, or (at your option) any later version.
8
9    The CCUnit Library is distributed in the hope that it will be
10    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the CCUnit Library; see the file COPYING.LESSER.
16    If not, write to the Free Software Foundation, Inc., 59 Temple
17    Place - Suite 330, Boston, MA 02111-1307, USA.  
18 */
19
20 /*
21  * $Id$
22  */
23 /**
24  * @file
25  * implements Test suite class.
26  */
27 #include <assert.h>
28 #include <ccunit/CCUnitList.h>
29 #include <ccunit/CCUnitTest.h>
30 #include <ccunit/CCUnitTestResult.h>
31 #include <ccunit/CCUnitTestSuite.h>
32
33 static void run (CCUnitTest* testSuite, CCUnitTestResult* result)
34 {
35   CCUnitTestSuite* suite = (CCUnitTestSuite*)testSuite;
36   CCUnitListIterator itor;
37   CCUnitTest* test;
38   assert (suite->test.type == ccunitTypeSuite);
39   ccunit_initListIterator (&suite->tests, &itor);
40   while ((test = ccunit_nextListIterator (&itor)) != NULL)
41     {
42       if (result->shouldStop)
43         break;
44       test->run (test, result);
45     }
46 }
47
48 static void (*super_dtor) (CCUnitTest*);
49
50 static void dtor (CCUnitTest* test)
51 {
52   CCUnitTestSuite *suite = (CCUnitTestSuite*)test;
53   assert (test->type == ccunitTypeSuite);
54   ccunit_deleteList (&suite->tests, (void (*)(void*))ccunit_deleteTest);
55   super_dtor (test);
56 }
57
58 inline CCUnitTestSuite* ccunit_newTestSuite (const char* name)
59 {
60   CCUnitTestSuite* suite = calloc (1, sizeof (*suite));
61   ccunit_initTest (&suite->test, name);
62   suite->test.type = ccunitTypeSuite;
63   super_dtor = suite->test.dtor_;
64   suite->test.dtor_ = dtor;
65   suite->test.run = run;
66   ccunit_initList (&suite->tests);
67   return suite;
68 }
69
70 inline void ccunit_deleteTestSuite (CCUnitTestSuite* suite)
71 {
72   ccunit_deleteTest (&suite->test);
73 }
74
75 inline void ccunit_addTest (CCUnitTestSuite* suite, CCUnitTest* test)
76 {
77   ccunit_addList (&suite->tests, test);
78 }
79
80 inline void ccunit_addTestSuite (CCUnitTestSuite* suite,
81                                  CCUnitTestSuite* testSuite)
82 {
83   ccunit_addList (&suite->tests, testSuite);
84 }
85
86 inline void ccunit_addTestCase ( CCUnitTestSuite* suite,
87                                 struct CCUnitTestCase* testCase)
88 {
89   ccunit_addList (&suite->tests, testCase);
90 }