[asterisk-commits] mmichelson: branch mmichelson/trunk-digiumphones r361655 - in /team/mmichelso...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 9 10:57:31 CDT 2012


Author: mmichelson
Date: Mon Apr  9 10:57:24 2012
New Revision: 361655

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=361655
Log:
Get the rest of the voicemail API tests passing:

* Fixes a few places I missed before where NULL pointer checks needed to be done.
* In ast_vm_msg_move(), tolerate a NULL pointer given for 'new_msg_nums'.
* Add the destination folder back into ast_vm_msg_forward(). This required changing
  copy_message() to take a folder parameter.


Modified:
    team/mmichelson/trunk-digiumphones/apps/app_voicemail.c
    team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h
    team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c

Modified: team/mmichelson/trunk-digiumphones/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/apps/app_voicemail.c?view=diff&rev=361655&r1=361654&r2=361655
==============================================================================
--- team/mmichelson/trunk-digiumphones/apps/app_voicemail.c (original)
+++ team/mmichelson/trunk-digiumphones/apps/app_voicemail.c Mon Apr  9 10:57:24 2012
@@ -2599,7 +2599,7 @@
  *
  * \return zero on success, -1 on error.
  */
-static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt, char *dir, char *flag)
+static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt, char *dir, char *flag, const char *dest_folder)
 {
 	struct vm_state *sendvms = NULL;
 	char messagestring[10]; /*I guess this could be a problem if someone has more than 999999999 messages...*/
@@ -2617,7 +2617,7 @@
 	}
 	snprintf(messagestring, sizeof(messagestring), "%ld", sendvms->msgArray[msgnum]);
 	ast_mutex_lock(&sendvms->lock);
-	if ((mail_copy(sendvms->mailstream, messagestring, (char *) mbox(vmu, imbox)) == T)) {
+	if ((mail_copy(sendvms->mailstream, messagestring, (char *) mbox(vmu, dest_folder)) == T)) {
 		ast_mutex_unlock(&sendvms->lock);
 		return 0;
 	}
@@ -5437,7 +5437,7 @@
  *
  * \return zero on success, -1 on error.
  */
-static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt, char *dir, const char *flag)
+static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt, char *dir, const char *flag, const char *dest_folder)
 {
 	char fromdir[PATH_MAX], todir[PATH_MAX], frompath[PATH_MAX], topath[PATH_MAX];
 	const char *frombox = mbox(vmu, imbox);
@@ -5449,6 +5449,8 @@
 
 	if (!ast_strlen_zero(flag) && !strcmp(flag, "Urgent")) { /* If urgent, copy to Urgent folder */
 		userfolder = "Urgent";
+	} else if (!ast_strlen_zero(dest_folder)) {
+		userfolder = dest_folder;
 	} else {
 		userfolder = "INBOX";
 	}
@@ -6492,7 +6494,7 @@
 							cntx++;
 						}
 						if ((recip = find_user(&recipu, cntx, exten))) {
-							copy_message(chan, vmu, 0, msgnum, duration, recip, fmt, dir, flag);
+							copy_message(chan, vmu, 0, msgnum, duration, recip, fmt, dir, flag, NULL);
 							free_user(recip);
 						}
 					}
@@ -7813,7 +7815,7 @@
 					vmstmp.fn, vmstmp.introfn, fmt, duration, attach_user_voicemail, chan,
 					NULL, urgent_str);
 #else
-				copy_msg_result = copy_message(chan, sender, 0, curmsg, duration, vmtmp, fmt, dir, urgent_str);
+				copy_msg_result = copy_message(chan, sender, 0, curmsg, duration, vmtmp, fmt, dir, urgent_str, NULL);
 #endif
 				saved_messages++;
 				AST_LIST_REMOVE_CURRENT(list);
@@ -14794,6 +14796,7 @@
 	const char *from_folder,
 	const char *to_mailbox,
 	const char *to_context,
+	const char *to_folder,
 	size_t num_msgs,
 	int *msg_ids,
 	int delete_old)
