|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Test::More tests => 62;
|
|
|
|
|
|
|
|
use Subtitle::Format::SSA::File;
|
|
|
|
|
|
|
|
sub random_data {
|
|
|
|
my $data = '';
|
|
|
|
my $len = 100 + int(rand(100));
|
|
|
|
open my $FH, '<', '/dev/urandom'
|
|
|
|
or die "can't open: /dev/urandom -- $!\n";
|
|
|
|
read($FH, $data, $len);
|
|
|
|
close $FH;
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $file = Subtitle::Format::SSA::File->new;
|
|
|
|
is(ref $file, 'Subtitle::Format::SSA::File');
|
|
|
|
can_ok($file, qw(new error size type name from_binary add_uue_line to_binary uue_string uue_block));
|
|
|
|
undef $file;
|
|
|
|
|
|
|
|
for (my $i = 0; $i < 15; $i++) {
|
|
|
|
my $bin = random_data();
|
|
|
|
$file = Subtitle::Format::SSA::File->new;
|
|
|
|
$file->from_binary($bin);
|
|
|
|
is($file->size => length $bin);
|
|
|
|
my $uue = $file->uue_string;
|
|
|
|
isnt($uue, '');
|
|
|
|
ok(length($uue) % 4 != 1);
|
|
|
|
my $invalid = 0;
|
|
|
|
for my $char (split(//, $uue)) {
|
|
|
|
next if ord($char) >= 33 and ord($char) <= 96;
|
|
|
|
$invalid = 1;
|
|
|
|
diag sprintf("unexpected char in encoded text: %s (code 0x%02X)", $char, ord($char));
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
is($invalid, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|