1 /* 2 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package org.jemmy.image.awt; 26 27 import java.awt.image.BufferedImage; 28 29 import org.jemmy.image.Image; 30 import org.jemmy.image.ImageComparator; 31 import org.jemmy.image.awt.AWTImage; 32 import org.jemmy.image.awt.ResizeImageComparator; 33 import org.jemmy.image.awt.ResizeImageComparator.ResizeMode; 34 import org.jemmy.image.awt.StrictImageComparator; 35 import org.testng.annotations.AfterClass; 36 import org.testng.annotations.AfterMethod; 37 import org.testng.annotations.BeforeClass; 38 import org.testng.annotations.BeforeMethod; 39 import org.testng.annotations.Test; 40 41 import static org.testng.Assert.assertNull; 42 import static org.testng.AssertJUnit.assertEquals; 43 44 /** 45 * 46 * @author mrkam 47 */ 48 public class ImageResizerTest { 49 50 public ImageResizerTest() { 51 } 52 53 @BeforeClass 54 public static void setUpClass() throws Exception { 55 } 56 57 @AfterClass 58 public static void tearDownClass() throws Exception { 59 } 60 61 @BeforeMethod 62 public void setUp() { 63 } 64 65 @AfterMethod 66 public void tearDown() { 67 } 68 69 /** 70 * Test of default value of ResizeMode, of class ImageResizer. 71 */ 72 @Test 73 public void testDefaultResizeMode() { 74 System.out.println("testDefaultResizeMode"); 75 ResizeMode expResult = ResizeMode.PROPORTIONAL_RESIZE; 76 ResizeMode result = new ResizeImageComparator(null).resizeMode; 77 assertEquals(expResult, result); 78 } 79 80 /** 81 * Test of setDefaultResizeMode method, of class ImageResizer. 82 */ 83 @Test 84 public void testProportionalResizeMode() { 85 System.out.println("testProportionalResizeMode"); 86 87 new ResizeImageComparator(new ImageComparator() { 88 89 public Image compare(Image image1, 90 Image image2) { 91 assertEquals(50, ((AWTImage) image2).getSize().width); 92 assertEquals(50, ((AWTImage) image2).getSize().height); 93 return null; 94 } 95 96 public String getID() { 97 return "test"; 98 } 99 }).compare(new AWTImage(new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB)), 100 new AWTImage(new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB))); 101 } 102 103 /** 104 * Test of getResized method, of class ImageResizer. 105 */ 106 @Test 107 public void testGetResizedNoResize() { 108 System.out.println("getResizedNoResize"); 109 final AWTImage image1 = 110 new AWTImage(new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB)); 111 final AWTImage image2 = 112 new AWTImage(new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB)); 113 114 new ResizeImageComparator(ResizeMode.NO_RESIZE, new ImageComparator() { 115 116 public Image compare(Image im1, 117 Image im2) { 118 assertEquals(image1, im1); 119 assertEquals(image2, im2); 120 return null; 121 } 122 123 public String getID() { 124 return "test"; 125 } 126 }).compare(image1, image2); 127 } 128 129 /** 130 * Test of getResized method, of class ImageResizer. 131 */ 132 @Test 133 public void testGetResizedProportional1() { 134 System.out.println("getResizedProportional1"); 135 BufferedImage image1 = 136 new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); 137 BufferedImage image2 = 138 new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); 139 assertNull(new ResizeImageComparator(ResizeMode.PROPORTIONAL_RESIZE, 140 new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2))); 141 } 142 143 /** 144 * Test of getResized method, of class ImageResizer. 145 */ 146 @Test 147 public void testGetResizedProportional2() { 148 System.out.println("getResizedProportional2"); 149 BufferedImage image1 = 150 new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); 151 BufferedImage image2 = 152 new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB); 153 assertNull(new ResizeImageComparator(ResizeMode.PROPORTIONAL_RESIZE, 154 new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2))); 155 } 156 157 /** 158 * Test of getResized method, of class ImageResizer. 159 */ 160 @Test 161 public void testGetResizedProportional3() { 162 System.out.println("getResizedProportional3"); 163 final AWTImage image1 = 164 new AWTImage(new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB)); 165 final AWTImage image2 = 166 new AWTImage(new BufferedImage(10, 15, BufferedImage.TYPE_INT_RGB)); 167 new ResizeImageComparator(ResizeMode.PROPORTIONAL_RESIZE, 168 new ImageComparator() { 169 170 public Image compare(Image im1, 171 Image im2) { 172 assertEquals(image1, im1); 173 assertEquals(image2, im2); 174 return null; 175 } 176 177 public String getID() { 178 return "test"; 179 } 180 }).compare(image1, image2); 181 } 182 183 /** 184 * Test of getResized method, of class ImageResizer. 185 */ 186 @Test 187 public void testGetResizedArbitrary1() { 188 System.out.println("getResizedArbitrary1"); 189 BufferedImage image1 = 190 new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); 191 BufferedImage image2 = 192 new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); 193 assertNull(new ResizeImageComparator(ResizeMode.ARBITRARY_RESIZE, 194 new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2))); 195 } 196 197 /** 198 * Test of getResized method, of class ImageResizer. 199 */ 200 @Test 201 public void testGetResizedArbitrary2() { 202 System.out.println("getResizedArbitrary2"); 203 BufferedImage image1 = 204 new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); 205 BufferedImage image2 = 206 new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB); 207 assertNull(new ResizeImageComparator(ResizeMode.ARBITRARY_RESIZE, 208 new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2))); 209 } 210 211 /** 212 * Test of getResized method, of class ImageResizer. 213 */ 214 @Test 215 public void testGetResizedArbitrary3() { 216 System.out.println("getResizedArbitrary3"); 217 BufferedImage image1 = 218 new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); 219 BufferedImage image2 = 220 new BufferedImage(10, 15, BufferedImage.TYPE_INT_RGB); 221 assertNull(new ResizeImageComparator(ResizeMode.ARBITRARY_RESIZE, 222 new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2))); 223 } 224 }