1 /* Copyright (C) 2003 TSUTSUMI Kikuo.
2 This file is part of the CCUnit Library.
4 The CCUnit Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public License
6 as published by the Free Software Foundation; either version 2.1 of
7 the License, or (at your option) any later version.
9 The CCUnit Library is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the CCUnit Library; see the file COPYING.LESSER.
16 If not, write to the Free Software Foundation, Inc., 59 Temple
17 Place - Suite 330, Boston, MA 02111-1307, USA.
23 * WriteSuite module implementation.
26 #include <ccunit/CCUnitMakeSuite.h>
27 #include <ccunit/CCUnitLogMessage.h>
31 * @ingroup CCunitMakeSuite
32 * @addtogroup CCUnitWriteSuite
37 * print test fixture prototypes.
39 * @param ofp output stream.
40 * @param suite test suite object to print.
42 static void writePrototypes (FILE* ofp, _CCUnitTestSuiteDef* suite)
44 CCUnitListIterator itor;
46 _CCUnitFuncDef* testCase;
47 static unsigned suiteid = 0;
49 sprintf (sname, "newSuite_%03u", ++ suiteid);
50 fprintf (ofp, "static CCUnitTestSuite* %s (const char* name);\n", sname);
51 ccunit_log ("testSuite: '%s'", sname);
52 ccunit_initListIterator (&suite->testdefs, &itor);
53 while ((test = (_CCUnitTestDef*)ccunit_nextListIterator (&itor)) != NULL)
55 if (test->type == ccunitTypeSuite)
57 writePrototypes (ofp, (_CCUnitTestSuiteDef*)test);
59 else if (test->type == ccunitTypeFixture)
61 _CCUnitTestFixtureDef* testFixture = (_CCUnitTestFixtureDef*)test;
62 CCUnitListIterator fitor;
63 ccunit_log ("testFixture: %s", testFixture->testdef.name);
64 if (testFixture->testdef.name)
65 fprintf (ofp, "/* test fixture: %s */\n", testFixture->testdef.name);
66 if (testFixture->setUp)
71 testFixture->setUp->desc,
72 testFixture->setUp->type,
73 testFixture->setUp->name);
74 ccunit_log ("setUp: %s %s",
75 testFixture->setUp->type, testFixture->setUp->name);
77 if (testFixture->tearDown)
82 testFixture->tearDown->desc,
83 testFixture->tearDown->type,
84 testFixture->tearDown->name);
85 ccunit_log ("tearDown: %s %s",
86 testFixture->tearDown->type, testFixture->tearDown->name);
88 ccunit_initListIterator (&testFixture->testCases, &fitor);
89 while ((testCase = ccunit_nextListIterator (&fitor)) != NULL)
97 ccunit_log ("runTest: %s %s", testCase->type, testCase->name);
105 * print test suite adding function.
107 * @param ofp output stream.
108 * @param name function name.
109 * @param suite test suite to print.
111 static void writeSuite (FILE* ofp,
113 _CCUnitTestSuiteDef* suite)
115 CCUnitListIterator itor;
116 _CCUnitTestDef* testdef;
117 static unsigned int suiteid = 0;
121 "static CCUnitTestSuite* newSuite_%03u (const char* name)\n"
123 " CCUnitTestSuite* suite;\n"
124 " suite = ccunit_newTestSuite (name);\n",
127 ccunit_initListIterator (&suite->testdefs, &itor);
128 while ((testdef = (_CCUnitTestDef*)ccunit_nextListIterator (&itor)) != NULL)
130 if (testdef->type == ccunitTypeSuite)
135 " CCUnitTestSuite* newSuite;\n"
136 " newSuite = newSuite_%03d (name);\n"
137 " if (newSuite != NULL)\n"
138 " ccunit_addTestSuite (suite, newSuite);\n"
142 else if (testdef->type == ccunitTypeFixture)
144 CCUnitListIterator fitor;
145 _CCUnitFuncDef* testCase;
146 _CCUnitTestFixtureDef* testFixture = (_CCUnitTestFixtureDef*)testdef;
149 " CCUnitTestFixture* testFixture;\n"
150 " testFixture = ccunit_newTestFixture (\"%s\",\n"
153 " if (testFixture != NULL)\n"
154 " ccunit_addTestFixture (suite, testFixture);\n",
156 !testFixture->setUp ? "NULL" : testFixture->setUp->name,
157 !testFixture->tearDown ? "NULL" : testFixture->tearDown->name);
158 ccunit_initListIterator (&testFixture->testCases, &fitor);
159 while ((testCase = ccunit_nextListIterator (&fitor)) != NULL)
163 " CCUnitTestCase* newCase;\n"
164 " newCase = ccunit_newTestCase (\"%s\",\n"
167 " if (newCase != NULL)\n"
168 " ccunit_addTestCase (testFixture, newCase);\n"
170 testCase->name, testCase->desc, testCase->name);
172 fprintf (ofp, " }\n");
175 fprintf (ofp, "\n return suite;\n}\n\n");
176 ccunit_initListIterator (&suite->testdefs, &itor);
177 while ((testdef = (_CCUnitTestDef*)ccunit_nextListIterator (&itor)) != NULL)
179 if (testdef->type == ccunitTypeSuite)
180 writeSuite (ofp, testdef->name, (_CCUnitTestSuiteDef*)testdef);
189 void ccunit_writeSuite (FILE* ofp, const char* name, _CCUnitTestSuiteDef* suite)
192 "#include <ccunit/CCUnitTestSuite.h>\n"
194 writePrototypes (ofp, suite);
195 writeSuite (ofp, NULL, suite);
197 name = "ccunit_suite";
200 "CCUnitTestSuite* %s (const char* name)\n"
202 " return newSuite_001 (name);\n"