blob: 86aa52a9192a0faad78e0103f85046cf72187fe4 [file] [log] [blame]
Akron85717512020-07-08 11:19:19 +02001use strict;
2use warnings;
3use Test::More;
Akron85717512020-07-08 11:19:19 +02004use File::Spec::Functions qw/catfile/;
Akron85717512020-07-08 11:19:19 +02005use IO::Uncompress::Unzip;
6
7use FindBin;
8BEGIN {
9 unshift @INC, "$FindBin::Bin/../lib";
10};
11
Peter Harders42e18a62020-07-21 02:43:26 +020012use Test::KorAP::XML::TEI qw!korap_tempfile!;
13
Akron85717512020-07-08 11:19:19 +020014require_ok('KorAP::XML::TEI::Zipper');
15
16my $data;
Akron5fb5e8d2020-07-23 17:45:13 +020017my ($fh, $outzip) = korap_tempfile('zipper');
Akron85717512020-07-08 11:19:19 +020018
19my $zip = KorAP::XML::TEI::Zipper->new($outzip);
Peter Harders57c884e2020-07-16 01:28:52 +020020$fh->close;
Akron85717512020-07-08 11:19:19 +020021
22ok($zip, 'Zipper initialized');
23
24ok($zip->new_stream('data/file1.txt')->print('hello'), 'Write to initial stream');
25ok($zip->new_stream('data/file2.txt')->print('world'), 'Write to appended stream');
26
27$zip->close;
28
29ok(-e $outzip, 'Zip exists');
30
31# Uncompress GOE/header.xml from zip file
32my $unzip = IO::Uncompress::Unzip->new($outzip, Name => 'data/file1.txt');
33
34$data .= $unzip->getline while !$unzip->eof;
35ok($unzip->close, 'Closed');
36
37is($data, 'hello', 'Data correct');
38
39
Peter Harders42e18a62020-07-21 02:43:26 +020040# Uncompress data/file2.txt from zip file
Akron85717512020-07-08 11:19:19 +020041$unzip = IO::Uncompress::Unzip->new($outzip, Name => 'data/file2.txt');
42
43$data = '';
44$data .= $unzip->getline while !$unzip->eof;
45ok($unzip->close, 'Closed');
46
47is($data, 'world', 'Data correct');
48
49done_testing;