[asterisk-commits] mjordan: branch mjordan/voicemail_refactor_11_10_19 r342541 - in /team/mjorda...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 26 14:50:40 CDT 2011


Author: mjordan
Date: Wed Oct 26 14:50:36 2011
New Revision: 342541

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=342541
Log:
Initial parsing / unit tests for vm config objects

Modified:
    team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail.h
    team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail_test.h
    team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/vm_config_parser.c

Modified: team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail.h?view=diff&rev=342541&r1=342540&r2=342541
==============================================================================
--- team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail.h (original)
+++ team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail.h Wed Oct 26 14:50:36 2011
@@ -143,6 +143,7 @@
 		AST_STRING_FIELD(pager_subject);
 		AST_STRING_FIELD(pager_body);
 		AST_STRING_FIELD(email_from_address);
+		AST_STRING_FIELD(locale);
 		AST_STRING_FIELD(mail_command);
 		AST_STRING_FIELD(zonetag);
 		AST_STRING_FIELD(timezone);

Modified: team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail_test.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail_test.h?view=diff&rev=342541&r1=342540&r2=342541
==============================================================================
--- team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail_test.h (original)
+++ team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/include/voicemail_test.h Wed Oct 26 14:50:36 2011
@@ -11,6 +11,14 @@
 #include "asterisk.h"
 #include "asterisk/test.h"
 
+/*! \internal \brief Test if two buffers are equal
+ * \param expected A buffer containing the expected values
+ * \param actual A buffer containing the actual values
+ * \param upperlimit The size of both expected and actual
+ * \note This expects an enum ast_test_result_state variable to exist in the same scope
+ * as the usage of this macro named 'result'.  This variable will be set to AST_TEST_FAIL
+ * if expected is not equal to actual
+ */
 #define VM_TEST_MEM_EQUAL(expected, actual, upperlimit) \
 	do { \
 	  int i = 0; \
@@ -21,6 +29,13 @@
 			  break; \
 		  }}} while (0)
 
+/*! \internal \brief Test if two strings are equal
+ * \param expected A const char * containing the expected value
+ * \param actual A const char * containing the actual value
+ * \note This expects an enum ast_test_result_state variable to exist in the same scope
+ * as the usage of this macro named 'result'.  This variable will be set to AST_TEST_FAIL
+ * if expected is not equal to actual
+ */
 #define VM_TEST_STRING_EQUAL(expected, actual) \
 	do { \
 		if (strncmp(expected, actual, sizeof(expected))) { \
@@ -28,6 +43,13 @@
 			result = AST_TEST_FAIL; \
 		} } while (0)
 
+/*! \internal \brief Test if two strings are not equal
+ * \param expected A const char * containing the expected value
+ * \param actual A const char * containing the actual value
+ * \note This expects an enum ast_test_result_state variable to exist in the same scope
+ * as the usage of this macro named 'result'.  This variable will be set to AST_TEST_FAIL
+ * if expected is equal to actual
+ */
 #define VM_TEST_STRING_NOT_EQUAL(expected, actual) \
 	do { \
 		if (!strncmp(expected, actual, sizeof(expected))) { \
@@ -35,6 +57,13 @@
 			result = AST_TEST_FAIL; \
 		} } while (0)
 
+/*! \internal \brief Test if two numeric values are not equal
+ * \param expected A numeric variable containing the expected value
+ * \param actual A numeric variable containing the actual value
+ * \note This expects an enum ast_test_result_state variable to exist in the same scope
+ * as the usage of this macro named 'result'.  This variable will be set to AST_TEST_FAIL
+ * if expected is equal to actual
+ */
 #define VM_TEST_NUMERIC_NOT_EQUAL(expected, actual) \
 	do { \
 		if (expected == actual) { \
@@ -42,6 +71,13 @@
 			result = AST_TEST_FAIL; \
 		} } while (0)
 
+/*! \internal \brief Test if two strings are not equal
+ * \param expected A numeric variable containing the expected value
+ * \param actual A numeric variable containing the actual value
+ * \note This expects an enum ast_test_result_state variable to exist in the same scope
+ * as the usage of this macro named 'result'.  This variable will be set to AST_TEST_FAIL
+ * if expected is not equal to actual
+ */
 #define VM_TEST_NUMERIC_EQUAL(expected, actual) \
 	do { \
 		if (expected != actual) { \
@@ -49,11 +85,17 @@
 			result = AST_TEST_FAIL; \
 		} } while (0)
 
+#ifdef TEST_FRAMEWORK
+
+/*! \internal \brief Register the configuration parsing tests */
 void vm_register_config_tests(void);
 