@@ -14819,8 +14822,8 @@
 		return -1;
 	}
 
-	if (ast_strlen_zero(from_folder)) {
-		ast_log(LOG_WARNING, "Cannot forward message because the fromfolder was not specified\n");
+	if (ast_strlen_zero(from_folder) || ast_strlen_zero(to_folder)) {
+		ast_log(LOG_WARNING, "Cannot forward message because the from_folder or to_folder was not specified\n");
 		return -1;
 	}
 
@@ -14830,6 +14833,10 @@
 
 	from_folder_index = get_folder_by_name(from_folder);
 	if (from_folder_index == -1) {
+		return -1;
+	}
+
+	if (get_folder_by_name(to_folder) == -1) {
 		return -1;
 	}
 
@@ -14888,7 +14895,7 @@
 			duration = atoi(value);
 		}
 
-		copy_message(NULL, vmu, from_folder_index, cur_msg, duration, to_vmu, vmfmts, from_vms.curdir, "");
+		copy_message(NULL, vmu, from_folder_index, cur_msg, duration, to_vmu, vmfmts, from_vms.curdir, "", to_folder);
 
 		if (delete_old) {
 			from_vms.deleted[cur_msg] = 1;
@@ -14985,7 +14992,7 @@
 
 	/* Now actually move the message */
 	for (i = 0; i < num_msgs; ++i) {
-		if (save_to_folder(vmu, &vms, old_msg_nums[i], new_folder_index, (new_msg_nums + i))) {
+		if (save_to_folder(vmu, &vms, old_msg_nums[i], new_folder_index, new_msg_nums ? (new_msg_nums + i) : NULL)) {
 			res = -1;
 			goto vm_move_cleanup;
 		}

Modified: team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h?view=diff&rev=361655&r1=361654&r2=361655
==============================================================================
--- team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h (original)
+++ team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h Mon Apr  9 10:57:24 2012
@@ -135,6 +135,7 @@
  * \brief from_folder The folder from which the message is being forwarded
  * \brief to_mailbox The mailbox to forward the message to
  * \brief to_context The voicemail context of the to_mailbox
+ * \brief to_folder The voicemail folder to forward the message to
  * \brief num_msgs The number of messages being forwarded
  * \brief msg_ids The message IDs of the messages in from_mailbox to forward
  * \brief delete_old If non-zero, the forwarded messages are also deleted from from_mailbox.
@@ -148,6 +149,7 @@
 	const char *from_folder,
 	const char *to_mailbox,
 	const char *to_context,
+	const char *to_folder,
 	size_t num_msgs,
 	int *msg_ids,
 	int delete_old);

Modified: team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c?view=diff&rev=361655&r1=361654&r2=361655
==============================================================================
--- team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c (original)
+++ team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c Mon Apr  9 10:57:24 2012
@@ -209,7 +209,7 @@
 
 /*! \internal \brief Forward a message, failing the test if the message could not be forwarded */
 # define VM_API_FORWARD_MESSAGE(from_mailbox, from_context, from_folder, to_mailbox, to_context, to_folder, number_of_messages, message_numbers_in, delete_old) do { \
-	if (ast_vm_msg_forward((from_mailbox), (from_context), (from_folder), (to_mailbox), (to_context), (number_of_messages), (message_numbers_in), (delete_old))) { \
+	if (ast_vm_msg_forward((from_mailbox), (from_context), (from_folder), (to_mailbox), (to_context), (to_folder), (number_of_messages), (message_numbers_in), (delete_old))) { \
 		ast_test_status_update(test, "Failed to forward message from %s@%s [%s] to %s@%s [%s]\n", \
 			(from_mailbox) ? (from_mailbox) : "(NULL)", (from_context) ? (from_context) : "(NULL)", (from_folder) ? (from_folder) : "(NULL)", \
 			(to_mailbox) ? (to_mailbox) : "(NULL)", (to_context) ? (to_context) : "(NULL)", (to_folder) ? (to_folder) : "(NULL)"); \
@@ -219,7 +219,7 @@
 
 	/*! \internal \brief Forward a message, failing the test if the message was successfully forwarded */
 #define VM_API_FORWARD_MESSAGE_OFF_NOMINAL(from_mailbox, from_context, from_folder, to_mailbox, to_context, to_folder, number_of_messages, message_numbers_in, delete_old) do { \
-	if (!ast_vm_msg_forward((from_mailbox), (from_context), (from_folder), (to_mailbox), (to_context), (number_of_messages), (message_numbers_in), (delete_old))) { \
+	if (!ast_vm_msg_forward((from_mailbox), (from_context), (from_folder), (to_mailbox), (to_context), (to_folder), (number_of_messages), (message_numbers_in), (delete_old))) { \
 		ast_test_status_update(test, "Succeeded in forwarding message from %s@%s [%s] to %s@%s [%s] when expected result was fail\n", \
 			(from_mailbox) ? (from_mailbox) : "(NULL)", (from_context) ? (from_context) : "(NULL)", (from_folder) ? (from_folder) : "(NULL)", \
 			(to_mailbox) ? (to_mailbox) : "(NULL)", (to_context) ? (to_context) : "(NULL)", (to_folder) ? (to_folder) : "(NULL)"); \
@@ -811,9 +811,8 @@
 	ast_test_status_update(test, "Test access to non-existent mailbox test_vm_api_3456\n");
 	VM_API_SNAPSHOT_OFF_NOMINAL_TEST("test_vm_api_3456", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
 
-	/* TODO: Currently fails */
 	ast_test_status_update(test, "Test access to null mailbox\n");
-/*	VM_API_SNAPSHOT_OFF_NOMINAL_TEST(NULL, "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); */
+	VM_API_SNAPSHOT_OFF_NOMINAL_TEST(NULL, "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
 
 	ast_test_status_update(test, "Test access non-existent context test_vm_api_defunct\n");
 	VM_API_SNAPSHOT_OFF_NOMINAL_TEST("test_vm_api_1234", "test_vm_api_defunct", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
@@ -881,19 +880,16 @@
 	VM_API_STRING_FIELD_VERIFY(test_snapshots[2]->folder_name, "Family");
 	VM_API_STRING_FIELD_VERIFY(test_snapshots[3]->folder_name, "Family");
 
-	/* Move both the messages back without an output number field */
-	/* TODO: This currently fails */
-	/*	ast_test_status_update(test, "Test move of test_vm_api_2345 message from Family to INBOX\n");
-	VM_API_MOVE_MESSAGE("test_vm_api_2345", "default", 2, "Family", multi_msg_nums, "INBOX", NULL); */
-
-	/* Take a snapshot and update the test snapshots for verification */
-/*	VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
+	ast_test_status_update(test, "Test move of test_vm_api_2345 message from Family to INBOX\n");
+	VM_API_MOVE_MESSAGE("test_vm_api_2345", "default", 2, "Family", multi_msg_nums, "INBOX", NULL);
+
+	VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
 	test_vm_api_update_test_snapshots(test_mbox_snapshot);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	VM_API_STRING_FIELD_VERIFY(test_snapshots[2]->folder_name, "INBOX");
 	VM_API_STRING_FIELD_VERIFY(test_snapshots[3]->folder_name, "INBOX");
-*/
+
 	VM_API_TEST_CLEANUP;
 
 	return AST_TEST_PASS;
@@ -902,8 +898,7 @@
 AST_TEST_DEFINE(voicemail_api_off_nominal_move)
 {
 	int single_msg_nums[] = { 0, };
-	/* TODO: Uncomment this if the multi-move is added back
-	int multi_msg_nums[] = { 0, 1, 2, 3};*/
+	int multi_msg_nums[] = { 0, 1, 2, 3};
 
 	switch (cmd) {
 	case TEST_INIT:
@@ -929,10 +924,7 @@
 	ast_test_status_update(test, "Test move attempt for invalid mailbox test_vm_3456\n");
 	VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_3456", "default", 1, "INBOX", single_msg_nums, "Family", NULL);
 
-	/* TODO: This currently fails
-	ast_test_status_update(test, "Test move attempt for invalid NULL mailbox\n");
 	VM_API_MOVE_MESSAGE_OFF_NOMINAL(NULL, "default", 1, "INBOX", single_msg_nums, "Family", NULL);
-	*/
 
 	ast_test_status_update(test, "Test move attempt for invalid context test_vm_api_defunct\n");
 	VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "test_vm_api_defunct", 1, "INBOX", single_msg_nums, "Family", NULL);
@@ -943,37 +935,29 @@
 	ast_test_status_update(test, "Test move attempt from invalid folder\n");
 	VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "MEATINACAN", single_msg_nums, "Family", NULL);
 
-	/* TODO: This currently fails
 	ast_test_status_update(test, "Test move attempt to NULL folder\n");
 	VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", single_msg_nums, NULL, NULL);
 
 	ast_test_status_update(test, "Test move attempt from NULL folder\n");
 	VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, NULL, single_msg_nums, "Family", NULL);
-	*/
 
 	ast_test_status_update(test, "Test move attempt with non-existent message number\n");
 	single_msg_nums[0] = 6;
 	VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", single_msg_nums, "Family", NULL);
 
-	/* TODO: This currently fails by 'succeeding', even though no message is moved
 	ast_test_status_update(test, "Test move attempt with invalid message number\n");
 	single_msg_nums[0] = -4;
 	VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", single_msg_nums, "Family", NULL);
-	*/
-
-	/* TODO: this currently fails, as ast_vm_move_msg returns success when it doesn't process any messages
+
 	ast_test_status_update(test, "Test move attempt with 0 number of messages\n");
 	single_msg_nums[0] = 0;
 	VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 0, "INBOX", single_msg_nums, "Family", NULL);
 
 	ast_test_status_update(test, "Test move attempt with invalid number of messages\n");
 	VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", -30, "INBOX", single_msg_nums, "Family", NULL);
-	*/
-
-	/* TODO: This currently fails as it moves the first message and fails afterwards
+
 	ast_test_status_update(test, "Test move attempt with non-existent multiple messages, where some messages exist\n");
 	VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 4, "INBOX", multi_msg_nums, "Family", NULL);
-	*/
 
 	VM_API_TEST_CLEANUP;
 
@@ -1162,21 +1146,18 @@
 	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 2);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
-	/* TODO: this test currently fails, as the destination folder is not honored
 	ast_test_status_update(test, "Test forwarding 2 messages from test_vm_api_2345 INBOX to test_vm_api_1234 Family, deleting original\n");
 	VM_API_FORWARD_MESSAGE("test_vm_api_2345", "default", "INBOX", "test_vm_api_1234", "default", "Family", 2, multi_msg_nums, 1);
-	*/
-	/* TODO: uncomment the snapshot tests when the previous test is fixed */
 	/* Make sure we deleted the messages */
-/*	VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
+	VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
 	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 4);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
-*/
+
 	/* We should now have a total of 2 messages in test_vm_api_1234 Family */
-/*	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Family", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
+	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Family", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
 	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 2);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
-*/
+
 	VM_API_TEST_CLEANUP;
 
 	return AST_TEST_PASS;
@@ -1237,12 +1218,10 @@
 
 	ast_test_status_update(test, "Test forwarding to an invalid folder\n");
 
-	/* VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "POTTEDMEAT", 1, single_msg_nums, 0); */
-
-	/*
+	VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "POTTEDMEAT", 1, single_msg_nums, 0);
+
 	ast_test_status_update(test, "Test forwarding to a NULL folder\n");
 	VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", NULL, 1, single_msg_nums, 0);
-	*/
 
 	ast_test_status_update(test, "Test forwarding when no messages are select\n");
 	VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 0, empty_msg_nums, 0);




More information about the asterisk-commits mailing list