void test_trailing_whitespace(void **state) { struct pam_hbac_config *conf; (void) state; /* unused */ conf = read_test_config(TEST_CONF_DIR"/src/tests/configs/twsp.conf"); print_config(conf); check_example_result(conf); ph_cleanup_config(conf); }
void test_whitespace_around_equal_sign(void **state) { struct pam_hbac_config *conf; (void) state; /* unused */ conf = read_test_config(TEST_CONF_DIR"/src/tests/configs/eqwsp.conf"); print_config(conf); check_example_result(conf); ph_cleanup_config(conf); }
/* ------------- the tests themselves ------------- */ void test_good_config(void **state) { struct pam_hbac_config *conf; (void) state; /* unused */ conf = read_test_config(TEST_CONF_DIR"/src/tests/configs/good1.conf"); print_config(conf); check_example_result(conf); ph_cleanup_config(conf); }
static void manual_geotiff(char *configFile) { char inFile[1024]; char specsFile[1024]; int ii, suite_passed = TRUE; test_config *cfg = read_test_config(configFile); if (strcmp_case(cfg->general->status, "new") != 0) asfPrintError("Can't run manual tests. Current status: '%s'\nTo run these " "tests manually, reset the general status to 'new'\n", cfg->general->status); asfPrintStatus(" Suite: %s\n", cfg->general->suite); for (ii=0; ii<cfg->general->test_count; ii++) { strcpy(inFile, cfg->test[ii]->file); strcpy(specsFile, cfg->test[ii]->specs); asfPrintStatus("\n Test[%d]: %s ...\n", ii+1, cfg->test[ii]->test); if (strcmp_case(cfg->test[ii]->status, "skip") != 0) { if (geotiff_test_ext(inFile, specsFile, REPORT_LEVEL_STATUS)) { asfPrintStatus(" Test passed\n"); strcpy(cfg->test[ii]->status, "passed"); } else { asfPrintStatus(" Test failed\n"); strcpy(cfg->test[ii]->status, "failed"); suite_passed = FALSE; } } else asfPrintStatus(" Test skipped\n"); } if (suite_passed) { asfPrintStatus("\n Suite passed\n\n"); strcpy(cfg->general->status, "passed"); } else { asfPrintStatus("\n Suite failed\n\n"); strcpy(cfg->general->status, "failed"); } write_test_config(configFile, cfg); free_test_config(cfg); }
int main(int argc, char *argv[]) { char *buffer = NULL; size_t bufsiz = 0; ssize_t bytes_read = 0; FILE *stream = stdin; union { cParseNumber num; double real; char str[2048]; } var; puts("AFL test harness"); read_env_config(); read_test_config(); if (!is_valid_config()) { die("test configuration is not valid"); } obj = cparse_object_with_class_name("Fuzzer"); atexit(harness_cleanup); while((bytes_read = getline(&buffer, &bufsiz, stream)) >= 0) { char key[128]; size_t len = strlen(buffer); if (len > 0) { buffer[len-1] = '\0'; } if (buffer[0] == '\0') { break; } if (sscanf(buffer, "%s = %d", key, &var.num) == 2) { cparse_object_set_number(obj, key, var.num); } else if (sscanf(buffer, "%s = %lf", key, &var.real) == 2) { cparse_object_set_real(obj, key, var.num); } else if (sscanf(buffer, "%s = %[^\n]", key, var.str) == 2) { cparse_object_set_string(obj, key, var.str); } else if (sscanf(buffer, "%s = %s", key, var.str) == 2 && !strcmp(var.str, "true")) { cparse_object_set_bool(obj, key, true); } else if (sscanf(buffer, "%s = %s", key, var.str) == 2 && !strcmp(var.str, "false")) { cparse_object_set_bool(obj, key, false); } else if (sscanf(buffer, "%s == %[^\n]", key, var.str) == 2) { if (harness_compare_string(key, var.str)) { exit(1); } } else if (sscanf(buffer, "%s != %[^\n]", key, var.str) == 2) { if (!harness_compare_string(key, var.str)) { exit(1); } } else if (sscanf(buffer, "%s == %d", key, &var.num) == 2) { if (harness_compare_number(key, var.num)) { exit(1); } } else if (sscanf(buffer, "%s != %d", key, &var.num) == 2) { if (!harness_compare_number(key, var.num)) { exit(1); } } else if (sscanf(buffer, "%s == %lf", key, &var.real) == 2) { if (harness_compare_real(key, var.real, MAX_REL_ERR)) { exit(1); } } else if (sscanf(buffer, "%s != %lf", key, &var.real) == 2) { if (!harness_compare_real(key, var.real, MAX_REL_ERR)) { exit(1); } } else if ((sscanf(buffer, "%s == %s", key, var.str) == 2 && !strcmp(var.str, "true")) || (sscanf(buffer, "%s != %s", key, var.str) == 2 && !strcmp(var.str, "false"))) { if (harness_compare_bool(key, true)) { exit(1); } } else if ((sscanf(buffer, "%s == %s", key, var.str) == 2 && !strcmp(var.str, "false")) || (sscanf(buffer, "%s != %s", key, var.str) == 2 && !strcmp(var.str, "true"))) { if (harness_compare_bool(key, false)) { exit(1); } } else if (sscanf(buffer, "rem %s", key) == 1) { if (!cparse_object_contains(obj, key)) { printf("object does not contain key (%s)\n", key); } else { cparse_object_remove(obj, key); } } else if (!strcmp(buffer, "save")) { if (!cparse_object_save(obj, &error)) { puts(cparse_error_message(error)); cparse_error_free(error); error = NULL; } } else if (!strcmp(buffer, "delete")) { if (!cparse_object_delete(obj, &error)) { puts(cparse_error_message(error)); cparse_error_free(error); error = NULL; } } else if (!strcmp(buffer, "refresh")) { if (!cparse_object_refresh(obj, &error)) { puts(cparse_error_message(error)); cparse_error_free(error); error = NULL; } } else if (!strcmp(buffer, "fetch")) { if (!cparse_object_fetch(obj, &error)) { puts(cparse_error_message(error)); cparse_error_free(error); error = NULL; } } else { printf("No op (%s) in AFL harness\n", buffer); } } return 0; }
int main(int argc, char *argv[]) { char configFile[1024], interface[25]; int createflag, unitflag, cleanflag; extern int logflag; int create_f, clean_f, log_f; createflag = unitflag = cleanflag = FALSE; create_f = clean_f, FLAG_NOT_SET; // Begin command line parsing *********************************************** if ( (checkForOption("--help", argc, argv) != FLAG_NOT_SET) || (checkForOption("-h", argc, argv) != FLAG_NOT_SET) || (checkForOption("-help", argc, argv) != FLAG_NOT_SET) ) { print_help(); } get_asf_share_dir_with_argv0(argv[0]); handle_license_and_version_args(argc, argv, ASF_NAME_STRING); // Check which options were provided create_f = checkForOption("-create", argc, argv); clean_f = checkForOption("-clean", argc, argv); log_f = checkForOption("-log", argc, argv); // We need to make sure the user specified the proper number of arguments int needed_args = 1 + REQUIRED_ARGS; // command & REQUIRED_ARGS int num_flags = 0; if (create_f != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option if (clean_f != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option if (log_f != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param // Make sure we have the right number of args if (argc != needed_args) { print_usage(); } // Make sure argument for each flag (that requires an arg) is not another // option flag & is not a required argument if (log_f != FLAG_NOT_SET) { if ((argv[log_f+1][0]=='-') || (log_f>=(argc-REQUIRED_ARGS))) { print_usage(); } } // Make sure all options occur before the config file name argument if (num_flags == 1 && (create_f > 1 || log_f > 1)) { print_usage(); } else if (num_flags > 1 && (create_f >= argc - REQUIRED_ARGS - 1 || log_f >= argc - REQUIRED_ARGS - 1)) { print_usage(); } // Do the actual flagging & such for each flag if (create_f != FLAG_NOT_SET) { createflag = TRUE; } if (clean_f != FLAG_NOT_SET) { cleanflag = TRUE; } if (log_f != FLAG_NOT_SET) { strcpy(logFile, argv[log_f+1]); logflag = TRUE; fLog = FOPEN(logFile, "w"); } // Fetch required arguments strcpy(interface, argv[argc-2]); strcpy(configFile, argv[argc-1]); // Report the command line asfSplashScreen(argc, argv); // End command line parsing ************************************************* // Get test information from configuration file test_config *cfg; char line[1024]; // Creating configuration files if (createflag && !fileExists(configFile)) { init_test_config(configFile); return(EXIT_SUCCESS); } else if (createflag && fileExists(configFile)) { cfg = read_test_config(configFile); check_return(write_test_config(configFile, cfg), "Could not update configuration file"); free_test_config(cfg); return(EXIT_SUCCESS); } else if (!fileExists(configFile)) asfPrintError("Could not find config file (%s)\n", configFile); // Unit tests or single configuration file? if (strcmp_case(interface, "basic") == 0 || strcmp_case(interface, "automated") == 0) unitflag = TRUE; if (unitflag) { extern int quietflag; quietflag = 2; if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); int test = FALSE; FILE *fpList = FOPEN(configFile, "r"); while(fgets(line, 1024, fpList)) { if (strcmp_case(trim_spaces(line), "uavsar_metadata") == 0) add_uavsar_metadata_tests(); if (strcmp_case(trim_spaces(line), "uavsar_geotiff") == 0) add_uavsar_geotiff_tests(); if (strcmp_case(trim_spaces(line), "rsat1_map_projections") == 0) add_rsat1_map_projections_tests(); if (strcmp_case(trim_spaces(line), "rsat1_geotiff") == 0) add_rsat1_geotiff_tests(); if (strcmp_case(trim_spaces(line), "alos_browse") == 0) add_alos_browse_tests(); if (strcmp_case(trim_spaces(line), "alos_leader") == 0) add_alos_leader_tests(); if (strcmp_case(trim_spaces(line), "rsat1_overlay") == 0) add_rsat1_overlay_tests(); if (strcmp_case(trim_spaces(line), "alos_calibration") == 0) add_alos_calibration_tests(); test = TRUE; } FCLOSE(fpList); if (test && strcmp_case(interface, "basic") == 0) { asfPrintStatus("Running tests in basic mode ...\n"); CU_basic_set_mode(CU_BRM_VERBOSE); if (CUE_SUCCESS != CU_basic_run_tests()) { CU_cleanup_registry(); return CU_get_error(); } } if (test && strcmp_case(interface, "automated") == 0) { asfPrintStatus("Running tests in automated mode ...\n\n"); CU_set_output_filename("asf_tools"); CU_automated_run_tests(); CU_list_tests_to_file(); } CU_cleanup_registry(); if (cleanflag) cleanup_test_results(configFile); } else { // Configuration file for manual mode cfg = read_test_config(configFile); asfPrintStatus("Running tests in manual mode ...\n\n"); // Run metadata tests if (strcmp_case(cfg->general->type, "metadata") == 0) manual_metadata(configFile); // Run geotiff tests else if (strcmp_case(cfg->general->type, "geotiff") == 0) manual_geotiff(configFile); // Run binary tests else if (strcmp_case(cfg->general->type, "binary") == 0) manual_binary(configFile); // Run library tests else if (strcmp_case(cfg->general->type, "library") == 0) manual_library(configFile); free_test_config(cfg); } return(EXIT_SUCCESS); }