fix various other problems found by gcc 4.3
[asterisk-bristuff.git] / agi / fastagi-test
blobd3f13cf6b0ac14a203d4f078c43369c2372fed38
1 #!/usr/bin/perl
2 use strict;
3 use Socket;
4 use Carp;
5 use IO::Handle;
7 my $port = 4573;
9 $|=1;
11 # Setup some variables
12 my %AGI; my $tests = 0; my $fail = 0; my $pass = 0;
14 sub checkresult {
15 my ($res) = @_;
16 my $retval;
17 $tests++;
18 chomp $res;
19 if ($res =~ /^200/) {
20 $res =~ /result=(-?\d+)/;
21 if (!length($1)) {
22 print STDERR "FAIL ($res)\n";
23 $fail++;
24 } else {
25 print STDERR "PASS ($1)\n";
26 $pass++;
28 } else {
29 print STDERR "FAIL (unexpected result '$res')\n";
30 $fail++;
34 socket(SERVER, PF_INET, SOCK_STREAM, 0);
35 setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, pack("l", 1));
36 bind(SERVER, sockaddr_in($port, INADDR_ANY)) || die("can't bind\n");
37 listen(SERVER, SOMAXCONN);
39 for(;;) {
40 my $raddr = accept(CLIENT, SERVER);
41 my ($s, $p) = sockaddr_in($raddr);
42 CLIENT->autoflush(1);
43 while(<CLIENT>) {
44 chomp;
45 last unless length($_);
46 if (/^agi_(\w+)\:\s+(.*)$/) {
47 $AGI{$1} = $2;
50 print STDERR "AGI Environment Dump from $s:$p --\n";
51 foreach my $i (sort keys %AGI) {
52 print STDERR " -- $i = $AGI{$i}\n";
55 print STDERR "1. Testing 'sendfile'...";
56 print CLIENT "STREAM FILE beep \"\"\n";
57 my $result = <CLIENT>;
58 &checkresult($result);
60 print STDERR "2. Testing 'sendtext'...";
61 print CLIENT "SEND TEXT \"hello world\"\n";
62 my $result = <CLIENT>;
63 &checkresult($result);
65 print STDERR "3. Testing 'sendimage'...";
66 print CLIENT "SEND IMAGE asterisk-image\n";
67 my $result = <CLIENT>;
68 &checkresult($result);
70 print STDERR "4. Testing 'saynumber'...";
71 print CLIENT "SAY NUMBER 192837465 \"\"\n";
72 my $result = <CLIENT>;
73 &checkresult($result);
75 print STDERR "5. Testing 'waitdtmf'...";
76 print CLIENT "WAIT FOR DIGIT 1000\n";
77 my $result = <CLIENT>;
78 &checkresult($result);
80 print STDERR "6. Testing 'record'...";
81 print CLIENT "RECORD FILE testagi gsm 1234 3000\n";
82 my $result = <CLIENT>;
83 &checkresult($result);
85 print STDERR "6a. Testing 'record' playback...";
86 print CLIENT "STREAM FILE testagi \"\"\n";
87 my $result = <CLIENT>;
88 &checkresult($result);
89 close(CLIENT);
90 print STDERR "================== Complete ======================\n";
91 print STDERR "$tests tests completed, $pass passed, $fail failed\n";
92 print STDERR "==================================================\n";