EMMA Coverage Report (generated Sun Apr 20 22:38:01 CEST 2008)
[all classes][net.sf.jomic.tools]

COVERAGE SUMMARY FOR SOURCE FILE [AntZipTest.java]

nameclass, %method, %block, %line, %
AntZipTest.java100% (1/1)57%  (4/7)20%  (25/127)20%  (7.9/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AntZipTest100% (1/1)57%  (4/7)20%  (25/127)20%  (7.9/39)
testUnzip (String): void 0%   (0/1)0%   (0/82)0%   (0/22)
testUnzipBrokenDirectoryIndex (): void 0%   (0/1)0%   (0/15)0%   (0/7)
testUnzipNonAsciiNames (): void 0%   (0/1)0%   (0/4)0%   (0/2)
<static initializer> 100% (1/1)91%  (10/11)91%  (0.9/1)
AntZipTest (): void 100% (1/1)100% (3/3)100% (1/1)
setUp (): void 100% (1/1)100% (6/6)100% (3/3)
tearDown (): void 100% (1/1)100% (6/6)100% (3/3)

1// Jomic - a viewer for comic book archives.
2// Copyright (C) 2004-2008 Thomas Aglassinger
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16package net.sf.jomic.tools;
17 
18import java.io.BufferedInputStream;
19import java.io.File;
20import java.io.IOException;
21import java.io.InputStream;
22import java.util.Enumeration;
23import java.util.zip.ZipException;
24 
25import junit.framework.TestCase;
26 
27import net.sf.wraplog.Logger;
28 
29import org.apache.tools.zip.ZipEntry;
30import org.apache.tools.zip.ZipFile;
31 
32/**
33 *  TestCase for alternative Zip implementation taken from Ant that allows to specify encoding of
34 *  file names.
35 *
36 * @author    Thomas Aglassinger
37 */
38public class AntZipTest extends TestCase
39{
40    private static final int BUFFER_SIZE = 4096;
41    private static Logger logger = Logger.getLogger(AntZipTest.class);
42    private TestTools testTools;
43 
44    protected void setUp()
45        throws Exception {
46        super.setUp();
47        testTools = TestTools.instance();
48    }
49 
50    public void testUnzipBrokenDirectoryIndex()
51        throws IOException {
52        try {
53            testUnzip("broken_archive_internal_zip_error.cbz");
54            fail("broken archive must result in ZipException");
55        } catch (ZipException error) {
56            if (logger.isInfoEnabled()) {
57                logger.info("ignoring expected error", error);
58            }
59        }
60    }
61 
62    public void testUnzipNonAsciiNames()
63        throws IOException {
64        testUnzip("test_no_stream_closed.cbz");
65    }
66 
67    protected void tearDown()
68        throws Exception {
69        testTools = null;
70        super.tearDown();
71    }
72 
73    private void testUnzip(String baseFileName)
74        throws IOException {
75        File testFileToUnzip = testTools.getTestFile(baseFileName);
76        ZipFile zipFile = new ZipFile(testFileToUnzip);
77 
78        try {
79            Enumeration zipEntries = zipFile.getEntries();
80 
81            while (zipEntries.hasMoreElements()) {
82                ZipEntry entry = (ZipEntry) zipEntries.nextElement();
83                String name = entry.getName();
84 
85                logger.info("extract \"{}\"", name);
86                if (!entry.isDirectory()) {
87                    InputStream in = zipFile.getInputStream(entry);
88 
89                    assertNotNull("in", in);
90                    try {
91                        BufferedInputStream inBuffered = new BufferedInputStream(in);
92 
93                        try {
94                            byte[] data = new byte[BUFFER_SIZE];
95 
96                            while (inBuffered.read(data, 0, BUFFER_SIZE) != -1) {
97                                logger.debug("discard data");
98                            }
99                        } finally {
100                            inBuffered.close();
101                        }
102                    } finally {
103                        in.close();
104                    }
105                }
106            }
107        } finally {
108            zipFile.close();
109        }
110    }
111 
112}

[all classes][net.sf.jomic.tools]
EMMA 2.0.4217 (C) Vladimir Roubtsov