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