diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 73b512acded40250b05ebd28d6a6aa5491dbc606..9e067d0daa4c6140b37dcc1e1ec50c1d93b646a2 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -768,6 +768,18 @@ static const char * const mailbox_folders[] = { "Urgent", }; +/*! + * \brief Reload voicemail.conf + * \param reload Whether this is a reload as opposed to module load + * \param force Forcefully reload the config, even it has not changed + * \retval 0 on success, nonzero on failure + */ +static int load_config_force(int reload, int force); + +/*! \brief Forcibly reload voicemail.conf, even if it has not changed. + * This is necessary after running unit tests. */ +#define force_reload_config() load_config_force(1, 1) + static int load_config(int reload); #ifdef TEST_FRAMEWORK static int load_config_from_memory(int reload, struct ast_config *cfg, struct ast_config *ucfg); @@ -13141,6 +13153,7 @@ AST_TEST_DEFINE(test_voicemail_vmuser) #endif free_user(vmu); + force_reload_config(); /* Restore original config */ return res ? AST_TEST_FAIL : AST_TEST_PASS; } #endif @@ -14233,10 +14246,10 @@ static const char *substitute_escapes(const char *value) return ast_str_buffer(str); } -static int load_config(int reload) +static int load_config_force(int reload, int force) { struct ast_config *cfg, *ucfg; - struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; + struct ast_flags config_flags = { reload && !force ? CONFIG_FLAG_FILEUNCHANGED : 0 }; int res; ast_unload_realtime("voicemail"); @@ -14274,6 +14287,11 @@ static int load_config(int reload) return res; } +static int load_config(int reload) +{ + return load_config_force(reload, 0); +} + #ifdef TEST_FRAMEWORK static int load_config_from_memory(int reload, struct ast_config *cfg, struct ast_config *ucfg) { @@ -15448,6 +15466,7 @@ AST_TEST_DEFINE(test_voicemail_msgcount) } free_user(vmu); + force_reload_config(); /* Restore original config */ return res; } @@ -15558,6 +15577,7 @@ AST_TEST_DEFINE(test_voicemail_notify_endl) } fclose(file); free_user(vmu); + force_reload_config(); /* Restore original config */ return res; } @@ -15630,8 +15650,8 @@ AST_TEST_DEFINE(test_voicemail_load_config) #undef CHECK - /* restore config */ - load_config(1); /* this might say "Failed to load configuration file." */ + /* Forcibly restore the original config, to reinitialize after test */ + force_reload_config(); /* this might say "Failed to load configuration file." */ cleanup: unlink(config_filename); @@ -15697,6 +15717,11 @@ AST_TEST_DEFINE(test_voicemail_vm_info) populate_defaults(vmu); vmu->email = ast_strdup("vm-info-test@example.net"); + if (!vmu->email) { + ast_test_status_update(test, "Cannot create vmu email\n"); + chan = ast_channel_unref(chan); + return AST_TEST_FAIL; + } ast_copy_string(vmu->fullname, "Test Framework Mailbox", sizeof(vmu->fullname)); ast_copy_string(vmu->pager, "vm-info-pager-test@example.net", sizeof(vmu->pager)); ast_copy_string(vmu->language, "en", sizeof(vmu->language));