| 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.awt.image.RenderedImage; |
| 19 | import java.io.File; |
| 20 | |
| 21 | import javax.swing.JFrame; |
| 22 | import javax.swing.JScrollPane; |
| 23 | |
| 24 | import junit.framework.TestCase; |
| 25 | import net.sf.jomic.tools.TestTools; |
| 26 | import org.apache.commons.logging.Log; |
| 27 | import org.apache.commons.logging.LogFactory; |
| 28 | |
| 29 | import com.sun.media.jai.widget.DisplayJAI; |
| 30 | |
| 31 | /** |
| 32 | * Abstract TestCase to extract a comic archive. |
| 33 | * |
| 34 | * @author Thomas Aglassinger |
| 35 | */ |
| 36 | abstract class AbstractComicArchiveTest extends TestCase |
| 37 | { |
| 38 | private Log logger; |
| 39 | private TestTools testTools; |
| 40 | |
| 41 | protected void setUp() |
| 42 | throws Exception { |
| 43 | super.setUp(); |
| 44 | logger = LogFactory.getLog(AbstractComicArchiveTest.class); |
| 45 | testTools = TestTools.instance(); |
| 46 | testTools.setupCache(); |
| 47 | } |
| 48 | |
| 49 | public TestTools getTestTools() { |
| 50 | return testTools; |
| 51 | } |
| 52 | |
| 53 | protected void tearDown() |
| 54 | throws Exception { |
| 55 | super.tearDown(); |
| 56 | testTools = null; |
| 57 | logger = null; |
| 58 | } |
| 59 | |
| 60 | protected void testExtract(String name) |
| 61 | throws Exception { |
| 62 | assert name != null; |
| 63 | testExtract(testTools.getTestFile(name)); |
| 64 | } |
| 65 | |
| 66 | protected void testExtract(File archive) |
| 67 | throws Exception { |
| 68 | assert archive != null; |
| 69 | if (logger.isInfoEnabled()) { |
| 70 | logger.info("test extract \"" + archive + "\""); |
| 71 | } |
| 72 | ComicModel model = null; |
| 73 | JFrame frame = null; |
| 74 | |
| 75 | try { |
| 76 | model = new ComicModel(archive); |
| 77 | frame = new JFrame(ComicModelTest.class.getName()); |
| 78 | |
| 79 | DisplayJAI imagePane = new DisplayJAI(); |
| 80 | |
| 81 | frame.getContentPane().add(new JScrollPane(imagePane)); |
| 82 | frame.setSize(TestTools.FRAME_WIDTH, TestTools.FRAME_HEIGHT); |
| 83 | |
| 84 | boolean firstTime = true; |
| 85 | |
| 86 | for (int page = 0; page < model.getImageCount(); page += 1) { |
| 87 | if (logger.isDebugEnabled()) { |
| 88 | logger.debug("view page " + page); |
| 89 | } |
| 90 | RenderedImage image = model.getImage(page); |
| 91 | |
| 92 | imagePane.set(image); |
| 93 | if (firstTime) { |
| 94 | firstTime = false; |
| 95 | frame.pack(); |
| 96 | frame.setVisible(true); |
| 97 | } |
| 98 | } |
| 99 | } finally { |
| 100 | if (model != null) { |
| 101 | model.dispose(); |
| 102 | } |
| 103 | if (frame != null) { |
| 104 | frame.dispose(); |
| 105 | } |
| 106 | // TOOD: assert all files have been removed |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | } |