diff --git a/t/format-ssa-file.t b/t/format-ssa-file.t new file mode 100644 index 0000000..d4cf04c --- /dev/null +++ b/t/format-ssa-file.t @@ -0,0 +1,41 @@ +use strict; +use warnings; + +use Test::More tests => 62; + +use Subtitle::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::SSA::File->new; +is(ref $file, 'Subtitle::SSA::File'); +can_ok($file, qw(new error size type name parse_uue_line binary uue_line uue_block)); +undef $file; + +for (my $i = 0; $i < 15; $i++) { + my $bin = random_data(); + $file = Subtitle::SSA::File->new; + $file->binary($bin); + is($file->size => length $bin); + my $uue = $file->uue_line; + 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;