Exemplo n.º 1
0
/**
 * @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;
}
Exemplo n.º 2
0
/** Main loop for curses interface.
 * Displays actions and responds based on user imput.
 * @param pRegistry The CU_pTestRegistry to use for testing (non-NULL).
 */
static STATUS curses_registry_level_run(CU_pTestRegistry pRegistry)
{
  char szSuiteName[STRING_LENGTH];
  CU_pSuite pSuite = NULL;
  bool bContinue = true;

  while (bContinue) {
    int option = toupper(getch());

    switch (option) {
      case 'R':
        curses_run_all_tests(pRegistry);
        break;

      case 'S':
        read_input_string("Enter Suite Name : ", szSuiteName, STRING_LENGTH);
        refresh_details_window();
        if (NULL != (pSuite = CU_get_suite_by_name(szSuiteName, (NULL == pRegistry) ? pRegistry : CU_get_registry()))) {
          if (STOP == curses_suite_level_run(pSuite)) {
            bContinue = false;
          }
          f_szOptions = MAIN_OPTIONS;
          refresh_options_window();
        }
        break;

      case 'L':
        list_suites(pRegistry);
        break;

      case 'F':
        show_failures();
        break;

      case 'Q':
        return bContinue = false;

      case KEY_UP:
      case KEY_DOWN:
      case KEY_RIGHT:
      case KEY_LEFT:
        scroll_window(option, &details_pad, refresh_details_window);
        break;

      default:
        break;
    }
  }

  return STOP;
}
Exemplo n.º 3
0
static int cunit_update_suite(odp_suiteinfo_t *updated_sinfo)
{
    CU_pSuite suite = NULL;
    CU_ErrorCode err;
    odp_suiteinfo_t *sinfo;
    odp_testinfo_t *tinfo;

    /* find previously registered suite with matching name */
    sinfo = cunit_get_suite_info(updated_sinfo->pName);

    if (sinfo) {
        /* lookup the associated CUnit suite */
        suite = CU_get_suite_by_name(updated_sinfo->pName,
                                     CU_get_registry());
    }

    if (!sinfo || !suite) {
        fprintf(stderr, "%s: unable to find existing suite named %s\n",
                __func__, updated_sinfo->pName);
        return -1;
    }

    sinfo->pInitFunc = updated_sinfo->pInitFunc;
    sinfo->pCleanupFunc = updated_sinfo->pCleanupFunc;

    err = CU_set_suite_cleanupfunc(suite, updated_sinfo->pCleanupFunc);
    if (err != CUE_SUCCESS) {
        fprintf(stderr, "%s: failed to update cleanup func for %s\n",
                __func__, updated_sinfo->pName);
        return -1;
    }

    for (tinfo = updated_sinfo->pTests; tinfo->pName; tinfo++) {
        int ret;

        ret = cunit_update_test(suite, sinfo, tinfo);
        if (ret != 0)
            return ret;
    }

    return 0;
}
Exemplo n.º 4
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_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;
}
Exemplo n.º 5
0
/*
** 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;
}