Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

TestDB.h

Go to the documentation of this file.
00001 /*
00002  *  CUnit - A Unit testing framework library for C.
00003  *  Copyright (C) 2001  Anil Kumar
00004  *  Copyright (C) 2004  Anil Kumar, Jerry St.Clair
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Library General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public
00017  *  License along with this library; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  *  Contains all the Type Definitions and functions declarations
00023  *  for the CUnit test database maintenance.
00024  *
00025  *  Created By     : Anil Kumar on ...(in month of Aug 2001)
00026  *  Last Modified  : 09/Aug/2001
00027  *  Comment        : Added Preprocessor conditionals for the file.
00028  *  EMail          : aksaharan@yahoo.com
00029  *
00030  *  Last Modified  : 24/aug/2001 by Anil Kumar
00031  *  Comment        : Made the linked list from SLL to DLL(doubly linked list).
00032  *  EMail          : aksaharan@yahoo.com
00033  *
00034  *  Last Modified  : 31-Aug-2004 (JDS)
00035  *  Comment        : Restructured to eliminate global variables error_number, g_pTestRegistry
00036  *                   new interface, support for deprecated version 1 interface,
00037  *                   moved error handling code to CUError.h and CUError.c, moved
00038  *                   test run counts and _TestResult out of TestRegistry to
00039  *                   TestRun.h.
00040  *  EMail          : jds2@users.sourceforge.net
00041  *
00042  *  Last Modified  : 1-Sep-2004 (JDS)
00043  *  Comment        : Added jmp_buf to CU_Test.
00044  *  Email          : jds2@users.sourceforge.net
00045  *
00046  *  Modified       : 5-Sep-2004 (JDS)
00047  *  Comment        : Added internal test interface.
00048  *  EMail          : jds2@users.sourceforge.net
00049  */
00050 
00063 #ifndef _CUNIT_TESTDB_H
00064 #define _CUNIT_TESTDB_H
00065 
00066 #include <setjmp.h>   /* jmp_buf */
00067 
00068 #include "CUnit.h"
00069 #include "CUError.h"
00070 
00071 #ifdef __cplusplus
00072 extern "C" {
00073 #endif
00074 
00075 /*  Type definition for Initialization/Cleaup/TestFunction */
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 /* Public interface functions */
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 /*  This section is based conceptually on code
00220  *  Copyright (C) 2004  Aurema Pty Ltd.
00221  *
00222  *  This library is free software; you can redistribute it and/or
00223  *  modify it under the terms of the GNU Library General Public
00224  *  License as published by the Free Software Foundation; either
00225  *  version 2 of the License, or (at your option) any later version.
00226  *
00227  *  This library is distributed in the hope that it will be useful,
00228  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00229  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00230  *  Library General Public License for more details.
00231  *
00232  *  You should have received a copy of the GNU Library General Public
00233  *  License along with this library; if not, write to the Free Software
00234  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00235  *
00236  *  Derived from code contributed by K. Cheung and Aurema Pty Ltd. (thanks!)
00237  *    test_case_t, test_group_t, test_suite_t
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    /* USE_DEPRECATED_CUNIT_NAMES */
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 /* Public interface functions */
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 /* private internal CUnit testing functions */
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  /* USE_DEPRECATED_CUNIT_NAMES */
00348 
00349 /* Internal CUnit system functions.  Should not be routinely called by users. */
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  /*  _CUNIT_TESTDB_H  */
00366 

Generated on Thu Apr 28 12:36:09 2005 for CUnit by  doxygen 1.3.9.1