OSDN Git Service

rename CCUnitTestFixture to CCUnitTestCase and CCUnitTestCase to CCUnitTestFunc
authortsntsumi <tsntsumi@users.sourceforge.jp>
Fri, 20 Aug 2010 07:55:11 +0000 (07:55 +0000)
committertsntsumi <tsntsumi@users.sourceforge.jp>
Fri, 20 Aug 2010 07:55:11 +0000 (07:55 +0000)
When the test function is registered, I tried to change the
registration classification by its name.

src/ccunit/CCUnitMakeSuite.h
src/ccunit/CCUnitPrintSuite.c
src/ccunit/CCUnitReadSuite.c
src/ccunit/CCUnitTestCase.c
src/ccunit/CCUnitTestSuite.c

index 62fa88c..0ec560b 100644 (file)
@@ -1,4 +1,4 @@
-/* -*- C -*- */
+/* -*- C; coding:euc-jp -*- */
 /* Copyright (C) 2003, 2010 TSUTSUMI Kikuo.
    This file is part of the CCUnit Library.
 
  * @~
  *
  * @code
- * SOURCEFILE ::= [SUITE]... | FIXTURE...
+ * SOURCEFILE ::= [SUITE]... | TESTCASE...
  *
  * SUITE ::= SUITE_HEADER
  *           [ any-C-code ]...
- *           FIXTURE...
+ *           TESTCASE...
  *           SUITE_END
  *
  * SUITE_HEADER ::= JAVADOC_COMMENT_BEGIN 'test suite:' SUITE_NAME COMMENT_END
  * SUITE_END ::= JAVADOC_COMMENT_BEGIN 'end test suite' wsp string COMMENT_END
  *
- * FIXTURE ::= FIXTURE_HEADER
- *             [FIXTURE_CODE]...
+ * TESTCASE ::= TESTCASE_HEADER
+ *             [TESTCASE_CODE]...
  *             [SETUP_SETUP_FUNC]
  *             [SETUP_TEARDOWN_FUNC]
  *             [SETUP_FUNC]
  *             [TEARDOWN_FUNC]
- *             [TESTCASE]...
- *             FIXTURE_END
+ *             [TESTFUNC]...
+ *             TESTCASE_END
  *
- * FIXTURE_HEADER ::= JAVADOC_COMMENT_BEGIN
- *                    'test case:' TESTFIXTURE_NAME
+ * TESTCASE_HEADER ::= JAVADOC_COMMENT_BEGIN
+ *                    'test case:' TESTCASE_NAME
  *                    COMMENT_END
- * FIXTURE_CODE ::= any C language codes.
+ * TESTCASE_CODE ::= any C language codes.
  *
  * SETUP_SETUP_FUNC ::= [ FUNC_DESC ]
  *                     ['static'] 'void setup_setUp'[A-Za-z0-9_]* '()'
@@ -88,9 +88,9 @@
  *                  ['static'] 'void tearDown'[A-Za-z0-9_]* '()'
  *                  FUNC_BODY
  *
- * TESTCASE ::= [ FUNC_DESC ] 'void test'[A-Za-z0-9_]* '()' FUNC_BODY
+ * TESTFUNC ::= [ FUNC_DESC ] 'void test'[A-Za-z0-9_]* '()' FUNC_BODY
  *
- * FIXTURE_END ::= JAVADOC_COMMENT_BEGIN 'end test case' wsp string COMMENT_END
+ * TESTCASE_END ::= JAVADOC_COMMENT_BEGIN 'end test case' wsp string COMMENT_END
  *
  * FUNC_DESC ::= JAVADOC_COMMENT_BEGIN string COMMENT_END
  *
@@ -155,13 +155,13 @@ extern inline void ccunit_deleteTestSuiteDef (_CCUnitTestSuiteDef* suite);
 /** @} */
 
 /**
- * @defgroup CCUnitTestCaseDef _TestCaseDef
- * Test case definition.
+ * @defgroup CCUnitTestFuncDef _TestFuncDef
+ * Test func definition.
  * @{
  */
 
 /**
- * Test case definition information.
+ * Test func definition information.
  */
 typedef struct _CCUnitFuncDef
 {
@@ -174,32 +174,28 @@ typedef struct _CCUnitFuncDef
 /** @} */
 
 /**
- * @defgroup CCUnitTestFixtureDef _TestFixtureDef
- * Test fixture definition.
+ * @defgroup CCUnitTestCaseDef _TestCaseDef
+ * Test case definition.
  * @{
  */
 
 /**
- * Test fixture definition information.
+ * Test case definition information.
  */
-typedef struct _CCUnitTestFixtureDef
+typedef struct _CCUnitTestCaseDef
 {
   _CCUnitTestDef testdef;                      /**< super class */
   _CCUnitFuncDef* ctor;                                /**< constructor */
   _CCUnitFuncDef* dtor;                                /**< destructor */
-  _CCUnitFuncDef* setup_setUp;                 /**< fixture setup function */
-  _CCUnitFuncDef* setup_tearDown;              /**< fixture tearDown function */
-  _CCUnitFuncDef* setUp;                       /**< test setup function */
-  _CCUnitFuncDef* tearDown;                    /**< test tearDown function */
-  CCUnitList testCases;                                /**< test case list */
-} _CCUnitTestFixtureDef;
+  CCUnitList testFuncs;                                /**< test func list */
+} _CCUnitTestCaseDef;
 
 /** @} */
 
 /**
  * @ingroup CCUnitMakeSuite
  * @defgroup CCUnitReadSuite _ReadSuite
- * Read test case definitions from test source code.
+ * Read test func definitions from test source code.
  * @{
  */
 
