[asterisk-commits] mjordan: branch 1.8 r332817 - in /branches/1.8: apps/ configs/ include/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 22 13:15:55 CDT 2011


Author: mjordan
Date: Mon Aug 22 13:15:51 2011
New Revision: 332817

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=332817
Log:
Review: https://reviewboard.asterisk.org/r/1364/

This update adds a new AMI event, TestEvent, which is enabled when the TEST_FRAMEWORK compiler flag is defined.  It also adds initial usage of this event to app_voicemail.  The TestEvent AMI event is used extensively by the voicemail tests in the Asterisk Test Suite.

Modified:
    branches/1.8/apps/app_voicemail.c
    branches/1.8/configs/manager.conf.sample
    branches/1.8/include/asterisk/manager.h
    branches/1.8/include/asterisk/test.h
    branches/1.8/main/app.c
    branches/1.8/main/file.c
    branches/1.8/main/manager.c
    branches/1.8/main/test.c

Modified: branches/1.8/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_voicemail.c?view=diff&rev=332817&r1=332816&r2=332817
==============================================================================
--- branches/1.8/apps/app_voicemail.c (original)
+++ branches/1.8/apps/app_voicemail.c Mon Aug 22 13:15:51 2011
@@ -1283,6 +1283,7 @@
 		ast_realtime_require_field("voicemail", "password", RQ_CHAR, strlen(password), SENTINEL);
 	}
 	if (ast_update2_realtime("voicemail", "context", vmu->context, "mailbox", vmu->mailbox, SENTINEL, "password", password, SENTINEL) > 0) {
+		ast_test_suite_event_notify("PASSWORDCHANGED", "Message: realtime engine updated with new password\r\nPasswordSource: realtime");
 		ast_copy_string(vmu->password, password, sizeof(vmu->password));
 		res = 0;
 	}
@@ -1514,6 +1515,7 @@
 	case OPT_PWLOC_SPOOLDIR:
 		snprintf(secretfn, sizeof(secretfn), "%s%s/%s/secret.conf", VM_SPOOL_DIR, vmu->context, vmu->mailbox);
 		if (write_password_to_file(secretfn, newpassword) == 0) {
+			ast_test_suite_event_notify("PASSWORDCHANGED", "Message: secret.conf updated with new password\r\nPasswordSource: secret.conf");
 			ast_verb(4, "Writing voicemail password to file %s succeeded\n", secretfn);
 			reset_user_pw(vmu->context, vmu->mailbox, newpassword);
 			ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
@@ -1548,6 +1550,7 @@
 			}
 			/* save the results */
 			if (found) {
+				ast_test_suite_event_notify("PASSWORDCHANGED", "Message: voicemail.conf updated with new password\r\nPasswordSource: voicemail.conf");
 				reset_user_pw(vmu->context, vmu->mailbox, newpassword);
 				ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
 				ast_config_text_file_save(VOICEMAIL_CONFIG, cfg, "AppVoicemail");
@@ -1587,6 +1590,7 @@
 			}
 			/* save the results and clean things up */
 			if (found) {
+				ast_test_suite_event_notify("PASSWORDCHANGED", "Message: users.conf updated with new password\r\nPasswordSource: users.conf");
 				reset_user_pw(vmu->context, vmu->mailbox, newpassword);
 				ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
 				ast_config_text_file_save("users.conf", cfg, "AppVoicemail");
@@ -1599,7 +1603,9 @@
 {
 	char buf[255];
 	snprintf(buf, sizeof(buf), "%s %s %s %s", ext_pass_cmd, vmu->context, vmu->mailbox, newpassword);
+	ast_debug(1, "External password: %s\n",buf);
 	if (!ast_safe_system(buf)) {
+		ast_test_suite_event_notify("PASSWORDCHANGED", "Message: external script updated with new password\r\nPasswordSource: external");
 		ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
 		/* Reset the password in memory, too */
 		reset_user_pw(vmu->context, vmu->mailbox, newpassword);
@@ -6754,6 +6760,7 @@
 				d = vm_play_folder_name(chan, "vm-INBOX");
 			}
 		} else {
+			ast_test_suite_event_notify("PLAYBACK", "Message: folder name %s", fn);
 			d = vm_play_folder_name(chan, fn);
 		}
 
@@ -6763,6 +6770,7 @@
 		if (d)
 			return d;
 	}
