-/*
- * $Id$
- */
/* Copyright (C) 2003 TSUTSUMI Kikuo.
This file is part of the CCUnit Library.
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>
}
/**
- * 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.
*/
}
/**
+ * 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.
*/
char* name;
char* doc;
char* desc = NULL;
- addTestDef (suite, &testCase->super);
while (readline ())
{
/* if current line is javaDoc comment, then read as description. */
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);
}
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);
}