Permalink
Browse files

[t/spec/S32-io] Add (fudged) tests for recv with a parameter

git-svn-id: http://svn.pugscode.org/pugs@28897 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent dde52a6 commit 12cdb6dd39a2cd568d6246b06a1e40e3055681cd carlin committed Oct 26, 2009
Showing with 55 additions and 1 deletion.
  1. +39 −0 S32-io/IO-Socket-INET.pl
  2. +16 −1 S32-io/IO-Socket-INET.t
View
@@ -82,6 +82,45 @@
$client.close();
}
}
+
+ when 4 { # test number 4 - recv with parameter
+ if $server_or_client eq 'server' {
+ my $server = IO::Socket::INET.socket(PF_INET, SOCK_STREAM, TCP);
+ $server.bind($host, $port.Int);
+ $server.listen();
+ my $fd = open( 't/spec/S32-io/server-ready-flag', :w );
+ $fd.close();
+ while my $client = $server.accept() {
+ my $received = $client.recv(); # receive everything
+ $client.send($received); # send it all back
+ $client.close();
+ }
+ }
+ else {
+ my $sock = IO::Socket::INET.new;
+ until 't/spec/S32-io/server-ready-flag' ~~ :e { sleep(1) }
+ $sock.open($host, $port.Int);
+ # Also sends two 3 byte unicode characters
+ $sock.send(([~] '0'..'9', 'a'..'z') ~ "{chr 0xbeef}{chr 0xbabe}");
+ # Tests that if we do not receive all the data available
+ # it is buffered correctly for when we do request it
+ say $sock.recv(7); # 0123456
+ say $sock.recv(3); # 789
+ say $sock.recv(26); # a-z
+ # All is left are the two 3 byte characters
+ my $beef = $sock.recv(3);
+ say $beef;
+ say $beef.bytes;
+ # get two bytes now
+ my $babe = $sock.recv(2);
+ say $babe.bytes;
+ # join it together
+ $babe ~= $sock.recv(1);
+ say $babe;
+ say $babe.bytes;
+ $sock.close();
+ }
+ }
}
=begin pod
View
@@ -1,7 +1,7 @@
use v6;
use Test;
-plan 3;
+plan 11;
# L<S32::IO/IO::Socket::INET>
@@ -63,6 +63,21 @@ if $*OS eq any <linux darwin> { # please add more valid OS names
#warn "TEST 3 $received";
$expected = "discard '' received\n";
is $received, $expected, "discard server and client";
+
+ #?rakudo 8 skip
+ # test 4 tests recv with a parameter
+ $received = qqx{sh t/spec/S32-io/IO-Socket-INET.sh 4 $port};
+ $expected = $received.split("\n");
+ my $i = 0;
+ is $expected[$i++], '0123456', 'received first 7 characters';
+ is $expected[$i++], '789', 'received next 3 characters';
+ is $expected[$i++], 'abcdefghijklmnopqrstuvwxyz', 'remaining 26 were buffered';
+ # Multibyte characters
+ is $expected[$i++], chr(0xbeef), "received {chr 0xbeef}";
+ is $expected[$i++], 3, '... which is 3 bytes';
+ is $expected[$i++], 2, 'received 2 bytes of a 3 byte unicode character';
+ is $expected[$i++], chr(0xbabe), "combined the bytes form {chr 0xbabe}";
+ is $expected[$i++], 3, '... which is 3 bytes';
}
else {
# eg Win32 shell script needs writing

0 comments on commit 12cdb6d

Please sign in to comment.