[asterisk-commits] mjordan: branch mmichelson/trunk-digiumphones r361656 - /team/mmichelson/trun...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 9 14:14:51 CDT 2012


Author: mjordan
Date: Mon Apr  9 14:14:48 2012
New Revision: 361656

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=361656
Log:
Updated per Mark's suggestions on having any messages in the
test voicemail user's mailboxes be removed on an initial run
of the test

Modified:
    team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c

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=361656&r1=361655&r2=361656
==============================================================================
--- team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c (original)
+++ team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c Mon Apr  9 14:14:48 2012
@@ -417,13 +417,85 @@
 	fclose(msg_file);
 
 	if (chmod(msg_path, VOICEMAIL_FILE_MODE) < 0) {
+		ast_unlock_path(snapshot->folder_dir);
 		ast_log(AST_LOG_ERROR, "Couldn't set permissions on voicemail text file %s: %s", msg_path, strerror(errno));
-		ast_unlock_path(snapshot->folder_dir);
 		return 1;
 	}
 	ast_unlock_path(snapshot->folder_dir);
 
 	return 0;
+}
+
+/*! \internal \brief Destroy the voicemail on the file system associated with a snapshot
+ * \param snapshot The snapshot describing the voicemail
+ */
+static void test_vm_api_remove_voicemail(struct ast_vm_msg_snapshot *snapshot)
+{
+	char msg_path[PATH_MAX];
+	char snd_path[PATH_MAX];
+	char folder_path[PATH_MAX];
+
+	if (!snapshot) {
+		return;
+	}
+
+	if (ast_strlen_zero(snapshot->folder_dir)) {
+		snprintf(folder_path, sizeof(folder_path), "%s/voicemail/%s/%s/%s",
+			ast_config_AST_SPOOL_DIR, "default", snapshot->exten, snapshot->folder_name);
+		ast_string_field_set(snapshot, folder_dir, folder_path);
+	}
+
+	snprintf(msg_path, sizeof(msg_path), "%s/msg%04d.txt",
+			snapshot->folder_dir, snapshot->msg_number);
+	snprintf(snd_path, sizeof(snd_path), "%s/msg%04d.gsm",
+			snapshot->folder_dir, snapshot->msg_number);
+	unlink(msg_path);
+	unlink(snd_path);
+
+	return;
+}
+
+/*! \internal \brief Destroy the voicemails associated with a mailbox snapshot
+ * \param mailbox The actual mailbox name
+ * \param mailbox_snapshot The mailbox snapshot containing the voicemails to destroy
+ * \note Its necessary to specify not just the snapshot, but the mailbox itself.  The
+ * message snapshots contained in the snapshot may have originated from a different mailbox
+ * then the one we're destroying, which means that we can't determine the files to delete
+ * without knowing the actual mailbox they exist in.
+ */
+static void test_vm_api_destroy_mailbox_voicemails(const char *mailbox, struct ast_vm_mailbox_snapshot *mailbox_snapshot)
+{
+	struct ast_vm_msg_snapshot *msg;
+	int i;
+
+	for (i = 0; i < 12; ++i) {
+		AST_LIST_TRAVERSE(&mailbox_snapshot->snapshots[i], msg, msg) {
+			ast_string_field_set(msg, exten, mailbox);
+			test_vm_api_remove_voicemail(msg);
+		}
+	}
+}
+
+/*! \internal \brief Use snapshots to remove all messages in the mailboxes */
+static void test_vm_api_remove_all_messages(void)
+{
+	struct ast_vm_mailbox_snapshot *mailbox_snapshot;
+
+	/* Take a snapshot of each mailbox and remove the contents.  Note that we need to use
+	 * snapshots of the mailboxes in addition to our tracked test snapshots, as there's a good chance
+	 * we've created copies of the snapshots */
+	if ((mailbox_snapshot = ast_vm_mailbox_snapshot_create("test_vm_api_1234", "default", NULL, 0, AST_VM_SNAPSHOT_SORT_BY_ID, 0))) {
+		test_vm_api_destroy_mailbox_voicemails("test_vm_api_1234", mailbox_snapshot);
+		mailbox_snapshot = ast_vm_mailbox_snapshot_destroy(mailbox_snapshot);
+	} else {
+		ast_log(AST_LOG_WARNING, "Failed to create mailbox snapshot - could not remove test messages for test_vm_api_1234\n");
+	}
+	if ((mailbox_snapshot = ast_vm_mailbox_snapshot_create("test_vm_api_2345", "default", NULL, 0, AST_VM_SNAPSHOT_SORT_BY_ID, 0))) {
+		test_vm_api_destroy_mailbox_voicemails("test_vm_api_2345", mailbox_snapshot);
+		mailbox_snapshot = ast_vm_mailbox_snapshot_destroy(mailbox_snapshot);
+	} else {
+		ast_log(AST_LOG_WARNING, "Failed to create mailbox snapshot - could not remove test messages for test_vm_api_2345\n");
+	}
 }
 
 /*! \internal \brief Set up the necessary voicemails for a unit test run
@@ -447,7 +519,7 @@
 	struct ast_vm_msg_snapshot *msg_three = NULL;
 	struct ast_vm_msg_snapshot *msg_four = NULL;
 
-	/* Make the three sample voicemails */
+	/* Make the four sample voicemails */
 	if (   !((msg_one = test_vm_api_create_mock_snapshot("default", "test_vm_api_1234", "\"Phil\" <2000>")))
 		|| !((msg_two = test_vm_api_create_mock_snapshot("default", "test_vm_api_1234", "\"Noel\" <8000>")))
 		|| !((msg_three = test_vm_api_create_mock_snapshot("default", "test_vm_api_2345", "\"Phil\" <2000>")))
@@ -474,6 +546,11 @@
 		return 1;
 	}
 
