blob: 6147f623ab5d6bc72cde23fd342497c920f97518 [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/;
Peter Harders57c884e2020-07-16 01:28:52 +02005use File::Temp qw/tempfile/;
Akron85717512020-07-08 11:19:19 +02006use IO::Uncompress::Unzip;
7
8use FindBin;
9BEGIN {
10 unshift @INC, "$FindBin::Bin/../lib";
11};
12
Peter Harders57c884e2020-07-16 01:28:52 +020013our %ENV;
14# default: remove temp. file created by func. tempfile
15# to keep temp. files use e.g. 'KORAPXMLTEI_DONTUNLINK=1 prove -lr t/script.t'
16my $_UNLINK = $ENV{KORAPXMLTEI_DONTUNLINK}?0:1;
17
Akron85717512020-07-08 11:19:19 +020018require_ok('KorAP::XML::TEI::Zipper');
19
20my $data;
Peter Harders57c884e2020-07-16 01:28:52 +020021my ($fh, $outzip) = tempfile("KorAP-XML-TEI_zipper_XXXXXXXXXX", SUFFIX => ".tmp", TMPDIR => 1, UNLINK => $_UNLINK);
Akron85717512020-07-08 11:19:19 +020022
23my $zip = KorAP::XML::TEI::Zipper->new($outzip);
Peter Harders57c884e2020-07-16 01:28:52 +020024$fh->close;
Akron85717512020-07-08 11:19:19 +020025
26ok($zip, 'Zipper initialized');
27
28ok($zip->new_stream('data/file1.txt')->print('hello'), 'Write to initial stream');
29ok($zip->new_stream('data/file2.txt')->print('world'), 'Write to appended stream');
30
31$zip->close;
32
33ok(-e $outzip, 'Zip exists');
34
35# Uncompress GOE/header.xml from zip file
36my $unzip = IO::Uncompress::Unzip->new($outzip, Name => 'data/file1.txt');
37
38$data .= $unzip->getline while !$unzip->eof;
39ok($unzip->close, 'Closed');
40
41is($data, 'hello', 'Data correct');
42
43
44# Uncompress GOE/header.xml from zip file
45$unzip = IO::Uncompress::Unzip->new($outzip, Name => 'data/file2.txt');
46
47$data = '';
48$data .= $unzip->getline while !$unzip->eof;
49ok($unzip->close, 'Closed');
50
51is($data, 'world', 'Data correct');
52
53done_testing;