EMMA Coverage Report (generated Sat Oct 08 11:41:37 CEST 2011)
[all classes][net.sf.jomic.tools]

COVERAGE SUMMARY FOR SOURCE FILE [AntZipTest.java]

nameclass, %method, %block, %line, %
AntZipTest.java100% (1/1)57%  (4/7)18%  (25/138)20%  (7.9/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AntZipTest100% (1/1)57%  (4/7)18%  (25/138)20%  (7.9/40)
testUnzip (String): void 0%   (0/1)0%   (0/93)0%   (0/23)
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-2011 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 org.apache.commons.logging.Log;
28import org.apache.commons.logging.LogFactory;
29 
30import org.apache.tools.zip.ZipEntry;
31import org.apache.tools.zip.ZipFile;
32 
33/**
34 *  TestCase for alternative Zip implementation taken from Ant that allows to specify encoding of
35 *  file names.
36 *
37 * @author    Thomas Aglassinger
38 */
39public class AntZipTest extends TestCase
40{
41    private static final int BUFFER_SIZE = 4096;
42    private static Log logger = LogFactory.getLog(AntZipTest.class);
43    private TestTools testTools;
44 
45    protected void setUp()
46        throws Exception {
47        super.setUp();
48        testTools = TestTools.instance();
49    }
50 
51    public void testUnzipBrokenDirectoryIndex()
52        throws IOException {
53        try {
54            testUnzip("broken_archive_internal_zip_error.cbz");
55            fail("broken archive must result in ZipException");
56        } catch (ZipException error) {
57            if (logger.isInfoEnabled()) {
58                logger.info("ignoring expected error", error);
59            }
60        }
61    }
62 
63    public void testUnzipNonAsciiNames()
64        throws IOException {
65        testUnzip("test_no_stream_closed.cbz");
66    }
67 
68    protected void tearDown()
69        throws Exception {
70        testTools = null;
71        super.tearDown();
72    }
73 
74    private void testUnzip(String baseFileName)
75        throws IOException {
76        File testFileToUnzip = testTools.getTestFile(baseFileName);
77        ZipFile zipFile = new ZipFile(testFileToUnzip);
78 
79        try {
80            Enumeration zipEntries = zipFile.getEntries();
81 
82            while (zipEntries.hasMoreElements()) {
83                ZipEntry entry = (ZipEntry) zipEntries.nextElement();
84                String name = entry.getName();
85 
86                if (logger.isInfoEnabled()) {
87                    logger.info("extract \"" + name + "\"");
88                }
89                if (!entry.isDirectory()) {
90                    InputStream in = zipFile.getInputStream(entry);
91 
92                    assertNotNull("in", in);
93                    try {
94                        BufferedInputStream inBuffered = new BufferedInputStream(in);
95 
96                        try {
97                            byte[] data = new byte[BUFFER_SIZE];
98 
99                            while (inBuffered.read(data, 0, BUFFER_SIZE) != -1) {
100                                logger.debug("discard data");
101                            }
102                        } finally {
103                            inBuffered.close();
104                        }
105                    } finally {
106                        in.close();
107                    }
108                }
109            }
110        } finally {
111            zipFile.close();
112        }
113    }
114 
115}

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