9 use Test
::More tests
=> 6;
11 use File
::Spec
::Unix
();
12 use Archive
::Zip
qw( :ERROR_CODES );
14 my $expected_fn = File
::Spec
->catfile(
15 File
::Spec
->curdir, "t", "badjpeg", "expected.jpg"
17 my $expected_zip = File
::Spec
::Unix
->catfile(
18 File
::Spec
::Unix
->curdir, "t", "badjpeg", "expected.jpg",
21 my $got_fn = "got.jpg";
22 my $archive_fn = "out.zip";
23 my ( $before, $after );
26 open my $fh, "<$filename"
27 or die 'Can not open file';
39 my ($got, $expected, $msg) = @_;
40 local $Test::Builder
::Level
= $Test::Builder
::Level
+1;
41 my $verdict = ($got eq $expected);
45 if (length($got) > length($expected)) {
46 $len = length($expected);
47 diag
("got is longer than expected");
48 } elsif (length($got) < length($expected)) {
50 diag
("expected is longer than got");
56 for my $byte_idx (0 .. ($len-1)) {
57 my $got_byte = substr($got, $byte_idx, 1);
58 my $expected_byte = substr($expected, $byte_idx, 1);
59 if ($got_byte ne $expected_byte) {
62 "Byte %i differ: got == 0x%.2x, expected == 0x%.2x",
63 $byte_idx, ord($got_byte), ord($expected_byte)
76 return "$id - $msg_raw";
79 # Read the contents of the good file into the variable.
80 $before = slurp_file
($expected_fn);
84 my $zip = Archive
::Zip
->new();
85 $zip->addFile( $expected_fn );
86 $zip->extractMember( $expected_zip, $got_fn );
87 $after = slurp_file
($got_fn);
94 $msg_it->("Content of file after extraction"),
97 my $status = $zip->writeToFileNamed( $archive_fn );
99 cmp_ok
( $status, '==', AZ_OK
, $msg_it->('Zip was written fine') );
102 # Read back the file from the archive.
105 $zip2 = Archive
::Zip
->new( $archive_fn );
107 $zip2->extractMember( $expected_zip, $got_fn );
109 $after = slurp_file
( $got_fn );
117 $msg_it->('Read back the file from the archive'),
122 # Run the tests once with $\ undef.
125 # Run them once while setting $\.
128 run_tests
(q{$\ is \n});