+
 	d = ast_play_and_wait(chan, "vm-tocancel"); /* "or pound to cancel" */
 	if (d)
 		return d;
@@ -6786,6 +6794,7 @@
 {
 	int res = 0;
 	int loops = 0;
+
 	res = ast_play_and_wait(chan, fn);	/* Folder name */
 	while (((res < '0') || (res > '9')) &&
 			(res != '#') && (res >= 0) &&
@@ -6794,8 +6803,10 @@
 		loops++;
 	}
 	if (loops == 4) { /* give up */
+		ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", '#', '#');
 		return '#';
 	}
+	ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", res, res);
 	return res;
 }
 
@@ -6940,16 +6951,20 @@
 
 			cmd = ast_play_and_wait(chan, "vm-forwardoptions");
 				/* "Press 1 to prepend a message or 2 to forward the message without prepending" */
-			if (!cmd)
+			if (!cmd) {
 				cmd = ast_play_and_wait(chan, "vm-starmain");
 				/* "press star to return to the main menu" */
-			if (!cmd)
+			}
+			if (!cmd) {
 				cmd = ast_waitfordigit(chan, 6000);
-			if (!cmd)
+			}
+			if (!cmd) {
 				retries++;
+			}
 			if (retries > 3) {
 				cmd = '*'; /* Let's cancel this beast */
 			}
+			ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", cmd, cmd);
 		}
 	}
 
@@ -7140,6 +7155,7 @@
 	dir = vms->curdir;
 	curmsg = vms->curmsg;
 
+	ast_test_suite_event_notify("FORWARD", "Message: entering forward message menu");
 	while (!res && !valid_extensions) {
 		int use_directory = 0;
 		if (ast_test_flag((&globalflags), VM_DIRECFORWARD)) {
@@ -7165,15 +7181,17 @@
 				default: 
 					/* Press 1 to enter an extension press 2 to use the directory */
 					cmd = ast_play_and_wait(chan, "vm-forward");
-					if (!cmd)
+					if (!cmd) {
 						cmd = ast_waitfordigit(chan, 3000);
-					if (!cmd)
+					}
+					if (!cmd) {
 						retries++;
+					}
 					if (retries > 3) {
 						cmd = 't';
 						done = 1;
 					}
-					
+					ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", cmd, cmd);
 				}
 			}
 			if (cmd < 0 || cmd == 't')
@@ -7212,6 +7230,7 @@
 			}
 		} else {
 			/* Ask for an extension */
+			ast_test_suite_event_notify("PLAYBACK", "Message: vm-extension");
 			res = ast_streamfile(chan, "vm-extension", chan->language);	/* "extension" */
 			prompt_played++;
 			if (res || prompt_played > 4)
@@ -7418,6 +7437,7 @@
 
 static int wait_file(struct ast_channel *chan, struct vm_state *vms, char *file) 
 {
+	ast_test_suite_event_notify("PLAYVOICE", "Message: Playing %s", file);
 	return ast_control_streamfile(chan, file, listen_control_forward_key, listen_control_reverse_key, listen_control_stop_key, listen_control_pause_key, listen_control_restart_key, skipms, NULL);
 }
 
@@ -7635,10 +7655,11 @@
 	vms->starting = 0;
 	make_file(vms->fn, sizeof(vms->fn), vms->curdir, vms->curmsg);
 	adsi_message(chan, vms);
-	if (!vms->curmsg)
+	if (!vms->curmsg) {
 		res = wait_file2(chan, vms, "vm-first");	/* "First" */
-	else if (vms->curmsg == vms->lastmsg)
+	} else if (vms->curmsg == vms->lastmsg) {
 		res = wait_file2(chan, vms, "vm-last");		/* "last" */
+	}
 
 	snprintf(filename, sizeof(filename), "%s.txt", vms->fn);
 	RETRIEVE(vms->curdir, vms->curmsg, vmu->mailbox, vmu->context);
@@ -7714,6 +7735,7 @@
 			}
 			if (vms->curmsg && (vms->curmsg != vms->lastmsg)) {
 				if (!res) {
+					ast_test_suite_event_notify("PLAYBACK", "Message: message number");
 					res = ast_say_number(chan, vms->curmsg + 1, AST_DIGIT_ANY, chan->language, NULL);
 				}
 			}
