| 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.Dimension; |
| 19 | import java.io.File; |
| 20 | import java.io.IOException; |
| 21 | |
| 22 | import junit.extensions.abbot.ComponentTestFixture; |
| 23 | import net.sf.jomic.tools.TestTools; |
| 24 | import org.apache.commons.logging.Log; |
| 25 | import org.apache.commons.logging.LogFactory; |
| 26 | |
| 27 | /** |
| 28 | * TestCase for ComicInfoPanel. |
| 29 | * |
| 30 | * @author Thomas Aglassinger |
| 31 | */ |
| 32 | public class ComicInfoTest extends ComponentTestFixture |
| 33 | { |
| 34 | private Log logger; |
| 35 | private TestTools testTools; |
| 36 | |
| 37 | protected void setUp() |
| 38 | throws Exception { |
| 39 | super.setUp(); |
| 40 | testTools = TestTools.instance(); |
| 41 | testTools.setupCache(); |
| 42 | logger = LogFactory.getLog(ComicInfoTest.class); |
| 43 | } |
| 44 | |
| 45 | public void testCheckIncomplete() |
| 46 | throws IOException, InterruptedException { |
| 47 | checkFile(TestTools.BROKEN_IMAGE_INCOMPLETE_CBZ); |
| 48 | } |
| 49 | |
| 50 | public void testCheckValid() |
| 51 | throws IOException, InterruptedException { |
| 52 | checkFile(TestTools.TEST_COMIC_FILE_NAME); |
| 53 | } |
| 54 | |
| 55 | public void testEmptyInfoFrame() { |
| 56 | showComicInfoFrame(null); |
| 57 | } |
| 58 | |
| 59 | protected void tearDown() |
| 60 | throws Exception { |
| 61 | logger = null; |
| 62 | testTools = null; |
| 63 | super.tearDown(); |
| 64 | } |
| 65 | |
| 66 | private void checkFile(final String testFileName) |
| 67 | throws IOException, InterruptedException { |
| 68 | assert testFileName != null; |
| 69 | File comicFile = testTools.getTestFile(testFileName); |
| 70 | |
| 71 | if (logger.isInfoEnabled()) { |
| 72 | logger.info("checking \"" + comicFile + "\""); |
| 73 | } |
| 74 | ComicModel model = new ComicModel(comicFile); |
| 75 | |
| 76 | model.check(null); |
| 77 | for (int i = 0; i < model.getImageCount(); i += 1) { |
| 78 | ComicImage comicImage = model.getComicImage(i); |
| 79 | File file = comicImage.getFile(); |
| 80 | String prefix = i + ": " + new File(file.getParentFile().getName(), file.getName()) + ": "; |
| 81 | |
| 82 | if (comicImage.hasError()) { |
| 83 | logger.warn(prefix + comicImage.getError()); |
| 84 | } else { |
| 85 | if (logger.isInfoEnabled()) { |
| 86 | logger.info(prefix + comicImage.getWidth() + "x" + comicImage.getHeight()); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | showComicInfoFrame(model); |
| 92 | } |
| 93 | |
| 94 | private void showComicInfoFrame(ComicModel model) { |
| 95 | ComicInfoPanel infoPane = new ComicInfoPanel(); |
| 96 | |
| 97 | infoPane.setComicModel(model); |
| 98 | showFrame(infoPane, new Dimension(TestTools.FRAME_WIDTH, TestTools.FRAME_HEIGHT)); |
| 99 | testTools.waitSomeTime(); |
| 100 | } |
| 101 | } |