1 /* Copyright (C) 2003 TSUTSUMI Kikuo.
2 This file is part of the CCUnit Library.
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.
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.
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.
25 * implements Test suite class.
28 #include <ccunit/CCUnitList.h>
29 #include <ccunit/CCUnitTest.h>
30 #include <ccunit/CCUnitTestResult.h>
31 #include <ccunit/CCUnitTestSuite.h>
33 static void run (CCUnitTest* testSuite, CCUnitTestResult* result)
35 CCUnitTestSuite* suite = (CCUnitTestSuite*)testSuite;
36 CCUnitListIterator itor;
38 assert (suite->test.type == ccunitTypeSuite);
39 ccunit_initListIterator (&suite->tests, &itor);
40 while ((test = ccunit_nextListIterator (&itor)) != NULL)
42 if (result->shouldStop)
44 test->run (test, result);
48 static void (*super_dtor) (CCUnitTest*);
50 static void dtor (CCUnitTest* test)
52 CCUnitTestSuite *suite = (CCUnitTestSuite*)test;
53 assert (test->type == ccunitTypeSuite);
54 ccunit_deleteList (&suite->tests, (void (*)(void*))ccunit_deleteTest);
58 inline CCUnitTestSuite* ccunit_newTestSuite (const char* name)
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);
70 inline void ccunit_deleteTestSuite (CCUnitTestSuite* suite)
72 ccunit_deleteTest (&suite->test);
75 inline void ccunit_addTest (CCUnitTestSuite* suite, CCUnitTest* test)
77 ccunit_addList (&suite->tests, test);
80 inline void ccunit_addTestSuite (CCUnitTestSuite* suite,
81 CCUnitTestSuite* testSuite)
83 ccunit_addList (&suite->tests, testSuite);
86 inline void ccunit_addTestCase ( CCUnitTestSuite* suite,
87 struct CCUnitTestCase* testCase)
89 ccunit_addList (&suite->tests, testCase);