@@ -7742,15 +7764,20 @@
 	if (!res) {
 		res = play_message_category(chan, category);
 	}
-	if ((!res) && (ast_test_flag(vmu, VM_ENVELOPE)))
+	if ((!res) && (ast_test_flag(vmu, VM_ENVELOPE))) {
 		res = play_message_datetime(chan, vmu, origtime, filename);
-	if ((!res) && (ast_test_flag(vmu, VM_SAYCID)))
+	}
+	if ((!res) && (ast_test_flag(vmu, VM_SAYCID))) {
 		res = play_message_callerid(chan, vms, cid, context, 0);
-	if ((!res) && (ast_test_flag(vmu, VM_SAYDURATION)))
+	}
+	if ((!res) && (ast_test_flag(vmu, VM_SAYDURATION))) {
 		res = play_message_duration(chan, vms, duration, vmu->saydurationm);
+	}
 	/* Allow pressing '1' to skip envelope / callerid */
-	if (res == '1')
+	if (res == '1') {
+		ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", res, res);
 		res = 0;
+	}
 	ast_config_destroy(msg_cfg);
 
 	if (!res) {
@@ -7768,6 +7795,7 @@
 			ast_log(AST_LOG_WARNING, "Playback of message %s failed\n", vms->fn);
 			res = 0;
 		}
+		ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", res, res);
 	}
 	DISPOSE(vms->curdir, vms->curmsg);
 	return res;
@@ -9153,6 +9181,7 @@
 	unsigned char buf[256];
 	int bytes = 0;
 
+	ast_test_suite_event_notify("NEWUSER", "Message: entering new user state");
 	if (ast_adsi_available(chan)) {
 		bytes += adsi_logo(buf + bytes);
 		bytes += ast_adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, "New User Setup", "");
@@ -9248,6 +9277,7 @@
 	unsigned char buf[256];
 	int bytes = 0;
 
+	ast_test_suite_event_notify("VMOPTIONS", "Message: entering mailbox options");
 	if (ast_adsi_available(chan)) {
 		bytes += adsi_logo(buf + bytes);
 		bytes += ast_adsi_display(buf + bytes, ADSI_COMM_PAGE, 3, ADSI_JUST_CENT, 0, "Options Menu", "");
@@ -9320,10 +9350,13 @@
 				}
 				break;
 			}
-			if (pwdchange & PWDCHANGE_INTERNAL)
+
+			if (pwdchange & PWDCHANGE_INTERNAL) {
 				vm_change_password(vmu, newpassword);
-			if ((pwdchange & PWDCHANGE_EXTERNAL) && !ast_strlen_zero(ext_pass_cmd))
+			}
+			if ((pwdchange & PWDCHANGE_EXTERNAL) && !ast_strlen_zero(ext_pass_cmd)) {
 				vm_change_password_shell(vmu, newpassword);
+			}
 
 			ast_debug(1, "User %s set password to %s of length %d\n",
 				vms->username, newpassword, (int) strlen(newpassword));
@@ -9352,6 +9385,7 @@
 			if (retries > 3) {
 				cmd = 't';
 			}
+			ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", cmd, cmd);
 		}
 	}
 	if (cmd == 't')
@@ -9393,6 +9427,7 @@
 		ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
 	}
 
+	ast_test_suite_event_notify("TEMPGREETING", "Message: entering temp greeting options");
 	snprintf(prefile, sizeof(prefile), "%s%s/%s/temp", VM_SPOOL_DIR, vmu->context, vms->username);
 	while ((cmd >= 0) && (cmd != 't')) {
 		if (cmd)
@@ -9418,12 +9453,16 @@
 				cmd = ast_play_and_wait(chan,
 					ast_fileexists(prefile, NULL, NULL) > 0 ? /* XXX always true ? */
 						"vm-tempgreeting2" : "vm-tempgreeting");
-				if (!cmd)
+				if (!cmd) {
 					cmd = ast_waitfordigit(chan, 6000);
-				if (!cmd)
+				}
+				if (!cmd) {
 					retries++;
-				if (retries > 3)
+				}
+				if (retries > 3) {
 					cmd = 't';
+				}
+				ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", cmd, cmd);
 			}
 		}
 		DISPOSE(prefile, -1);