@@ -245,7 +241,7 @@ extern void ccunit_printSuite (FILE* ofp,
 
 /**
  * @english
- * Generate a code to creating test suite code from the test case
+ * Generate a code to creating test suite code from the test func
  * source codes.
  * @japanese
  * ¥Æ¥¹¥È¥±¡¼¥¹¤Î¥½¡¼¥¹¥³¡¼¥É¤«¤é¡¢¥Æ¥¹¥È¥¹¡¼¥Ä¤òºîÀ®¤¹¤ë¥³¡¼¥É¤òÀ¸À®¤¹¤ë¡£
@@ -286,7 +282,7 @@ extern void ccunit_printSuite (FILE* ofp,
 extern int ccunit_makeSuite (int ac, char** av);
 
 /**
- * Generate a code to creating test suite code from the test case
+ * Generate a code to creating test suite code from the test func
  * source codes. 
  * @param prg program name
  * @param ... arguments. The last arg must be NULL.
index af2056a..18a72b4 100644 (file)
@@ -40,8 +40,7 @@
 static const char* ccunitTypeNames[] = {
   "ccunitTypeTest",                            /**< Test class */
   "ccunitTypeSuite",                           /**< TestSuite class */
-  "ccunitTypeFixture",                         /**< TestFixture class */
-  "ccunitTypeCase",                            /**< TestCase class */
+  "ccunitTypeTestCase",                                /**< TestCase class */
 };
 
 /**
@@ -62,7 +61,7 @@ static void printPrototype (FILE* ofp, const char* type, _CCUnitFuncDef* fdef)
 }
 
 /**
- * print test suite/fixture prototypes.
+ * print test suite/test case prototypes.
  *
  * @param ofp output stream.
  * @param suitedef test suite object to print.
@@ -76,27 +75,19 @@ static void printPrototypes (FILE* ofp, _CCUnitTestSuiteDef* suitedef)
     {
       if (testdef->type == ccunitTypeSuite)
        printPrototypes (ofp, (_CCUnitTestSuiteDef*)testdef);
-      else if (testdef->type == ccunitTypeFixture)
+      else if (testdef->type == ccunitTypeTestCase)
        {
-         _CCUnitTestFixtureDef* fdef = (_CCUnitTestFixtureDef*)testdef;
-         ccunit_log ("fixturdef: %s", fdef->testdef.name);
-         if (fdef->testdef.name)
-           fprintf (ofp, "/* test fixture: %s */\n", fdef->testdef.name);
-         if (fdef->setup_setUp)
-           printPrototype (ofp, "setup_setUp", fdef->setup_setUp);
-         if (fdef->setup_tearDown)
-           printPrototype (ofp, "setup_tearDown", fdef->setup_tearDown);
-         if (fdef->setUp)
-           printPrototype (ofp, "setUp", fdef->setUp);
-         if (fdef->tearDown)
-           printPrototype (ofp, "tearDown", fdef->tearDown);
-         /* print testCase prototypes */
+         _CCUnitTestCaseDef* tcdef = (_CCUnitTestCaseDef*)testdef;
+         ccunit_log ("tcdef: %s", tcdef->testdef.name);
+         if (tcdef->testdef.name)
+           fprintf (ofp, "/* test case: %s */\n", tcdef->testdef.name);
+         /* print testFunc prototypes */
          {
            CCUnitListIterator fitor;
-           _CCUnitFuncDef* casedef;
-           ccunit_initListIterator (&fdef->testCases, &fitor);
-           while ((casedef = ccunit_nextListIterator (&fitor)) != NULL)
-             printPrototype (ofp, "testCase", casedef);
+           _CCUnitFuncDef* funcdef;
+           ccunit_initListIterator (&tcdef->testFuncs, &fitor);
+           while ((funcdef = ccunit_nextListIterator (&fitor)) != NULL)
+             printPrototype (ofp, "testFunc", funcdef);
          }
        }
     }
