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

📄 console.c

📁 CUNIT
💻 C
📖 第 1 页 / 共 2 页
字号:
  CU_set_registry(pOldRegistry);  return result;}/*------------------------------------------------------------------------*//** Run a specified suite within the console interface. * @param pSuite The suite to be run (non-NULL). * @return An error code indicating the error status *         during the test run. */static CU_ErrorCode console_run_suite(CU_pSuite pSuite){  f_pRunningSuite = NULL;  return CU_run_suite(pSuite);}/*------------------------------------------------------------------------*//** Run a specific test for the specified suite within  * the console interface. * @param pSuite The suite containing the test to be run (non-NULL). * @param pTest  The test to be run (non-NULL). * @return An error code indicating the error status *         during the test run. */static CU_ErrorCode console_run_single_test(CU_pSuite pSuite, CU_pTest pTest){  f_pRunningSuite = NULL;  return CU_run_test(pSuite, pTest);}/*------------------------------------------------------------------------*//** Read the name of a test from standard input and * locate the test having the specified name. * A pointer to the located test is stored in pTest * upon return. * @param pSuite The suite to be queried. * @param ppTest Pointer to location to store the selected test. * @return CUE_SUCCESS if a test was successfully selected, *         CUE_NOTEST otherwise.  On return, ppTest points *         to the test selected. */static CU_ErrorCode select_test(CU_pSuite pSuite, CU_pTest* ppTest){  char szTestName[MAX_TEST_NAME_LENGTH];  fprintf(stdout,"\nEnter Test Name : ");  fgets(szTestName, MAX_TEST_NAME_LENGTH, stdin);  sscanf(szTestName, "%[^\n]s", szTestName);  *ppTest = CU_get_test_by_name(szTestName, pSuite);  return (*ppTest) ? CUE_SUCCESS : CUE_NOTEST;}/*------------------------------------------------------------------------*//** Read the name of a suite from standard input and * locate the suite having the specified name. * The input string is used to locate the suite having the * indicated name, which is returned in pSuite.  ppSuite will * be NULL if there is no suite registered in pRegistry having * the input name.  Returns NULL if the suite is successfully * located, non-NULL otherwise. * @param pRegistry The CU_pTestRegistry to query (non-NULL). * @param ppSuite Pointer to location to store the selected suite. * @return CUE_SUCCESS if a suite was successfully selected, *         CUE_NOSUITE otherwise.  On return, ppSuite points *         to the suite selected. */static CU_ErrorCode select_suite(CU_pTestRegistry pRegistry, CU_pSuite* ppSuite){  char szSuiteName[MAX_SUITE_NAME_LENGTH];  assert(pRegistry);  fprintf(stdout,"\n\nEnter Suite Name : ");  fgets(szSuiteName, MAX_SUITE_NAME_LENGTH, stdin);  sscanf(szSuiteName, "%[^\n]s", szSuiteName);  *ppSuite = CU_get_suite_by_name(szSuiteName, pRegistry);  return (*ppSuite) ? CUE_SUCCESS : CUE_NOSUITE;}/*------------------------------------------------------------------------*//** List the suites in a registry to standard output. * @param pRegistry The CU_pTestRegistry to query (non-NULL). */static void list_suites(CU_pTestRegistry pRegistry){  CU_pSuite pCurSuite = NULL;  int i;  assert(pRegistry);  if (0 == pRegistry->uiNumberOfSuites) {    fprintf(stdout, "\nNo suites registered.\n");    return;  }  assert(pRegistry->pSuite);  fprintf(stdout, "\n--------------------- Registered Suites --------------------------");  fprintf(stdout, "\n     Suite Name                          Init?  Cleanup?  # Tests\n");  for (i = 1, pCurSuite = pRegistry->pSuite; pCurSuite; pCurSuite = pCurSuite->pNext, ++i) {    fprintf(stdout, "\n%3d. %-34.33s   %3s     %3s       %3d",            i,            pCurSuite->pName,            pCurSuite->pInitializeFunc ? "YES" : "NO",            pCurSuite->pCleanupFunc ? "YES" : "NO",            pCurSuite->uiNumberOfTests);  }  fprintf(stdout, "\n------------------------------------------------------------------"                  "\nTotal Number of Suites : %-d\n", pRegistry->uiNumberOfSuites);}/*------------------------------------------------------------------------*//** List the tests in a suite to standard output. * @param pSuite The suite to query (non-NULL). */static void list_tests(CU_pSuite pSuite){  CU_pTest pCurTest = NULL;   unsigned int uiCount;  assert(pSuite);  if (0 == pSuite->uiNumberOfTests) {    fprintf(stdout, "\nSuite %s contains no tests.\n", pSuite->pName);    return;  }  assert(pSuite->pTest);  fprintf(stdout, "\n--------------- Test List ---------------------------------");  fprintf(stdout, "\n      Test Names (Suite: %s)\n", pSuite->pName);  for (uiCount = 1, pCurTest = pSuite->pTest; pCurTest; uiCount++, pCurTest = pCurTest->pNext) {    fprintf(stdout, "\n%3d.  %s", uiCount, pCurTest->pName);  }  fprintf(stdout, "\n-----------------------------------------------------------"                  "\nTotal Number of Tests : %-d\n", pSuite->uiNumberOfTests);}/*------------------------------------------------------------------------*//** Display the record of test failures on standard output. */static void show_failures(void){  int i;  CU_pFailureRecord pFailure = CU_get_failure_list();  if (NULL == pFailure) {    fprintf(stdout, "\nNo failures.\n");  }  else {    fprintf(stdout, "\n--------------- Test Run Failures -------------------------");    fprintf(stdout, "\n   src_file:line# : (suite:test) : failure_condition\n");    for (i = 1 ; pFailure ; pFailure = pFailure->pNext, i++) {      fprintf(stdout, "\n%d. %s:%d : (%s : %s) : %s", i,          pFailure->strFileName ? pFailure->strFileName : "",          pFailure->uiLineNumber,          pFailure->pSuite ? pFailure->pSuite->pName : "",          pFailure->pTest ? pFailure->pTest->pName : "",          pFailure->strCondition ? pFailure->strCondition : "");    }    fprintf(stdout, "\n-----------------------------------------------------------"                    "\nTotal Number of Failures : %-d\n", i - 1);  }}/*------------------------------------------------------------------------*//** Handler function called at start of each test. * @param pTest  The test being run. * @param pSuite The suite containing the test. */static void console_test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite){  assert(pTest);  assert(pSuite);    /* Comparing the Addresses rather than the Group Names. */  if (!f_pRunningSuite || f_pRunningSuite != pSuite) {    fprintf(stdout, "\nRunning Suite : %s", pSuite->pName);    fprintf(stdout, "\n\tRunning test : %s", pTest->pName);    f_pRunningSuite = pSuite;  }  else {    fprintf(stdout, "\n\tRunning test : %s", pTest->pName);  }}/*------------------------------------------------------------------------*//** Handler function called at completion of each test. * @param pTest   The test being run. * @param pSuite  The suite containing the test. * @param pFailure Pointer to the 1st failure record for this test. */static void console_test_complete_message_handler(const CU_pTest pTest, const CU_pSuite pSuite, const CU_pFailureRecord pFailure){  /*   *   For console interface do nothing. This is useful only for the test   *   interface where UI is involved.  Just silence compiler warnings.   */  (void)pTest;  (void)pSuite;  (void)pFailure;}/*------------------------------------------------------------------------*//** Handler function called at completion of all tests in a suite. * @param pFailure Pointer to the test failure record list. */static void console_all_tests_complete_message_handler(const CU_pFailureRecord pFailure){  CU_pRunSummary pRunSummary = CU_get_run_summary();  CU_pTestRegistry pRegistry = CU_get_registry();  (void)pFailure; /* not used in console interface - silence warning */  assert(pRunSummary);  assert(pRegistry);  fprintf(stdout,"\n\n--Run Summary: Type      Total     Ran  Passed  Failed"                   "\n               suites %8u%8u     n/a%8u"                   "\n               tests  %8u%8u%8u%8u"                   "\n               asserts%8u%8u%8u%8u\n",          pRegistry->uiNumberOfSuites,          pRunSummary->nSuitesRun,          pRunSummary->nSuitesFailed,          pRegistry->uiNumberOfTests,          pRunSummary->nTestsRun,          pRunSummary->nTestsRun - pRunSummary->nTestsFailed,          pRunSummary->nTestsFailed,          pRunSummary->nAsserts,          pRunSummary->nAsserts,          pRunSummary->nAsserts - pRunSummary->nAssertsFailed,          pRunSummary->nAssertsFailed);} /*------------------------------------------------------------------------*//** Handler function called when suite initialization fails. * @param pSuite The suite for which initialization failed. */static void console_suite_init_failure_message_handler(const CU_pSuite pSuite){  assert(pSuite);  fprintf(stdout, "\nWARNING - Suite initialization failed for %s.",          pSuite->pName);}/** @} */

⌨️ 快捷键说明

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