Ejemplo n.º 1
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]);
	}

	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;
}
Ejemplo n.º 2
0
void parse_arguments(int argc, const char** argv) {
    if(argc <= 0) {
        /* run all tests of all suites */
        return;
    }

    /* selective runs: deactivate all tests of all suites */
    unsigned int ui_suite, ui_test;
    for(ui_suite = 1; ui_suite <= CU_get_registry()->uiNumberOfSuites; ui_suite++) {
        CU_pSuite suite = CU_get_suite_at_pos(ui_suite);
        for(ui_test = 1; ui_test <= suite->uiNumberOfTests; ui_test++)
            CU_set_test_active(CU_get_test_at_pos(suite, ui_test), CU_FALSE);
    }

    /* activate selected tests */
    int i;
    for(i = 0; i < argc; i++) {
        const char* pos = strchr(argv[i], '.');
        if(pos == NULL) {
            /* suite name: activate all tests of this suite */
            if(argv[i][0] == 0) OXWS_TEST_ARG_ERROR("warning: ignoring empty suite name.");
            CU_pSuite suite = CU_get_suite(argv[i]);
            if(suite == NULL) OXWS_TEST_ARG_ERROR_1("warning: ignoring unknown suite '%s'.", argv[i]);
            for(ui_test = 1; ui_test <= suite->uiNumberOfTests; ui_test++)
                CU_set_test_active(CU_get_test_at_pos(suite, ui_test), CU_TRUE);
        } else {
            /* test name: activate the test only */
            /*   find suite */
            if(pos == argv[i]) OXWS_TEST_ARG_ERROR_1("warning: ignoring empty suite name of argument '%s'.", argv[i]);
            char* suite_name = alloca(sizeof(char) * (pos - argv[i] + 1));
            strncpy(suite_name, argv[i], pos - argv[i]);
            suite_name[pos - argv[i]] = 0;
            CU_pSuite suite = CU_get_suite(suite_name);
            if(suite == NULL) OXWS_TEST_ARG_ERROR_1("warning: ignoring unknown suite '%s'.", suite_name);
            /* find test */
            const char* test_name = pos + 1;
            if(test_name[0] == 0) OXWS_TEST_ARG_ERROR_1("warning: ignoring empty test name of argument '%s'.", argv[i]);
            CU_pTest test = CU_get_test(suite, test_name);
            if(test == NULL) OXWS_TEST_ARG_ERROR_2("warning: ignoring unknown test '%s.%s'.", suite_name, test_name);
            /* activate it */
            CU_set_test_active(test, CU_TRUE);
        }
    }
}
Ejemplo n.º 3
0
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();
}
Ejemplo n.º 4
0
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;

}
Ejemplo n.º 5
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;
}