/** * @brief copies a suite from one registry to another * * @param[in] in_registry input registry * @param[in] suite_name the test suite name * @param[in] test_name the test name * @return * - 0 when no test or suite have been copied * - 1 if a suite/test has been copied * * @details set test to NULL to copy the whole suite */ static unsigned char copySuite(const CU_pTestRegistry in_registry, const char *suite_name, const char *test_name) { unsigned char ret; CU_pSuite old_suite, new_suite; CU_pTest old_test; old_suite = CU_get_suite_by_name(suite_name, in_registry); if (!old_suite) return 0; new_suite = CU_get_suite_by_name(suite_name, CU_get_registry()); if (!new_suite) new_suite = CU_add_suite(old_suite->pName, old_suite->pInitializeFunc, old_suite->pCleanupFunc); if (test_name) { old_test = CU_get_test_by_name(test_name, old_suite); if (old_test) CU_add_test(new_suite, old_test->pName, old_test->pTestFunc); else return 0; } else { for (old_test = old_suite->pTest; old_test; old_test = old_test->pNext) CU_add_test(new_suite, old_test->pName, old_test->pTestFunc); } return 1; }
int liblinphone_tester_run_tests(const char *suite_name, const char *test_name) { int i; int ret; /* initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); for (i = 0; i < liblinphone_tester_nb_test_suites(); i++) { run_test_suite(test_suite[i]); } if (suite_name){ CU_pSuite suite; CU_basic_set_mode(CU_BRM_VERBOSE); suite=CU_get_suite(suite_name); if (!suite) { ms_error("Could not find suite '%s'. Available suites are:", suite_name); liblinphone_tester_list_suites(); return -1; } else if (test_name) { CU_pTest test=CU_get_test_by_name(test_name, suite); if (!test) { ms_error("Could not find test '%s' in suite '%s'. Available tests are:", test_name, suite_name); // do not use suite_name here, since this method is case sentisitive liblinphone_tester_list_suite_tests(suite->pName); return -2; } else { CU_ErrorCode err= CU_basic_run_test(suite, test); if (err != CUE_SUCCESS) ms_error("CU_basic_run_test error %d", err); } } else { CU_basic_run_suite(suite); } } else { #if HAVE_CU_CURSES if (curses) { /* Run tests using the CUnit curses interface */ CU_curses_run_tests(); } else #endif { /* Run all tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); } } ret=CU_get_number_of_tests_failed()!=0; /* Redisplay list of failed tests on end */ if (CU_get_number_of_failure_records()){ CU_basic_show_failures(CU_get_failure_list()); printf("\n"); } CU_cleanup_registry(); return ret; }
/** Run a selected suite within the curses interface. * Displays actions and responds based on user imput. * @param pSuite The suite to use for testing (non-NULL). */ static STATUS curses_suite_level_run(CU_pSuite pSuite) { char szTestName[STRING_LENGTH]; CU_pTest pTest = NULL; f_szOptions = SUITE_OPTIONS; refresh_options_window(); while (true) { int option = toupper(getch()); switch (option) { case 'R': curses_run_suite_tests(pSuite); break; case 'S': read_input_string("Enter Test Name : ", szTestName, STRING_LENGTH); if (NULL != (pTest = CU_get_test_by_name(szTestName, pSuite))) { curses_run_single_test(pSuite, pTest); } refresh_details_window(); break; case 'L': list_tests(pSuite); break; case 'F': show_failures(); break; case 'U': return CONTINUE; case 'Q': return STOP; case KEY_UP: case KEY_DOWN: case KEY_RIGHT: case KEY_LEFT: scroll_window(option, &details_pad, refresh_details_window); break; default: break; } } return CONTINUE; }
/* A wrapper for the suite's init function. This is done to allow for a * potential runtime check to determine whether each test in the suite * is active (enabled by using ODP_TEST_INFO_CONDITIONAL()). If present, * the conditional check is run after the suite's init function. */ static int _cunit_suite_init(void) { int ret = 0; CU_pSuite cur_suite = CU_get_current_suite(); odp_suiteinfo_t *sinfo; odp_testinfo_t *tinfo; /* find the suite currently being run */ cur_suite = CU_get_current_suite(); if (!cur_suite) return -1; sinfo = cunit_get_suite_info(cur_suite->pName); if (!sinfo) return -1; /* execute its init function */ if (sinfo->pInitFunc) { ret = sinfo->pInitFunc(); if (ret) return ret; } /* run any configured conditional checks and mark inactive tests */ for (tinfo = sinfo->pTests; tinfo->pName; tinfo++) { CU_pTest ptest; CU_ErrorCode err; if (!tinfo->check_active || tinfo->check_active()) continue; /* test is inactive, mark it as such */ ptest = CU_get_test_by_name(tinfo->pName, cur_suite); if (ptest) err = CU_set_test_active(ptest, CU_FALSE); else err = CUE_NOTEST; if (err != CUE_SUCCESS) { fprintf(stderr, "%s: failed to set test %s inactive\n", __func__, tinfo->pName); return -1; } } return ret; }
int liblinphone_tester_run_tests(const char *suite_name, const char *test_name) { int i; int ret; /* initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); for (i = 0; i < liblinphone_tester_nb_test_suites(); i++) { run_test_suite(test_suite[i]); } if (suite_name){ CU_pSuite suite; CU_basic_set_mode(CU_BRM_VERBOSE); suite=CU_get_suite_by_name(suite_name, CU_get_registry()); if (test_name) { CU_pTest test=CU_get_test_by_name(test_name, suite); CU_ErrorCode err= CU_basic_run_test(suite, test); if (err != CUE_SUCCESS) ms_error("CU_basic_run_test error %d", err); } else CU_basic_run_suite(suite); } else { #if HAVE_CU_CURSES if (curses) { /* Run tests using the CUnit curses interface */ CU_curses_run_tests(); } else #endif { /* Run all tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); } } ret=CU_get_number_of_tests_failed()!=0; CU_cleanup_registry(); return ret; }
int mediastreamer2_tester_run_tests(const char *suite_name, const char *test_name) { int i; /* initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); for (i = 0; i < mediastreamer2_tester_nb_test_suites(); i++) { run_test_suite(test_suite[i]); } #if HAVE_CU_GET_SUITE if (suite_name){ CU_pSuite suite; CU_basic_set_mode(CU_BRM_VERBOSE); suite=CU_get_suite(suite_name); if (test_name) { CU_pTest test=CU_get_test_by_name(test_name, suite); CU_basic_run_test(suite, test); } else CU_basic_run_suite(suite); } else #endif { #if HAVE_CU_CURSES if (curses) { /* Run tests using the CUnit curses interface */ CU_curses_run_tests(); } else #endif { /* Run all tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); } } CU_cleanup_registry(); return CU_get_error(); }
int bc_tester_run_tests(const char *suite_name, const char *test_name) { int i; /* initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); for (i = 0; i < nb_test_suites; i++) { bc_tester_run_suite(test_suite[i]); } #ifdef HAVE_CU_GET_SUITE CU_set_suite_start_handler(suite_start_message_handler); CU_set_suite_complete_handler(suite_complete_message_handler); CU_set_test_start_handler(test_start_message_handler); CU_set_test_complete_handler(test_complete_message_handler); #endif CU_set_all_test_complete_handler(all_complete_message_handler); CU_set_suite_init_failure_handler(suite_init_failure_message_handler); CU_set_suite_cleanup_failure_handler(suite_cleanup_failure_message_handler); if( xml_enabled != 0 ){ CU_automated_run_tests(); } else { #ifndef HAVE_CU_GET_SUITE if( suite_name ){ bc_tester_printf(bc_printf_verbosity_info, "Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'", suite_name); } #else if (suite_name){ CU_pSuite suite; suite=CU_get_suite(suite_name); if (!suite) { bc_tester_printf(bc_printf_verbosity_error, "Could not find suite '%s'. Available suites are:", suite_name); bc_tester_list_suites(); return -1; } else if (test_name) { CU_pTest test=CU_get_test_by_name(test_name, suite); if (!test) { bc_tester_printf(bc_printf_verbosity_error, "Could not find test '%s' in suite '%s'. Available tests are:", test_name, suite_name); // do not use suite_name here, since this method is case sensitive bc_tester_list_tests(suite->pName); return -2; } else { CU_ErrorCode err= CU_run_test(suite, test); if (err != CUE_SUCCESS) bc_tester_printf(bc_printf_verbosity_error, "CU_basic_run_test error %d", err); } } else { CU_run_suite(suite); } } else #endif { #ifdef HAVE_CU_CURSES if (curses) { /* Run tests using the CUnit curses interface */ CU_curses_run_tests(); } else #endif { /* Run all tests using the CUnit Basic interface */ CU_run_all_tests(); } } } #ifdef __linux bc_tester_printf(bc_printf_verbosity_info, "Still %i kilobytes allocated when all tests are finished.", mallinfo().uordblks / 1024); #endif return CU_get_number_of_tests_failed()!=0; }
int liblinphone_tester_run_tests(const char *suite_name, const char *test_name) { int i; int ret; /* initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); for (i = 0; i < liblinphone_tester_nb_test_suites(); i++) { run_test_suite(test_suite[i]); } CU_set_test_start_handler(test_start_message_handler); CU_set_test_complete_handler(test_complete_message_handler); CU_set_all_test_complete_handler(test_all_tests_complete_message_handler); CU_set_suite_init_failure_handler(test_suite_init_failure_message_handler); CU_set_suite_cleanup_failure_handler(test_suite_cleanup_failure_message_handler); CU_set_suite_start_handler(test_suite_start_message_handler); if( liblinphone_tester_xml_file != NULL ){ CU_set_output_filename(liblinphone_tester_xml_file); } if( liblinphone_tester_xml_enabled != 0 ){ CU_automated_run_tests(); } else { #if !HAVE_CU_GET_SUITE if( suite_name ){ ms_warning("Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'\n", suite_name); } #else if (suite_name){ CU_pSuite suite; suite=CU_get_suite(suite_name); if (!suite) { ms_error("Could not find suite '%s'. Available suites are:", suite_name); liblinphone_tester_list_suites(); return -1; } else if (test_name) { CU_pTest test=CU_get_test_by_name(test_name, suite); if (!test) { ms_error("Could not find test '%s' in suite '%s'. Available tests are:", test_name, suite_name); // do not use suite_name here, since this method is case sensitive liblinphone_tester_list_suite_tests(suite->pName); return -2; } else { CU_ErrorCode err= CU_run_test(suite, test); if (err != CUE_SUCCESS) ms_error("CU_basic_run_test error %d", err); } } else { CU_run_suite(suite); } } else #endif { #if HAVE_CU_CURSES if (curses) { /* Run tests using the CUnit curses interface */ CU_curses_run_tests(); } else #endif { /* Run all tests using the CUnit Basic interface */ CU_run_all_tests(); } } } ret=CU_get_number_of_tests_failed()!=0; /* Redisplay list of failed tests on end */ if (CU_get_number_of_failure_records()){ CU_basic_show_failures(CU_get_failure_list()); liblinphone_tester_fprintf(stdout,"\n"); } CU_cleanup_registry(); if( liblinphone_tester_keep_accounts_flag == 0){ liblinphone_tester_clear_accounts(); } return ret; }
/* ** The main() function for setting up and running the tests. ** Returns a CUE_SUCCESS on successful running, another ** CUnit error code on failure. */ int main(int argc, char *argv[]) { int index; char *suite_name; CU_pSuite suite_to_run; char *test_name; CU_pTest test_to_run; CU_ErrorCode errCode = 0; CU_pTestRegistry registry; int num_run; int num_failed; PG_SuiteSetup *setupfunc = setupfuncs; /* Install the custom error handler */ lwgeom_set_handlers(0, 0, 0, cu_errorreporter, 0); /* Initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) { errCode = CU_get_error(); printf(" Error attempting to initialize registry: %d. See CUError.h for error code list.\n", errCode); return errCode; } /* Register all the test suites. */ while ( *setupfunc ) { (*setupfunc)(); setupfunc++; } /* Run all tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); if (argc <= 1) { errCode = CU_basic_run_tests(); } else { /* NOTE: The cunit functions used here (CU_get_registry, CU_get_suite_by_name, and CU_get_test_by_name) are * listed with the following warning: "Internal CUnit system functions. Should not be routinely called by users." * However, there didn't seem to be any other way to get tests by name, so we're calling them. */ registry = CU_get_registry(); for (index = 1; index < argc; index++) { suite_name = argv[index]; test_name = NULL; suite_to_run = CU_get_suite_by_name(suite_name, registry); if (NULL == suite_to_run) { /* See if it's a test name instead of a suite name. */ suite_to_run = registry->pSuite; while (suite_to_run != NULL) { test_to_run = CU_get_test_by_name(suite_name, suite_to_run); if (test_to_run != NULL) { /* It was a test name. */ test_name = suite_name; suite_name = suite_to_run->pName; break; } suite_to_run = suite_to_run->pNext; } } if (suite_to_run == NULL) { printf("\n'%s' does not appear to be either a suite name or a test name.\n\n", suite_name); } else { if (test_name != NULL) { /* Run only this test. */ printf("\nRunning test '%s' in suite '%s'.\n", test_name, suite_name); /* This should be CU_basic_run_test, but that method is broken, see: * https://sourceforge.net/tracker/?func=detail&aid=2851925&group_id=32992&atid=407088 * This one doesn't output anything for success, so we have to do it manually. */ errCode = CU_run_test(suite_to_run, test_to_run); if (errCode != CUE_SUCCESS) { printf(" Error attempting to run tests: %d. See CUError.h for error code list.\n", errCode); } else { num_run = CU_get_number_of_asserts(); num_failed = CU_get_number_of_failures(); printf("\n %s - asserts - %3d passed, %3d failed, %3d total.\n\n", (0 == num_failed ? "PASSED" : "FAILED"), (num_run - num_failed), num_failed, num_run); } } else { /* Run all the tests in the suite. */ printf("\nRunning all tests in suite '%s'.\n", suite_name); /* This should be CU_basic_run_suite, but that method is broken, see: * https://sourceforge.net/tracker/?func=detail&aid=2851925&group_id=32992&atid=407088 * This one doesn't output anything for success, so we have to do it manually. */ errCode = CU_run_suite(suite_to_run); if (errCode != CUE_SUCCESS) { printf(" Error attempting to run tests: %d. See CUError.h for error code list.\n", errCode); } else { num_run = CU_get_number_of_tests_run(); num_failed = CU_get_number_of_tests_failed(); printf("\n %s - tests - %3d passed, %3d failed, %3d total.\n", (0 == num_failed ? "PASSED" : "FAILED"), (num_run - num_failed), num_failed, num_run); num_run = CU_get_number_of_asserts(); num_failed = CU_get_number_of_failures(); printf(" - asserts - %3d passed, %3d failed, %3d total.\n\n", (num_run - num_failed), num_failed, num_run); } } } } /* Presumably if the CU_basic_run_[test|suite] functions worked, we wouldn't have to do this. */ CU_basic_show_failures(CU_get_failure_list()); printf("\n\n"); /* basic_show_failures leaves off line breaks. */ } num_failed = CU_get_number_of_failures(); CU_cleanup_registry(); return num_failed; }