Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame^] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use File::Basename 'dirname'; |
| 5 | use File::Spec::Functions qw/catfile/; |
| 6 | use File::Temp ':POSIX'; |
| 7 | use IO::Uncompress::Unzip; |
| 8 | |
| 9 | use FindBin; |
| 10 | BEGIN { |
| 11 | unshift @INC, "$FindBin::Bin/../lib"; |
| 12 | }; |
| 13 | |
| 14 | require_ok('KorAP::XML::TEI::Zipper'); |
| 15 | |
| 16 | my $data; |
| 17 | my $outzip = tmpnam(); |
| 18 | |
| 19 | my $zip = KorAP::XML::TEI::Zipper->new($outzip); |
| 20 | |
| 21 | ok($zip, 'Zipper initialized'); |
| 22 | |
| 23 | ok($zip->new_stream('data/file1.txt')->print('hello'), 'Write to initial stream'); |
| 24 | ok($zip->new_stream('data/file2.txt')->print('world'), 'Write to appended stream'); |
| 25 | |
| 26 | $zip->close; |
| 27 | |
| 28 | ok(-e $outzip, 'Zip exists'); |
| 29 | |
| 30 | # Uncompress GOE/header.xml from zip file |
| 31 | my $unzip = IO::Uncompress::Unzip->new($outzip, Name => 'data/file1.txt'); |
| 32 | |
| 33 | $data .= $unzip->getline while !$unzip->eof; |
| 34 | ok($unzip->close, 'Closed'); |
| 35 | |
| 36 | is($data, 'hello', 'Data correct'); |
| 37 | |
| 38 | |
| 39 | # Uncompress GOE/header.xml from zip file |
| 40 | $unzip = IO::Uncompress::Unzip->new($outzip, Name => 'data/file2.txt'); |
| 41 | |
| 42 | $data = ''; |
| 43 | $data .= $unzip->getline while !$unzip->eof; |
| 44 | ok($unzip->close, 'Closed'); |
| 45 | |
| 46 | is($data, 'world', 'Data correct'); |
| 47 | |
| 48 | done_testing; |