agi-test.agi 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/perl
  2. use strict;
  3. $|=1;
  4. # Setup some variables
  5. my %AGI; my $tests = 0; my $fail = 0; my $pass = 0;
  6. while(<STDIN>) {
  7. chomp;
  8. last unless length($_);
  9. if (/^agi_(\w+)\:\s+(.*)$/) {
  10. $AGI{$1} = $2;
  11. }
  12. }
  13. print STDERR "AGI Environment Dump:\n";
  14. foreach my $i (sort keys %AGI) {
  15. print STDERR " -- $i = $AGI{$i}\n";
  16. }
  17. sub checkresult {
  18. my ($res) = @_;
  19. my $retval;
  20. $tests++;
  21. chomp $res;
  22. if ($res =~ /^200/) {
  23. $res =~ /result=(-?\d+)/;
  24. if (!length($1)) {
  25. print STDERR "FAIL ($res)\n";
  26. $fail++;
  27. } else {
  28. print STDERR "PASS ($1)\n";
  29. $pass++;
  30. }
  31. } else {
  32. print STDERR "FAIL (unexpected result '$res')\n";
  33. $fail++;
  34. }
  35. }
  36. print STDERR "1. Testing 'sendfile'...";
  37. print "STREAM FILE beep \"\"\n";
  38. my $result = <STDIN>;
  39. &checkresult($result);
  40. print STDERR "2. Testing 'sendtext'...";
  41. print "SEND TEXT \"hello world\"\n";
  42. my $result = <STDIN>;
  43. &checkresult($result);
  44. print STDERR "3. Testing 'sendimage'...";
  45. print "SEND IMAGE asterisk-image\n";
  46. my $result = <STDIN>;
  47. &checkresult($result);
  48. print STDERR "4. Testing 'saynumber'...";
  49. print "SAY NUMBER 192837465 \"\"\n";
  50. my $result = <STDIN>;
  51. &checkresult($result);
  52. print STDERR "5. Testing 'waitdtmf'...";
  53. print "WAIT FOR DIGIT 1000\n";
  54. my $result = <STDIN>;
  55. &checkresult($result);
  56. print STDERR "6. Testing 'record'...";
  57. print "RECORD FILE testagi gsm 1234 3000\n";
  58. my $result = <STDIN>;
  59. &checkresult($result);
  60. print STDERR "6a. Testing 'record' playback...";
  61. print "STREAM FILE testagi \"\"\n";
  62. my $result = <STDIN>;
  63. &checkresult($result);
  64. print STDERR "================== Complete ======================\n";
  65. print STDERR "$tests tests completed, $pass passed, $fail failed\n";
  66. print STDERR "==================================================\n";