| 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 | import java.io.IOException; |
| 21 | |
| 22 | import junit.framework.TestCase; |
| 23 | import net.sf.jomic.common.Settings; |
| 24 | import net.sf.jomic.tools.FileTools; |
| 25 | import net.sf.jomic.tools.TestTools; |
| 26 | import net.sf.wraplog.Logger; |
| 27 | |
| 28 | /** |
| 29 | * TestCase for Thumbnail. |
| 30 | * |
| 31 | * @author Thomas Aglassinger |
| 32 | */ |
| 33 | public class ThumbnailTest extends TestCase |
| 34 | { |
| 35 | static final int MAX_THUMB_HEIGHT = 100; |
| 36 | static final int MAX_THUMB_WIDTH = 135; |
| 37 | |
| 38 | private Logger logger; |
| 39 | private TestTools testTools; |
| 40 | |
| 41 | /* |
| 42 | * @see TestCase#setUp() |
| 43 | */ |
| 44 | protected void setUp() |
| 45 | throws Exception { |
| 46 | super.setUp(); |
| 47 | logger = Logger.getLogger(ThumbnailTest.class); |
| 48 | testTools = TestTools.instance(); |
| 49 | } |
| 50 | |
| 51 | public void testThumbsCache() |
| 52 | throws IOException { |
| 53 | File cacheDir = Settings.instance().getCacheDir(); |
| 54 | |
| 55 | clearComicCaches(cacheDir); |
| 56 | |
| 57 | ComicCache comicCache = ComicCache.instance(); |
| 58 | |
| 59 | comicCache.setUp(cacheDir); |
| 60 | |
| 61 | File imageFile = testTools.getTestImageFile(); |
| 62 | RenderedImage thumbImage = comicCache.getThumbnail(imageFile); |
| 63 | |
| 64 | assertNotNull(thumbImage); |
| 65 | |
| 66 | RenderedImage againThumbImage = comicCache.getThumbnail(imageFile); |
| 67 | |
| 68 | assertNotNull(againThumbImage); |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * @see TestCase#tearDown() |
| 73 | */ |
| 74 | protected void tearDown() |
| 75 | throws Exception { |
| 76 | testTools = null; |
| 77 | super.tearDown(); |
| 78 | } |
| 79 | |
| 80 | // TODO: find a dencent way to clear the files in the cache |
| 81 | private void clearComicCaches(File cacheDir) { |
| 82 | FileTools.instance().attemptToDeleteAll(cacheDir, logger); |
| 83 | } |
| 84 | } |
| 85 | |