@@ -9687,13 +9726,14 @@
 	adsi_begin(chan, &useadsi);
 	if (!skipuser && useadsi)
 		adsi_login(chan);
+	ast_test_suite_event_notify("PLAYBACK", "Message: vm-login");
 	if (!silent && !skipuser && ast_streamfile(chan, "vm-login", chan->language)) {
 		ast_log(AST_LOG_WARNING, "Couldn't stream login file\n");
 		return -1;
 	}
-	
+
 	/* Authenticate them and get their mailbox/password */
-	
+
 	while (!valid && (logretries < max_logins)) {
 		/* Prompt for, and read in the username */
 		if (!skipuser && ast_readstring(chan, mailbox, mailbox_size - 1, 2000, 10000, "#") < 0) {
@@ -9734,6 +9774,7 @@
 			/* saved password is blank, so don't bother asking */
 			password[0] = '\0';
 		} else {
+			ast_test_suite_event_notify("PLAYBACK", "Message: %s", vm_password);
 			if (ast_streamfile(chan, vm_password, chan->language)) {
 				ast_log(AST_LOG_WARNING, "Unable to stream password file\n");
 				return -1;
@@ -9770,11 +9811,13 @@
 		logretries++;
 		if (!valid) {
 			if (skipuser || logretries >= max_logins) {
+				ast_test_suite_event_notify("PLAYBACK", "Message: vm-incorrect");
 				if (ast_streamfile(chan, "vm-incorrect", chan->language)) {
 					ast_log(AST_LOG_WARNING, "Unable to stream incorrect message\n");
 					return -1;
 				}
 			} else {
+				ast_test_suite_event_notify("PLAYBACK", "Message: vm-incorrect-mailbox");
 				if (useadsi)
 					adsi_login(chan);
 				if (ast_streamfile(chan, "vm-incorrect-mailbox", chan->language)) {
@@ -9830,6 +9873,7 @@
 
 	memset(&vmus, 0, sizeof(vmus));
 
+	ast_test_suite_event_notify("START", "Message: vm_execmain started");
 	if (chan->_state != AST_STATE_UP) {
 		ast_debug(1, "Before ast_answer\n");
 		ast_answer(chan);
@@ -9924,6 +9968,7 @@
 
 		/* user entered '*' */
 		if (!ast_goto_if_exists(chan, chan->context, "a", 1)) {
+			ast_test_suite_event_notify("REDIRECT", "Message: redirecting user to 'a' extension");
 			res = 0;	/* prevent hangup */
 			goto out;
 		}
@@ -9940,9 +9985,11 @@
 	/* If ADSI is supported, setup login screen */
 	adsi_begin(chan, &useadsi);
 
+	ast_test_suite_assert(valid);
 	if (!valid) {
 		goto out;
 	}
+	ast_test_suite_event_notify("AUTHENTICATED", "Message: vm_user authenticated");
 
 #ifdef IMAP_STORAGE
 	pthread_once(&ts_vmstate.once, ts_vmstate.key_init);
@@ -9994,6 +10041,7 @@
 
 	/* Select proper mailbox FIRST!! */
 	if (play_auto) {
+		ast_test_suite_event_notify("AUTOPLAY", "Message: auto-playing messages");
 		if (vms.urgentmessages) {
 			in_urgent = 1;
 			res = open_mailbox(&vms, vmu, 11);
@@ -10040,10 +10088,12 @@
 		cmd = vm_newuser(chan, vmu, &vms, vmfmts, record_gain);
 		if ((cmd == 't') || (cmd == '#')) {
 			/* Timeout */
+			ast_test_suite_event_notify("TIMEOUT", "Message: response from user timed out");
 			res = 0;
 			goto out;
 		} else if (cmd < 0) {
 			/* Hangup */
+			ast_test_suite_event_notify("HANGUP", "Message: hangup detected");
 			res = -1;
 			goto out;
 		}
@@ -10060,11 +10110,14 @@
 			cmd = ast_play_and_wait(chan, "vm-mailboxfull");
 		}
 #endif
+
+	ast_test_suite_event_notify("INTRO", "playing intro menu");
 	if (play_auto) {
 		cmd = '1';
 	} else {
 		cmd = vm_intro(chan, vmu, &vms);
 	}
+	ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", cmd, cmd);
 
 	vms.repeats = 0;
 	vms.starting = 1;
@@ -10075,12 +10128,16 @@
 			vms.curmsg = 0;
 			/* Fall through */
 		case '5': /* Play current message */
+			ast_test_suite_event_notify("BROWSE", "Message: browsing message %d\r\nVoicemail: %d", vms.curmsg, vms.curmsg);
 			cmd = vm_browse_messages(chan, &vms, vmu);
 			break;
 		case '2': /* Change folders */
+			ast_test_suite_event_notify("CHANGEFOLDER", "Message: browsing to a different folder");
 			if (useadsi)
 				adsi_folders(chan, 0, "Change to folder...");
+
 			cmd = get_folder2(chan, "vm-changeto", 0);
+			ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", cmd, cmd);
 			if (cmd == '#') {
 				cmd = 0;
 			} else if (cmd > 0) {
@@ -10098,13 +10155,15 @@
 			}
 			if (useadsi)
 				adsi_status2(chan, &vms);
-				
-			if (!cmd)
+
+			if (!cmd) {
 				cmd = vm_play_folder_name(chan, vms.vmbox);
+			}
 
 			vms.starting = 1;
 			break;
 		case '3': /* Advanced options */
+			ast_test_suite_event_notify("ADVOPTIONS", "Message: entering advanced options menu");
 			cmd = 0;
 			vms.repeats = 0;
 			while ((cmd > -1) && (cmd != 't') && (cmd != '#')) {
@@ -10116,8 +10175,9 @@
 							res = cmd;
 							goto out;
 						}
-					} else
+					} else {
 						cmd = ast_play_and_wait(chan, "vm-sorry");
+					}
 					cmd = 't';
 					break;
 				case '2': /* Callback */
@@ -10132,8 +10192,9 @@
 							res = cmd;
 							goto out;
 						}
-					} else 
+					} else {
 						cmd = ast_play_and_wait(chan, "vm-sorry");
+					}
 					cmd = 't';
 					break;
 				case '3': /* Envelope */
@@ -10143,8 +10204,9 @@
 							res = cmd;
 							goto out;
 						}
-					} else
+					} else {
 						cmd = ast_play_and_wait(chan, "vm-sorry");
+					}
 					cmd = 't';
 					break;
 				case '4': /* Dialout */
