| 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 | import java.io.IOException; |
| 21 | |
| 22 | import javax.swing.event.ListSelectionEvent; |
| 23 | import javax.swing.event.ListSelectionListener; |
| 24 | |
| 25 | import junit.extensions.abbot.ComponentTestFixture; |
| 26 | import net.sf.jomic.common.Settings; |
| 27 | import net.sf.jomic.tools.TestTools; |
| 28 | import org.apache.commons.logging.Log; |
| 29 | import org.apache.commons.logging.LogFactory; |
| 30 | |
| 31 | /** |
| 32 | * TestCase for ComicThumbView. |
| 33 | */ |
| 34 | public class ComicThumbViewTest extends ComponentTestFixture implements ListSelectionListener |
| 35 | { |
| 36 | private Log logger; |
| 37 | private Settings settings; |
| 38 | private TestTools testTools; |
| 39 | |
| 40 | protected void setUp() |
| 41 | throws Exception { |
| 42 | super.setUp(); |
| 43 | testTools = TestTools.instance(); |
| 44 | testTools.setupCache(); |
| 45 | logger = LogFactory.getLog(ComicThumbViewTest.class); |
| 46 | settings = Settings.instance(); |
| 47 | } |
| 48 | |
| 49 | public void testComicThumbView() |
| 50 | throws IOException, InterruptedException { |
| 51 | |
| 52 | File comicFile = testTools.getTestComicFile(); |
| 53 | ComicModel comic = new ComicModel(comicFile); |
| 54 | ComicThumbView thumbView = new ComicThumbView(); |
| 55 | |
| 56 | thumbView.addListSelectionListener(this); |
| 57 | try { |
| 58 | thumbView.setOpaque(true); |
| 59 | thumbView.setBackground(settings.getFillColor()); |
| 60 | thumbView.setComic(comic); |
| 61 | showFrame(thumbView); |
| 62 | |
| 63 | assertEquals(0, thumbView.getThumbIndexAtOrAfterY(0)); |
| 64 | assertEquals(0, thumbView.getThumbIndexAtOrAfterY(1)); |
| 65 | |
| 66 | testTools.waitSomeTime(); |
| 67 | thumbView.setComic(null); |
| 68 | } finally { |
| 69 | thumbView.dispose(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | public void testImageTest() |
| 74 | throws IOException, InterruptedException { |
| 75 | ComicCache comicCache = ComicCache.instance(); |
| 76 | File comicFile = testTools.getTestComicFile(); |
| 77 | ComicModel comic = new ComicModel(comicFile); |
| 78 | |
| 79 | for (int i = 0; i < comic.getImageCount(); i += 1) { |
| 80 | ComicImage comicImage = comic.getComicImage(i); |
| 81 | File imageFile = comicImage.getFile(); |
| 82 | RenderedImage image = comicCache.getImage(imageFile); |
| 83 | |
| 84 | assertNotNull("image", image); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | public void valueChanged(ListSelectionEvent event) { |
| 89 | assert event != null; |
| 90 | if (logger.isInfoEnabled()) { |
| 91 | logger.info("selection changed: " + event); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | protected void tearDown() |
| 96 | throws Exception { |
| 97 | settings = null; |
| 98 | testTools = null; |
| 99 | logger = null; |
| 100 | super.tearDown(); |
| 101 | } |
| 102 | |
| 103 | } |