0.67.305
by Bernt M. Johnsen
Copyright headres and license added |
1 |
# Copyright (C) 2010 Sun Microsystems, Inc. All rights reserved. Use
|
2 |
# is subject to license terms.
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; version 2 of the License.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful, but
|
|
9 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
11 |
# General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
|
16 |
# USA
|
|
17 |
||
0.67.279
by Bernt M. Johnsen
Better IPC Pipe handling + Unit test |
18 |
# Do a simple run of scripts to see that they're sound
|
19 |
#
|
|
20 |
package IPC; |
|
21 |
use base qw(Test::Unit::TestCase); |
|
22 |
use lib 'lib'; |
|
23 |
use lib 'unit'; |
|
24 |
||
25 |
use Data::Dumper; |
|
26 |
||
27 |
use GenTest::IPC::Channel; |
|
28 |
use GenTest::IPC::Process; |
|
29 |
||
30 |
use IPC_P1; |
|
31 |
||
32 |
sub new { |
|
33 |
my $self = shift()->SUPER::new(@_); |
|
34 |
# your state for fixture here
|
|
35 |
return $self; |
|
36 |
}
|
|
37 |
||
38 |
my $generator; |
|
39 |
sub set_up { |
|
40 |
}
|
|
41 |
||
42 |
sub tear_down { |
|
43 |
# clean up after test
|
|
44 |
}
|
|
45 |
||
46 |
sub testChannel { |
|
47 |
my $self = shift; |
|
48 |
||
49 |
my $outgoing = GenTest::IPC::Channel->new(); |
|
50 |
$self->assert_not_null($outgoing); |
|
51 |
||
52 |
my $incoming = GenTest::IPC::Channel->new(); |
|
53 |
$self->assert_not_null($incoming); |
|
54 |
||
55 |
my $relay = IPC_P1->new($outgoing,$incoming); |
|
56 |
$self->assert_not_null($relay); |
|
57 |
||
0.67.285
by Bernt M. Johnsen
RQG-style constructors in Channel/Process/ErrorFilter |
58 |
my $relay_p = GenTest::IPC::Process->new(object=>$relay); |
0.67.279
by Bernt M. Johnsen
Better IPC Pipe handling + Unit test |
59 |
$self->assert_not_null($relay_p); |
60 |
||
0.67.283
by Bernt Johnsen
Test fork/process in combination |
61 |
if (fork()) { |
62 |
$relay_p->start(); |
|
63 |
} else { |
|
64 |
$incoming->close(); |
|
65 |
$outgoing->writer(); |
|
66 |
$outgoing->send(["foo","bar"]); |
|
67 |
$outgoing->close(); |
|
68 |
exit 0; |
|
69 |
}
|
|
0.67.279
by Bernt M. Johnsen
Better IPC Pipe handling + Unit test |
70 |
|
71 |
$outgoing->writer; |
|
72 |
$incoming->reader; |
|
73 |
||
74 |
$message = ['foo','bar']; |
|
75 |
||
76 |
$outgoing->send($message); |
|
77 |
$outgoing->send($message); |
|
78 |
||
79 |
$outgoing->close; |
|
80 |
||
0.67.283
by Bernt Johnsen
Test fork/process in combination |
81 |
my $n=0; |
0.67.279
by Bernt M. Johnsen
Better IPC Pipe handling + Unit test |
82 |
while ($incoming->more) { |
83 |
my $in_message = $incoming->recv; |
|
84 |
$self->assert_not_null($in_message); |
|
85 |
$self->assert_num_equals(1,$#{$in_message}); |
|
86 |
$self->assert_str_equals($message->[0],$in_message->[0]); |
|
87 |
$self->assert_str_equals($message->[1],$in_message->[1]); |
|
0.67.283
by Bernt Johnsen
Test fork/process in combination |
88 |
$n++; |
0.67.279
by Bernt M. Johnsen
Better IPC Pipe handling + Unit test |
89 |
}
|
90 |
||
0.67.283
by Bernt Johnsen
Test fork/process in combination |
91 |
$self->assert_num_equals(3,$n); |
92 |
||
0.67.279
by Bernt M. Johnsen
Better IPC Pipe handling + Unit test |
93 |
$incoming->close; |
94 |
}
|
|
95 |
||
96 |
||
97 |
1; |