}
static inline void printTestFunc (FILE* ofp,
- const char* leadspc,
_CCUnitFuncDef* fndef)
{
- fprintf (ofp, "%s{\n", leadspc);
+ fprintf (ofp, " {\n");
if (!fndef)
- fprintf (ofp, "%s NULL, NULL, NULL\n", leadspc);
+ fprintf (ofp, " NULL, NULL, NULL\n");
else
fprintf (ofp,
- "%s \"%s\",\n"
- "%s \"%s\",\n"
- "%s %s\n",
- leadspc, fndef->name,
- leadspc, fndef->desc,
- leadspc, fndef->name);
- fprintf (ofp, "%s},\n", leadspc);
+ " \"%s\",\n"
+ " \"%s\",\n"
+ " %s\n",
+ fndef->name,
+ fndef->desc,
+ fndef->name);
+ fprintf (ofp, " },\n");
}
/**
static void printFixture (FILE* ofp, _CCUnitTestFixtureDef* fxdef)
{
static int fxid = 0;
+ CCUnitListIterator fnitor;
+ _CCUnitFuncDef* fndef;
if (!fxdef->testdef.idname)
{
fxdef->testdef.idname = calloc (1, 8);
fxid ++;
sprintf (fxdef->testdef.idname, "fx_%03d", fxid);
}
+ fprintf (ofp, "static CCUnitTestFunc %s_cases[] = {\n", fxdef->testdef.idname);
+ ccunit_initListIterator (&fxdef->testCases, &fnitor);
+ while ((fndef = ccunit_nextListIterator (&fnitor)) != NULL)
+ {
+ printTestFunc (ofp, fndef);
+ }
+ printTestFunc (ofp, NULL);
+ fputs ("};\n\n", ofp);
fprintf (ofp,
"static CCUnitTestFixtureDfn %s = {\n"
" { %s },\n"
fxdef->testdef.idname,
ccunitTypeNames[fxdef->testdef.type],
!fxdef->testdef.name ? "NULL" : fxdef->testdef.name);
- printTestFunc (ofp, " ", fxdef->setUp);
- printTestFunc (ofp, " ", fxdef->tearDown);
- fputs (" {\n", ofp);
- {
- CCUnitListIterator fnitor;
- _CCUnitFuncDef* fndef;
- ccunit_initListIterator (&fxdef->testCases, &fnitor);
- while ((fndef = ccunit_nextListIterator (&fnitor)) != NULL)
- {
- printTestFunc (ofp, " ", fndef);
- }
- printTestFunc (ofp, " ", NULL);
- }
- fputs (" }\n};\n\n", ofp);
+ printTestFunc (ofp, fxdef->setUp);
+ printTestFunc (ofp, fxdef->tearDown);
+ fprintf (ofp, " %s_cases,\n", fxdef->testdef.idname);
+ fputs ("};\n\n", ofp);
}
/**
else
;
}
+ fprintf (ofp, "static CCUnitTestDfn* %s_test[] = {\n", suite->testdef.idname);
+ ccunit_initListIterator (&suite->testdefs, &itor);
+ while ((testdef = ccunit_nextListIterator (&itor)) != NULL)
+ {
+ fprintf (ofp, " &%s.test,\n", testdef->idname);
+ }
+ fputs (" NULL,\n};\n\n", ofp);
fprintf (ofp,
"static CCUnitTestSuiteDfn %s = {\n"
" { %s },\n"
" \"%s\",\n"
- " {\n",
+ " %s_test\n",
suite->testdef.idname,
ccunitTypeNames[suite->testdef.type],
- !suite->testdef.name ? "" : suite->testdef.name);
- ccunit_initListIterator (&suite->testdefs, &itor);
- while ((testdef = ccunit_nextListIterator (&itor)) != NULL)
- {
- fprintf (ofp, " &%s.test,\n", testdef->idname);
- }
- fputs (" NULL,\n },\n", ofp);
- fputs ("};\n", ofp);
+ !suite->testdef.name ? "" : suite->testdef.name,
+ suite->testdef.idname);
+ fputs ("};\n\n", ofp);
}
/*
static inline _CCUnitTestDef* addTestSuiteDef (_CCUnitTestSuiteDef* suite,
_CCUnitTestSuiteDef* test)
{
+ const char* name;
if (!suite || !test)
return NULL;
- const char* name = test->testdef.name;
+ name = test->testdef.name;
if (!name)
name = "";
ccunit_log ("add test suite: %s", name);
static inline _CCUnitTestDef* addTestFixtureDef (_CCUnitTestSuiteDef* suite,
_CCUnitTestFixtureDef* test)
{
+ const char* name;
if (!suite || !test)
return NULL;
- const char* name = test->testdef.name;
+ name = test->testdef.name;
if (!name)
name = "";
ccunit_log ("add test fixture: %s", name);
static int readline ()
{
static const size_t MIN_LINE_BUF_LEN = 512;
+ char* insertAt;
+ size_t restSize;
+ char* sp;
+ char* tail;
/* buffer hasn't been allocate yet */
if (line.str == NULL)
{
/* shrink to minimum size */
else if (line.capacity > MIN_LINE_BUF_LEN)
{
+ char* str;
line.capacity = MIN_LINE_BUF_LEN;
- char* str = realloc (line.str, line.capacity);
+ str = realloc (line.str, line.capacity);
if (str)
line.str = str;
}
- char* insertAt = line.str;
- size_t restSize = line.capacity;
+ insertAt = line.str;
+ restSize = line.capacity;
line.length = 0;
- char* sp = 0;
+ sp = 0;
while ((sp = fgets (insertAt, restSize, line.ifp)) != NULL)
{
line.length += strlen(insertAt);
if (!sp)
return 0;
/* chomp CR/LF */
- char* tail = line.str + line.length - 1;
+ tail = line.str + line.length - 1;
while (*tail == '\n' || *tail == '\r') /* for dos/mac? */
{
line.length --;