⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdb.c

📁 CUNIT
💻 C
📖 第 1 页 / 共 5 页
字号:
  return CU_register_nsuites(1, suite_info);}/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*//* *  Private static function definitions *//*------------------------------------------------------------------------*//** Internal function to clean up the specified test registry. * cleanup_suite() will be called for each registered suite to perform * cleanup of the associated test cases.  Then, the suite's memory will * be freed.  Note that any pointers to tests or suites in pRegistry * held by the user will be invalidated by this function.  Severe problems * can occur if this function is called during a test run involving pRegistry. * Note that memory held for data members in the registry (e.g. pName) and * the registry itself are not freed by this function. * @see cleanup_suite() * @see cleanup_test() * @param pRegistry CU_pTestRegistry to clean up (non-NULL). */static void cleanup_test_registry(CU_pTestRegistry pRegistry){  CU_pSuite pCurSuite = NULL;  CU_pSuite pNextSuite = NULL;  assert(pRegistry);  pCurSuite = pRegistry->pSuite;  while (pCurSuite) {    pNextSuite = pCurSuite->pNext;    cleanup_suite(pCurSuite);    CU_FREE(pCurSuite);    pCurSuite = pNextSuite;  }  pRegistry->pSuite = NULL;  pRegistry->uiNumberOfSuites = 0;  pRegistry->uiNumberOfTests = 0;}/*------------------------------------------------------------------------*//** Internal function to create a new test suite having the specified parameters. * This function creates a new test suite having the specified * name and initialization/cleanup functions.  The strName cannot * be NULL (checked by assertion), but either or both function * pointers can be.  A pointer to the newly-created suite is returned, * or NULL if there was an error allocating memory for the new suite. * It is the responsibility of the caller to destroy the returned * suite (use cleanup_suite() before freeing the returned pointer). * @param strName Name for the new test suite (non-NULL). * @param pInit   Initialization function to call before running suite. * @param pClean  Cleanup function to call after running suite. * @return A pointer to the newly-created suite (NULL if creation failed) */static CU_pSuite create_suite(const char* strName, CU_InitializeFunc pInit, CU_CleanupFunc pClean){  CU_pSuite pRetValue = (CU_pSuite)CU_MALLOC(sizeof(CU_Suite));  assert(strName);  if (NULL != pRetValue) {    pRetValue->pName = (char *)CU_MALLOC(strlen(strName)+1);    if (NULL == pRetValue->pName) {      CU_FREE(pRetValue);      pRetValue = NULL;    }    else {      strcpy(pRetValue->pName, strName);      pRetValue->pInitializeFunc = pInit;      pRetValue->pCleanupFunc = pClean;      pRetValue->pTest = NULL;      pRetValue->pNext = NULL;      pRetValue->pPrev = NULL;      pRetValue->uiNumberOfTests = 0;    }  }  return pRetValue;}/*------------------------------------------------------------------------*//** Internal function to clean up the specified test suite. * Each test case registered with pSuite will be freed. * Severe problems can occur if this function is called * during a test run involving pSuite. * @see cleanup_test_registry() * @see cleanup_test() * @param pSuite CU_pSuite to clean up (non-NULL). */static void cleanup_suite(CU_pSuite pSuite){  CU_pTest pCurTest = NULL;  CU_pTest pNextTest = NULL;  assert(pSuite);  pCurTest = pSuite->pTest;  while (pCurTest) {    pNextTest = pCurTest->pNext;    cleanup_test(pCurTest);    CU_FREE(pCurTest);    pCurTest = pNextTest;  }  if (pSuite->pName)    CU_FREE(pSuite->pName);  pSuite->pName = NULL;  pSuite->pTest = NULL;  pSuite->uiNumberOfTests = 0;}/*------------------------------------------------------------------------*//** Internal function to insert a suite into a registry. * The suite name is assumed to be unique.  Internally, the list * of suites is a double-linked list, which this function manages. * Insertion of duplicate (or NULL) pSuites is not allowed. * Severe problems can occur if this function is called during a * test run involving pRegistry. * @param pRegistry CU_pTestRegistry to insert into (non-NULL). * @param pSuite    CU_pSuite to insert (non-NULL). * @see insert_test() */static void insert_suite(CU_pTestRegistry pRegistry, CU_pSuite pSuite){  CU_pSuite pCurSuite = NULL;  assert(pRegistry);  assert(pSuite);  pCurSuite = pRegistry->pSuite;  assert(pCurSuite != pSuite);  pSuite->pNext = NULL;  pRegistry->uiNumberOfSuites++;  /* if this is the 1st suite to be added... */  if (NULL == pCurSuite) {    pRegistry->pSuite = pSuite;    pSuite->pPrev = NULL;  }  /* otherwise, add it to the end of the linked list... */  else {    while (NULL != pCurSuite->pNext) {      pCurSuite = pCurSuite->pNext;      assert(pCurSuite != pSuite);    }    pCurSuite->pNext = pSuite;    pSuite->pPrev = pCurSuite;  }}/*------------------------------------------------------------------------*//** Internal function to create a new test case having the specified parameters. * This function creates a new test having the specified name and * test function.  The strName cannot be NULL (checked by assertion), * but the function pointer may be.  A pointer to the newly-created  * test is returned, or NULL if there was an error allocating memory for * the new test.  It is the responsibility of the caller to destroy the * returned test (use cleanup_test() before freeing the returned pointer). * @param strName   Name for the new test. * @param pTestFunc Test function to call when running this test. * @return A pointer to the newly-created test (NULL if creation failed) */static CU_pTest create_test(const char* strName, CU_TestFunc pTestFunc){  CU_pTest pRetValue = (CU_pTest)CU_MALLOC(sizeof(CU_Test));  assert(strName);  if (NULL != pRetValue) {    pRetValue->pName = (char *)CU_MALLOC(strlen(strName)+1);    if (NULL == pRetValue->pName) {      CU_FREE(pRetValue);      pRetValue = NULL;    }    else {      strcpy(pRetValue->pName, strName);      pRetValue->pTestFunc = pTestFunc;      pRetValue->pJumpBuf = NULL;      pRetValue->pNext = NULL;      pRetValue->pPrev = NULL;    }  }  return pRetValue;}/*------------------------------------------------------------------------*//** Internal function to clean up the specified test. * All memory associated with the test will be freed. * Severe problems can occur if this function is called * during a test run involving pTest. * @see cleanup_test_registry() * @see cleanup_suite() * @param pTest CU_pTest to clean up (non-NULL). */static void cleanup_test(CU_pTest pTest){  assert(pTest);  if (pTest->pName)    CU_FREE(pTest->pName);  pTest->pName = NULL;}/*------------------------------------------------------------------------*//** Internal function to insert a test into a suite. * The test name is assumed to be unique.  Internally, the list * of tests in a suite is a double-linked list, which this * function manages.   Insertion of duplicate tests (or NULL * pTest) is not allowed.  Severe problems can occur if this function * is called during a test run involving pSuite. * @param pSuite CU_pSuite to insert into (non-NULL). * @param pTest  CU_pTest to insert (non-NULL). * @see insert_suite() */static void insert_test(CU_pSuite pSuite, CU_pTest pTest){  CU_pTest pCurTest = NULL;  assert(pSuite);  assert(pTest);  pCurTest = pSuite->pTest;  assert(pCurTest != pTest);  pTest->pNext = NULL;  pSuite->uiNumberOfTests++;  /* if this is the 1st suite to be added... */  if (NULL == pCurTest) {    pSuite->pTest = pTest;    pTest->pPrev = NULL;  }  else {    while (NULL != pCurTest->pNext) {      pCurTest = pCurTest->pNext;      assert(pCurTest != pTest);    }    pCurTest->pNext = pTest;    pTest->pPrev = pCurTest;  }}/*------------------------------------------------------------------------*//** Internal function to check whether a suite having a specified * name already exists. * @param pRegistry   CU_pTestRegistry to check (non-NULL). * @param szSuiteName Suite name to check. * @return TRUE if suite exists in the registry, FALSE otherwise. */static BOOL suite_exists(CU_pTestRegistry pRegistry, const char* szSuiteName){  CU_pSuite pSuite = NULL;  assert(pRegistry);  pSuite = pRegistry->pSuite;  while (pSuite) {    if (!CU_compare_strings(szSuiteName, pSuite->pName))      return TRUE;    pSuite = pSuite->pNext;  }  return FALSE;}/*------------------------------------------------------------------------*//** Internal function to check whether a test having a specified * name is already registered in a given suite. * @param pSuite     CU_pSuite to check. * @param szTestName Test case name to check. * @return TRUE if test exists in the suite, FALSE otherwise. */static BOOL test_exists(CU_pSuite pSuite, const char* szTestName){  CU_pTest pTest = NULL;  assert(pSuite);  pTest = pSuite->pTest;  while (pTest) {    if (!CU_compare_strings(szTestName, pTest->pName))      return TRUE;    pTest = pTest->pNext;  }  return FALSE;}/*------------------------------------------------------------------------*//** Create and initialize a new test registry. * Returns a pointer to a new, initialized registry (NULL if * memory could not be allocated).  It is the caller's * responsibility to destroy and free the new registry * (unless it is made the active test registry using * CU_set_registry(). */CU_pTestRegistry CU_create_new_registry(void){  CU_pTestRegistry pRegistry = (CU_pTestRegistry)CU_MALLOC(sizeof(CU_TestRegistry));  if (NULL != pRegistry) {    pRegistry->pSuite = NULL;    pRegistry->uiNumberOfSuites = 0;    pRegistry->uiNumberOfTests = 0;  }  return pRegistry;}/*------------------------------------------------------------------------*//** Destroy and free all memory for an existing test registry. * The active test registry is destroyed by the CUnit system in * CU_cleanup_registry(), so only call this function on registries * created independently of the internal CUnit system.  Once a * registry is made the active test registry using CU_set_registry(), * its destruction will be handled by the framework.  Passing a * NULL *ppRegistry will have no effect. * @param ppRegistry Address of a pointer to the registry to destroy. */void CU_destroy_existing_registry(CU_pTestRegistry* ppRegistry){  /* Note - CU_cleanup_registry counts on being able to pass NULL */  if (NULL != *ppRegistry) {    cleanup_test_registry(*ppRegistry);    CU_FREE(*ppRegistry);    *ppRegistry = NULL;  }}/*------------------------------------------------------------------------*//** Retrieve a pointer to the suite having the specified name. * Scans the pRegistry and returns a pointer to the first * suite located having the specified name. * @param szSuiteName The name of the suite to locate. * @param pRegistry   The registry to scan. * @return Pointer to the first suite having the specified name, *         NULL if not found. */CU_pSuite CU_get_suite_by_name(const char* szSuiteName, CU_pTestRegistry pRegistry){	CU_pSuite pSuite = NULL;	CU_pSuite pCur = NULL;  assert(pRegistry);	pCur = pRegistry->pSuite;	while (pCur) {		if (!CU_compare_strings(pCur->pName, szSuiteName)) {			pSuite = pCur;			break;		}		pCur = pCur->pNext;	}	return pSuite;}/*------------------------------------------------------------------------*//** Retrieve a pointer to the test case having the specified name. * Scans the pSuite and returns a pointer to the first * test case located having the specified name. * @param szTestName The name of the test case to locate. * @param pSuite     The suite to scan.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -