/*
* $Id$
*/
-
-/**
- * @file
- * implements Test case class.
+/**@file
+ * TestCase module implementation.
*/
-#include <stdlib.h>
-#include <assert.h>
-#include <setjmp.h>
-#include <ccunit/CCUnitTest.h>
-#include <ccunit/CCUnitTestResult.h>
-#include <ccunit/CCUnitTestCase.h>
-
-jmp_buf ccunit_runTestCase_env_;
-
-static ccunit_testdtor_t super_func_dtor;
-
-static void destroyTestFunc (CCUnitTest* test)
-{
- assert (test->type == ccunitTypeFunc);
- safe_free ((char*)((CCUnitTestFunc*)test)->desc);
- super_func_dtor (test);
-}
-
-static CCUnitTestFunc* newTestFunc (const char* name,
- void (*testFunc)(),
- const char* desc)
-{
- CCUnitTestFunc* func = calloc (1, sizeof (*func));
- ccunit_initTest (&func->test, name);
- func->test.type = ccunitTypeFunc;
- super_func_dtor = func->test.dtor_;
- func->test.dtor_ = destroyTestFunc;
- func->testFunc = testFunc;
- func->desc = safe_strdup (desc);
- return func;
-}
-
-static ccunit_testdtor_t super_dtor;
+#include <CCUnit/CCUnitTestCase.h>
-static void dtor (CCUnitTest* test)
-{
- assert (test->type == ccunitTypeCase);
- ccunit_deleteList (&((CCUnitTestCase*)test)->testFuncs,
- (void (*)(void*))ccunit_deleteTest);
- super_dtor (test);
-}
-
-static void run (CCUnitTest* test, CCUnitTestResult* result)
-{
- assert (test->type == ccunitTypeCase);
- ccunit_runResult (result, (struct CCUnitTestCase*)test);
-}
+/**
+ * @addtogroup CCUnitTestCase
+ * @{
+ */
-struct CCUnitTestCase* ccunit_newTestCase (const char* name,
- void (*setUp)(),
- void (*tearDown)())
+CCUnitTestCase* ccunit_newTestCase (const char* name,
+ const char* desc,
+ void (*runTest)())
{
CCUnitTestCase* testCase = calloc (1, sizeof (*testCase));
- ccunit_initTest (&testCase->test, name);
- testCase->test.type = ccunitTypeCase;
- testCase->test.run = run;
- super_dtor = testCase->test.dtor_;
- testCase->test.dtor_ = dtor;
- ccunit_initList (&testCase->testFuncs);
- testCase->setUp = setUp;
- testCase->tearDown = tearDown;
+ if (!testCase)
+ return NULL;
+ testCase->name = safe_strdup (name);
+ testCase->desc = !desc ? safe_strdup (name) : strdup (desc);
+ testCase->runTest = runTest;
return testCase;
}
-void ccunit_addTestFunc (CCUnitTestCase* testCase,
- const char* name,
- void (*testFunc)(),
- const char* desc)
+void ccunit_deleteTestCase (CCUnitTestCase* testCase)
{
- CCUnitTestFunc* func = newTestFunc (name, testFunc, desc);
- ccunit_addList (&testCase->testFuncs, func);
+ if (!testCase)
+ return;
+ safe_free ((char*)testCase->name);
+ safe_free ((char*)testCase->desc);
+ free (testCase);
}
-void ccunit_runTestCase (CCUnitTestCase* testCase, CCUnitTestFunc* func)
-{
- extern jmp_buf ccunit_runResult_env_;
- int r;
- assert (testCase->test.type == ccunitTypeCase);
- if (testCase->setUp)
- testCase->setUp ();
- if ((r = setjmp (ccunit_runTestCase_env_)) == 0)
- {
- if (func->testFunc)
- {
- func->testFunc ();
- }
- }
- if (testCase->tearDown)
- testCase->tearDown ();
- if (r != 0)
- longjmp (ccunit_runResult_env_, r);
-}
+/** @} */