mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-02 20:08:17 +00:00
Add regression tests for issue ASTERISK-18838.
Review: https://reviewboard.asterisk.org/r/1572 Reviewed by: Matt Jordan git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@347131 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -540,6 +540,10 @@ AST_APP_OPTIONS(vm_app_options, {
|
||||
});
|
||||
|
||||
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);
|
||||
#endif
|
||||
static int actual_load_config(int reload, struct ast_config *cfg, struct ast_config *ucfg);
|
||||
|
||||
/*! \page vmlang Voicemail Language Syntaxes Supported
|
||||
|
||||
@@ -11777,16 +11781,9 @@ static const char *substitute_escapes(const char *value)
|
||||
|
||||
static int load_config(int reload)
|
||||
{
|
||||
struct ast_vm_user *current;
|
||||
struct ast_config *cfg, *ucfg;
|
||||
char *cat;
|
||||
struct ast_variable *var;
|
||||
const char *val;
|
||||
char *q, *stringp, *tmp;
|
||||
int x;
|
||||
int tmpadsi[4];
|
||||
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
|
||||
char secretfn[PATH_MAX] = "";
|
||||
int res;
|
||||
|
||||
ast_unload_realtime("voicemail");
|
||||
ast_unload_realtime("voicemail_data");
|
||||
@@ -11814,6 +11811,35 @@ static int load_config(int reload)
|
||||
ucfg = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
res = actual_load_config(reload, cfg, ucfg);
|
||||
|
||||
ast_config_destroy(cfg);
|
||||
ast_config_destroy(ucfg);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifdef TEST_FRAMEWORK
|
||||
static int load_config_from_memory(int reload, struct ast_config *cfg, struct ast_config *ucfg)
|
||||
{
|
||||
ast_unload_realtime("voicemail");
|
||||
ast_unload_realtime("voicemail_data");
|
||||
return actual_load_config(reload, cfg, ucfg);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int actual_load_config(int reload, struct ast_config *cfg, struct ast_config *ucfg)
|
||||
{
|
||||
struct ast_vm_user *current;
|
||||
char *cat;
|
||||
struct ast_variable *var;
|
||||
const char *val;
|
||||
char *q, *stringp, *tmp;
|
||||
int x;
|
||||
int tmpadsi[4];
|
||||
char secretfn[PATH_MAX] = "";
|
||||
|
||||
#ifdef IMAP_STORAGE
|
||||
ast_copy_string(imapparentfolder, "\0", sizeof(imapparentfolder));
|
||||
#endif
|
||||
@@ -12411,7 +12437,6 @@ static int load_config(int reload)
|
||||
}
|
||||
}
|
||||
}
|
||||
ast_config_destroy(ucfg);
|
||||
}
|
||||
|
||||
/* load mailboxes from voicemail.conf */
|
||||
@@ -12446,7 +12471,6 @@ static int load_config(int reload)
|
||||
}
|
||||
} else {
|
||||
AST_LIST_UNLOCK(&users);
|
||||
ast_config_destroy(cfg);
|
||||
return -1;
|
||||
}
|
||||
var = var->next;
|
||||
@@ -12457,7 +12481,6 @@ static int load_config(int reload)
|
||||
}
|
||||
|
||||
AST_LIST_UNLOCK(&users);
|
||||
ast_config_destroy(cfg);
|
||||
|
||||
if (poll_mailboxes && poll_thread == AST_PTHREADT_NULL)
|
||||
start_poll_thread();
|
||||
@@ -12468,8 +12491,6 @@ static int load_config(int reload)
|
||||
} else {
|
||||
AST_LIST_UNLOCK(&users);
|
||||
ast_log(AST_LOG_WARNING, "Failed to load configuration file.\n");
|
||||
if (ucfg)
|
||||
ast_config_destroy(ucfg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -12929,6 +12950,84 @@ AST_TEST_DEFINE(test_voicemail_notify_endl)
|
||||
fclose(file);
|
||||
return res;
|
||||
}
|
||||
|
||||
AST_TEST_DEFINE(test_voicemail_load_config)
|
||||
{
|
||||
int res = AST_TEST_PASS;
|
||||
struct ast_vm_user *vmu;
|
||||
struct ast_config *cfg;
|
||||
char config_filename[32] = "/tmp/voicemail.conf.XXXXXX";
|
||||
int fd;
|
||||
FILE *file;
|
||||
struct ast_flags config_flags = { CONFIG_FLAG_NOCACHE };
|
||||
|
||||
switch (cmd) {
|
||||
case TEST_INIT:
|
||||
info->name = "test_voicemail_load_config";
|
||||
info->category = "/apps/app_voicemail/";
|
||||
info->summary = "Test loading Voicemail config";
|
||||
info->description =
|
||||
"Verify that configuration is loaded consistently. "
|
||||
"This is to test regressions of ASTERISK-18838 where it was noticed that "
|
||||
"some options were loaded after the mailboxes were instantiated, causing "
|
||||
"those options not to be set correctly.";
|
||||
return AST_TEST_NOT_RUN;
|
||||
case TEST_EXECUTE:
|
||||
break;
|
||||
}
|
||||
|
||||
/* build a config file by hand... */
|
||||
if ((fd = mkstemp(config_filename)) < 0) {
|
||||
return AST_TEST_FAIL;
|
||||
}
|
||||
if (!(file = fdopen(fd, "w"))) {
|
||||
close(fd);
|
||||
unlink(config_filename);
|
||||
return AST_TEST_FAIL;
|
||||
}
|
||||
fputs("[general]\ncallback=somecontext\nlocale=de_DE.UTF-8\ntz=european\n[test]", file);
|
||||
fputs("00000001 => 9999,Mr. Test,,,callback=othercontext|locale=nl_NL.UTF-8|tz=central\n", file);
|
||||
fputs("00000002 => 9999,Mrs. Test\n", file);
|
||||
fclose(file);
|
||||
|
||||
if (!(cfg = ast_config_load(config_filename, config_flags))) {
|
||||
res = AST_TEST_FAIL;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
load_config_from_memory(1, cfg, NULL);
|
||||
ast_config_destroy(cfg);
|
||||
|
||||
#define CHECK(u, attr, value) else if (strcmp(u->attr, value)) { \
|
||||
ast_test_status_update(test, "mailbox %s should have %s '%s', but has '%s'\n", \
|
||||
u->mailbox, #attr, value, u->attr); res = AST_TEST_FAIL; break; }
|
||||
|
||||
AST_LIST_LOCK(&users);
|
||||
AST_LIST_TRAVERSE(&users, vmu, list) {
|
||||
if (!strcmp(vmu->mailbox, "00000001")) {
|
||||
if (0); /* trick to get CHECK to work */
|
||||
CHECK(vmu, callback, "othercontext")
|
||||
CHECK(vmu, locale, "nl_NL.UTF-8")
|
||||
CHECK(vmu, zonetag, "central")
|
||||
} else if (!strcmp(vmu->mailbox, "00000002")) {
|
||||
if (0); /* trick to get CHECK to work */
|
||||
CHECK(vmu, callback, "somecontext")
|
||||
CHECK(vmu, locale, "de_DE.UTF-8")
|
||||
CHECK(vmu, zonetag, "european")
|
||||
}
|
||||
}
|
||||
AST_LIST_UNLOCK(&users);
|
||||
|
||||
#undef CHECK
|
||||
|
||||
/* restore config */
|
||||
load_config(1); /* this might say "Failed to load configuration file." */
|
||||
|
||||
cleanup:
|
||||
unlink(config_filename);
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif /* defined(TEST_FRAMEWORK) */
|
||||
|
||||
static int reload(void)
|
||||
@@ -12953,6 +13052,7 @@ static int unload_module(void)
|
||||
res |= AST_TEST_UNREGISTER(test_voicemail_msgcount);
|
||||
res |= AST_TEST_UNREGISTER(test_voicemail_vmuser);
|
||||
res |= AST_TEST_UNREGISTER(test_voicemail_notify_endl);
|
||||
res |= AST_TEST_UNREGISTER(test_voicemail_load_config);
|
||||
#endif
|
||||
ast_cli_unregister_multiple(cli_voicemail, ARRAY_LEN(cli_voicemail));
|
||||
ast_uninstall_vm_functions();
|
||||
@@ -13002,6 +13102,7 @@ static int load_module(void)
|
||||
res |= AST_TEST_REGISTER(test_voicemail_msgcount);
|
||||
res |= AST_TEST_REGISTER(test_voicemail_vmuser);
|
||||
res |= AST_TEST_REGISTER(test_voicemail_notify_endl);
|
||||
res |= AST_TEST_REGISTER(test_voicemail_load_config);
|
||||
#endif
|
||||
|
||||
if (res)
|
||||
|
||||
Reference in New Issue
Block a user