/**
* Test class type.
*/
-enum CCUnitTestType_t {
+typedef enum CCUnitTestType_t {
ccunitTypeTest, /**< Test class */
ccunitTypeSuite, /**< TestSuite class */
ccunitTypeCase, /**< TestCase class */
ccunitTypeFunc, /**< TestFunc class */
ccunitTypeLast_ /**< last tag */
-};
-typedef enum CCUnitTestType_t CCUnitTestType_t;
+} CCUnitTestType_t;
struct CCUnitTestResult;
+
+/**
+ * run Test and collect its results.
+ *
+ * @see CCUnitTestResult
+ */
typedef struct CCUnitTest CCUnitTest;
+
+/**
+ * run test function pointer type.
+ */
typedef void (*ccunit_runtest_func_t) (CCUnitTest* test,
struct CCUnitTestResult* result);
+
+/**
+ * test destructor function pointer type.
+ */
typedef void (*ccunit_testdtor_t) (CCUnitTest* dt);
/**
#include <ccunit/CCUnitList.h>
#include <ccunit/CCUnitTest.h>
+/**
+ * test method information.
+ */
typedef struct CCUnitTestFunc
{
- CCUnitTest test;
- void (*testFunc) ();
- const char* desc;
+ CCUnitTest test; /**< super class */
+ void (*testFunc) (); /**< test method */
+ const char* desc; /**< description */
} CCUnitTestFunc;
+/**
+ * A test case defines the fixture to run multiple tests. To define a
+ * test case:
+ * <ol>
+ * <li>define static variable that store the state of the fixture.
+ * <li>initialize the fixture state by <code>setUp</code> function.
+ * <li>clean-up after a test by <code>tearDown</code>.
+ * </ol>
+ * <p>
+ * Each test runs in its own fixture so there can be no side effects
+ * among test runs. Here is an example:
+ * </p>
+ * <pre>
+ * /a;* test case: MathTest a;/
+ * static double value1;
+ * static double value2;
+ *
+ * void setUp_MathTest()
+ * {
+ * value1 = 2.0;
+ * value2 = 3.0;
+ * }
+ * </pre>
+ * <p>
+ * For each test implement a function which interacts with the
+ * fixture. Verify the expected results with assertions specified by
+ * calling <code>CCUNIT_ASSERT</code><var>_XXX</var> with a boolean.
+ * </p>
+ * <pre>
+ * /a;* add test a;/
+ * void testAdd()
+ * {
+ * double result = fValue1 + fValue2;
+ * CCUNIT_ASSERT_EQ_DOUBLE(5.0, result);
+ * }
+ * </pre>
+ * <p>
+ * Once the functions are defined you can run them.
+ * <pre>
+ * int main ()
+ * {
+ * CCUnitTestRunner* runner = ccunit_newTestRunner (stdout);
+ * CCUnitTestSuite* suite = ccunit_newTestSuite ("suite");
+ * CCUnitTestCase* testCase = ccunit_newTestCase ("MathTest",
+ * setUp_MathTest,
+ * tearDown_MathTest);
+ * ccunit_addTestFunc (testCase, "testAdd", testAdd, "add test");
+ * ccunit_addTestCase (suite, testCase);
+ * runner->run (runner, suite);
+ * return ccunit_wasSuccessful (runner->result) ? 0 : -1;
+ * }
+ * </pre>
+ * @see CCUnitTestResult
+ * @see CCUnitTestSuite
+ * @see CCUnitMakeSuite
+ */
typedef struct CCUnitTestCase
{
- CCUnitTest test;
- CCUnitList testFuncs;
- void (*setUp) ();
- void (*tearDown) ();
+ CCUnitTest test; /**< super class */
+ CCUnitList testFuncs; /**< test functions list */
+ void (*setUp) (); /**< setUp function */
+ void (*tearDown) (); /**< tearDown function */
} CCUnitTestCase;
+/**
+ * create new test case.
+ *
+ * @param name test case name.
+ * @param setUp test fixture setUp function.
+ * @param tearDown test fixture tearDown function.
+ * @return new test case.
+ */
extern CCUnitTestCase* ccunit_newTestCase (const char* name,
void (*setUp)(),
void (*tearDown)());
+/**
+ * add test function into test case.
+ * @param testCase test case to add.
+ * @param name function name.
+ * @param testFunc test function.
+ * @param desc test function description.
+ */
extern void ccunit_addTestFunc (CCUnitTestCase* testCase,
const char* name,
void(*testFunc)(),
const char* desc);
+/**
+ * run a test function in test case.
+ * @param testCase test case to run.
+ * @param func test function to be run.
+ */
extern void ccunit_runTestCase (CCUnitTestCase* testCase, CCUnitTestFunc* func);
#endif
typedef void (*ccunit_notifytest_func_t)(CCUnitTestListener* listener,
CCUnitTestCase* testCase);
+/**
+ * A Listener for test progress.
+ */
struct CCUnitTestListener
{
+ /**
+ * A failure occurred.
+ */
ccunit_addfailure_func_t addFailure;
+
+ /**
+ * A test started.
+ */
ccunit_notifytest_func_t startTest;
+
+ /**
+ * A test ended.
+ */
ccunit_notifytest_func_t endTest;
};
#include <ccunit/CCUnitTest.h>
#include <ccunit/CCUnitTestCase.h>
+/**
+ * A <code>Composite</code> class of Tests.
+ * It runs a collection of test cases. Here is an example.
+ * <pre>
+ * CCUnitTestSuite* suite = ccunit_newTestSuite ();
+ * ccunit_addTestCase (suite, CREATE_TESTCASE_1 ());
+ * ccunit_addTestCase (suite, CREATE_TESTCASE_2 ());
+ * </pre>
+ *
+ * @see CCUnitTest
+ */
typedef struct CCUnitTestSuite
{
- CCUnitTest test;
- CCUnitList tests;
+ CCUnitTest test; /**< super class */
+ CCUnitList tests; /**< added test case/suite list */
} CCUnitTestSuite;
+/**
+ * Constructs an empty TestSuite.
+ * @param name test suite name.
+ * @return new test suite.
+ */
extern inline CCUnitTestSuite* ccunit_newTestSuite(const char* name);
-extern inline void ccunit_deleteTestSuite (CCUnitTestSuite*);
+/**
+ * Delete test suite.
+ * @param suite test suite to delete.
+ */
+extern inline void ccunit_deleteTestSuite (CCUnitTestSuite* suite);
+
+/**
+ * Adds a test to the suite.
+ * @param suite test suite.
+ * @param test test to add.
+ */
extern inline void ccunit_addTest (CCUnitTestSuite* suite, CCUnitTest* test);
+
+/**
+ * Adds a test suite to the suite.
+ * @param suite test suite.
+ * @param testSuite test to add.
+ */
extern inline void ccunit_addTestSuite (CCUnitTestSuite* suite,
CCUnitTestSuite* testSuite);
+
+/**
+ * Adds a test case to the suite.
+ * @param suite test suite.
+ * @param testCase test to add.
+ */
extern inline void ccunit_addTestCase (CCUnitTestSuite* suite,
CCUnitTestCase* testCase);
+/**
+ * Create a test suite from test source file.
+ * @param name test suite name.
+ * @return new test suite.
+ */
extern CCUnitTestSuite* ccunit_suite (const char* name);
#endif