diff options
author | Joshua Colp <jcolp@digium.com> | 2016-04-27 16:20:31 -0500 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2016-04-27 16:20:31 -0500 |
commit | a16aa467f5d8645cb13fb6429924df140c4d0faf (patch) | |
tree | 6c4047d07666a3470b029a42ae76e1b728e466e7 /tests | |
parent | e0e03cd2c87b9edb1de0f247570e79c9b236302a (diff) | |
parent | b38f1146e54f295c89727de4fde150ed731d5b64 (diff) |
Merge "config: Fix ast_config_text_file_save2 writability check for missing files" into 13
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_config.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/test_config.c b/tests/test_config.c index 40de2652b..fd14908b6 100644 --- a/tests/test_config.c +++ b/tests/test_config.c @@ -34,6 +34,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$"); #include <math.h> /* HUGE_VAL */ +#include <sys/stat.h> #include "asterisk/config.h" #include "asterisk/module.h" @@ -49,6 +50,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$"); #include "asterisk/format_cap.h" #define CONFIG_FILE "test_config.conf" +#define CONFIG_INCLUDE_FILE "test_config_include.conf" /* * This builds the folowing config: @@ -881,6 +883,77 @@ static int hook_cb(struct ast_config *cfg) return 0; } +AST_TEST_DEFINE(config_save) +{ + enum ast_test_result_state res = AST_TEST_FAIL; + struct ast_flags config_flags = { 0 }; + struct ast_config *cfg; + char config_filename[PATH_MAX]; + char include_filename[PATH_MAX]; + struct stat config_stat; + off_t before_save; + + switch (cmd) { + case TEST_INIT: + info->name = "config_save"; + info->category = "/main/config/"; + info->summary = "Test config save"; + info->description = + "Test configuration save."; + return AST_TEST_NOT_RUN; + case TEST_EXECUTE: + break; + } + + if (write_config_file()) { + ast_test_status_update(test, "Could not write initial config files\n"); + return res; + } + + snprintf(config_filename, PATH_MAX, "%s/%s", ast_config_AST_CONFIG_DIR, CONFIG_FILE); + snprintf(include_filename, PATH_MAX, "%s/%s", ast_config_AST_CONFIG_DIR, CONFIG_INCLUDE_FILE); + + cfg = ast_config_load(CONFIG_FILE, config_flags); + if (!cfg) { + ast_test_status_update(test, "Could not load config\n"); + goto out; + } + + /* We need to re-save to get the generator header */ + if (ast_config_text_file_save(CONFIG_FILE, cfg, "TEST")) { + ast_test_status_update(test, "Unable to write files\n"); + goto out; + } + + stat(config_filename, &config_stat); + before_save = config_stat.st_size; + + if (!ast_include_new(cfg, CONFIG_FILE, CONFIG_INCLUDE_FILE, 0, NULL, 4, include_filename, PATH_MAX)) { + ast_test_status_update(test, "Could not create include\n"); + goto out; + } + + if (ast_config_text_file_save(CONFIG_FILE, cfg, "TEST")) { + ast_test_status_update(test, "Unable to write files\n"); + goto out; + } + + stat(config_filename, &config_stat); + if (config_stat.st_size <= before_save) { + ast_test_status_update(test, "Did not save config file with #include\n"); + goto out; + } + + res = AST_TEST_PASS; + +out: + ast_config_destroy(cfg); + unlink(config_filename); + unlink(include_filename); + + return res; +} + AST_TEST_DEFINE(config_hook) { enum ast_test_result_state res = AST_TEST_FAIL; @@ -1734,6 +1807,7 @@ AST_TEST_DEFINE(variable_lists_match) static int unload_module(void) { + AST_TEST_UNREGISTER(config_save); AST_TEST_UNREGISTER(config_basic_ops); AST_TEST_UNREGISTER(config_filtered_ops); AST_TEST_UNREGISTER(config_template_ops); @@ -1748,6 +1822,7 @@ static int unload_module(void) static int load_module(void) { + AST_TEST_REGISTER(config_save); AST_TEST_REGISTER(config_basic_ops); AST_TEST_REGISTER(config_filtered_ops); AST_TEST_REGISTER(config_template_ops); |