/* test that the correct line configuration is created for a valid config file */ void test_load_correct_line_configuration_for_valid_config() { const char *filename; unsigned long address; fh_shr_cfg_lh_proc_t lh_config; fh_cfg_node_t *config; memset(&lh_config, 0, sizeof(fh_shr_cfg_lh_proc_t)); filename = valid_config(); config = fh_cfg_load(filename); delete_config(filename); /* load configuration and make some basic assertions */ FH_TEST_ASSERT_NOTNULL(config); FH_TEST_ASSERT_EQUAL(fh_shr_cfg_lh_load("foo", "itch", config, &lh_config), FH_OK); FH_TEST_ASSERT_EQUAL(lh_config.num_lines, 1); /* assert that the proper lines are enabled/disabled */ FH_TEST_ASSERT_TRUE(lh_config.lines[0].primary.enabled); FH_TEST_ASSERT_FALSE(lh_config.lines[0].secondary.enabled); /* assert that the proper options are set for the line(s) that is/are enabled */ address = inet_addr(fh_cfg_get_string(config, "itch.lines.foo.primary.address")); FH_TEST_ASSERT_LEQUAL((long int)lh_config.lines[0].primary.address, (long int)address); FH_TEST_ASSERT_LEQUAL((long int)lh_config.lines[0].primary.port, (long int)12345); FH_TEST_ASSERT_STREQUAL(lh_config.lines[0].primary.interface, "eth0"); }
/* test that loading a config without a line configuration for process lines produces FH_ERROR */ void test_failure_when_loading_config_with_no_line_configuration_for_process_lines() { const char *filename; fh_shr_cfg_lh_proc_t lh_config; fh_cfg_node_t *config; FILE *outfile; filename = empty_config(); outfile = fopen(filename, "a"); fprintf(outfile, "itch = {\n"); fprintf(outfile, " processes = {\n"); fprintf(outfile, " foo = {\n"); fprintf(outfile, " lines = ( \"foo\" )\n"); fprintf(outfile, " }\n"); fprintf(outfile, " }\n"); fprintf(outfile, " lines = {\n"); fprintf(outfile, " bar = {\n"); fprintf(outfile, " primary = { address:\"10.0.0.1\" port:12345 interface:eth0 }\n"); fprintf(outfile, " }\n"); fprintf(outfile, " }\n"); fprintf(outfile, "}\n"); fclose(outfile); config = fh_cfg_load(filename); delete_config(filename); memset(&lh_config, 0, sizeof(fh_shr_cfg_lh_proc_t)); FH_TEST_ASSERT_NOTNULL(config); FH_TEST_ASSERT_EQUAL(fh_shr_cfg_lh_load("foo", "itch", config, &lh_config), FH_ERROR); }
static int free_handler(TSCont cont, TSEvent event, void *edata) { config_t *config; TSDebug(PLUGIN_TAG, "Freeing old config"); config = (config_t *) TSContDataGet(cont); delete_config(config); TSContDestroy(cont); return 0; }
// test that an included index value in the configuration produces the correct result void test_index_configuration_produces_correct_index() { const char *filename; fh_cfg_node_t *config; filename = index_config(); config = fh_cfg_load(filename); delete_config(filename); FH_TEST_ASSERT_EQUAL(fh_arca_cfg_load(config, "foo"), FH_OK); FH_TEST_ASSERT_LEQUAL(fh_arca_cfg.index, 5); }
/* default process */ void test_get_proc_failure_with_no_name_and_invalid_config() { const char *filename; fh_cfg_node_t *config; char process[MAX_PROPERTY_LENGTH] = "\0"; filename = empty_config(); config = fh_cfg_load(filename); delete_config(filename); FH_TEST_ASSERT_NOTNULL(config); FH_TEST_ASSERT_EQUAL(fh_shr_cfg_lh_get_proc(process, "itch", config), FH_ERROR); }
/* test that ...load() returns FH_ERROR when given a process name that doesn't exist */ void test_load_failure_with_nonexistent_name() { const char *filename; fh_shr_cfg_lh_proc_t lh_config; fh_cfg_node_t *config; filename = valid_config(); config = fh_cfg_load(filename); delete_config(filename); FH_TEST_ASSERT_NOTNULL(config); FH_TEST_ASSERT_EQUAL(fh_shr_cfg_lh_load("bar", "itch", config, &lh_config), FH_ERROR); }
/* test that ...get_process() returns FH_OK when given a process name that exists */ void test_get_proc_success_with_existent_name() { const char *filename; fh_cfg_node_t *config; char process[MAX_PROPERTY_LENGTH] = "foo"; filename = valid_config(); config = fh_cfg_load(filename); delete_config(filename); FH_TEST_ASSERT_NOTNULL(config); FH_TEST_ASSERT_EQUAL(fh_shr_cfg_lh_get_proc(process, "itch", config), FH_OK); }
/* process name */ void test_load_success_with_existent_name() { const char *filename; fh_shr_cfg_lh_proc_t lh_config; fh_cfg_node_t *config; memset(&lh_config, 0, sizeof(fh_shr_cfg_lh_proc_t)); filename = valid_config(); config = fh_cfg_load(filename); delete_config(filename); FH_TEST_ASSERT_NOTNULL(config); FH_TEST_ASSERT_EQUAL(fh_shr_cfg_lh_load("foo", "itch", config, &lh_config), FH_OK); FH_TEST_ASSERT_STREQUAL(lh_config.name, "foo"); }
// Run function of whole program static void run(const char *config_filename) { double max_z, min_z; source_object *object; double complex *optical_field; // Initialize FFTW threads fftw_init_threads(); // Load config to memory load_config(config_filename); // Initialize logger initialize_logger(get_integer_value(CONF_LOGGER_DEBUG_MODE)); // Load source object load_source_object(&object, get_string_value(CONF_OBJECT_POINTS_FILE)); // Initialize final optical field initialize_optical_field(&optical_field); // Extract z position extremes of source object extract_object_proportions(object, &min_z, &max_z, OBJECT_DEPTH); // Modified WRP method itself perform_wrp_method(object, optical_field, min_z, max_z); // Numerical reconstruction on hologram perform_numerical_reconstruction(optical_field, min_z); // Memory clear log_info("Deleting all structures from memory\n"); free(optical_field); delete_source_object(object); delete_lookup_table(); delete_config(); }
/* test that loading a config without and lines produces FH_ERROR */ void test_failure_when_loading_config_with_no_lines() { const char *filename; fh_shr_cfg_lh_proc_t lh_config; fh_cfg_node_t *config; FILE *outfile; filename = empty_config(); outfile = fopen(filename, "a"); fprintf(outfile, "itch = {\n"); fprintf(outfile, " processes = {\n"); fprintf(outfile, " foo = {\n"); fprintf(outfile, " }\n"); fprintf(outfile, " }\n"); fprintf(outfile, "}\n"); fclose(outfile); config = fh_cfg_load(filename); delete_config(filename); memset(&lh_config, 0, sizeof(fh_shr_cfg_lh_proc_t)); FH_TEST_ASSERT_NOTNULL(config); FH_TEST_ASSERT_EQUAL(fh_shr_cfg_lh_load("foo", "itch", config, &lh_config), FH_ERROR); }