]> git.vpit.fr Git - perl/modules/IPC-MorseSignals.git/blob - t/10-base.t
Importing IPC-MorseSignals-0.01.tar.gz
[perl/modules/IPC-MorseSignals.git] / t / 10-base.t
1 #!perl -T
2
3 use Test::More tests => 6;
4
5 use POSIX qw/SIGTERM SIGKILL EXIT_SUCCESS/;
6
7 use IPC::MorseSignals qw/msend mrecv/;
8
9 sub try2send {
10  my ($msg, $desc) = @_;
11  pipe $rdr, $wtr or die "pipe() failed : $!";
12  my $pid = fork;
13  if (!defined $pid) {
14   die "fork() failed : $!";
15  } elsif ($pid == 0) {
16   close $rdr;
17   local @SIG{qw/USR1 USR2/} = mrecv sub {
18    print $wtr $_[0], "\n";
19    exit EXIT_SUCCESS;
20   };
21   1 while 1;
22  }
23  close $wtr or die "close() failed : $!";
24  msend $msg => $pid, 100;
25  eval {
26   local $SIG{ALRM} = sub { die };
27   alarm 5;
28   waitpid $pid, 0;
29   alarm 0;
30  };
31  if ($@) {
32   kill SIGINT,  $pid;
33   kill SIGTERM, $pid;
34   kill SIGKILL, $pid;
35   die "$@ in $desc";
36  }
37  my $recv = do { local $/; <$rdr> };
38  close $rdr;
39  chomp $recv;
40  ok($msg eq $recv, $desc);
41 }
42
43 try2send 'hello', 'ascii';
44 try2send 'éàùçà', 'extended';
45 try2send '€€€', 'unicode';
46 try2send 'a€bécàd€e', 'mixed';
47 try2send "\x{FF}", 'lots of bits';
48 try2send "a\0b", 'null character';