From: tsutsumi <> Date: Sat, 13 Sep 2003 05:34:00 +0000 (+0000) Subject: add doxycomment X-Git-Tag: rel-0-4~29 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=90dd3264244768aeb359fc0898bae827e0d9adf0;p=ccunit%2Fccunit.git add doxycomment The role of the test fixture was exchanged for the test case. tried to ignore the command of doxygen. --- diff --git a/src/ccunit/CCUnitReadSuite.c b/src/ccunit/CCUnitReadSuite.c index ba70778..8a46c0a 100644 --- a/src/ccunit/CCUnitReadSuite.c +++ b/src/ccunit/CCUnitReadSuite.c @@ -20,13 +20,21 @@ * $Id$ */ -#include +/** @file + * ReadSuite module implementation. + */ +#include #include #include #include #include /** + * @addtogroup CCUnitReadSuite + * @{ + */ + +/** * destroy test def. * * @param test testdef to destroy. @@ -109,24 +117,61 @@ static CCUnitTestDef* addTestDef (CCUnitTestSuiteDef* suite, { if (!suite || !test) return NULL; - ccunit_log ("add test: %s", test->name); ccunit_addList (&suite->testdefs, test); return test; } /** - * create new test fixture. + * add test suite to test suite. + * + * @param suite test suite to add. + * @param test test suite. + * @return added test. + */ +static inline CCUnitTestDef* addTestSuiteDef (CCUnitTestSuiteDef* suite, + CCUnitTestSuiteDef* test) +{ + if (!suite || !test) + return NULL; + const char* name = test->testdef.name; + if (!name) + name = ""; + ccunit_log ("add test suite: %s", name); + return addTestDef (suite, &test->testdef); +} + +/** + * add test fixture to test suite. * - * @param type return type of fixture. - * @param name fixture name. + * @param suite test suite to add. + * @param test test fixture. + * @return added test. + */ +static inline CCUnitTestDef* addTestFixtureDef (CCUnitTestSuiteDef* suite, + CCUnitTestFixtureDef* test) +{ + if (!suite || !test) + return NULL; + const char* name = test->testdef.name; + if (!name) + name = ""; + ccunit_log ("add test fixture: %s", name); + return addTestDef (suite, &test->testdef); +} + +/** + * create new test case. + * + * @param type return type of case. + * @param name case name. * @param desc description. - * @return new test fixture def. + * @return new test case def. */ -static CCUnitTestFixtureDef* newTestFixtureDef (const char* type, +static CCUnitTestCaseDef* newTestCaseDef (const char* type, const char* name, const char* desc) { - struct CCUnitTestFixtureDef* f = calloc (1, sizeof (*f)); + struct CCUnitTestCaseDef* f = calloc (1, sizeof (*f)); ccunit_log ("create new test func: %s %s", type, name); if (!f) return f; @@ -140,7 +185,7 @@ static CCUnitTestFixtureDef* newTestFixtureDef (const char* type, * delete test func def. * @param func test func def to delete. */ -static void deleteTestFixtureDef (CCUnitTestFixtureDef* func) +static void deleteTestCaseDef (CCUnitTestCaseDef* func) { if (!func) return; @@ -151,37 +196,43 @@ static void deleteTestFixtureDef (CCUnitTestFixtureDef* func) } /** - * destroy test case def. - * @param testCase test case def to destroy. + * destroy test fixture def. + * @param fixture test fixture def to destroy. */ -static void destroyTestCaseDef (CCUnitTestCaseDef* testCase) +static void destroyTestFixtureDef (CCUnitTestFixtureDef* fixture) { - ccunit_deleteList (&testCase->fixtures, (void(*)(void*))deleteTestFixtureDef); - deleteTestFixtureDef (testCase->setUp); - deleteTestFixtureDef (testCase->tearDown); - destroyTestDef (&testCase->testdef); + ccunit_deleteList (&fixture->testCases, (void(*)(void*))deleteTestCaseDef); + deleteTestCaseDef (fixture->setUp); + deleteTestCaseDef (fixture->tearDown); + destroyTestDef (&fixture->testdef); } /** - * create new test case def. + * create new test fixture def. * - * @param name test case name. - * @param setUp test case setup func def. - * @param tearDown test case tearDown func def. + * @param name test fixture name. + * @param setUp test fixture setup func def. + * @param tearDown test fixture tearDown func def. */ -static CCUnitTestCaseDef* newTestCaseDef (const char* name) +static CCUnitTestFixtureDef* newTestFixtureDef (const char* name) { - CCUnitTestCaseDef* testCase = calloc (1, sizeof (*testCase)); - ccunit_log ("create new test case: %s", name); - if (!testCase) + CCUnitTestFixtureDef* fixture = calloc (1, sizeof (*fixture)); + ccunit_log ("create new test fixture: %s", name); + if (!fixture) return NULL; - initTestDef (&testCase->testdef, ccunitTypeCase, name); - testCase->testdef.dtor = (void(*)(CCUnitTestDef*))destroyTestCaseDef; - ccunit_initList (&testCase->fixtures); - return testCase; + initTestDef (&fixture->testdef, ccunitTypeFixture, name); + fixture->testdef.dtor = (void(*)(CCUnitTestDef*))destroyTestFixtureDef; + ccunit_initList (&fixture->testCases); + return fixture; } /** + * @defgroup _CCUnitLine Line + * Read one line module. + * @{ + */ + +/** * Read line. */ struct _CCUnitLine @@ -201,7 +252,7 @@ static struct _CCUnitLine line; /** * Get one line from stream. - * This fixture copies a read line on the global variable line. + * This case copies a read line on the global variable line. * * @return When reading succeeds, value except for the zero is * returned. When an error occurs, a zero is returned. @@ -287,13 +338,27 @@ static char* readDocCommentContents () /* skip white spaces */ for (; *start && isspace (*start); start ++) ; - if (*start != '*') /* block comment '*' */ + /* skip leading block comment '*'... */ + if (*start != '*') ; else if (start[1] == '/') /* eoc */ ; else /* skip white spaces */ for (start ++; *start && isspace (*start); start ++) ; + /* skip doxygen command line */ + if (*start == '@') + { + ccunit_log ("skip doxygen javadoc style comment"); + for (end = start + 1; *end; end ++) + if (end[0] == '*' && end[1] == '/') + { + ccunit_log ("end of comment"); + eoc = true; + break; + } + start = end; + } /* seek to eol or end of comment */ for (end = start; *end; end ++) if (end[0] == '*' && end[1] == '/') @@ -331,7 +396,7 @@ static char* readDocCommentContents () break; start = line.str; } - ccunit_dbg ("comment content: \"%s\"", content); + ccunit_log ("comment content: \"%s\"", !content ? "" : content); return content; } @@ -356,12 +421,12 @@ static char* readDocComment () } /** - * get test case def. + * get test fixture def. * * @param str comment string. * @return group attribute object. */ -static char* getTestCaseName (const char* str) +static char* getTestFixtureName (const char* str) { static const char* const prefix = "TEST CASE:"; const size_t prefixLen = strlen (prefix); @@ -374,21 +439,21 @@ static char* getTestCaseName (const char* str) if (!*name) { name = NULL; - ccunit_err ("no test case name: %s. near line %lu", + ccunit_err ("no test fixture name: %s. near line %lu", str, line.lno); } } else - ccunit_dbg ("not a test case name: %s", str); + ccunit_dbg ("not a test fixture name: %s", str); return (char*)name; } /** - * get end of case string. + * get end of fixture string. * @param str string. * @return eoc string. */ -static char* getEndOfCase (const char* str) +static char* getEndOfFixture (const char* str) { static const char* const prefix = "END TEST CASE"; const size_t prefixLen = strlen (prefix); @@ -399,7 +464,7 @@ static char* getEndOfCase (const char* str) if (*name && !isspace (*name) && !ispunct (*name)) { name = NULL; - ccunit_dbg ("not a end of test case: %s", str); + ccunit_dbg ("not a end of test fixture: %s", str); } else { @@ -409,29 +474,29 @@ static char* getEndOfCase (const char* str) if (!*name) ; else - ccunit_log ("end of test case: %s", name); + ccunit_log ("end of test fixture: %s", name); } } else - ccunit_dbg ("not a end of test case: %s", str); + ccunit_dbg ("not a end of test fixture: %s", str); return (char*)name; } /** - * read test fixturedef. + * read test casedef. * * @param type required type string. - * @param prefix required fixture name prefix. + * @param prefix required case name prefix. * @param desc description. * @return funcdef object. */ -static CCUnitTestFixtureDef* readFixture (const char* type, - const char* prefix, - const char* desc) +static CCUnitTestCaseDef* readTestCase (const char* type, + const char* prefix, + const char* desc) { char* typ; char* name; - ccunit_dbg ("read fixture: %s %s... from '%s'", type, prefix, line.str); + ccunit_dbg ("read case: %s %s... from '%s'", type, prefix, line.str); for (typ = line.str; *typ; typ ++) if (!isspace (*typ)) break; @@ -468,7 +533,7 @@ static CCUnitTestFixtureDef* readFixture (const char* type, *tail = '\0'; break; } - return newTestFixtureDef (type, name, desc); + return newTestCaseDef (type, name, desc); } else ccunit_dbg ("name mismatch: %s %s", prefix, name); @@ -476,82 +541,82 @@ static CCUnitTestFixtureDef* readFixture (const char* type, } /** - * read test case function. + * read test fixture function. * * @param parent parent suite. - * @param cname test case name to read. + * @param cname test fixture name to read. */ -static void readTestCase (CCUnitTestSuiteDef* parent, const char* cname) +static void readTestFixture (CCUnitTestSuiteDef* parent, const char* cname) { CCUnitTestSuiteDef* suite; - CCUnitTestCaseDef* testCase; - CCUnitTestFixtureDef* f = NULL; + CCUnitTestFixtureDef* fixture; + CCUnitTestCaseDef* f = NULL; char* name; char* doc; char* desc = NULL; suite = ccunit_newTestSuiteDef (NULL); if (!suite) return; - testCase = newTestCaseDef (cname); - if (!testCase) + fixture = newTestFixtureDef (cname); + if (!fixture) { deleteTestDef (&suite->testdef); return; } - addTestDef (parent, &suite->testdef); - addTestDef (suite, &testCase->testdef); + addTestSuiteDef (parent, suite); + addTestFixtureDef (suite, fixture); while (readline ()) { /* setUp function def */ - if ((f = readFixture ("void", "setUp", desc)) != NULL) + if ((f = readTestCase ("void", "setUp", desc)) != NULL) { - if (!testCase->setUp) - testCase->setUp = f; + if (!fixture->setUp) + fixture->setUp = f; else { ccunit_err ("%s:%lu: setUp multiply defined %s... ignored.\n" " previous definition is %s\n" - " perhaps missing /** test case: ... */", - line.fname, line.lno, f->name, testCase->setUp->name); - deleteTestFixtureDef (f); + " perhaps missing /** test fixture: ... */", + line.fname, line.lno, f->name, fixture->setUp->name); + deleteTestCaseDef (f); } safe_free (desc); } /* tearDown function def */ - else if ((f = readFixture ("void", "tearDown", desc)) != NULL) + else if ((f = readTestCase ("void", "tearDown", desc)) != NULL) { - if (!testCase->tearDown) - testCase->tearDown = f; + if (!fixture->tearDown) + fixture->tearDown = f; else { ccunit_err ("%s:%lu: tearDown multiply defined %s... ignored.\n" " previous definition is %s\n" - " perhaps missing /** test case: ... */", - line.fname, line.lno, f->name, testCase->tearDown->name); - deleteTestFixtureDef (f); + " perhaps missing /** test fixture: ... */", + line.fname, line.lno, f->name, fixture->tearDown->name); + deleteTestCaseDef (f); } safe_free (desc); } - /* if test fixture function def, then read as test fixture. */ - else if ((f = readFixture ("void", "test", desc)) != NULL) + /* if test case function def, then read as test case. */ + else if ((f = readTestCase ("void", "test", desc)) != NULL) { - ccunit_addList (&testCase->fixtures, f); + ccunit_addList (&fixture->testCases, f); safe_free (desc); } /* if current line is javaDoc comment, then read as description. */ else if ((doc = readDocComment ()) != NULL) { - if ((name = getTestCaseName (doc)) != NULL) + if ((name = getTestFixtureName (doc)) != NULL) { - ccunit_err ("%s:%lu: unbaranced end case comment '%s', " - "need /** end case: %s */", + ccunit_err ("%s:%lu: unbaranced end fixture comment '%s', " + "need /** end fixture: %s */", line.fname, line.lno, doc, cname); - readTestCase (suite, name); + readTestFixture (suite, name); safe_free (doc); } - else if ((name = getEndOfCase (doc)) != NULL) + else if ((name = getEndOfFixture (doc)) != NULL) { - ccunit_log ("exit test case: %s", testCase->testdef.name); + ccunit_log ("exit test fixture: %s", fixture->testdef.name); safe_free (doc); break; } @@ -570,7 +635,7 @@ static void readTestCase (CCUnitTestSuiteDef* parent, const char* cname) */ static void readSuite (CCUnitTestSuiteDef* parent) { - CCUnitTestFixtureDef* f; + CCUnitTestCaseDef* f; const char* name; char* doc; char* desc = NULL; @@ -579,27 +644,27 @@ static void readSuite (CCUnitTestSuiteDef* parent) /* if current line is javaDoc comment, then read as description. */ if ((doc = readDocComment ()) != NULL) { - if ((name = getTestCaseName (doc)) != NULL) + if ((name = getTestFixtureName (doc)) != NULL) { - readTestCase (parent, name); + readTestFixture (parent, name); safe_free (doc); } - else if ((name = getEndOfCase (doc)) != NULL) + else if ((name = getEndOfFixture (doc)) != NULL) { - ccunit_err ("%s:%lu: invalid end test case comment '%s'", + ccunit_err ("%s:%lu: invalid end test fixture comment '%s'", line.fname, line.lno, doc); safe_free (doc); } else desc = doc; } - else if ((f = readFixture ("void", "test", desc)) != NULL - || (f = readFixture ("void", "setUp", desc)) != NULL - || (f = readFixture ("void", "tearDown", desc)) != NULL) + else if ((f = readTestCase ("void", "test", desc)) != NULL + || (f = readTestCase ("void", "setUp", desc)) != NULL + || (f = readTestCase ("void", "tearDown", desc)) != NULL) { - ccunit_err ("%s:%lu: missing test case start comment '%s': ignored", + ccunit_err ("%s:%lu: missing test fixture start comment '%s': ignored", line.fname, line.lno, line.str); - deleteTestFixtureDef (f); + deleteTestCaseDef (f); safe_free (desc); } else @@ -608,6 +673,8 @@ static void readSuite (CCUnitTestSuiteDef* parent) safe_free (desc); } +/** @} */ + void ccunit_readSuite (const char* fname, CCUnitTestSuiteDef* parent) { if (strcmp (fname, "-") == 0) /* special file name '-' as stdin */ @@ -632,3 +699,5 @@ void ccunit_readSuite (const char* fname, CCUnitTestSuiteDef* parent) fclose (line.ifp); memset (&line, 0, sizeof (line)); } + +/** @} */