OSDN Git Service

integrated test func to test case
authortsutsumi <>
Tue, 9 Sep 2003 15:22:20 +0000 (15:22 +0000)
committertsutsumi <>
Tue, 9 Sep 2003 15:22:20 +0000 (15:22 +0000)
src/ccunit/CCUnitReadTestDef.c

index 620d049..0031a79 100644 (file)
@@ -1,6 +1,3 @@
-/*
- * $Id$
- */
 /* Copyright (C) 2003 TSUTSUMI Kikuo.
    This file is part of the CCUnit Library.
 
@@ -19,6 +16,9 @@
    If not, write to the Free Software Foundation, Inc., 59 Temple
    Place - Suite 330, Boston, MA 02111-1307, USA.  
 */
+/*
+ * $Id$
+ */
 
 #include <ccunit/CCUnitMakeSuite.h>
 #include <ccunit/CCUnitLogMessage.h>
@@ -147,21 +147,6 @@ static CCUnitTestFuncDef* newTestFuncDef (const char* type,
 }
 
 /**
- * copy test function def.
- *
- * @param def function def.
- * @return new test function def.
- */
-static inline CCUnitTestFuncDef* copyTestFuncDef (CCUnitTestFuncDef* def)
-     __attribute__ ((unused));
-static inline CCUnitTestFuncDef* copyTestFuncDef (CCUnitTestFuncDef* def)
-{
-  if (!def)
-    return NULL;
-  return newTestFuncDef (def->type, def->name, def->desc);
-}
-
-/**
  * delete test func def.
  * @param func test func def to delete.
  */
@@ -194,6 +179,19 @@ static CCUnitTestCaseDef* newTestCaseDef (const char* name)
 }
 
 /**
+ * copy test function def.
+ *
+ * @param def function def.
+ * @return new test function def.
+ */
+static inline CCUnitTestFuncDef* copyTestFuncDef (CCUnitTestFuncDef* def)
+{
+  if (!def)
+    return NULL;
+  return newTestFuncDef (def->type, def->name, def->desc);
+}
+
+/**
  * destroy test case def.
  * @param testCase test case def to destroy.
  */
@@ -579,7 +577,6 @@ static void readTestCase (CCUnitTestSuiteDef* parent, const char* caseName)
   char* name;
   char* doc;
   char* desc = NULL;
-  addTestDef (suite, &testCase->super);
   while (readline ())
     {
       /* if current line is javaDoc comment, then read as description. */
@@ -588,7 +585,7 @@ static void readTestCase (CCUnitTestSuiteDef* parent, const char* caseName)
          if ((name = getCaseName (doc)) != NULL)
            {
              ccunit_err ("%s:%lu: unbaranced end case comment '%s', "
-                         "expects /** end case: %s */",
+                         "need /** end case: %s */",
                          line.fname, line.lno, doc, caseName);
              readTestCase (suite, name);
              safe_free (doc);
@@ -600,37 +597,59 @@ static void readTestCase (CCUnitTestSuiteDef* parent, const char* caseName)
            }
          desc = doc;
        }
-      /* if test case function def, then read as test case. */
-      else if ((f = readTestFuncDef ("void", "test", desc)) != NULL)
-       {
-         testCase->runTest = f;
-         safe_free (desc);
-       }
       /* setUp function def */
       else if ((f = readTestFuncDef ("void", "setUp", desc)) != NULL)
        {
-         if (!testCase->setUp)
+         if (!testCase)
+           setUp = f;
+         else if (!testCase->setUp)
            testCase->setUp = f;
          else
            {
-             snprintf (casename, sizeof (casename),
-                       "%s_case%03lu", suite->super.name, (unsigned long)caseid);
-             caseid ++;
-             readTestCaseDef (suite, casename, NULL, f, NULL);
+             ccunit_err ("%s:%lu: multiply setUp function defined. %s\n"
+                         "    perhaps missing /** test case: ... */",
+                         line.fname, line.lno, line.str);
+             deleteTestFuncDef (f);
+             f = NULL;
            }
          safe_free (desc);
        }
       /* tearDown function def */
       else if ((f = readTestFuncDef ("void", "tearDown", desc)) != NULL)
        {
-         if (!testCase->tearDown)
+         if (!testCase)
+           tearDown = f;
+         else if (!testCase->tearDown)
            testCase->tearDown = f;
          else
            {
-             snprintf (casename, sizeof (casename),
-                       "%s_case%03lu", suite->super.name, (unsigned long)caseid);
-             caseid ++;
-             readTestCaseDef (suite, casename, NULL, NULL, f);
+             ccunit_err ("%s:%lu: multiply tearDown function defined. %s\n"
+                         "    perhaps missing /** test case: ... */",
+                         line.fname, line.lno, line.str);
+             testCase = newTestCaseDef (NULL);
+             addTestDef (suite, &testCase->super);
+             tearDown = f;
+           }
+         safe_free (desc);
+       }
+      /* if test case function def, then read as test case. */
+      else if ((f = readTestFuncDef ("void", "test", desc)) != NULL)
+       {
+         if (testCase != NULL && !testCase->runTest)
+           {
+             testCase->runTest = f;
+             if (!testCase->super.name)
+               testCase->super.name = safe_strdup (f->name);
+             if (!testCase->desc)
+               testCase->desc = safe_strdup (f->desc);
+           }
+         else
+           {
+             testCase = newTestCaseDef (desc);
+             testCase->runTest = f;
+             testCase->setUp = setUp;
+             testCase->tearDown = tearDown;
+             addTestDef (suite, &testCase->super);
            }
          safe_free (desc);
        }