Debian Codegraph @

agi/agi-test.agi

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