Re: Inline PI function
[p5sagit/p5-mst-13.2.git] / t / lib / io_sel.t
CommitLineData
7a4c00b4 1#!./perl
2
3BEGIN {
4 unless(grep /blib/, @INC) {
5 chdir 't' if -d 't';
6 @INC = '../lib' if -d '../lib';
7 }
8}
9
10select(STDERR); $| = 1;
11select(STDOUT); $| = 1;
12
13print "1..21\n";
14
15use IO::Select 1.09;
16
17my $sel = new IO::Select(\*STDIN);
18$sel->add(4, 5) == 2 or print "not ";
19print "ok 1\n";
20
21$sel->add([\*STDOUT, 'foo']) == 1 or print "not ";
22print "ok 2\n";
23
24@handles = $sel->handles;
25print "not " unless $sel->count == 4 && @handles == 4;
26print "ok 3\n";
27#print $sel->as_string, "\n";
28
29$sel->remove(\*STDIN) == 1 or print "not ";
30print "ok 4\n",
31;
32$sel->remove(\*STDIN, 5, 6) == 1 # two of there are not present
33 or print "not ";
34print "ok 5\n";
35
36print "not " unless $sel->count == 2;
37print "ok 6\n";
38#print $sel->as_string, "\n";
39
40$sel->remove(1, 4);
41print "not " unless $sel->count == 0 && !defined($sel->bits);
42print "ok 7\n";
43
44$sel = new IO::Select;
45print "not " unless $sel->count == 0 && !defined($sel->bits);
46print "ok 8\n";
47
48$sel->remove([\*STDOUT, 5]);
49print "not " unless $sel->count == 0 && !defined($sel->bits);
50print "ok 9\n";
51
52@a = $sel->can_read(); # should return imediately
53print "not " unless @a == 0;
54print "ok 10\n";
55
56# we assume that we can write to STDOUT :-)
57$sel->add([\*STDOUT, "ok 12\n"]);
58
59@a = $sel->can_write;
60print "not " unless @a == 1;
61print "ok 11\n";
62
63my($fd, $msg) = @{shift @a};
64print $fd $msg;
65
66$sel->add(\*STDOUT); # update
67
68@a = IO::Select::select(undef, $sel, undef, 1);
69print "not " unless @a == 3;
70print "ok 13\n";
71
72($r, $w, $e) = @a;
73
74print "not " unless @$r == 0 && @$w == 1 && @$e == 0;
75print "ok 14\n";
76
77$fd = $w->[0];
78print $fd "ok 15\n";
79
80# Test new exists() method
81$sel->exists(\*STDIN) and print "not ";
82print "ok 16\n";
83
84($sel->exists(0) || $sel->exists([\*STDERR])) and print "not ";
85print "ok 17\n";
86
87$fd = $sel->exists(\*STDOUT);
88if ($fd) {
89 print $fd "ok 18\n";
90} else {
91 print "not ok 18\n";
92}
93
94$fd = $sel->exists([1, 'foo']);
95if ($fd) {
96 print $fd "ok 19\n";
97} else {
98 print "not ok 19\n";
99}
100
101# Try self clearing
102$sel->add(5,6,7,8,9,10);
103print "not " unless $sel->count == 7;
104print "ok 20\n";
105
106$sel->remove($sel->handles);
107print "not " unless $sel->count == 0 && !defined($sel->bits);
108print "ok 21\n";