2 /* Copyright (C) 2003 TSUTSUMI Kikuo.
3 This file is part of the CCUnit Library.
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.
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.
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, write to the Free Software Foundation, Inc., 59 Temple
18 Place - Suite 330, Boston, MA 02111-1307, USA.
29 #ifndef CCUNITTESTFIXTURE_H
30 #define CCUNITTESTFIXTURE_H
32 #include <ccunit/CCUnitConfig.h>
33 #include <ccunit/CCUnitList.h>
34 #include <ccunit/CCUnitTest.h>
35 #include <ccunit/CCUnitTestCase.h>
39 * @defgroup CCUnitTestFixture TestFixture
40 * A test fixture defines the fixture to run multiple tests.
46 * Wraps a test case with setUp and tearDown methods.
48 * @ingroup WritingTestFixture
50 * A TestCase is used to provide a common environment for a set
53 * To define a test case, do the following:
54 * - the case is defined by static variables
55 * - initialize the case state by setUp function
56 * - clean-up after a test by tearDown function
58 * Each test runs in its own case so there
59 * can be no side effects among test runs.
63 * static int value1, value2;
65 * void setUp_MathTest ()
73 * CCUnitTestFixture* MathTest_newTestFixture ()
75 * return ccunit_newTestFixture ("MathTest", setUp_MathTest, NULL);
79 * For each test implement a method which interacts with the
80 * case. Verify the expected results with assertions specified by
81 * calling CPPUNIT_ASSERT on the expression you want to test:
86 * int result = value1 + value2;
87 * CCUNIT_ASSERT (result == 5);
92 * void MathTest_newTestCase_testAdd ()
94 * return ccunit_newTestCase ("addTest", "add test", addTest);
98 * The tests to be run can be collected into a TestSuite.
101 * CCUintTestSuite* MathTest_suite ()
103 * CCUnitTestSuite* suite = ccunit_newTestSuite ("MathTest");
104 * CCUnitTestFixture* fixture = MathTest_newTestFixture ();
105 * ccunit_addTestFixture (suite, fixture);
106 * ccunit_addTestCase (fixture, MathTest_newTestCase_testAdd ());
107 * ccunit_addTestCase (fixture, MathTest_newTestCase_testDivZero ())
112 * Once the functions are defined you can run them. To do this, use a
116 * CCUnitTestRunner *runner = ccunit_newTestRunner (stdout);
117 * CCUnitTestSuite *suite = MathTest_suite ();
118 * runner->run (runner, suite);
121 * A command line tool have been created for convenience. It is located
122 * in src/tools/ccunit_makeSuite.c.
124 * @see CCUnitTestResult, CCUnitTestSuite, CCUnitMakeSuite,
126 typedef struct CCUnitTestFixture
128 CCUnitTest test; /**< super class */
129 const char* name; /**< test fixture name */
130 CCUnitList testCases; /**< test cases */
131 void (*setUp) (); /**< setUp function */
132 void (*tearDown) (); /**< tearDown function */
136 * create new test fixture.
137 * @ingroup WritingTestFixture
139 * @param name test fixture name.
140 * @param setUp test fixture setUp function.
141 * @param tearDown test fixture tearDown function.
142 * @return new test fixture.
144 extern CCUnitTestFixture* ccunit_newTestFixture (const char* name,
149 * add test case to test fixture.
151 * @param fixture test fixture.
152 * @param testCase test case
154 extern inline void ccunit_addTestCase (CCUnitTestFixture* fixture,
155 CCUnitTestCase* testCase);
158 * add new test case to test fixture.
159 * @ingroup WritingTestFixture
161 * @param fixture test fixture.
162 * @param name test case name.
163 * @param desc test case description.
164 * @param runTest run test function.
165 * @return new test case
167 extern CCUnitTestCase* ccunit_addNewTestCase (CCUnitTestFixture* fixture,
173 * Runs the bare test sequence.
175 * @param testFixture test fixture to run.
176 * @param runTest test run function.
177 * @throws _ccunit_runResult_env by longjmp.
179 extern void ccunit_runBare (CCUnitTestFixture* testFixture, void (*runTest)());