OSDN Git Service

rename struct.
authortsntsumi <tsntsumi@users.sourceforge.jp>
Sun, 28 Sep 2003 13:51:32 +0000 (13:51 +0000)
committertsntsumi <tsntsumi@users.sourceforge.jp>
Sun, 28 Sep 2003 13:51:32 +0000 (13:51 +0000)
to read static ident.

src/ccunit/CCUnitReadSuite.c

index 0fd5238..66f24f9 100644 (file)
@@ -43,6 +43,7 @@ static void destroyTestDef (CCUnitTestDef* test)
   if (!test)
     return;
   safe_free (test->name);
+  safe_free (test->idname);
 }
 
 /**
@@ -58,6 +59,7 @@ static CCUnitTestDef* initTestDef (CCUnitTestDef* test,
 {
   test->type = type;
   test->name = safe_strdup (name);
+  test->idname = NULL;
   return test;
 }
 
@@ -166,14 +168,16 @@ static inline CCUnitTestDef* addTestFixtureDef (CCUnitTestSuiteDef* suite,
  * @param desc description.
  * @return new test case def.
  */
-static CCUnitTestCaseDef* newTestCaseDef (const char* type,
-                                               const char* name,
-                                               const char* desc)
+static CCUnitFuncDef* newFuncDef (const char* scope,
+                                 const char* type,
+                                 const char* name,
+                                 const char* desc)
 {
-  struct CCUnitTestCaseDef* f = calloc (1, sizeof (*f));
+  struct CCUnitFuncDef* f = calloc (1, sizeof (*f));
   ccunit_log ("create new test func: %s %s", type, name);
   if (!f)
     return f;
+  f->scope = !scope ? strdup ("extern") : safe_strdup (scope);
   f->type = safe_strdup (type);
   f->name = safe_strdup (name);
   f->desc = !desc ? safe_strdup (name) : strdup (desc);
@@ -184,10 +188,11 @@ static CCUnitTestCaseDef* newTestCaseDef (const char* type,
  * delete test func def.
  * @param func test func def to delete.
  */
-static void deleteTestCaseDef (CCUnitTestCaseDef* func)
+static void deleteFuncDef (CCUnitFuncDef* func)
 {
   if (!func)
     return;
+  safe_free (func->scope);
   safe_free (func->type);
   safe_free (func->name);
   safe_free (func->desc);
@@ -200,9 +205,9 @@ static void deleteTestCaseDef (CCUnitTestCaseDef* func)
  */
 static void destroyTestFixtureDef (CCUnitTestFixtureDef* fixture)
 {
-  ccunit_deleteList (&fixture->testCases, (void(*)(void*))deleteTestCaseDef);
-  deleteTestCaseDef (fixture->setUp);
-  deleteTestCaseDef (fixture->tearDown);
+  ccunit_deleteList (&fixture->testCases, (void(*)(void*))deleteFuncDef);
+  deleteFuncDef (fixture->setUp);
+  deleteFuncDef (fixture->tearDown);
   destroyTestDef (&fixture->testdef);
 }
 
@@ -296,7 +301,7 @@ static int readline ()
          if (!str)
            {
              ccunit_log ("/* no more memory */");
-             break;
+             return 0;
            }
          line.str = str;
          restSize = newCapacity - line.capacity;
@@ -425,7 +430,7 @@ static char* readDocComment ()
  * @param str comment string.
  * @return group attribute object.
  */
-static char* getTestFixtureName (const char* str)
+static const char* getTestFixtureName (const char* str)
 {
   static const char* const prefix = "TEST CASE:";
   const size_t prefixLen = strlen (prefix);
@@ -444,7 +449,7 @@ static char* getTestFixtureName (const char* str)
     }
   else
     ccunit_dbg ("not a test fixture name: %s", str);
-  return (char*)name;
+  return name;
 }
 
 /**
@@ -452,7 +457,7 @@ static char* getTestFixtureName (const char* str)
  * @param str string.
  * @return eoc string.
  */
-static char* getEndOfFixture (const char* str)
+static const char* getEndOfFixture (const char* str)
 {
   static const char* const prefix = "END TEST CASE";
   const size_t prefixLen = strlen (prefix);
@@ -478,7 +483,7 @@ static char* getEndOfFixture (const char* str)
     }
   else
     ccunit_dbg ("not a end of test fixture: %s", str);
-  return (char*)name;
+  return name;
 }
 
 /**
@@ -489,16 +494,42 @@ static char* getEndOfFixture (const char* str)
  * @param desc description.
  * @return funcdef object.
  */
-static CCUnitTestCaseDef* readTestCase (const char* type,
-                                       const char* prefix,
-                                       const char* desc)
+static CCUnitFuncDef* readTestCase (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);
   for (typ = line.str; *typ; typ ++)
     if (!isspace (*typ))
       break;
+  if (strncmp (typ, scope, strlen (scope)) != 0)
+    scope = "extern";
+  else
+    {
+      typ += strlen (scope);
+      if (*typ && !isspace (*typ))
+       {
+         ccunit_dbg ("type mismatch: %s %s", type, typ);
+         return NULL;
+       }
+      for (;;)
+       {
+         for (; *typ; typ ++)
+           if (!isspace (*typ))
+             break;
+         if (*typ)
+           break;
+         if (!readline ())
+           {
+             ccunit_err ("unexpected EOF");
+             return NULL;
+           }
+         typ = line.str;
+       }
+    }
   if (strncmp (typ, type, strlen (type)) != 0)
     {
       ccunit_dbg ("type mismatch: %s %s", type, typ);
@@ -522,6 +553,7 @@ static CCUnitTestCaseDef* readTestCase (const char* type,
          ccunit_err ("unexpected EOF");
          return NULL;
        }
+      name = line.str;
     }
   if (strncmp (name, prefix, strlen(prefix)) == 0)
     {
@@ -532,7 +564,7 @@ static CCUnitTestCaseDef* readTestCase (const char* type,
            *tail = '\0';
            break;
          }
-      return newTestCaseDef (type, name, desc);
+      return newFuncDef (scope, type, name, desc);
     }
   else
     ccunit_dbg ("name mismatch: %s %s", prefix, name);
@@ -548,8 +580,8 @@ static CCUnitTestCaseDef* readTestCase (const char* type,
 static void readTestFixture (CCUnitTestSuiteDef* suite, const char* cname)
 {
   CCUnitTestFixtureDef* fixture;
-  CCUnitTestCaseDef* f = NULL;
-  char* name;
+  CCUnitFuncDef* f = NULL;
+  const char* name;
   char* doc;
   char* desc = NULL;
   fixture = newTestFixtureDef (cname);
@@ -569,7 +601,7 @@ static void readTestFixture (CCUnitTestSuiteDef* suite, const char* cname)
                          "    previous definition is %s\n"
                          "    perhaps missing /** test fixture: ... */",
                          line.fname, line.lno, f->name, fixture->setUp->name);
-             deleteTestCaseDef (f);
+             deleteFuncDef (f);
            }
          safe_free (desc);
        }
@@ -584,7 +616,7 @@ static void readTestFixture (CCUnitTestSuiteDef* suite, const char* cname)
                          "    previous definition is %s\n"
                          "    perhaps missing /** test fixture: ... */",
                          line.fname, line.lno, f->name, fixture->tearDown->name);
-             deleteTestCaseDef (f);
+             deleteFuncDef (f);
            }
          safe_free (desc);
        }
@@ -625,7 +657,7 @@ static void readTestFixture (CCUnitTestSuiteDef* suite, const char* cname)
  */
 static void readSuite (CCUnitTestSuiteDef* suite)
 {
-  CCUnitTestCaseDef* f;
+  CCUnitFuncDef* f;
   const char* name;
   char* doc;
   char* desc = NULL;
@@ -655,7 +687,7 @@ static void readSuite (CCUnitTestSuiteDef* suite)
        {
          ccunit_err ("%s:%lu: missing test fixture start comment '%s': ignored",
                      line.fname, line.lno, line.str);
-         deleteTestCaseDef (f);
+         deleteFuncDef (f);
          safe_free (desc);
        }
       else