OSDN Git Service

TestFixture was separated from TestCase.
authortsutsumi <>
Thu, 11 Sep 2003 01:54:16 +0000 (01:54 +0000)
committertsutsumi <>
Thu, 11 Sep 2003 01:54:16 +0000 (01:54 +0000)
src/ccunit/CCUnitTestCase.c
src/ccunit/CCUnitTestCase.h

index ee6a0ca..6b26a7d 100755 (executable)
@@ -32,6 +32,7 @@
 #include <ccunit/CCUnitTest.h>
 #include <ccunit/CCUnitTestResult.h>
 #include <ccunit/CCUnitTestCase.h>
+#include <ccunit/CCUnitTestFixture.h>
 
 /**
  * run test cases exception.
@@ -43,15 +44,15 @@ jmp_buf _ccunit_run_env;
  */
 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.
@@ -74,11 +75,12 @@ static void destroy (CCUnitTest* test)
   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)())
 {
@@ -86,23 +88,24 @@ CCUnitTestCase* ccunit_newTestCase (const char* name,
   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);
 }
index a30b06b..ca68c18 100755 (executable)
@@ -32,6 +32,7 @@
 #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
@@ -94,7 +95,7 @@ typedef struct CCUnitTestCase
   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;
@@ -104,22 +105,31 @@ typedef struct 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