]>
Dogcows Code - chaz/p5-File-KDBX/blob - t/hash-block.t
006f617e5af8defee7421f65ac2dd573db650f42
7 use TestCommon
qw(:no_warnings_test);
9 use File
::KDBX
::Util
qw(can_fork);
13 BEGIN { use_ok
'PerlIO::via::File::KDBX::HashBlock' }
16 my $expected_plaintext = 'Tiny food from Spain!';
18 pipe(my $read, my $write) or die "pipe failed: $!\n";
20 PerlIO
::via
::File
::KDBX
::HashBlock-
>push($write, block_size
=> 3);
21 print $write $expected_plaintext;
22 binmode($write, ':pop'); # finish stream
23 close($write) or die "close failed: $!";
25 PerlIO
::via
::File
::KDBX
::HashBlock-
>push($read);
26 my $plaintext = do { local $/; <$read> };
29 is $plaintext, $expected_plaintext, 'Hash-block just a little bit';
32 subtest
'Error handling' => sub {
33 pipe(my $read, my $write) or die "pipe failed: $!\n";
35 PerlIO
::via
::File
::KDBX
::HashBlock-
>push($read);
37 print $write 'blah blah blah';
38 close($write) or die "close failed: $!";
40 is $read->error, 0, 'Read handle starts out fine';
41 my $data = do { local $/; <$read> };
42 is $read->error, 1, 'Read handle can enter and error state';
44 like
$PerlIO::via
::File
::KDBX
::HashBlock
::ERROR
, qr/invalid block index/i,
45 'Error object is available';
49 skip
'Tests require fork' if !can_fork
;
51 my $expected_plaintext = "\x64" x
(1024*1024*12 - 57);
53 pipe(my $read, my $write) or die "pipe failed: $!\n";
55 defined(my $pid = fork) or die "fork failed: $!\n";
57 PerlIO
::via
::File
::KDBX
::HashBlock-
>push($write);
58 print $write $expected_plaintext;
59 binmode($write, ':pop'); # finish stream
60 close($write) or die "close failed: $!";
64 PerlIO
::via
::File
::KDBX
::HashBlock-
>push($read);
65 my $plaintext = do { local $/; <$read> };
68 is $plaintext, $expected_plaintext, 'Hash-block a lot';
70 waitpid($pid, 0) or die "wait failed: $!\n";
This page took 0.039166 seconds and 3 git commands to generate.