18 #include "libfocunit.h" 39 int focunit_main(
int argc,
char **argv,
char *test_name, CU_SuiteInfo *
suites)
44 CU_pTestRegistry pRegistry;
48 CU_pFailureRecord FailureList;
49 CU_RunSummary *pRunSummary;
55 fprintf(stderr,
"FATAL: empty test name.\n");
59 if (CU_initialize_registry())
61 fprintf(stderr,
"FATAL: Initialization of Test Registry failed.\n");
65 assert(CU_get_registry());
66 assert(!CU_is_test_running());
68 if (CU_register_suites(suites) != CUE_SUCCESS)
70 fprintf(stderr,
"FATAL: Register suites failed - %s\n", CU_get_error_msg());
73 pRegistry = CU_get_registry();
78 while ((iopt = getopt(argc, argv,
"s:t:")) != -1)
89 fprintf(stderr,
"Invalid argument for %s\n", argv[0]);
95 if (TestName && !SuiteName)
97 fprintf(stderr,
"A Suite name (-s) is required if you specify a test name.\n");
103 pSuite = CU_get_suite_by_name(SuiteName, pRegistry);
106 fprintf(stderr,
"Suite %s not found.\n", SuiteName);
112 pTest = CU_get_test_by_name(TestName, pSuite);
115 fprintf(stderr,
"Test %s not found in suite %s.\n", TestName, SuiteName);
118 ErrCode = CU_run_test(pSuite, pTest);
122 ErrCode = CU_run_suite(pSuite);
127 fprintf(stderr,
"Error: %s\n", CU_get_error_msg());
134 CU_set_output_filename(test_name);
135 CU_list_tests_to_file();
136 CU_automated_run_tests();
139 pRunSummary = CU_get_run_summary();
140 printf(
"%s summary:\n", test_name);
141 printf(
" Number of suites run: %d\n", pRunSummary->nSuitesRun);
142 printf(
" Number of suites failed: %d\n", pRunSummary->nSuitesFailed);
143 printf(
" Number of tests run: %d\n", pRunSummary->nTestsRun);
144 printf(
" Number of tests failed: %d\n", pRunSummary->nTestsFailed);
145 printf(
" Number of asserts: %d\n", pRunSummary->nAsserts);
146 printf(
" Number of asserts failed: %d\n", pRunSummary->nAssertsFailed);
147 printf(
" Number of failures: %d\n", pRunSummary->nFailureRecords);
151 if (pRunSummary->nFailureRecords)
153 printf(
"\nFailures:\n");
155 for (FailureList = CU_get_failure_list(); FailureList; FailureList = FailureList->pNext)
157 printf(
"%d. File: %s Line: %u",
159 FailureList->strFileName,
160 FailureList->uiLineNumber);
162 if (FailureList->pTest) {
163 printf(
" Test: %s", (FailureList->pTest)->pName);
165 if (FailureList->pSuite) {
166 printf(
" Suite: %s", (FailureList->pSuite)->pName);
170 FailureList->strCondition);
178 CU_cleanup_registry();
CU_SuiteInfo suites[]
all test suites for delagent