#include <ccunit/CCUnitTest.h>
#include <ccunit/CCUnitTestResult.h>
#include <ccunit/CCUnitTestCase.h>
+#include <ccunit/CCUnitTestFixture.h>
/**
* run test cases exception.
*/
jmp_buf _ccunit_runTest_env;
-/**
- * Runs a TestCase.
- *
- * @param result result container.
- * @param testCase test case to be run.
- */
extern void _ccunit_runTestCase (CCUnitTestResult* result,
CCUnitTestCase* testCase);
+inline void ccunit_addTestFixture (CCUnitTestCase* testCase,
+ CCUnitTestFixture* fixture)
+{
+ ccunit_addList (&testCase->fixtures, fixture);
+}
+
/**
* Runs the test case and collects the results in CCUnitTestResult.
* @param test A test to run.
testCase = (CCUnitTestCase*)test;
safe_free ((char*)testCase->name);
safe_free ((char*)testCase->desc);
+ ccunit_deleteList (&testCase->fixtures,
+ (void (*)(void*))ccunit_deleteTestFixture);
}
CCUnitTestCase* ccunit_newTestCase (const char* name,
const char* desc,
- void (*runTest)(),
void (*setUp)(),
void (*tearDown)())
{
ccunit_initTest (&testCase->test, ccunitTypeCase, run, destroy);
testCase->name = safe_strdup (name);
testCase->desc = safe_strdup (desc);
- testCase->runTest = runTest;
+ ccunit_initList (&testCase->fixtures);
testCase->setUp = setUp;
testCase->tearDown = tearDown;
return testCase;
}
-void ccunit_runBare (CCUnitTestCase* testCase)
+void ccunit_runBare (CCUnitTestCase* testCase, void (*runTest) ())
{
- int r;
- assert (testCase->runTest != NULL);
+ int failure;
assert (testCase->test.type == ccunitTypeCase);
if (testCase->setUp)
testCase->setUp ();
- if ((r = setjmp (_ccunit_runTest_env)) == 0)
- testCase->runTest ();
+ if ((failure = setjmp (_ccunit_runTest_env)) == 0)
+ {
+ runTest ();
+ }
if (testCase->tearDown)
testCase->tearDown ();
- if (r != 0)
- longjmp (_ccunit_run_env, r);
+ if (failure != 0)
+ longjmp (_ccunit_run_env, failure);
}
#include <ccunit/CCUnitConfig.h>
#include <ccunit/CCUnitList.h>
#include <ccunit/CCUnitTest.h>
+#include <ccunit/CCUnitTestFixture.h>
/**
* A test case defines the fixture to run multiple tests. To define a
CCUnitTest test; /**< super class */
const char* name; /**< test case name */
const char* desc; /**< test description */
- void (*runTest) (); /**< runTest function */
+ CCUnitList fixtures; /**< test fixtures */
void (*setUp) (); /**< setUp function */
void (*tearDown) (); /**< tearDown function */
} CCUnitTestCase;
*
* @param name test case name.
* @param desc test case description.
- * @param runTest runTest function.
* @param setUp test fixture setUp function.
* @param tearDown test fixture tearDown function.
* @return new test case.
*/
extern CCUnitTestCase* ccunit_newTestCase (const char* name,
const char* desc,
- void (*runTest)(),
void (*setUp)(),
void (*tearDown)());
+struct CCUnitTestFixture;
+
+/**
+ * add test fixture
+ * @param testCase test case.
+ * @param fixture test fixture
+ */
+extern inline void ccunit_addTestFixture (CCUnitTestCase* testCase,
+ CCUnitTestFixture* fixture);
+
/**
* Runs the bare test sequence.
* @param testCase test case to run.
+ * @param runTest test run function.
* @throws _ccunit_runResult_env by longjmp.
*/
-extern void ccunit_runBare (CCUnitTestCase* testCase);
+extern void ccunit_runBare (CCUnitTestCase* testCase, void (*runTest)());
#endif