| 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.jaiunit; |
| 17 | |
| 18 | import java.awt.image.BufferedImage; |
| 19 | import java.awt.image.RenderedImage; |
| 20 | |
| 21 | import junit.framework.TestCase; |
| 22 | import net.sf.jomic.tools.TestTools; |
| 23 | |
| 24 | /** |
| 25 | * TestCase for Tools. |
| 26 | * |
| 27 | * @author Thomas Aglassinger |
| 28 | */ |
| 29 | public class ToolsTest extends TestCase |
| 30 | { |
| 31 | private static final int IMAGE_HEIGHT = 480; |
| 32 | private static final int IMAGE_WIDTH = 640; |
| 33 | private Tools tools; |
| 34 | |
| 35 | /* |
| 36 | * (non-Javadoc) |
| 37 | * @see junit.framework.TestCase#setUp() |
| 38 | */ |
| 39 | protected void setUp() |
| 40 | throws Exception { |
| 41 | TestTools.instance(); |
| 42 | tools = Tools.instance(); |
| 43 | } |
| 44 | |
| 45 | public void testCreateGolorTestImage() { |
| 46 | RenderedImage image = createColorImage(); |
| 47 | |
| 48 | tools.showImage(image, ToolsTest.class, "testCreateGolorTestImage"); |
| 49 | } |
| 50 | |
| 51 | public void testCreateGrayTestImage() { |
| 52 | RenderedImage image = createGrayImage(); |
| 53 | |
| 54 | tools.showImage(image, ToolsTest.class, "testCreateGrayTestImage"); |
| 55 | } |
| 56 | |
| 57 | public void testDifferentImageDeltaFrame() { |
| 58 | tools.showDeltaImage(createColorImage(), createGrayImage(), ToolsTest.class, "testDifferentImageDeltaFrame"); |
| 59 | } |
| 60 | |
| 61 | public void testImagesAreEqual() { |
| 62 | RenderedImage color = createColorImage(); |
| 63 | RenderedImage gray = createGrayImage(); |
| 64 | |
| 65 | assertEquals(true, tools.imagesAreEqual(color, color)); |
| 66 | assertEquals(false, tools.imagesAreEqual(color, gray)); |
| 67 | assertEquals(false, tools.imagesAreEqual(gray, color)); |
| 68 | assertEquals(true, tools.imagesAreEqual(gray, gray)); |
| 69 | |
| 70 | } |
| 71 | |
| 72 | public void testSameImageDeltaFrame() { |
| 73 | tools.showDeltaImage(createColorImage(), createColorImage(), ToolsTest.class, "testSameImageDeltaFrame"); |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * (non-Javadoc) |
| 78 | * @see junit.framework.TestCase#tearDown() |
| 79 | */ |
| 80 | protected void tearDown() |
| 81 | throws Exception { |
| 82 | tools = null; |
| 83 | } |
| 84 | |
| 85 | private RenderedImage createColorImage() { |
| 86 | return tools.createTestImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB, "test", "color image"); |
| 87 | } |
| 88 | |
| 89 | private RenderedImage createGrayImage() { |
| 90 | return tools.createTestImage(IMAGE_WIDTH, 480, BufferedImage.TYPE_BYTE_GRAY, "test", "gray scale image"); |
| 91 | } |
| 92 | |
| 93 | } |