| 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/>. |
| 16 | package net.sf.jomic.comic; |
| 17 | |
| 18 | import java.io.File; |
| 19 | |
| 20 | import junit.framework.Test; |
| 21 | import junit.framework.TestSuite; |
| 22 | import net.sf.jomic.tools.TestTools; |
| 23 | import org.apache.commons.logging.Log; |
| 24 | import org.apache.commons.logging.LogFactory; |
| 25 | |
| 26 | /** |
| 27 | * TestCase to test that broken comic archives in <code>net.sf.jomic.tests.data</code> can not be |
| 28 | * be opened. |
| 29 | * |
| 30 | * @author Thomas Aglassinger |
| 31 | */ |
| 32 | public final class BrokenComicArchiveTest extends AbstractComicArchiveTest |
| 33 | { |
| 34 | private static Log logger = LogFactory.getLog(BrokenComicArchiveTest.class); |
| 35 | private File archive; |
| 36 | |
| 37 | private BrokenComicArchiveTest(File newArchive) { |
| 38 | super(); |
| 39 | assert newArchive != null; |
| 40 | setName("testBrokenArchive"); |
| 41 | archive = newArchive; |
| 42 | } |
| 43 | |
| 44 | public static Test suite() { |
| 45 | TestSuite suite = new TestSuite(); |
| 46 | TestTools testTools = TestTools.instance(); |
| 47 | File[] archives = testTools.getTestFiles("^(broken).*\\.(cbz|cbr)$"); |
| 48 | |
| 49 | for (int i = 0; i < archives.length; i += 1) { |
| 50 | suite.addTest(new BrokenComicArchiveTest(archives[i])); |
| 51 | } |
| 52 | return suite; |
| 53 | } |
| 54 | |
| 55 | public void testBrokenArchive() |
| 56 | throws Exception { |
| 57 | try { |
| 58 | testExtract(archive); |
| 59 | if (!archive.getName().startsWith("broken_image_")) { |
| 60 | fail("archive must be recognized as broken: \"" + archive + "\""); |
| 61 | } |
| 62 | } catch (Exception error) { |
| 63 | logger.debug("ignoring expected exception", error); |
| 64 | } |
| 65 | } |
| 66 | } |