@@ -121,24 +112,24 @@ static inline void printTestFunc (FILE* ofp,
 }
 
 /**
- * print test fixture adding function.
+ * print test case adding function.
  *
  * @param ofp output stream.
- * @param fxdef test suite to print.
+ * @param tcdef test case to print.
  */
-static void printFixture  (FILE* ofp, _CCUnitTestFixtureDef* fxdef)
+static void printTestCase  (FILE* ofp, _CCUnitTestCaseDef* tcdef)
 {
   static int fxid = 0;
   CCUnitListIterator fnitor;
   _CCUnitFuncDef* fndef;
-  if (!fxdef->testdef.idname)
+  if (!tcdef->testdef.idname)
     {
-      fxdef->testdef.idname = calloc (1, 8);
+      tcdef->testdef.idname = calloc (1, 8);
       fxid ++;
-      sprintf (fxdef->testdef.idname, "fx_%03d", fxid);
+      sprintf (tcdef->testdef.idname, "fx_%03d", fxid);
     }
-  fprintf (ofp, "static CCUnitTestFunc %s_cases[] = {\n", fxdef->testdef.idname);
-  ccunit_initListIterator (&fxdef->testCases, &fnitor);
+  fprintf (ofp, "static CCUnitTestFunc %s_cases[] = {\n", tcdef->testdef.idname);
+  ccunit_initListIterator (&tcdef->testFuncs, &fnitor);
   while ((fndef = ccunit_nextListIterator (&fnitor)) != NULL)
     {
       printTestFunc (ofp, fndef);
@@ -146,17 +137,13 @@ static void printFixture  (FILE* ofp, _CCUnitTestFixtureDef* fxdef)
   printTestFunc (ofp, NULL);
   fputs ("};\n\n", ofp);
   fprintf (ofp,
-          "static CCUnitTestFixtureDfn %s = {\n"
+          "static CCUnitTestCaseDfn %s = {\n"
           "  { %s },\n"
           "  \"%s\",\n",
-          fxdef->testdef.idname,
-          ccunitTypeNames[fxdef->testdef.type],
-          !fxdef->testdef.name ? "NULL" : fxdef->testdef.name);
-  printTestFunc (ofp, fxdef->setup_setUp);
-  printTestFunc (ofp, fxdef->setup_tearDown);
-  printTestFunc (ofp, fxdef->setUp);
-  printTestFunc (ofp, fxdef->tearDown);
-  fprintf (ofp, "  %s_cases,\n", fxdef->testdef.idname);
+          tcdef->testdef.idname,
+          ccunitTypeNames[tcdef->testdef.type],
+          !tcdef->testdef.name ? "NULL" : tcdef->testdef.name);
+  fprintf (ofp, "  %s_cases,\n", tcdef->testdef.idname);
   fputs ("};\n\n", ofp);
 }
 
@@ -183,8 +170,8 @@ static void printSuite (FILE* ofp, const char* name, _CCUnitTestSuiteDef* suite)
     {
       if (testdef->type == ccunitTypeSuite)
        printSuite (ofp, testdef->name, (_CCUnitTestSuiteDef*)testdef);
-      else if (testdef->type == ccunitTypeFixture)
-       printFixture (ofp, (_CCUnitTestFixtureDef*)testdef);
+      else if (testdef->type == ccunitTypeTestCase)
+       printTestCase (ofp, (_CCUnitTestCaseDef*)testdef);
       else
        ;
     }