+	/* Now that the users exist from the perspective of the voicemail
+	 * application, attempt to remove any existing voicemails
+	 */
+	test_vm_api_remove_all_messages();
+
 	/* Set the basic properties on each */
 	ast_string_field_set(msg_one, callerchan, "SIP/2000-00000000");
 	ast_string_field_set(msg_one, origdate, "Mon Mar 19 04:14:21 PM UTC 2012");
@@ -524,59 +601,8 @@
 	return res;
 }
 
-/*! \internal \brief Destroy the voicemail on the file system associated with a snapshot
- * \param snapshot The snapshot describing the voicemail
- */
-static void test_vm_api_remove_voicemail(struct ast_vm_msg_snapshot *snapshot)
-{
-	char msg_path[PATH_MAX];
-	char snd_path[PATH_MAX];
-	char folder_path[PATH_MAX];
-
-	if (!snapshot) {
-		return;
-	}
-
-	if (ast_strlen_zero(snapshot->folder_dir)) {
-		snprintf(folder_path, sizeof(folder_path), "%s/voicemail/%s/%s/%s",
-			ast_config_AST_SPOOL_DIR, "default", snapshot->exten, snapshot->folder_name);
-		ast_string_field_set(snapshot, folder_dir, folder_path);
-	}
-
-	snprintf(msg_path, sizeof(msg_path), "%s/msg%04d.txt",
-			snapshot->folder_dir, snapshot->msg_number);
-	snprintf(snd_path, sizeof(snd_path), "%s/msg%04d.gsm",
-			snapshot->folder_dir, snapshot->msg_number);
-	unlink(msg_path);
-	unlink(snd_path);
-
-	return;
-}
-
-/*! \internal \brief Destroy the voicemails associated with a mailbox snapshot
- * \param mailbox The actual mailbox name
- * \param mailbox_snapshot The mailbox snapshot containing the voicemails to destroy
- * \note Its necessary to specify not just the snapshot, but the mailbox itself.  The
- * message snapshots contained in the snapshot may have originated from a different mailbox
- * then the one we're destroying, which means that we can't determine the files to delete
- * without knowing the actual mailbox they exist in.
- */
-static void test_vm_api_destroy_mailbox_voicemails(const char *mailbox, struct ast_vm_mailbox_snapshot *mailbox_snapshot)
-{
-	struct ast_vm_msg_snapshot *msg;
-	int i;
-
-	for (i = 0; i < 12; ++i) {
-		AST_LIST_TRAVERSE(&mailbox_snapshot->snapshots[i], msg, msg) {
-			ast_string_field_set(msg, exten, mailbox);
-			test_vm_api_remove_voicemail(msg);
-		}
-	}
-}
-
 static void test_vm_api_test_teardown(void)
 {
-	struct ast_vm_mailbox_snapshot *mailbox_snapshot;
 	int i;
 
 	/* Remove our test message snapshots */
@@ -586,21 +612,7 @@
 		test_snapshots[i] = NULL;
 	}
 
-	/* Take a snapshot of each mailbox and remove the contents.  Note that we need to use
-	 * snapshots of the mailboxes in addition to our tracked test snapshots, as there's a good chance
-	 * we've created copies of the snapshots */
-	if ((mailbox_snapshot = ast_vm_mailbox_snapshot_create("test_vm_api_1234", "default", NULL, 0, AST_VM_SNAPSHOT_SORT_BY_ID, 0))) {
-		test_vm_api_destroy_mailbox_voicemails("test_vm_api_1234", mailbox_snapshot);
-		mailbox_snapshot = ast_vm_mailbox_snapshot_destroy(mailbox_snapshot);
-	} else {
-		ast_log(AST_LOG_WARNING, "Failed to create mailbox snapshot - could not remove test messages for test_vm_api_1234\n");
-	}
-	if ((mailbox_snapshot = ast_vm_mailbox_snapshot_create("test_vm_api_2345", "default", NULL, 0, AST_VM_SNAPSHOT_SORT_BY_ID, 0))) {
-		test_vm_api_destroy_mailbox_voicemails("test_vm_api_2345", mailbox_snapshot);
-		mailbox_snapshot = ast_vm_mailbox_snapshot_destroy(mailbox_snapshot);
-	} else {
-		ast_log(AST_LOG_WARNING, "Failed to create mailbox snapshot - could not remove test messages for test_vm_api_2345\n");
-	}
+	test_vm_api_remove_all_messages();
 
 	/* Remove the test users */
 	ast_vm_test_destroy_user("default", "test_vm_api_1234");




More information about the asterisk-commits mailing list