Blame t/07io.t

Packit Service a45ac5
#!/usr/bin/perl
Packit Service f99136
Packit Service f99136
use Convert::ASN1 qw(:io);
Packit Service f99136
use IO::Socket;
Packit Service be69e4
use File::Temp ();
Packit Service f99136
Packit Service f99136
print "1..11\n";
Packit Service f99136
Packit Service f99136
my  $result = pack("C*", 0x30, 0x3D, 0x04, 0x04, 0x46, 0x72, 0x65, 0x64,
Packit Service f99136
			 0x30, 0x13, 0x04, 0x11, 0x41, 0x20, 0x73, 0x74,
Packit Service f99136
			 0x72, 0x69, 0x6E, 0x67, 0x20, 0x66, 0x6F, 0x72,
Packit Service f99136
			 0x20, 0x66, 0x72, 0x65, 0x64, 0x04, 0x03, 0x4A,
Packit Service f99136
			 0x6F, 0x65, 0x30, 0x1B, 0x04, 0x03, 0x68, 0x61,
Packit Service f99136
			 0x73, 0x04, 0x01, 0x61, 0x04, 0x04, 0x6C, 0x69,
Packit Service f99136
			 0x73, 0x74, 0x04, 0x02, 0x6F, 0x66, 0x04, 0x07,
Packit Service f99136
			 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x73);
Packit Service f99136
Packit Service be69e4
$fd = File::Temp->new('UNLINK' => 0);
Packit Service be69e4
$file = $fd->filename;
Packit Service be69e4
asn_write($fd, $result);
Packit Service be69e4
asn_write($fd, $result);
Packit Service be69e4
$fd->close;
Packit Service f99136
Packit Service f99136
open(IN,"< $file");
Packit Service f99136
sysread(IN,$buffer,1024);
Packit Service f99136
close(IN);
Packit Service f99136
Packit Service f99136
print "not " unless $buffer eq $result x 2;
Packit Service f99136
print "ok 1\n";
Packit Service f99136
Packit Service f99136
open(IN,"< $file");
Packit Service f99136
asn_read(*IN, $input);
Packit Service f99136
close(IN);
Packit Service f99136
Packit Service f99136
print "not " unless $input eq $result;
Packit Service f99136
print "ok 2\n";
Packit Service f99136
Packit Service f99136
open(IN,"< $file");
Packit Service f99136
Packit Service f99136
undef $input;
Packit Service f99136
$input = asn_get(*IN);
Packit Service f99136
print "not " unless $input eq $result;
Packit Service f99136
print "ok 3\n";
Packit Service f99136
Packit Service f99136
print "not " unless asn_ready(*IN);
Packit Service f99136
print "ok 4\n";
Packit Service f99136
Packit Service f99136
undef $input;
Packit Service f99136
$input = asn_get(*IN);
Packit Service f99136
print "not " unless $input eq $result;
Packit Service f99136
print "ok 5\n";
Packit Service f99136
Packit Service f99136
print "not " if asn_ready(*IN);
Packit Service f99136
print "ok 6\n";
Packit Service f99136
Packit Service f99136
close(IN);
Packit Service f99136
Packit Service f99136
unlink($file);
Packit Service f99136
Packit Service f99136
my $src = IO::Socket::INET->new(Proto => 'udp');
Packit Service f99136
my $dst = IO::Socket::INET->new(Proto => 'udp');
Packit Service f99136
bind($dst, pack_sockaddr_in(0, INADDR_ANY));
Packit Service f99136
my $host = $dst->sockhost eq '0.0.0.0' ? '127.0.0.1' : $dst->sockhost;
Packit Service f99136
my $addr = pack_sockaddr_in($dst->sockport, inet_aton($host));
Packit Service f99136
Packit Service f99136
asn_send($src,$result,0,$addr) or print "not ";
Packit Service f99136
print "ok 7\n";
Packit Service f99136
Packit Service f99136
asn_recv($dst, $in2, 0) or print "not ";
Packit Service f99136
print "ok 8\n";
Packit Service f99136
Packit Service f99136
print "not " unless $in2 && $in2 eq $result;
Packit Service f99136
print "ok 9\n";
Packit Service f99136
  
Packit Service f99136
open(IN,"t/07input.dat") or die "Cannot open 07input.dat: $!\n";
Packit Service f99136
undef $input;
Packit Service f99136
my $n = asn_read(*IN,$input);
Packit Service f99136
print "not " unless $n and $n == length($input);
Packit Service f99136
print "ok 10\n";
Packit Service f99136
print "not " unless $n == 1283;
Packit Service f99136
print "ok 11\n";
Packit Service f99136