@@ -214,8 +201,8 @@ void ccunit_printSuite (FILE* ofp, const char* name, _CCUnitTestSuiteDef* suite)
 {
   fprintf (ofp,
           "#include <ccunit/CCUnitTestSuite.h>\n"
-          "#include <ccunit/CCUnitTestFixture.h>\n"
           "#include <ccunit/CCUnitTestCase.h>\n"
+          "#include <ccunit/CCUnitTestFunc.h>\n"
           "\n");
   printPrototypes (ofp, suite);
   printSuite (ofp, NULL, suite);
index dd44b4a..65efab8 100644 (file)
@@ -143,14 +143,14 @@ static inline _CCUnitTestDef* addTestSuiteDef (_CCUnitTestSuiteDef* suite,
 }
 
 /**
- * add test fixture to test suite.
+ * add test case to test suite.
  *
  * @param suite test suite to add.
- * @param test test fixture.
+ * @param test test case.
  * @return added test.
  */
-static inline _CCUnitTestDef* addTestFixtureDef (_CCUnitTestSuiteDef* suite,
-                                                _CCUnitTestFixtureDef* test)
+static inline _CCUnitTestDef* addTestCaseDef (_CCUnitTestSuiteDef* suite,
+                                                _CCUnitTestCaseDef* test)
 {
   const char* name;
   if (!suite || !test)
@@ -158,18 +158,18 @@ static inline _CCUnitTestDef* addTestFixtureDef (_CCUnitTestSuiteDef* suite,
   name = test->testdef.name;
   if (!name)
     name = "";
-  ccunit_log ("add test fixture: %s", name);
+  ccunit_log ("add test case: %s", name);
   return addTestDef (suite, &test->testdef);
 }
 
 /**
- * create new test case.
+ * create new test func.
  *
  * @param scope scope.
- * @param type return type of case.
- * @param name case name.
+ * @param type return type of func.
+ * @param name func name.
  * @param desc description.
- * @return new test case def.
+ * @return new test func def.
  */
 static _CCUnitFuncDef* newFuncDef (const char* scope,
                                   const char* type,
@@ -203,32 +203,30 @@ static void deleteFuncDef (_CCUnitFuncDef* func)
 }
 
 /**
- * destroy test fixture def.
- * @param fixture test fixture def to destroy.
+ * destroy test case def.
+ * @param testCase test case def to destroy.
  */
-static void destroyTestFixtureDef (_CCUnitTestFixtureDef* fixture)
+static void destroyTestCaseDef (_CCUnitTestCaseDef* testCase)
 {
-  ccunit_deleteList (&fixture->testCases, (void(*)(void*))deleteFuncDef);
-  deleteFuncDef (fixture->setUp);
-  deleteFuncDef (fixture->tearDown);
-  destroyTestDef (&fixture->testdef);
+  ccunit_deleteList (&testCase->testFuncs, (void(*)(void*))deleteFuncDef);
+  destroyTestDef (&testCase->testdef);
 }
 
 /**
- * create new test fixture def.
+ * create new test case def.
  *
- * @param name test fixture name.
+ * @param name test case name.
  */
-static _CCUnitTestFixtureDef* newTestFixtureDef (const char* name)
+static _CCUnitTestCaseDef* newTestCaseDef (const char* name)
 {
-  _CCUnitTestFixtureDef* fixture = calloc (1, sizeof (*fixture));
-  ccunit_log ("create new test fixture: %s", name);
-  if (!fixture)
+  _CCUnitTestCaseDef* testCase = calloc (1, sizeof (*testCase));
+  ccunit_log ("create new test case: %s", name);
+  if (!testCase)
     return NULL;
-  initTestDef (&fixture->testdef, ccunitTypeFixture, name);
-  fixture->testdef.dtor = (void(*)(_CCUnitTestDef*))destroyTestFixtureDef;
-  ccunit_initList (&fixture->testCases);
-  return fixture;
+  initTestDef (&testCase->testdef, ccunitTypeTestCase, name);
+  testCase->testdef.dtor = (void(*)(_CCUnitTestDef*))destroyTestCaseDef;
+  ccunit_initList (&testCase->testFuncs);
+  return testCase;
 }
 
 /**
@@ -257,7 +255,7 @@ static struct _CCUnitLine line;
 
 /**
  * Get one line from stream.
- * This case copies a read line on the global variable <code>line</code>.
+ * This func copies a read line on the global variable <code>line</code>.
  *
  * @return When reading succeeds, value except for the zero is
  * returned. When an error occurs, a zero is returned.
@@ -443,7 +441,7 @@ static char* readDocComment ()
 }
 
 static const char* testTypeStr[] = {
-  "fixture", "suite"
+  "case", "suite"
 };
 
 /**
@@ -522,21 +520,21 @@ getEndOfTest (CCUnitTestType_t type, const char* str)
 }
 
 /**
- * read test casedef.
+ * read test funcdef.
  *
  * @param type required type string.
- * @param prefix required case name prefix.
+ * @param prefix required func name prefix.
  * @param desc description.
  * @return funcdef object.
  */
-static _CCUnitFuncDef* readTestCase (const char* type,
+static _CCUnitFuncDef* readTestFunc (const char* type,
                                    const char* prefix,
                                    const char* desc)
 {
   const char* scope = "static";
   char* typ;
   char* name;
-  ccunit_dbg ("read case: %s %s... from '%s'", type, prefix, line.str);
+  ccunit_dbg ("read func: %s %s... from '%s'", type, prefix, line.str);
   for (typ = line.str; *typ; typ ++)
     if (!isspace (*typ))
       break;
@@ -607,86 +605,68 @@ static _CCUnitFuncDef* readTestCase (const char* type,
 }
 
 /**
- * set fixture function.
- * @param fpp fixture function adderss.
- * @param fp fixture function to set.
- */
-static void setFixtureFunc (_CCUnitFuncDef** fpp, _CCUnitFuncDef* fp)
-{
-  if (!*fpp)
-    *fpp = fp;
-  else
-    {
-      ccunit_err ("%s:%lu: %s definition is conflicted... ignore.\n"
-                 "    previous definition is %s\n",
-                 line.fname, line.lno, fp->name, (*fpp)->name);
-      deleteFuncDef (fp);
-    }
-}
-
-/**
- * read test fixture function.
+ * read test case function.
  *
  * @param suite parent suite.
- * @param cname test fixture name to read.
+ * @param cname test case name to read.
  */
-static void readTestFixture (_CCUnitTestSuiteDef* suite, const char* cname)
+static void readTestCase (_CCUnitTestSuiteDef* suite, const char* cname)
 {
-  _CCUnitTestFixtureDef* fixture;
+  _CCUnitTestCaseDef* testCase;
   _CCUnitFuncDef* f = NULL;
   const char* name;
   char* doc;
   char* desc = NULL;
   if (!suite)
     return;
-  fixture = newTestFixtureDef (cname);
-  if (!fixture)
+  testCase = newTestCaseDef (cname);
+  if (!testCase)
     return;
-  addTestFixtureDef (suite, fixture);
+  addTestCaseDef (suite, testCase);
   while (readline ())
     {
       /* setUp function def */
-      if ((f = readTestCase ("void", "setUp", desc)) != NULL)
+      if ((f = readTestFunc ("void", "setUp", desc)) != NULL)
        {
-         setFixtureFunc (&fixture->setUp, f);
+         ccunit_addList (&testCase->testFuncs, f);
          safe_free (desc);
        }
       /* tearDown function def */
-      else if ((f = readTestCase ("void", "tearDown", desc)) != NULL)
+      else if ((f = readTestFunc ("void", "tearDown", desc)) != NULL)
        {
-         setFixtureFunc (&fixture->tearDown, f);
+         ccunit_addList (&testCase->testFuncs, f);
          safe_free (desc);
        }
       /* setup_setUp function def */
-      else if ((f = readTestCase ("void", "setup_setUp", desc)) != NULL)
+      else if ((f = readTestFunc ("void", "setup_setUp", desc)) != NULL)
        {
-         setFixtureFunc (&fixture->setup_setUp, f);
+         ccunit_addList (&testCase->testFuncs, f);
          safe_free (desc);
        }
       /* setup_tearDown function def */
-      else if ((f = readTestCase ("void", "setup_tearDown", desc)) != NULL)
+      else if ((f = readTestFunc ("void", "setup_tearDown", desc)) != NULL)
        {
-         setFixtureFunc (&fixture->setup_tearDown, f);
+         ccunit_addList (&testCase->testFuncs, f);
          safe_free (desc);
        }
-      /* if test case function def, then read as test case. */
-      else if ((f = readTestCase ("void", "test", desc)) != NULL)
+      /* if test case function def, then read as test func. */
+      else if ((f = readTestFunc ("void", "test", desc)) != NULL)
        {
-         ccunit_addList (&fixture->testCases, f);
+         ccunit_addList (&testCase->testFuncs, f);
          safe_free (desc);
        }
       /* if current line is javaDoc comment, then read as description. */
       else if ((doc = readDocComment ()) != NULL)
        {
-         if ((name = getTestName (ccunitTypeFixture, doc)) != NULL)
+         if ((name = getTestName (ccunitTypeTestCase, doc)) != NULL)
            {
-             readTestFixture (suite, name);
+             readTestCase (suite, name);
              safe_free (doc);
            }
-         else if ((name = getEndOfTest (ccunitTypeFixture, doc))
+         else if ((name = getEndOfTest (ccunitTypeTestCase, doc))
                   != NULL)
            {
-             ccunit_log ("end test fixture: %s", fixture->testdef.name);
+             ccunit_log ("end test case: %s", testCase->testdef.name);
              safe_free (doc);
              break;
            }
@@ -716,14 +696,14 @@ static void readSuite (_CCUnitTestSuiteDef* suite)
       /* if current line is javaDoc comment, then read as description. */
       if ((doc = readDocComment ()) != NULL)
        {
-         if ((name = getTestName (ccunitTypeFixture, doc)) != NULL)
+         if ((name = getTestName (ccunitTypeTestCase, doc)) != NULL)
            {
-             readTestFixture (suite, name);
+             readTestCase (suite, name);
              safe_free (doc);
            }
-         else if ((name = getEndOfTest (ccunitTypeFixture, doc)) != NULL)
+         else if ((name = getEndOfTest (ccunitTypeTestCase, doc)) != NULL)
            {
-             ccunit_err ("%s:%lu: invalid end test fixture comment '%s'",
+             ccunit_err ("%s:%lu: invalid end test case comment '%s'",
                          line.fname, line.lno, doc);
              safe_free (doc);
            }
@@ -745,11 +725,13 @@ static void readSuite (_CCUnitTestSuiteDef* suite)
          desc = doc;
          doc = NULL;
        }
-      else if ((f = readTestCase ("void", "test", desc)) != NULL
-              || (f = readTestCase ("void", "setUp", desc)) != NULL
-              || (f = readTestCase ("void", "tearDown", desc)) != NULL)
+      else if ((f = readTestFunc ("void", "test", desc)) != NULL
+              || (f = readTestFunc ("void", "setUp", desc)) != NULL
+              || (f = readTestFunc ("void", "tearDown", desc)) != NULL
+              || (f = readTestFunc ("void", "setup_setUp", desc)) != NULL
+              || (f = readTestFunc ("void", "setup_tearDown", desc)) != NULL)
        {
-         ccunit_err ("%s:%lu: missing test fixture start comment '%s': ignored",
+         ccunit_err ("%s:%lu: missing test case start comment '%s': ignored",
                      line.fname, line.lno, line.str);
          deleteFuncDef (f);
          safe_free (desc);
@@ -768,7 +750,7 @@ void ccunit_readSuite (const char* fname, _CCUnitTestSuiteDef* suite)
   if (strcmp (fname, "-") == 0) /* special file name '-' as stdin  */
     {
       line.ifp = stdin;
-      line.fname = "stdin";
+      line.fname = "(stdin)";
     }
   else
     {
index 80f02a4..546a6ec 100755 (executable)
 /*
  * $Id$
  */
-/**@file
+
+/**
+ * @file
  * TestCase module implementation.
  */
 
 #include <ccunit/CCUnitTestCase.h>
+#include <ccunit/CCUnitTestResult.h>
+#include <assert.h>
+#include <setjmp.h>
+
+/**
+ * run tests exception environment.
+ */
+jmp_buf _ccunit_runTest_env;
 
 /**
- * @addtogroup CCUnitTestCase
- * @{
+ * run tests exception.
  */
+CCUnitTestFailure* _ccunit_testFailure;
+
+extern void _ccunit_startTest (CCUnitTestResult* result,
+                              CCUnitTestFunc* test);
+extern void _ccunit_endTest (CCUnitTestResult* result,
+                            CCUnitTestFunc* test);
 
-CCUnitTestCase* ccunit_newTestCase (const char* name,
-                                   const char* desc,
-                                   void (*runTest)())
+void ccunit_addTestFunc (CCUnitTestCase* testCase, CCUnitTestFunc* f)
 {
-  CCUnitTestCase* testCase = calloc (1, sizeof (*testCase));
+  static const char* ssu = "setup_setUp";
+  static const char* std = "setup_tearDown";
+  static const char* su = "setUp";
+  static const char* td = "tearDown";
+  static const char* ts = "test";
+  if (strncmp (f->name, ts, strlen (ts)) == 0)
+    ccunit_addList (&testCase->testFuncs, f);
+  else if (strncmp (f->name, ssu, strlen (ssu)) == 0)
+    {
+      if (testCase->setup_setUp)
+       ccunit_deleteTestFunc (testCase->setup_setUp);
+      testCase->setup_setUp = f;
+    }
+  else if (strncmp (f->name, std, strlen (std)) == 0)
+    {
+      if (testCase->setup_tearDown)
+       ccunit_deleteTestFunc (testCase->setup_tearDown);
+      testCase->setup_tearDown = f;
+    }
+  else if (strncmp (f->name, su, strlen (su)) == 0)
+    {
+      if (testCase->setUp)
+       ccunit_deleteTestFunc (testCase->setUp);
+      testCase->setUp = f;
+    }
+  else if (strncmp (f->name, td, strlen (td)) == 0)
+    {
+      if (testCase->tearDown)
+       ccunit_deleteTestFunc (testCase->tearDown);
+      testCase->tearDown = f;
+    }
+  else
+    ccunit_addList (&testCase->testFuncs, f);
+}
+
+CCUnitTestFunc* ccunit_addNewTestFunc (CCUnitTestCase* testCase,
+                                      const char* name,
+                                      const char* desc,
+                                      void (*runTest)())
+{
+  CCUnitTestFunc* f;
   if (!testCase)
     return NULL;
-  testCase->name = safe_strdup (name);
-  testCase->desc = !desc ? safe_strdup (name) : strdup (desc);
-  testCase->runTest = runTest;
-  return testCase;
+  f = ccunit_newTestFunc (name, desc, runTest);
+  if (!f)
+    return NULL;
+  ccunit_addTestFunc (testCase, f);
+  return f;
 }
 
-inline CCUnitTestFunc* ccunit_newTestFunc (const char* name,
-                                          const char* desc,
-                                          void (*func)())
+/**
+ * Runs the bare test sequence.
+ *
+ * @return failure
+ */
+static CCUnitTestFailure* runTest (CCUnitTestFunc* testFunc,
+                                  CCUnitTestFunc* setUp,
+                                  CCUnitTestFunc* tearDown,
+                                  CCUnitTestResult* result)
 {
-  return (CCUnitTestFunc*) ccunit_newTestCase (name, desc, func);
+  CCUnitTestFailure* runFailure = NULL;
+  _ccunit_testFailure = NULL;
+  if (setUp && setUp->runTest)
+    {
+      if (setjmp (_ccunit_runTest_env) == 0)
+       setUp->runTest ();
+      else
+       {
+         _ccunit_testFailure->testFunc = setUp;
+         ccunit_addFailure (result, _ccunit_testFailure);
+       }
+    }
+  if (_ccunit_testFailure)
+    ;
+  else if (setjmp (_ccunit_runTest_env) == 0)
+    {
+      result->runCount ++;
+      testFunc->runTest ();
+    }
+  else
+    {
+      runFailure = _ccunit_testFailure;
+      runFailure->testFunc = testFunc;
+      _ccunit_testFailure = NULL;
+    }
+  if (tearDown && tearDown->runTest)
+    {
+      if (setjmp (_ccunit_runTest_env) == 0)
+       tearDown->runTest ();
+      else
+       {
+         _ccunit_testFailure->testFunc = tearDown;
+         ccunit_addFailure (result, _ccunit_testFailure);
+       }
+    }
+  return runFailure;
 }
 
-void ccunit_deleteTestCase (CCUnitTestCase* testCase)
+/**
+ * Runs the test case and collects the results in CCUnitTestResult.
+ * @param test A test to run.
+ * @param result A result container.
+ */
+static void run (CCUnitTest* test, CCUnitTestResult* result)
 {
-  if (!testCase)
-    return;
+  CCUnitTestCase* testCase = (CCUnitTestCase*)test;
+  CCUnitListIterator itor;
+  CCUnitTestFunc* testFunc;
+  assert (test->type == ccunitTypeTestCase);
+  _ccunit_testFailure = NULL;
+  if (testCase->setup_setUp && testCase->setup_setUp->runTest)
+    {
+      if (setjmp (_ccunit_runTest_env) == 0)
+       testCase->setup_setUp->runTest ();
+      else
+       {
+         _ccunit_testFailure->testFunc = testCase->setup_setUp;
+         ccunit_addFailure (result, _ccunit_testFailure);
+       }
+    }
+  if (!_ccunit_testFailure)
+    {
+      ccunit_initListIterator (&testCase->testFuncs, &itor);
+      while ((testFunc = ccunit_nextListIterator (&itor)) != NULL)
+       {
+         CCUnitTestFailure* failure;
+         _ccunit_startTest (result, testFunc);
+         failure = runTest (testFunc, testCase->setUp, testCase->tearDown, result);
+         if (failure)
+           ccunit_addFailure (result, failure);
+         _ccunit_endTest (result, testFunc);
+       }
+    }
+  if (testCase->setup_tearDown && testCase->setup_tearDown->runTest)
+    {
+      if (setjmp (_ccunit_runTest_env) == 0)
+       testCase->setup_tearDown->runTest ();
+      else
+       {
+         _ccunit_testFailure->testFunc = testCase->setup_tearDown;
+         ccunit_addFailure (result, _ccunit_testFailure);
+       }
+    }
+}
+
+/**
+ * Destruct test case.
+ * @param test destruct test.
+ */
+static void destroy (CCUnitTest* test)
+{
+  CCUnitTestCase* testCase;
+  assert (test->type == ccunitTypeTestCase);
+  testCase = (CCUnitTestCase*)test;
   safe_free (testCase->name);
-  safe_free (testCase->desc);
-  free (testCase);
+  ccunit_deleteTestFunc (testCase->setUp);
+  ccunit_deleteTestFunc (testCase->tearDown);
+  ccunit_deleteList (&testCase->testFuncs,
+                    (void (*)(void*))ccunit_deleteTestFunc);
 }
 
-inline void ccunit_deleteTestFunc (CCUnitTestFunc* testFunc)
+CCUnitTestCase* ccunit_newTestCase (const char* name)
 {
-  ccunit_deleteTestCase ((CCUnitTestCase*)testFunc);
+  CCUnitTestCase* testCase = calloc (1, sizeof (*testCase));
+  ccunit_initTest (&testCase->test, ccunitTypeTestCase, run, destroy);
+  testCase->name = safe_strdup (name);
+  ccunit_initList (&testCase->testFuncs);
+  return testCase;
 }
 
-/** @} */
+inline struct CCUnitTestResult* ccunit_runTestCase (CCUnitTestCase* testCase)
+{
+  CCUnitTestResult* result;
+  if (!testCase)
+    return NULL;
+  result = ccunit_newTestResult ();
+  if (!result)
+    return NULL;
+  testCase->test.run (&testCase->test, result);
+  return result;
+}
index 0df351f..7d7c67f 100755 (executable)
@@ -94,35 +94,17 @@ CCUnitTestSuite* ccunit_newTestSuiteFromDfn (const CCUnitTestSuiteDfn* sdp)
          if (sp)
            ccunit_addTestSuite (suite, sp);
        }
-      else if (tdp->type == ccunitTypeFixture)
+      else if (tdp->type == ccunitTypeTestCase)
        {
-         CCUnitTestFixtureDfn* fdp = (CCUnitTestFixtureDfn*)tdp;
-         CCUnitTestFixture* fp;
-         CCUnitTestCase* cd;
-         fp = ccunit_newTestFixture (fdp->name,
-                                     ccunit_newTestFunc (fdp->setUp.name,
-                                                         fdp->setUp.desc,
-                                                         fdp->setUp.runTest),
-                                     ccunit_newTestFunc (fdp->tearDown.name,
-                                                         fdp->tearDown.desc,
-                                                         fdp->tearDown.runTest));
-         if (fp)
+         CCUnitTestCaseDfn* cdp = (CCUnitTestCaseDfn*)tdp;
+         CCUnitTestCase* cp;
+         cp = ccunit_newTestCase (cdp->name);
+         if (cp)
            {
-             CCUnitTestFunc* ssu = ccunit_newTestFunc (fdp->setup_setUp.name,
-                                                       fdp->setup_setUp.desc,
-                                                       fdp->setup_setUp.runTest);
-             CCUnitTestFunc* std = ccunit_newTestFunc (fdp->setup_tearDown.name,
-                                                       fdp->setup_tearDown.desc,
-                                                       fdp->setup_tearDown.runTest);
-             ccunit_setTestFixtureSetup (fp, ssu, std);
-             ccunit_addTestFixture (suite, fp);
-             for (cd = (CCUnitTestCase*)fdp->testCases; cd->name; cd ++)
-               {
-                 CCUnitTestCase* cp;
-                 cp = ccunit_newTestCase (cd->name, cd->desc, cd->runTest);
-                 if (cp)
-                   ccunit_addTestCase (fp, cp);
-               }
+             CCUnitTestFunc* fp;
+             ccunit_addTestCase (suite, cp);
+             for (fp = cdp->testFuncs; fp->name; fp ++)
+               ccunit_addNewTestFunc (cp, fp->name, fp->desc, fp->runTest);
            }
        }
     }
@@ -145,10 +127,10 @@ inline void ccunit_addTestSuite (CCUnitTestSuite* suite,
   ccunit_addTest (suite, &testSuite->test);
 }
 
-inline void ccunit_addTestFixture (CCUnitTestSuite* suite,
-                                  CCUnitTestFixture* fixture)
+inline void ccunit_addTestCase (CCUnitTestSuite* suite,
+                               CCUnitTestCase* testCase)
 {
-  ccunit_addTest (suite, &fixture->test);
+  ccunit_addTest (suite, &testCase->test);
 }
 
 inline CCUnitTestResult* ccunit_runTestSuite (CCUnitTestSuite* suite,