Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 4 | use File::Spec::Functions qw/catfile/; |
Akron | 5fb5e8d | 2020-07-23 17:45:13 +0200 | [diff] [blame^] | 5 | use Test::KorAP::XML::TEI qw!korap_tempfile!; |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 6 | use IO::Uncompress::Unzip; |
| 7 | |
| 8 | use FindBin; |
| 9 | BEGIN { |
| 10 | unshift @INC, "$FindBin::Bin/../lib"; |
| 11 | }; |
| 12 | |
| 13 | require_ok('KorAP::XML::TEI::Zipper'); |
| 14 | |
| 15 | my $data; |
Akron | 5fb5e8d | 2020-07-23 17:45:13 +0200 | [diff] [blame^] | 16 | my ($fh, $outzip) = korap_tempfile('zipper'); |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 17 | |
| 18 | my $zip = KorAP::XML::TEI::Zipper->new($outzip); |
Peter Harders | 57c884e | 2020-07-16 01:28:52 +0200 | [diff] [blame] | 19 | $fh->close; |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 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; |