@@ -10154,8 +10216,9 @@
 							silentexit = 1;
 							goto out;
 						}
-					} else 
+					} else {
 						cmd = ast_play_and_wait(chan, "vm-sorry");
+					}
 					cmd = 't';
 					break;
 
@@ -10166,11 +10229,12 @@
 							res = cmd;
 							goto out;
 						}
-					} else
+					} else {
 						cmd = ast_play_and_wait(chan, "vm-sorry");
+					}
 					cmd = 't';
 					break;
-					
+
 				case '*': /* Return to main menu */
 					cmd = 't';
 					break;
@@ -10189,16 +10253,22 @@
 					if (!ast_strlen_zero(vmu->dialout) && !cmd) {
 						cmd = ast_play_and_wait(chan, "vm-tomakecall");
 					}
-					if (ast_test_flag(vmu, VM_SVMAIL) && !cmd)
+					if (ast_test_flag(vmu, VM_SVMAIL) && !cmd) {
 						cmd = ast_play_and_wait(chan, "vm-leavemsg");
-					if (!cmd)
+					}
+					if (!cmd) {
 						cmd = ast_play_and_wait(chan, "vm-starmain");
-					if (!cmd)
+					}
+					if (!cmd) {
 						cmd = ast_waitfordigit(chan, 6000);
-					if (!cmd)
+					}
+					if (!cmd) {
 						vms.repeats++;
-					if (vms.repeats > 3)
+					}
+					if (vms.repeats > 3) {
 						cmd = 't';
+					}
+					ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", cmd, cmd);
 				}
 			}
 			if (cmd == 't') {
@@ -10207,6 +10277,7 @@
 			}
 			break;
 		case '4': /* Go to the previous message */
