File: 13-pipely-twoway.t

package info (click to toggle)
libio-pipely-perl 0.006-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 188 kB
  • sloc: perl: 698; makefile: 2
file content (80 lines) | stat: -rw-r--r-- 1,988 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl -w
# vim: ts=2 sw=2 filetype=perl expandtab

use strict;

use Test::More tests => 7;

BEGIN { use_ok 'IO::Pipely', 'socketpairly' };

### Test two-way pipe.
SKIP: {
  my ($a_rd, $a_wr, $b_rd, $b_wr) = socketpairly(type => 'pipe');

  skip "$^O does not support two-way pipe()", 2
    unless defined $a_rd and defined $a_wr and defined $b_rd and defined $b_wr;

  print $a_wr "a wr inet\n";
  my $b_input = <$b_rd>; chomp $b_input;
  ok(
    $b_input eq 'a wr inet',
    "two-way pipe passed data from a -> b unscathed"
  );

  print $b_wr "b wr inet\n";
  my $a_input = <$a_rd>; chomp $a_input;
  ok(
    $a_input eq 'b wr inet',
    "two-way pipe passed data from b -> a unscathed"
  );
}

### Test two-way socketpair.
SKIP: {
  my ($a_rd, $a_wr, $b_rd, $b_wr) = socketpairly(type => 'socketpair');

  skip "$^O does not support two-way socketpair", 2
    unless defined $a_rd and defined $a_wr and defined $b_rd and defined $b_wr;

  print $a_wr "a wr inet\n";
  my $b_input = <$b_rd>; chomp $b_input;
  ok(
    $b_input eq 'a wr inet',
    "two-way socketpair passed data from a -> b unscathed"
  );

  print $b_wr "b wr inet\n";
  my $a_input = <$a_rd>; chomp $a_input;
  ok(
    $a_input eq 'b wr inet',
    "two-way socketpair passed data from b -> a unscathed"
  );
}

### Test two-way inet sockets.
SKIP: {
  unless ($ENV{RUN_NETWORK_TESTS}) {
    skip 'RUN_NETWORK_TESTS environment variable is not true.', 2;
  }

  my ($a_rd, $a_wr, $b_rd, $b_wr) = socketpairly(type => 'inet');

  skip "$^O does not support two-way inet pipes", 2
    unless defined $a_rd and defined $a_wr and defined $b_rd and defined $b_wr;

  print $a_wr "a wr inet\n";
  my $b_input = <$b_rd>; chomp $b_input;
  ok(
    $b_input eq 'a wr inet',
    "two-way inet pipe passed data from a -> b unscathed"
  );

  print $b_wr "b wr inet\n";
  my $a_input = <$a_rd>; chomp $a_input;
  ok(
    $a_input eq 'b wr inet',
    "two-way inet pipe passed data from b -> a unscathed"
  );
}

exit 0;