00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00063 #ifndef _CUNIT_TESTDB_H
00064 #define _CUNIT_TESTDB_H
00065
00066 #include <setjmp.h>
00067
00068 #include "CUnit.h"
00069 #include "CUError.h"
00070
00071 #ifdef __cplusplus
00072 extern "C" {
00073 #endif
00074
00075
00076 typedef int (*CU_InitializeFunc)(void);
00077 typedef int (*CU_CleanupFunc)(void);
00078 typedef void (*CU_TestFunc)(void);
00101 typedef struct CU_Test
00102 {
00103 char* pName;
00104 CU_TestFunc pTestFunc;
00105 jmp_buf* pJumpBuf;
00107 struct CU_Test* pNext;
00108 struct CU_Test* pPrev;
00110 } CU_Test;
00111 typedef CU_Test* CU_pTest;
00138 typedef struct CU_Suite
00139 {
00140 char* pName;
00141 CU_pTest pTest;
00142 CU_InitializeFunc pInitializeFunc;
00143 CU_CleanupFunc pCleanupFunc;
00145 unsigned int uiNumberOfTests;
00146 struct CU_Suite* pNext;
00147 struct CU_Suite* pPrev;
00149 } CU_Suite;
00150 typedef CU_Suite* CU_pSuite;
00186 typedef struct CU_TestRegistry
00187 {
00188 #ifdef USE_DEPRECATED_CUNIT_NAMES
00189
00190 union {
00191 unsigned int uiNumberOfSuites;
00192 unsigned int uiNumberOfGroups;
00193 };
00194 unsigned int uiNumberOfTests;
00196 union {
00197 CU_pSuite pSuite;
00198 CU_pSuite pGroup;
00199 };
00200 #else
00201 unsigned int uiNumberOfSuites;
00202 unsigned int uiNumberOfTests;
00203 CU_pSuite pSuite;
00204 #endif
00205 } CU_TestRegistry;
00206 typedef CU_TestRegistry* CU_pTestRegistry;
00208
00209 CU_ErrorCode CU_initialize_registry(void);
00210 void CU_cleanup_registry(void);
00211
00212 CU_pSuite CU_add_suite(const char* strName, CU_InitializeFunc pInit, CU_CleanupFunc pClean);
00213 CU_pTest CU_add_test(CU_pSuite pSuite, const char* strName, CU_TestFunc pTestFunc);
00214
00216 #define CU_ADD_TEST(suite, test) (CU_add_test(suite, #test, (CU_TestFunc)test))
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00247 typedef struct CU_TestInfo {
00248 char *pName;
00249 CU_TestFunc pTestFunc;
00250 } CU_TestInfo;
00251 typedef CU_TestInfo* CU_pTestInfo;
00261 typedef struct CU_SuiteInfo {
00262 char *pName;
00263 CU_InitializeFunc pInitFunc;
00264 CU_CleanupFunc pCleanupFunc;
00265 CU_TestInfo *pTests;
00266 } CU_SuiteInfo;
00267 typedef CU_SuiteInfo* CU_pSuiteInfo;
00270 #define CU_TEST_INFO_NULL { NULL, NULL }
00271
00272 #define CU_SUITE_INFO_NULL { NULL, NULL, NULL, NULL }
00273
00274 CU_ErrorCode CU_register_suites(CU_SuiteInfo suite_info[]);
00275 CU_ErrorCode CU_register_nsuites(int suite_count, ...);
00276
00277 #ifdef USE_DEPRECATED_CUNIT_NAMES
00278 typedef CU_TestInfo test_case_t;
00279 typedef CU_SuiteInfo test_group_t;
00282 typedef struct test_suite {
00283 char *name;
00284 test_group_t *groups;
00285 } test_suite_t;
00286
00288 #define TEST_CASE_NULL { NULL, NULL }
00289
00290 #define TEST_GROUP_NULL { NULL, NULL, NULL, NULL }
00291
00293 #define test_group_register(tg) CU_register_suites(tg)
00294
00296 int test_suite_register(test_suite_t *ts)
00297 {
00298 test_group_t *tg;
00299 int error;
00300
00301 for (tg = ts->groups; tg->pName; tg++)
00302 if ((error = CU_register_suites(tg)) != CUE_SUCCESS)
00303 return error;
00304
00305 return CUE_SUCCESS;
00306 }
00307 #endif
00308
00309
00310 #ifdef USE_DEPRECATED_CUNIT_NAMES
00311 typedef CU_InitializeFunc InitializeFunc;
00312 typedef CU_CleanupFunc CleanupFunc;
00313 typedef CU_TestFunc TestFunc;
00315 typedef CU_Test _TestCase;
00316 typedef CU_pTest PTestCase;
00318 typedef CU_Suite _TestGroup;
00319 typedef CU_pSuite PTestGroup;
00321 typedef CU_TestRegistry _TestRegistry;
00322 typedef CU_pTestRegistry PTestRegistry;
00324
00326 #define initialize_registry() CU_initialize_registry()
00327
00328 #define cleanup_registry() CU_cleanup_registry()
00329
00330 #define add_test_group(name, init, clean) CU_add_suite(name, init, clean)
00331
00332 #define add_test_case(group, name, test) CU_add_test(group, name, test)
00333
00334
00336 #define get_registry() CU_get_registry()
00337
00338 #define set_registry(reg) CU_set_registry((reg))
00339
00341 #define get_group_by_name(group, reg) CU_get_suite_by_name(group, reg)
00342
00343 #define get_test_by_name(test, group) CU_get_test_by_name(test, group)
00344
00346 #define ADD_TEST_TO_GROUP(group, test) (CU_add_test(group, #test, (CU_TestFunc)test))
00347 #endif
00348
00349
00350 CU_pTestRegistry CU_get_registry(void);
00351 CU_pTestRegistry CU_set_registry(CU_pTestRegistry pTestRegistry);
00352 CU_pTestRegistry CU_create_new_registry(void);
00353 void CU_destroy_existing_registry(CU_pTestRegistry* ppRegistry);
00354 CU_pSuite CU_get_suite_by_name(const char* szSuiteName, CU_pTestRegistry pRegistry);
00355 CU_pTest CU_get_test_by_name(const char* szTestName, CU_pSuite pSuite);
00356
00357 #ifdef CUNIT_BUILD_TESTS
00358 void test_cunit_TestDB(void);
00359 #endif
00360
00361 #ifdef __cplusplus
00362 }
00363 #endif
00364
00365 #endif
00366