+			ast_test_suite_event_notify("PREVMSG", "Message: browsing message %d\r\nVoicemail: %d", vms.curmsg - 1, vms.curmsg - 1);
 			if (vms.curmsg > 0) {
 				vms.curmsg--;
 				cmd = play_message(chan, vmu, &vms);
@@ -10226,8 +10297,9 @@
 						goto out;
 					ast_debug(1, "No more new messages, opened INBOX and got %d Urgent messages\n", vms.lastmsg + 1);
 					vms.curmsg = vms.lastmsg;
-					if (vms.lastmsg < 0)
+					if (vms.lastmsg < 0) {
 						cmd = ast_play_and_wait(chan, "vm-nomore");
+					}
 				} else if (ast_test_flag(vmu, VM_MESSAGEWRAP) && vms.lastmsg > 0) {
 					vms.curmsg = vms.lastmsg;
 					cmd = play_message(chan, vmu, &vms);
@@ -10237,6 +10309,7 @@
 			}
 			break;
 		case '6': /* Go to the next message */
+			ast_test_suite_event_notify("PREVMSG", "Message: browsing message %d\r\nVoicemail: %d", vms.curmsg + 1, vms.curmsg + 1);
 			if (vms.curmsg < vms.lastmsg) {
 				vms.curmsg++;
 				cmd = play_message(chan, vmu, &vms);
@@ -10317,8 +10390,9 @@
 								goto out;
 							ast_debug(1, "No more urgent messages, opened INBOX and got %d new messages\n", vms.lastmsg + 1);
 							vms.curmsg = -1;
-							if (vms.lastmsg < 0)
+							if (vms.lastmsg < 0) {
 								cmd = ast_play_and_wait(chan, "vm-nomore");
+							}
 						} else {
 							cmd = ast_play_and_wait(chan, "vm-nomore");
 						}
@@ -10354,14 +10428,16 @@
 						goto out;
 					ast_debug(1, "No more urgent messages, opened INBOX and got %d new messages\n", vms.lastmsg + 1);
 					vms.curmsg = -1;
-					if (vms.lastmsg < 0)
+					if (vms.lastmsg < 0) {
 						cmd = ast_play_and_wait(chan, "vm-nomore");
+					}
 				} else {
 					cmd = ast_play_and_wait(chan, "vm-nomore");
 				}
 			}
 			break;
 		case '9': /* Save message to folder */
+			ast_test_suite_event_notify("SAVEMSG", "Message: saving message %d\r\nVoicemail: %d", vms.curmsg, vms.curmsg);
 			if (vms.curmsg < 0 || vms.curmsg > vms.lastmsg) {
 				/* No message selected */
 				cmd = 0;
@@ -10370,6 +10446,7 @@
 			if (useadsi)
 				adsi_folders(chan, 1, "Save to folder...");
 			cmd = get_folder2(chan, "vm-savefolder", 1);
+			ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", cmd, cmd);
 			box = 0;	/* Shut up compiler */
 			if (cmd == '#') {
 				cmd = 0;
@@ -10427,8 +10504,9 @@
 							goto out;
 						ast_debug(1, "No more urgent messages, opened INBOX and got %d new messages\n", vms.lastmsg + 1);
 						vms.curmsg = -1;
-						if (vms.lastmsg < 0)
+						if (vms.lastmsg < 0) {
 							cmd = ast_play_and_wait(chan, "vm-nomore");
+						}
 					} else {
 						cmd = ast_play_and_wait(chan, "vm-nomore");
 					}
@@ -10456,6 +10534,7 @@
 				adsi_status(chan, &vms);
 			break;
 		default:	/* Nothing */
+			ast_test_suite_event_notify("PLAYBACK", "Message: instructions");
 			cmd = vm_instructions(chan, vmu, &vms, 0, in_urgent);
 			break;
 		}
@@ -12942,6 +13021,7 @@
 				else
 					cmd = 't';
 			}
+			ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", cmd, cmd);
 		}
 		if (retries >= 3) {
 			return 0;
@@ -13094,15 +13174,19 @@
 							res = ast_play_and_wait(chan, "vm-toenternumber");
 					}
 				}
-				if (!res)
+				if (!res) {
 					res = ast_play_and_wait(chan, "vm-star-cancel");
-				if (!res)
+				}
+				if (!res) {
 					res = ast_waitfordigit(chan, 6000);
+				}
 				if (!res) {
 					retries++;
-					if (retries > 3)
+					if (retries > 3) {
 						res = 't';
+					}
 				}
