????1.3 ??????÷???

???????CUnit??????????????£?

??????д??????????????б????????????г????????????

???????????????? CU_initialize_registry()

?????????????????? CU_add_suite()

?????????????????????? CU_add_test()

??????ú???????????в???CU_automated(basic/console/curses)_run_tests()

?????????????? CU_cleanup_registry()

????1.4 Linux??CUnit????

The usual sequence of steps should succeed in building and installing CUnit:
aclocal  (if necessary)
autoconf (if necessary)
automake (if necessary)
chmod u+x configure (if necessary)
./configure --prefix <Your choice of directory for installation>
make
make install
What's installed:
libcunit.a (Library file)
CUnit Header files
DTD and XSL files supporting xml output files in share directory
Man Pages in relevant man directories under the installation path.
HTML users guide in the doc subdirectory of the installation path.
Example & test programs in the share subdirectory of the install path.

????2. ??дCUnit????????

????2.1 ??????????????????

????CUnit?ж?????????????????????淶????????????????£?

????int maxi(int i1?? int i2)
????{
????return (i1 > i2)  i1 : i2;
????}
????void test_maxi(void)
????{
????CU_ASSERT(maxi(0??2) == 2);
????CU_ASSERT(maxi(0??-2) == 0);
????CU_ASSERT(maxi(2??2) == 2);
????}

????2.2 CUnit?е????

????CUnit???????????????????е?????????????????Щ??????????????????????????????????????

???????????????????????????????????CU_FALSE??????????????????????????????????У???????????“xxx_FATAL”??????????????????ò???????????????????????FATAL??????????ú??????????????FATAL??????????2??????????????????л?????????????????????????????????κ????á?

?????????Щ?????????????“pass”??“fail”??????????????????????????????????????????????????????????????磺

void test_longjmp(void)
{
jmp_buf buf;
int i;
i = setjmp(buf);
if (i == 0) {
run_other_func();
CU_PASS("run_other_func() succeeded.");
}
else
CU_FAIL("run_other_func() issued longjmp.");
}

???????е???????????<CUnit/CUnit.h>

????3. ???????

????3.1 ??????????

#include  <CUnit/TestDB.h>
typedef struct CU_TestRegistry
typedef CU_TestRegistry* CU_pTestRegistry
CU_ErrorCode CU_initialize_registry(void)
void CU_cleanup_registry(void)
CU_BOOL CU_registry_initialized(void)
CU_pTestRegistry CU_get_registry(void)
CU_pTestRegistry CU_set_registry(CU_pTestRegistry pTestRegistry)
CU_pTestRegistry CU_create_new_registry(void)
void CU_destroy_existing_registry(CU_pTestRegistry* ppRegistry)

????3.2 ??????????

?????????????????????????????????????????????????????????CUnit???????????????????????£????????????????в?????????????????????????е???????????С?

???????????????<CUnit_TestDB.h>?ж??壬?????????в???????????????в???????????????????????????в????????????

typedef struct CU_TestRegistry
{
unsigned int uiNumberOfSuites;
unsigned int uiNumberOfTests;
CU_pSuite    pSuite;
} CU_TestRegistry;
typedef CU_TestRegistry* CU_pTestRegistry;

????????????????????????????????????????????????ɡ?????CUnit???????Щ??????????????????