| 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.tools; |
| 17 | |
| 18 | import java.io.File; |
| 19 | |
| 20 | import junit.framework.TestCase; |
| 21 | import net.sf.jomic.comic.ComicCache; |
| 22 | |
| 23 | /** |
| 24 | * TestCase for ImageCacheRenderThread. |
| 25 | * |
| 26 | * @author Thomas Aglassinger |
| 27 | */ |
| 28 | public class ImageCacheRenderThreadTest extends TestCase implements ImageInCacheListener, StandardConstants |
| 29 | { |
| 30 | private TestTools testTools; |
| 31 | |
| 32 | /* |
| 33 | * (non-Javadoc) |
| 34 | * @see junit.framework.TestCase#setUp() |
| 35 | */ |
| 36 | protected void setUp() |
| 37 | throws Exception { |
| 38 | super.setUp(); |
| 39 | testTools = TestTools.instance(); |
| 40 | testTools.setupCache(); |
| 41 | } |
| 42 | |
| 43 | public void imageCached(File imageFile) { |
| 44 | // TODO Auto-generated method stub |
| 45 | |
| 46 | } |
| 47 | |
| 48 | public void testDisposeEmpty() { |
| 49 | ComicCache cache = ComicCache.instance(); |
| 50 | ImageCacheRenderThread renderer = new ImageCacheRenderThread(cache.getImageCache()); |
| 51 | |
| 52 | renderer.start(); |
| 53 | renderer.dispose(); |
| 54 | } |
| 55 | |
| 56 | public void testDisposeNonEmpty() { |
| 57 | ComicCache cache = ComicCache.instance(); |
| 58 | ImageCacheRenderThread renderer = new ImageCacheRenderThread(cache.getImageCache()); |
| 59 | |
| 60 | renderer.start(); |
| 61 | renderer.addTask(testTools.getTestImageFile(), this, |
| 62 | ImageCacheRenderThread.PRIORITY_SOMETIMES); |
| 63 | renderer.addTask(testTools.getTestGeneratedInputFile("02.png"), this, |
| 64 | ImageCacheRenderThread.PRIORITY_SOMETIMES); |
| 65 | renderer.addTask(testTools.getTestGeneratedInputFile("03.png"), this, |
| 66 | ImageCacheRenderThread.PRIORITY_SOMETIMES); |
| 67 | renderer.dispose(); |
| 68 | } |
| 69 | |
| 70 | public void testRenderAndDispose() |
| 71 | throws InterruptedException { |
| 72 | ComicCache cache = ComicCache.instance(); |
| 73 | ImageCache imageCache = cache.getImageCache(); |
| 74 | ImageCacheRenderThread renderer = new ImageCacheRenderThread(imageCache); |
| 75 | |
| 76 | renderer.start(); |
| 77 | |
| 78 | File imageFile = testTools.getTestImageFile(); |
| 79 | |
| 80 | renderer.addTask(imageFile, this, ImageCacheRenderThread.PRIORITY_SOMETIMES); |
| 81 | while (!imageCache.has(imageFile)) { |
| 82 | Thread.sleep(TICK); |
| 83 | } |
| 84 | renderer.dispose(); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | /* |
| 89 | * (non-Javadoc) |
| 90 | * @see junit.framework.TestCase#tearDown() |
| 91 | */ |
| 92 | protected void tearDown() |
| 93 | throws Exception { |
| 94 | testTools = null; |
| 95 | super.tearDown(); |
| 96 | } |
| 97 | |
| 98 | } |