+				ast_test_suite_event_notify("USERPRESS", "Message: User pressed %c\r\nDTMF: %c", res, res);
 				break; 
 				
 			}

Modified: branches/1.8/configs/manager.conf.sample
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/configs/manager.conf.sample?view=diff&rev=332817&r1=332816&r2=332817
==============================================================================
--- branches/1.8/configs/manager.conf.sample (original)
+++ branches/1.8/configs/manager.conf.sample Mon Aug 22 13:15:51 2011
@@ -138,6 +138,9 @@
 ; cc        - Call Completion events.  Read-only.
 ; aoc       - Permission to send Advice Of Charge messages and receive Advice
 ;           - Of Charge events.
+; test      - Ability to read TestEvent notifications sent to the Asterisk Test
+;             Suite.  Note that this is only enabled when the TEST_FRAMEWORK
+;             compiler flag is defined.
 ;
 ;read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
 ;write = system,call,agent,user,config,command,reporting,originate

Modified: branches/1.8/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/include/asterisk/manager.h?view=diff&rev=332817&r1=332816&r2=332817
==============================================================================
--- branches/1.8/include/asterisk/manager.h (original)
+++ branches/1.8/include/asterisk/manager.h Mon Aug 22 13:15:51 2011
@@ -84,6 +84,7 @@
 #define EVENT_FLAG_HOOKRESPONSE		(1 << 14) /* Hook Response */
 #define EVENT_FLAG_CC			(1 << 15) /* Call Completion events */
 #define EVENT_FLAG_AOC			(1 << 16) /* Advice Of Charge events */
+#define EVENT_FLAG_TEST			(1 << 17) /* Test event used to signal the Asterisk Test Suite */
 /*@} */
 
 /*! \brief Export manager structures */

Modified: branches/1.8/include/asterisk/test.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/include/asterisk/test.h?view=diff&rev=332817&r1=332816&r2=332817
==============================================================================
--- branches/1.8/include/asterisk/test.h (original)
+++ branches/1.8/include/asterisk/test.h Mon Aug 22 13:15:51 2011
@@ -130,6 +130,62 @@
 
 #endif
 
