Crypt-FileHandle
view release on metacpan or search on metacpan
t/Crypt-FileHandle.t view on Meta::CPAN
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Crypt-FileHandle.t'
#########################
use Test;
BEGIN { plan tests => 47 };
use Crypt::FileHandle;
ok(1);
$|=1;
############################################################
# inline package for testing a Crypt::CBC compatible cipher
# without the dependency of Crypt::CBC
{
package CryptXOR;
sub new {
my $class = shift;
my $self = bless({}, $class);
# ensure non-zero
$self->{'xor'} = chr(int(rand()*10) + 1);
return $self;
}
sub start { return 1; }
sub crypt {
my $self = shift;
my $data = shift;
return undef if (! defined $data);
my $xor = "";
for (my $i = 0; $i < length($data); $i++) {
my $ch = substr($data, $i, 1);
$xor .= chr(ord($ch) ^ ord($self->{'xor'}));
}
return $xor;
}
sub finish { return ""; }
sub xor {
my $self = shift;
return $self->{'xor'};
}
1;
}
############################################################
# temporary file (must have write access to test!)
my $filename = 'make_test.tmp';
# create test data
my @data;
push @data, "!";
push @data, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
push @data, "THIS IS A LINE.\r\n";
push @data, "THIS IS A ANOTHER LINE AT THE END OF THE FILE";
my $total_len = 0;
foreach (@data) {
$total_len += length($_);
}
# create new random XOR cipher
my $cipher = CryptXOR->new();
# new / verify_cipher / readsize
my $fh = Crypt::FileHandle->new($cipher);
ok(Crypt::FileHandle->verify_cipher($cipher));
ok(Crypt::FileHandle->readsize() == 4096);
ok(Crypt::FileHandle->readsize(2048) == 2048);
ok($fh);
# OPEN
eval { open($fh, '>>', $filename); };
ok($@ =~ /^APPEND mode not supported/);
$@ = undef;
( run in 0.899 second using v1.01-cache-2.11-cpan-e1769b4cff6 )