From 7f47e4b9feb2f950f19380f9c15e3408ed6bef0e Mon Sep 17 00:00:00 2001 From: tsntsumi Date: Fri, 20 Aug 2010 07:44:05 +0000 Subject: [PATCH] rename CCUnitTestFixture to CCUnitTestCase --- src/ccunit/CCUnitTestCase.h | 156 ++++++++++++++++++++++++++++++++------------ 1 file changed, 113 insertions(+), 43 deletions(-) diff --git a/src/ccunit/CCUnitTestCase.h b/src/ccunit/CCUnitTestCase.h index 7d8b5e5..1295ffc 100755 --- a/src/ccunit/CCUnitTestCase.h +++ b/src/ccunit/CCUnitTestCase.h @@ -22,28 +22,58 @@ * $Id$ */ -/** @file +/** + * @file * TestCase module. */ - #ifndef CCUNITTESTCASE_H #define CCUNITTESTCASE_H #include +#include +#include +#include +#include /** - * @ingroup CCUnitTestFixture + * @ingroup CCUnitTest * @defgroup CCUnitTestCase TestCase - * - * A single test object. - * - * This class is used to implement a simple test case. + * A test case defines the case to run multiple tests. * * @{ */ /** - * A single test object. + * Wraps a test case with setUp and tearDown function. + * + * A TestCase is used to provide a common environment for a set + * of test cases. + * + * To define a test case, do the following: + * - the case is defined by static variables + * - initialize the case state by setUp function + * - clean-up after a test by tearDown function + * + * Each test runs in its own case so there + * can be no side effects among test runs. + * Here is an example: + * + * @code + * static int value1, value2; + * + * void setUp_MathTest () + * { + * value1 = 2; + * value2 = 3; + * } + * + * ... + * + * CCUnitTestCase* MathTest_newTestCase () + * { + * return ccunit_newTestCase ("MathTest", setUp_MathTest, NULL); + * } + * @endcode * * For each test implement a function which interacts with the * case. Verify the expected results with assertions specified by @@ -63,59 +93,99 @@ * return ccunit_newTestCase ("testAdd", "add test", testAdd); * } * @endcode - * - * @see CCUnitTestFixture, CCUnitTestSuite, CCUnitMakeSuite * - * @ingroup WritingTestFixture + * The tests to be run can be collected into a TestSuite. + * + * @code + * CCUintTestSuite* MathTest_suite () + * { + * CCUnitTestSuite* suite = ccunit_newTestSuite ("MathTest"); + * CCUnitTestCase* tcase = MathTest_newTestCase (); + * ccunit_addTestCase (suite, tcase); + * ccunit_addTestCase (tcase, MathTest_newTestCase_testAdd ()); + * ccunit_addTestCase (tcase, MathTest_newTestCase_testDivZero ()) + * return suite; + * } + * @endcode + * + * Once the functions are defined you can run them. To do this, use a + * TestRunner. + * + * @code + * CCUnitTestRunner *runner = ccunit_newTestRunner (stdout); + * CCUnitTestSuite *suite = MathTest_suite (); + * runner->run (runner, suite); + * @endcode + * + * A command line tool have been created for convenience. It is located + * in src/tools/ccunit_makeSuite.c. + * + * @see CCUnitTestResult, CCUnitTestCase, CCUnitTestSuite, CCUnitMakeSuite, + * + * @ingroup WritingTestCase */ typedef struct CCUnitTestCase { + CCUnitTest test; /**< super class */ const char* name; /**< test case name */ - const char* desc; /**< test description */ - void (*runTest) (); /**< run test function */ + CCUnitTestFunc* setup_setUp; /**< setUp for a case */ + CCUnitTestFunc* setup_tearDown; /**< tearDown for a case */ + CCUnitTestFunc* setUp; /**< setUp for each cases */ + CCUnitTestFunc* tearDown; /**< tearDown for each cases */ + CCUnitList testFuncs; /**< test functions */ } CCUnitTestCase; -typedef CCUnitTestCase CCUnitTestFunc; +/** + * TestCase definition structure + */ +typedef struct CCUnitTestCaseDfn +{ + CCUnitTestDfn test; /**< super class */ + const char* name; /**< test case name */ + CCUnitTestFunc* testFuncs; /**< test functions */ +} CCUnitTestCaseDfn; /** - * Create new test case. - * @param name case name. - * @param desc case description. - * @param runTest run test function. - * @return new test case - * @ingroup WritingTestFixture + * create new test case. + * + * @param name test case name. + * @return new test case. + * @ingroup WritingTestCase */ -extern CCUnitTestCase* ccunit_newTestCase (const char* name, - const char* desc, - void (*runTest)()); +extern CCUnitTestCase* ccunit_newTestCase (const char* name); /** - * Create new test function. - * @param name func name. - * @param desc func description. - * @param func run test function. - * @return new test func. - * @ingroup WritingTestFixture + * add test function to test case. + * + * @param testCase test case. + * @param f test function. + * @ingroup WritingTestCase */ -extern inline CCUnitTestFunc* ccunit_newTestFunc (const char* name, - const char* desc, - void (*func)()); -#define CCUNIT_NEWTESTFUNC(FUNC) ccunit_newTestFunc (#FUNC, NULL, FUNC) +extern void ccunit_addTestFunc (CCUnitTestCase* testCase, CCUnitTestFunc* f); /** - * Delete test case. - * @param testCase deleting case. - * @ingroup WritingTestFixture + * add new test func to test case. + * + * @param testCase test case. + * @param name test case name. + * @param desc test case description. + * @param runTest run test function. + * @return new test func + * @ingroup WritingTestCase */ -extern void ccunit_deleteTestCase (CCUnitTestCase* testCase); +extern CCUnitTestFunc* ccunit_addNewTestFunc (CCUnitTestCase* testCase, + const char* name, + const char* desc, + void (*runTest)()); +#define CCUNIT_ADDNEWTESTFUNC(TESTCASE, FN) ccunit_addNewTestFunc (TESTCASE, #FN, NULL, FN) /** - * Delete test func. - * @param testFunc deleting func. - * @ingroup WritingTestFixture + * run test cases and collect its results. + * @param testCase test case. + * @return test result. + * @ingroup ExecutingTest */ -extern inline void ccunit_deleteTestFunc (CCUnitTestFunc* testFunc); +extern inline struct CCUnitTestResult* ccunit_runTestCase (CCUnitTestCase* testCase); /** @} */ - -#endif /* !CCUNITTESTCASE_H */ +#endif -- 2.11.0