static int cunit_update_test(CU_pSuite suite, odp_suiteinfo_t *sinfo, odp_testinfo_t *updated_tinfo) { CU_pTest test = NULL; CU_ErrorCode err; odp_testinfo_t *tinfo; const char *test_name = updated_tinfo->pName; tinfo = cunit_get_test_info(sinfo, test_name); if (tinfo) test = CU_get_test(suite, test_name); if (!tinfo || !test) { fprintf(stderr, "%s: unable to find existing test named %s\n", __func__, test_name); return -1; } err = CU_set_test_func(test, updated_tinfo->pTestFunc); if (err != CUE_SUCCESS) { fprintf(stderr, "%s: failed to update test func for %s\n", __func__, test_name); return -1; } tinfo->check_active = updated_tinfo->check_active; return 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); } } }