+/*! Macros used for the Asterisk Test Suite AMI events */
+#ifdef TEST_FRAMEWORK
+
+/*!
+ * \brief Notifies the test suite of a change in application state
+ *
+ * \details
+ * Raises a TestEvent manager event with a subtype of StateChange.  Additional parameters
+ * The fmt parameter allows additional parameters to be added to the manager event using
+ * printf style statement formatting.
+ *
+ * \param state		The state the application has changed to
+ * \param fmt		The message with format parameters to add to the manager event
+ *
+ * \returns 0 on success
+ * \returns any other value on failure
+ */
+int __ast_test_suite_event_notify(const char *file, const char *func, int line,
+		const char *state, const char *fmt, ...)
+		__attribute__((format(printf, 5, 6)));
+
+/*!
+ * \brief Notifies the test suite of a failed assert on an expression
+ *
+ * \details
+ * If the expression provided evaluates to true, no action is taken.  If the expression
+ * evaluates to a false, a TestEvent manager event is raised with a subtype of Assert, notifying
+ * the test suite that the expression failed to evaluate to true.
+ *
+ * \param exp	The expression to evaluate
+ *
+ * \returns 0 on success
+ * \returns any other value on failure
+ */
+int __ast_test_suite_assert_notify(const char *file, const char *func, int line,
+		const char *exp);
+
+/*!
+ * \ref __ast_test_suite_event_notify()
+ */
+#define ast_test_suite_event_notify(s, f, ...) \
+	__ast_test_suite_event_notify(__FILE__, __PRETTY_FUNCTION__, __LINE__, (s), (f), ## __VA_ARGS__)
+
+/*!
+ * \ref __ast_test_suite_assert_notify()
+ */
+#define ast_test_suite_assert(exp) \
+	( (exp) ? (void)0 : __ast_test_suite_assert_notify(__FILE__, __PRETTY_FUNCTION__, __LINE__, #exp))
+
+#else
+
+#define ast_test_suite_event_notify(s, f, ...) (void)0;
+#define ast_test_suite_assert(exp) (void)0;
+
+#endif
+
 enum ast_test_result_state {
 	AST_TEST_NOT_RUN,
 	AST_TEST_PASS,

Modified: branches/1.8/main/app.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/app.c?view=diff&rev=332817&r1=332816&r2=332817
==============================================================================
--- branches/1.8/main/app.c (original)
+++ branches/1.8/main/app.c Mon Aug 22 13:15:51 2011
@@ -54,6 +54,7 @@
 #include "asterisk/indications.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/threadstorage.h"
+#include "asterisk/test.h"
 
 AST_THREADSTORAGE_PUBLIC(ast_str_thread_global_buf);
 
@@ -697,6 +698,7 @@
 {
 	int d = 0;
 
+	ast_test_suite_event_notify("PLAYBACK", "Message: %s", fn);
 	if ((d = ast_streamfile(chan, fn, chan->language))) {
 		return d;
 	}

Modified: branches/1.8/main/file.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/file.c?view=diff&rev=332817&r1=332816&r2=332817
==============================================================================
--- branches/1.8/main/file.c (original)
+++ branches/1.8/main/file.c Mon Aug 22 13:15:51 2011
@@ -1356,6 +1356,7 @@
 {
 	int res = 0;
 	if (!ast_strlen_zero(file)) {
+		ast_test_suite_event_notify("PLAYBACK", "Message: %s", file);
 		res = ast_streamfile(chan, file, chan->language);
 		if (!res) {
 			res = ast_waitstream(chan, digits);

Modified: branches/1.8/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/manager.c?view=diff&rev=332817&r1=332816&r2=332817
==============================================================================
--- branches/1.8/main/manager.c (original)
+++ branches/1.8/main/manager.c Mon Aug 22 13:15:51 2011
@@ -1136,6 +1136,7 @@
 	{ EVENT_FLAG_AGI, "agi" },
 	{ EVENT_FLAG_CC, "cc" },
 	{ EVENT_FLAG_AOC, "aoc" },
+	{ EVENT_FLAG_TEST, "test" },
 	{ INT_MAX, "all" },
 	{ 0, "none" },
 };

Modified: branches/1.8/main/test.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/test.c?view=diff&rev=332817&r1=332816&r2=332817
==============================================================================
--- branches/1.8/main/test.c (original)
+++ branches/1.8/main/test.c Mon Aug 22 13:15:51 2011
@@ -41,6 +41,7 @@
 #include "asterisk/version.h"
 #include "asterisk/paths.h"
 #include "asterisk/time.h"
+#include "asterisk/manager.h"
 
 /*! This array corresponds to the values defined in the ast_test_state enum */
 static const char * const test_result2str[] = {
@@ -884,6 +885,48 @@
 	AST_CLI_DEFINE(test_cli_show_results,              "show last test results"),
 	AST_CLI_DEFINE(test_cli_generate_results,          "generate test results to file"),
 };
+
+int __ast_test_suite_event_notify(const char *file, const char *func, int line,
+		const char *state, const char *fmt, ...)
+{
+	struct ast_str *buf = NULL;
+	va_list ap;
+
+	if (!(buf = ast_str_create(128))) {
+		return -1;
+	}
+
+	va_start(ap, fmt);
+	ast_str_set_va(&buf, 0, fmt, ap);
+	va_end(ap);
+
+	manager_event(EVENT_FLAG_TEST, "TestEvent",
+		"Type: StateChange\r\n"
+		"State: %s\r\n"
+		"AppFile: %s\r\n"
+		"AppFunction: %s\r\n"
+		"AppLine: %d\r\n%s\r\n",
+		state, file, func, line, ast_str_buffer(buf));
+
+	ast_free(buf);
+
+	return 0;
+}
+
+int __ast_test_suite_assert_notify(const char *file, const char *func, int line,
+		const char *exp)
+{
+	manager_event(EVENT_FLAG_TEST, "TestEvent",
+		"Type: Assert\r\n"
+		"AppFile: %s\r\n"
+		"AppFunction: %s\r\n"
+		"AppLine: %d\r\n"
+		"Expression: %s\r\n",
+		file, func, line, exp);
+
+	return 0;
+}
+
 #endif /* TEST_FRAMEWORK */
 
 int ast_test_init()




More information about the asterisk-commits mailing list