+/* \internal \brief Unregister the configuration parsing tests */
 void vm_unregister_config_tests(void);
 
 /* TODO: add other backends / test entry points */
 
+#endif
+
 #endif /* TEST_VOICEMAIL_H_ */
 

Modified: team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/vm_config_parser.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/vm_config_parser.c?view=diff&rev=342541&r1=342540&r2=342541
==============================================================================
--- team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/vm_config_parser.c (original)
+++ team/mjordan/voicemail_refactor_11_10_19/apps/voicemail/vm_config_parser.c Wed Oct 26 14:50:36 2011
@@ -19,8 +19,8 @@
 static int init_configuration(void);
 static int is_valid_dtmf(const char *key);
 static int load_voicemail_options(struct vm_config *vmcfg, struct ast_config *cfg);
-static int load_timezones(const struct vm_config * const vmcfg, struct ast_config *cfg);
-static int load_voicemail_users(const struct vm_config * const vmcfg, struct ast_config *ucfg, int load_from_variable);
+static int load_timezones(const struct vm_config * const vmcfg, struct ast_config *cfg, struct ao2_container *timezone_container);
+static int load_voicemail_users(const struct vm_config * const vmcfg, struct ast_config *ucfg, int load_from_variable, struct ao2_container *user_container);
 static void populate_default_vm_config_options(struct vm_config *vmcfg);
 static void populate_default_listen_control(struct vm_config *vmcfg);
 static void populate_default_sounds(struct vm_config *vmcfg);
@@ -54,10 +54,10 @@
 static const char *default_listen_control_stop_key = "13456789";
 static const char *valid_dtmf = "1234567890*#ABCD";
 
-/*static const char *default_character_set = "ISO-8859-1";*/
+static const char *default_character_set = "ISO-8859-1";
 static const char *default_general_context = "general";
 static const char *default_timezone_context = "zonemessages";
-/*static const char *default_smdi_interface = "/dev/ttyS0";*/
+static const char *default_smdi_interface = "/dev/ttyS0";
 static const char *default_format_string = "wav";
 static const char *default_asterisk_username = "asterisk";
 static const char *default_users_context = "default";
@@ -195,12 +195,12 @@
 	}
 
 	/* From here on, the loading becomes destructive to the configuration that was previously loaded */
-	res |= load_timezones(vmcfg, cfg);
-
-	res |= load_voicemail_users(vmcfg, cfg, 1);
+	res |= load_timezones(vmcfg, cfg, timezones);
+
+	res |= load_voicemail_users(vmcfg, cfg, 1, voicemail_users);
 	/* If a user config exists, load users from there as well */
 	if (ucfg) {
-		res |= load_voicemail_users(vmcfg, ucfg, 0);
+		res |= load_voicemail_users(vmcfg, ucfg, 0, voicemail_users);
 	}
 
 	/* Set the global config object to the one we just created */
