]> git.vpit.fr Git - perl/modules/IPC-MorseSignals.git/blobdiff - t/10-base.t
Importing IPC-MorseSignals-0.04.tar.gz
[perl/modules/IPC-MorseSignals.git] / t / 10-base.t
index bc55f14925352c77776be4f52e7d44f913e7af7d..3eb877ccc3be3ae25638e2c35b135f18f5969e1d 100644 (file)
@@ -1,8 +1,8 @@
 #!perl -T
 
-use Test::More tests => 7 * 5;
+use Test::More tests => 4 * 5;
 
-use POSIX qw/SIGINT SIGTERM SIGKILL EXIT_SUCCESS/;
+use POSIX qw/SIGINT SIGTERM SIGKILL EXIT_SUCCESS EXIT_FAILURE WIFEXITED WEXITSTATUS/;
 
 use IPC::MorseSignals qw/msend mrecv/;
 
@@ -13,51 +13,37 @@ sub trysend {
 SPEED:
  while (($speed > 1) && !$ok) {
   $speed /= 2;
-  pipe my $rdr, my $wtr or die "$desc: pipe() failed : $!";
   my $pid = fork;
   if (!defined $pid) {
    die "$desc: fork() failed : $!";
   } elsif ($pid == 0) {
-   close $rdr;
    local @SIG{qw/USR1 USR2/} = mrecv sub {
-    print $wtr $_[0], "\n";
-    close $wtr;
-    exit EXIT_SUCCESS;
+    exit(($msg eq $_[0]) ? EXIT_SUCCESS : EXIT_FAILURE);
    };
    1 while 1;
+   exit EXIT_FAILURE;
   }
-  close $wtr or die "$desc: close() failed : $!";
   eval {
    local $SIG{ALRM} = sub { die 'timeout' };
    my $a = (int(100 * (3 * length $msg) / $speed) || 1);
    $a = 10 if $a > 10;
    alarm $a;
-   msend $msg => $pid, $speed;
+   msend $msg => $pid, speed => $speed;
    waitpid $pid, 0;
+   $ok = (WIFEXITED($?) && (WEXITSTATUS($?) == EXIT_SUCCESS));
   };
   alarm 0;
   if ($@) {
    kill SIGINT,  $pid;
    kill SIGTERM, $pid;
    kill SIGKILL, $pid;
-   close $rdr or die "$desc: close() failed : $!";
-   next SPEED;
   }
-  my $recv = do { local $/; <$rdr> };
-  close $rdr or die "$desc: close() failed : $!";
-  next SPEED unless $recv;
-  chomp $recv;
-  next SPEED unless $msg eq $recv;
-  $ok = 1;
  }
  ok($speed >= 1, $desc);
 }
 
 for (1 .. 5) {
  trysend 'hello', 'ascii';
- trysend 'éàùçà', 'extended';
- trysend '€€€', 'unicode';
- trysend 'a€bécàd€e', 'mixed';
  trysend "\0" x 10, 'few bits';
  trysend "\x{FF}" x 10, 'lots of bits';
  trysend "a\0b", 'null character';