@@ -572,6 +572,9 @@
 			}
 		} else if (!strcasecmp(var->name, "smdienable")) {
 			vmcfg->smdi_config->enabled = ast_true(var->value);
+			if (vmcfg->smdi_config->enabled && ast_strlen_zero(vmcfg->smdi_config->smdi_interface)) {
+				ast_string_field_set(vmcfg->smdi_config, smdi_interface, default_smdi_interface);
+			}
 		} else if (!strcasecmp(var->name, "smdiport")) {
 			ast_string_field_set(vmcfg->smdi_config, smdi_interface, var->value);
 		} else {
@@ -585,11 +588,12 @@
 /*! \internal \brief Load the timezone information
  * \param vmcfg The loaded voicemail configuration object
  * \param cfg The Asterisk configuration object containing the timezone information
+ * \param timezone_container The container that will contain (or contains) the timezone objects
  * \note A lack of timezones defined in cfg does not constitute a failure
  * \returns 0 on success
  * \returns 1 on failure
  */
-static int load_timezones(const struct vm_config * const vmcfg, struct ast_config *cfg)
+static int load_timezones(const struct vm_config * const vmcfg, struct ast_config *cfg, struct ao2_container *timezone_container)
 {
 	struct ast_variable *var;
 	struct vm_timezone *tmz;
@@ -617,8 +621,8 @@
 		} else {
 			/* If the timezone already exists, remove it */
 			ast_string_field_set(tmp_tmz, name, var->name);
-			if ((tmz = ao2_find(timezones, tmp_tmz, OBJ_POINTER))) {
-				ao2_unlink(timezones, tmz);
+			if ((tmz = ao2_find(timezone_container, tmp_tmz, OBJ_POINTER))) {
+				ao2_unlink(timezone_container, tmz);
 				ao2_ref(tmz, -1);
 			}
 
@@ -628,7 +632,7 @@
 				ast_string_field_set(tmz, name, var->name);
 				ast_string_field_set(tmz, msg_format, msg_format);
 				ast_string_field_set(tmz, timezone, timezone);
-				ao2_link(timezones, tmz);
+				ao2_link(timezone_container, tmz);
 				ao2_ref(tmz, -1);
 			} else {
 				ast_log(AST_LOG_ERROR, "Failed to allocate memory for vm_timezone object\n");
@@ -646,10 +650,11 @@
  * \param ucfg The Asterisk configuration object containing the users to load
  * \param load_from_variable If non-zero, assume that each user is defined by an ast_variable; otherwise assume that
  *    the user is defined by an ast_category
+ * \param user_container The container that either will contain (or contains) the voicemail users
  * \returns 0 on success
  * \returns 1 if an error occurred
  */
-static int load_voicemail_users(const struct vm_config * const vmcfg, struct ast_config *ucfg, int load_from_variable)
+static int load_voicemail_users(const struct vm_config * const vmcfg, struct ast_config *ucfg, int load_from_variable, struct ao2_container *user_container)
 {
 	int res = 0;
 	char *cat_name;
@@ -688,11 +693,11 @@
 			if (!validate_user(vmcfg, vmu)) {
 				strcpy(tmp->context, vmu->context);
 				strcpy(tmp->mailbox, vmu->mailbox);
-				if ((vmu_old = ao2_find(voicemail_users, tmp, OBJ_POINTER))) {
-					ao2_unlink(voicemail_users, vmu_old);
+				if ((vmu_old = ao2_find(user_container, tmp, OBJ_POINTER))) {
+					ao2_unlink(user_container, vmu_old);
 					ao2_ref(vmu_old, -1);
 				}
-				ao2_link(voicemail_users, vmu);
+				ao2_link(user_container, vmu);
 			}
 			ao2_ref(vmu, -1);
 		}
@@ -794,6 +799,7 @@
 
 	ast_string_field_set(vmu, mail_command, vmcfg->mail_command);
 	ast_string_field_set(vmu, zonetag, vmcfg->zonetag);
+	ast_string_field_set(vmu, locale, vmcfg->locale);
 
 	ast_copy_flags(&(vmu->flags), &(vmcfg->globalflags), AST_FLAGS_ALL);
 
@@ -1039,6 +1045,7 @@
 	ast_string_field_set(vmcfg, mail_command, default_mail_command);
 	ast_string_field_set(vmcfg, email_date_format, default_email_date_format);
 	ast_string_field_set(vmcfg, pager_date_format, default_pager_date_format);
+	ast_string_field_set(vmcfg, charset, default_character_set);
 
 	ast_set2_flag(&(vmcfg->passwordflags), 1, VM_OPT_PWCHG_INTERNAL);
 	ast_set2_flag(&(vmcfg->globalflags), 1, VM_ATTACH);
@@ -1181,7 +1188,7 @@
 
 #ifdef TEST_FRAMEWORK
 
-static struct ast_config * make_empty_config(void)
+static struct ast_config *make_empty_config(void)
 {
 	struct ast_config *cfg = ast_config_new();
 	struct ast_category *tmp_category;
@@ -1193,12 +1200,124 @@
 	return cfg;
 }
 
-static struct ast_config * make_populated_config(void)
-{
-	struct ast_config * cfg = ast_config_new();
+static struct ast_config *make_user_config(void)
+{
+	struct ast_config *cfg = ast_config_new();
 	struct ast_category *tmp_category;
 	struct ast_variable *tmp_variable;
 
+	/* Add a user without voicemail */
+	tmp_category = ast_category_new("5000", "users.conf", 1);
+	tmp_variable = ast_variable_new("fullname", "User 5000", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("vmsecret", "1234", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	ast_category_append(cfg, tmp_category);
+
+	/* Basic user */
+	tmp_category = ast_category_new("5001", "users.conf", 1);
+	tmp_variable = ast_variable_new("hasvoicemail", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("fullname", "User 5001", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("vmsecret", "1234", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	/* Should not override vmsecret */
+	tmp_variable = ast_variable_new("secret", "5678", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	ast_category_append(cfg, tmp_category);
+
+	/* User with options */
+	tmp_category = ast_category_new("5002", "users.conf", 1);
+	tmp_variable = ast_variable_new("hasvoicemail", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("fullname", "User 5002", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("secret", "1234", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("context", "users_context", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("uniqueid", "123456789", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("email", "5002 at 5002.com", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("pager", "pager_address at pagerserver", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("attach", "yes", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("attachfmt", "g729", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("serveremail", "asterisk at asterisk.org", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("emailbody", "Click on the attachment to listen.\n\nThanks-\tAsterisk!\n", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("emailsubject", "You have a new voicemail.", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("pagerbody", "Listen to your voicemail - Thanks-\tAsterisk!\n", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("pagersubject", "You have a new voicemail.", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("language", "Spanish", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("tz", "Central", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("deletevoicemail", "yes", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("saycid", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("sendvoicemail", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("review", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("tempgreetwarn", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("messagewrap", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("operator", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("envelope", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("moveheard", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("sayduration", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("saydurationmin", "3", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("forcename", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("forcegreetings", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("callback", "callback_context", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("dialout", "dialout_context", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("exitcontext", "exitcontext_context", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("minsecs", "3", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("maxsecs", "4", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("maxmsg", "100", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("nextaftercmd", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("backupdeleted", "true", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("volgain", "3.1", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	tmp_variable = ast_variable_new("passwordlocation", "spooldir", USER_CONFIG);
+	ast_variable_append(tmp_category, tmp_variable);
+	ast_category_append(cfg, tmp_category);
+
+	return cfg;
+}
+
+static struct ast_config *make_populated_config(void)
+{
+	struct ast_config *cfg = ast_config_new();
+	struct ast_category *tmp_category;
+	struct ast_variable *tmp_variable;
+
 	/* Add the [general] category */
 	tmp_category = ast_category_new("general", "voicemail.conf", 1);
 
@@ -1400,9 +1519,7 @@
 AST_TEST_DEFINE(test_vm_default_config)
 {
 	enum ast_test_result_state result = AST_TEST_PASS;
-	struct ast_config *cfg = make_empty_config();
-	struct ast_category *tmp_category;
-	struct ast_variable *tmp_variable;
+	struct ast_config *cfg = NULL;
 	struct vm_config * vmcfg = NULL;
 
 	switch (cmd) {
@@ -1424,8 +1541,11 @@
 		return result;
 	}
 	populate_default_vm_config_options(vmcfg);
+	cfg = make_empty_config();
+
 	if (load_voicemail_options(vmcfg, cfg)) {
 		ao2_ref(vmcfg, -1);
+		ast_config_destroy(cfg);
 		ast_test_status_update(test, "Errors occurred while loading a default ast_config object\n");
 		result = AST_TEST_FAIL;
 		return result;
@@ -1478,7 +1598,7 @@
 AST_TEST_DEFINE(test_vm_parse_config)
 {
 	enum ast_test_result_state result = AST_TEST_PASS;
-	struct ast_config * cfg = make_populated_config();
+	struct ast_config * cfg = NULL;
 	struct vm_config * vmcfg = NULL;
 	unsigned char test_adsifdn[4] = "\xAB\xAB\xAB\xAB";
 	unsigned char test_adsisec[4] = "\xCD\xCD\xCD\xCD";
@@ -1497,12 +1617,16 @@
 
 	/* Test loading an empty ast_config object */
 	if (!(vmcfg = voicemail_config_new())) {
+		ast_config_destroy(cfg);
 		ast_test_status_update(test, "Failed to create vm_config object\n");
 		result = AST_TEST_FAIL;
 		return result;
 	}
+
 	populate_default_vm_config_options(vmcfg);
+	cfg = make_populated_config();
 	if (load_voicemail_options(vmcfg, cfg)) {
+		ast_config_destroy(cfg);
 		ao2_ref(vmcfg, -1);
 		ast_test_status_update(test, "Errors occurred while loading a default ast_config object\n");
 		result = AST_TEST_FAIL;
@@ -1543,7 +1667,7 @@
 	VM_TEST_NUMERIC_EQUAL(VM_SVMAIL, ast_test_flag((&vmcfg->globalflags), VM_SVMAIL));
 	VM_TEST_NUMERIC_EQUAL(VM_REVIEW, ast_test_flag((&vmcfg->globalflags), VM_REVIEW));
 	VM_TEST_NUMERIC_EQUAL(VM_OPERATOR, ast_test_flag((&vmcfg->globalflags), VM_OPERATOR));
-	VM_TEST_NUMERIC_EQUAL(0, ast_test_flag((&vm_config->vmcfg), VM_ENVELOPE));
+	VM_TEST_NUMERIC_EQUAL(0, ast_test_flag((&vmcfg->globalflags), VM_ENVELOPE));
 	VM_TEST_NUMERIC_EQUAL(VM_SKIPAFTERCMD, ast_test_flag((&vmcfg->globalflags), VM_SKIPAFTERCMD));
 	VM_TEST_NUMERIC_EQUAL(VM_FORCEGREET, ast_test_flag((&vmcfg->globalflags), VM_FORCEGREET));
 	VM_TEST_NUMERIC_EQUAL(VM_FORCENAME, ast_test_flag((&vmcfg->globalflags), VM_FORCENAME));
@@ -1571,7 +1695,7 @@
 	VM_TEST_STRING_EQUAL("New ${VM_DUR} long msg in box ${VM_MAILBOX}\nfrom ${VM_CALLERID}, on ${VM_DATE}", vmcfg->pager_body);
 	VM_TEST_STRING_EQUAL("The Asterisk PBX", vmcfg->pager_from_string);
 	VM_TEST_STRING_EQUAL("New VM", vmcfg->pager_subject);
-	VM_TEST_NUMERIC_EQUAL(OPT_PWLOC_SPOOLDIR, vmcfg->password_location);
+	VM_TEST_NUMERIC_EQUAL(VM_OPT_PWLOC_SPOOLDIR, vmcfg->password_location);
 	VM_TEST_NUMERIC_EQUAL(VM_OPT_PWCHG_EXTERNAL, ast_test_flag((&vmcfg->passwordflags), VM_OPT_PWCHG_EXTERNAL));
 	VM_TEST_NUMERIC_EQUAL(180, vmcfg->poll_frequency);
 	VM_TEST_NUMERIC_EQUAL(128, vmcfg->silence_threshold);
@@ -1592,7 +1716,6 @@
 	VM_TEST_STRING_EQUAL("central", vmcfg->zonetag);
 
 	ao2_ref(vmcfg, -1);
-
 	ast_config_destroy(cfg);
 
 	return result;
@@ -1601,10 +1724,11 @@
 
 AST_TEST_DEFINE(test_vm_user_default)
 {
-	int result = AST_TEST_PASS;
-	struct ast_config * cfg = make_populated_config();
-	struct ast_vm_user * vmu = NULL;
-	struct vm_config * vmcfg = NULL;
+	enum ast_test_result_state result = AST_TEST_PASS;
+	struct ast_config *cfg = NULL;
+	struct ast_vm_user *vmu = NULL;
+	struct vm_config *vmcfg = NULL;
+	struct ao2_container *tmp_voicemail_users;
 
 	switch (cmd) {
 	case TEST_INIT:
@@ -1618,54 +1742,79 @@
 		break;
 	}
 
-	if (vm_load_config(0, &cfg, &vm_config)) {
-		ast_test_status_update(test, "Failed to load vm_config using empty ast_config object\n");
+	if (!(tmp_voicemail_users = ao2_container_alloc(283, voicemail_user_hash_fn, voicemail_user_cmp_fn))) {
+		ast_test_status_update(test, "Failed to allocate sufficient memory for temp voicemail users container\n");
 		result = AST_TEST_FAIL;
-	} else {
-
-		/* Extract the basic user */
-		if (!(vmu = vm_find_user("default", "1234"))) {
-			ast_test_status_update(test, "Failed to find user default, 1234\n");
-			result = AST_TEST_FAIL;
-		} else {
-			/* Check the properties to make sure the defaults are populated either from the config or from presets */
-			VM_TEST_STRING_EQUAL("", vmu->attachfmt);
-			VM_TEST_STRING_EQUAL("fromvm", vmu->callback);
-			VM_TEST_STRING_EQUAL("default", vmu->context);
-			VM_TEST_STRING_EQUAL("fromvm", vmu->dialout);
-			VM_TEST_STRING_EQUAL("root at localhost", vmu->email);
-			VM_TEST_STRING_EQUAL("fromvm",vmu->exit);
-			VM_TEST_STRING_EQUAL("Example Mailbox", vmu->fullname);
-			VM_TEST_STRING_EQUAL(vm_config->locale, vmu->locale);
-			VM_TEST_STRING_EQUAL("1234", vmu->mailbox);
-			VM_TEST_NUMERIC_EQUAL(vm_config->max_deleted_messages, vmu->maxdeletedmsg);
-			VM_TEST_NUMERIC_EQUAL(vm_config->max_messages, vmu->maxmsg);
-			VM_TEST_NUMERIC_EQUAL(vm_config->max_message_duration, vmu->maxsecs);
-			VM_TEST_NUMERIC_EQUAL(vm_config->min_message_duration, vmu->minsecs);
-			VM_TEST_STRING_EQUAL("", vmu->pager);
-			VM_TEST_STRING_EQUAL("4242", vmu->password);
-			VM_TEST_NUMERIC_EQUAL(OPT_PWLOC_SPOOLDIR, vmu->passwordlocation);
-			VM_TEST_NUMERIC_EQUAL(5, vmu->saydurationm);
-			VM_TEST_STRING_EQUAL("", vmu->serveremail);
-			VM_TEST_NUMERIC_EQUAL(1.0, vmu->volgain);
-			VM_TEST_STRING_EQUAL("central", vmu->zonetag);
-
-			ao2_ref(vmu, -1);
-		}
-	}
-
+		return result;
+	}
+
+	/* Test loading an empty ast_config object */
+	if (!(vmcfg = voicemail_config_new())) {
+		ast_test_status_update(test, "Failed to create vm_config object\n");
+		result = AST_TEST_FAIL;
+		ao2_ref(tmp_voicemail_users, -1);
+		return result;
+	}
+
+	populate_default_vm_config_options(vmcfg);
+	cfg = make_empty_config();
+
+	if (load_voicemail_options(vmcfg, cfg) || load_voicemail_users(vmcfg, cfg, 1, tmp_voicemail_users)) {
+		ao2_ref(vmcfg, -1);
+		ao2_ref(tmp_voicemail_users, -1);
+		ast_config_destroy(cfg);
+		ast_test_status_update(test, "Errors occurred while loading a default ast_config object\n");
+		result = AST_TEST_FAIL;
+		return result;
+	}
+
+	/* Extract the basic user */
+	if (!(vmu = vm_get_user("default", "1234"))) {
+		ast_test_status_update(test, "Failed to find user default, 1234\n");
+		result = AST_TEST_FAIL;
+		ast_config_destroy(cfg);
+		ao2_ref(vmcfg, -1);
+		ao2_ref(tmp_voicemail_users, -1);
+		return result;
+	}
+
+	/* Check the properties to make sure the defaults are populated either from the config or from presets */
+	VM_TEST_STRING_EQUAL("", vmu->attachfmt);
+	VM_TEST_STRING_EQUAL("fromvm", vmu->callback);
+	VM_TEST_STRING_EQUAL("default", vmu->context);
+	VM_TEST_STRING_EQUAL("fromvm", vmu->dialout);
+	VM_TEST_STRING_EQUAL("root at localhost", vmu->email_address);
+	VM_TEST_STRING_EQUAL("fromvm",vmu->exit);
+	VM_TEST_STRING_EQUAL("Example Mailbox", vmu->fullname);
+	VM_TEST_STRING_EQUAL(vmcfg->locale, vmu->locale);
+	VM_TEST_STRING_EQUAL("1234", vmu->mailbox);
+	VM_TEST_NUMERIC_EQUAL(vmcfg->max_deleted_messages, vmu->max_deleted_messages);
+	VM_TEST_NUMERIC_EQUAL(vmcfg->max_messages, vmu->max_messages);
+	VM_TEST_NUMERIC_EQUAL(vmcfg->max_message_duration, vmu->max_message_duration);
+	VM_TEST_NUMERIC_EQUAL(vmcfg->min_message_duration, vmu->min_message_duration);
+	VM_TEST_STRING_EQUAL("", vmu->pager_address);
+	VM_TEST_STRING_EQUAL("4242", vmu->password);
+	VM_TEST_NUMERIC_EQUAL(VM_OPT_PWLOC_SPOOLDIR, vmu->password_location);
+	VM_TEST_NUMERIC_EQUAL(5, vmu->min_say_duration);
+	VM_TEST_STRING_EQUAL("", vmu->email_from_address);
+	VM_TEST_NUMERIC_EQUAL(1.0, vmu->volgain);
+	VM_TEST_STRING_EQUAL("central", vmu->zonetag);
+
+	ao2_ref(vmu, -1);
+	ao2_ref(tmp_voicemail_users, -1);
 	ast_config_destroy(cfg);
-	ao2_ref(vm_config, -1);
+	ao2_ref(vmcfg, -1);
 
 	return result;
 }
 
 AST_TEST_DEFINE(test_vm_user_overrides)
 {
-	int result = AST_TEST_PASS;
-	struct ast_config * cfg = make_populated_config();
-	struct ast_vm_user * vmu = NULL;
-	struct vm_config * vm_config;
+	enum ast_test_result_state result = AST_TEST_PASS;
+	struct ast_config *cfg = NULL;
+	struct ast_vm_user *vmu = NULL;
+	struct vm_config *vmcfg = NULL;
+	struct ao2_container *tmp_voicemail_users;
 
 	switch (cmd) {
 	case TEST_INIT:
@@ -1679,52 +1828,132 @@
 		break;
 	}
 
-	if (vm_load_config(0, &cfg, &vm_config)) {
-		ast_test_status_update(test, "Failed to load vm_config using empty ast_config object\n");
+	if (!(tmp_voicemail_users = ao2_container_alloc(283, voicemail_user_hash_fn, voicemail_user_cmp_fn))) {
+		ast_test_status_update(test, "Failed to allocate sufficient memory for temp voicemail users container\n");
 		result = AST_TEST_FAIL;
-	} else {
-
-		/* Extract a user */
-		if (!(vmu = vm_find_user("default", "7200"))) {
-			ast_test_status_update(test, "Failed to find user default, 7200\n");
-			result = AST_TEST_FAIL;
-		} else {
-			/* Check the properties to make sure the defaults are populated either from the config or from presets */
-			VM_TEST_STRING_EQUAL("", vmu->attachfmt);
-			VM_TEST_STRING_EQUAL("fromvm", vmu->callback);
-			VM_TEST_STRING_EQUAL("default", vmu->context);
-			VM_TEST_STRING_EQUAL("fromvm", vmu->dialout);
-			VM_TEST_STRING_EQUAL("", vmu->email);
-			VM_TEST_STRING_EQUAL("fromvm",vmu->exit);
-			VM_TEST_NUMERIC_EQUAL(VM_DELETE, ast_test_flag(vmu, VM_DELETE));
-			VM_TEST_STRING_EQUAL("Matt Jordan", vmu->fullname);
-			VM_TEST_STRING_EQUAL(vm_config->locale, vmu->locale);
-			VM_TEST_STRING_EQUAL("7200", vmu->mailbox);
-			VM_TEST_STRING_EQUAL("You have a new voicemail.", vmu->emailsubject);
-			VM_TEST_STRING_EQUAL("Click on the attachment to listen.\n\nThanks-\tAsterisk!\n", vmu->emailbody);
-			VM_TEST_NUMERIC_EQUAL(vm_config->max_deleted_messages, vmu->maxdeletedmsg);
-			VM_TEST_NUMERIC_EQUAL(vm_config->max_messages, vmu->maxmsg);
-			VM_TEST_NUMERIC_EQUAL(vm_config->max_message_duration, vmu->maxsecs);
-			VM_TEST_NUMERIC_EQUAL(vm_config->min_message_duration, vmu->minsecs);
-			VM_TEST_STRING_EQUAL("", vmu->pager);
-			VM_TEST_STRING_EQUAL("6522", vmu->password);
-			VM_TEST_NUMERIC_EQUAL(OPT_PWLOC_SPOOLDIR, vmu->passwordlocation);
-			VM_TEST_NUMERIC_EQUAL(5, vmu->saydurationm);
-			VM_TEST_STRING_EQUAL("", vmu->serveremail);
-			VM_TEST_NUMERIC_EQUAL(1.0, vmu->volgain);
-			VM_TEST_STRING_EQUAL("central", vmu->zonetag);
-
-			ao2_ref(vmu, -1);
-		}
-	}
-
+		return result;
+	}
+
+	/* Test loading an empty ast_config object */
+	if (!(vmcfg = voicemail_config_new())) {
+		ast_test_status_update(test, "Failed to create vm_config object\n");
+		result = AST_TEST_FAIL;
+		ao2_ref(tmp_voicemail_users, -1);
+		return result;
+	}
+
+	populate_default_vm_config_options(vmcfg);
+	cfg = make_populated_config();
+
+	if (load_voicemail_options(vmcfg, cfg) || load_voicemail_users(vmcfg, cfg, 1, tmp_voicemail_users)) {
+		ao2_ref(vmcfg, -1);
+		ao2_ref(tmp_voicemail_users, -1);
+		ast_config_destroy(cfg);
+		ast_test_status_update(test, "Errors occurred while loading voicemail options or users\n");
+		result = AST_TEST_FAIL;
+		return result;
+	}
+
+	/* Extract a user */
+	if (!(vmu = vm_get_user("default", "7200"))) {
+		ast_test_status_update(test, "Failed to find user default, 7200\n");
+		result = AST_TEST_FAIL;
+		ast_config_destroy(cfg);
+		ao2_ref(vmcfg, -1);
+		ao2_ref(tmp_voicemail_users, -1);
+		return result;
+	}
+
+	/* Check the properties to make sure the defaults are populated either from the config or from presets */
+	VM_TEST_STRING_EQUAL("", vmu->attachfmt);
+	VM_TEST_STRING_EQUAL("fromvm", vmu->callback);
+	VM_TEST_STRING_EQUAL("default", vmu->context);
+	VM_TEST_STRING_EQUAL("fromvm", vmu->dialout);
+	VM_TEST_STRING_EQUAL("", vmu->email_address);
+	VM_TEST_STRING_EQUAL("fromvm",vmu->exit);
+	VM_TEST_NUMERIC_EQUAL(VM_DELETE, ast_test_flag((&vmu->flags), VM_DELETE));
+	VM_TEST_STRING_EQUAL("Matt Jordan", vmu->fullname);
+	VM_TEST_STRING_EQUAL(vmcfg->locale, vmu->locale);
+	VM_TEST_STRING_EQUAL("7200", vmu->mailbox);
+	VM_TEST_STRING_EQUAL("You have a new voicemail.", vmu->email_subject);
+	VM_TEST_STRING_EQUAL("Click on the attachment to listen.\n\nThanks-\tAsterisk!\n", vmu->email_body);
+	VM_TEST_NUMERIC_EQUAL(vmcfg->max_deleted_messages, vmu->max_deleted_messages);
+	VM_TEST_NUMERIC_EQUAL(vmcfg->max_messages, vmu->max_messages);
+	VM_TEST_NUMERIC_EQUAL(vmcfg->max_message_duration, vmu->max_message_duration);
+	VM_TEST_NUMERIC_EQUAL(vmcfg->min_message_duration, vmu->min_message_duration);
+	VM_TEST_STRING_EQUAL("", vmu->pager_address);
+	VM_TEST_STRING_EQUAL("6522", vmu->password);
+	VM_TEST_NUMERIC_EQUAL(VM_OPT_PWLOC_SPOOLDIR, vmu->password_location);
+	VM_TEST_NUMERIC_EQUAL(5, vmu->min_say_duration);
+	VM_TEST_STRING_EQUAL("", vmu->email_from_address);
+	VM_TEST_NUMERIC_EQUAL(1.0, vmu->volgain);
+	VM_TEST_STRING_EQUAL("central", vmu->zonetag);
+
+	ao2_ref(vmu, -1);
 	ast_config_destroy(cfg);
-	ao2_ref(vm_config, -1);
+	ao2_ref(vmcfg, -1);
+	ao2_ref(tmp_voicemail_users, -1);
 
 	return result;
 }
 
-#endif
+AST_TEST_DEFINE(test_vm_user_multi_config)
+{
+	enum ast_test_result_state result = AST_TEST_PASS;
+	struct ast_config *cfg = NULL;
+	struct ast_config *ucfg = NULL;
+	struct vm_config *vmcfg = NULL;
+	struct ao2_container *tmp_voicemail_users;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "test_vm_user_multi_config";
+		info->category = "/apps/app_voicemail/";
+		info->summary = "VoiceMail Config Parser default user test";
+		info->description =
+			"This tests configuring voicemail users from a variety of configuration sources";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(tmp_voicemail_users = ao2_container_alloc(283, voicemail_user_hash_fn, voicemail_user_cmp_fn))) {
+		ast_test_status_update(test, "Failed to allocate sufficient memory for temp voicemail users container\n");
+		result = AST_TEST_FAIL;
+		return result;
+	}
+
+	if (!(vmcfg = voicemail_config_new())) {
+		ast_test_status_update(test, "Failed to create vm_config object\n");
+		result = AST_TEST_FAIL;
+		ao2_ref(tmp_voicemail_users, -1);
+		return result;
+	}
+
+	populate_default_vm_config_options(vmcfg);
+	cfg = make_populated_config();
+	ucfg = make_user_config();
+
+	if (load_voicemail_options(vmcfg, cfg) ||
+			load_voicemail_users(vmcfg, cfg, 1, tmp_voicemail_users) ||
+			load_voicemail_users(vmcfg, ucfg, 0, tmp_voicemail_users)) {
+		ao2_ref(vmcfg, -1);
+		ao2_ref(tmp_voicemail_users, -1);
+		ast_config_destroy(cfg);
+		ast_config_destroy(ucfg);
+		ast_test_status_update(test, "Errors occurred while loading a default ast_config object\n");
+		result = AST_TEST_FAIL;
+		return result;
+	}
+
+	ast_config_destroy(cfg);
+	ast_config_destroy(ucfg);
+	ao2_ref(vmcfg, -1);
+	ao2_ref(tmp_voicemail_users, -1);
+
+	return result;
+}
+
 
 void vm_register_config_tests(void)
 {
@@ -1744,3 +1973,4 @@
 	AST_TEST_UNREGISTER(test_vm_user_multi_config);
 }
 
+#endif




More information about the asterisk-commits mailing list