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.pixel; 26 27 import org.jemmy.env.Environment; 28 import org.jemmy.image.Image; 29 import org.jemmy.image.pixel.Raster.Component; 30 import org.testng.Assert; 31 import org.testng.AssertJUnit; 32 import org.testng.annotations.BeforeClass; 33 import org.testng.annotations.BeforeMethod; 34 import org.testng.annotations.Test; 35 36 37 public class PixelImageComparatorTest { 38 39 private static Component[] supportedComps; 40 41 private PixelImageComparator comparator; 42 43 @BeforeClass 44 public static void setUpClass() throws Exception { 45 supportedComps = new Component[] { 46 Component.RED, Component.GREEN, Component.BLUE, Component.ALPHA 47 }; 48 } 49 50 @BeforeMethod 51 public void setUp() { 52 comparator = new PixelImageComparator(new Environment()) { 53 @Override 54 protected Image toImage(Raster image) { 55 throw new UnsupportedOperationException("Not supported yet."); 56 } 57 58 @Override 59 protected Raster toRaster(Image image) { 60 throw new UnsupportedOperationException("Not supported yet."); 61 } 62 63 @Override 64 protected WriteableRaster createDiffRaster(Raster r1, Raster r2) { 65 throw new UnsupportedOperationException("Not supported yet."); 66 } 67 }; 68 } 69 70 @Test 71 public void testGetComponentsValueFunction() { 72 //Translucent colors 73 final double alpha = 0.5; 74 double[] black = new double[] { 0.0, 0.0, 0.0, alpha }; 75 double[] white = new double[] { 1.0, 1.0, 1.0, alpha }; 76 double result; 77 78 result = comparator.getComponentValue(supportedComps, black, Component.RED); 79 AssertJUnit.assertEquals(0.5, result, 0.001); 80 81 result = comparator.getComponentValue(supportedComps, white, Component.RED); 82 AssertJUnit.assertEquals(1.0, result, 0.001); 83 84 //Opaque colors 85 black = new double[] { 0.0, 0.0, 0.0, 1.0 }; 86 white = new double[] { 1.0, 1.0, 1.0, 1.0 }; 87 88 result = comparator.getComponentValue(supportedComps, black, Component.RED); 89 AssertJUnit.assertEquals(0.0, result, 0.001); 90 91 result = comparator.getComponentValue(supportedComps, white, Component.RED); 92 AssertJUnit.assertEquals(1.0, result, 0.001); 93 94 //Transparent colors 95 black = new double[] { 0.0, 0.0, 0.0, 0.0 }; 96 white = new double[] { 1.0, 1.0, 1.0, 0.0 }; 97 98 result = comparator.getComponentValue(supportedComps, black, Component.RED); 99 AssertJUnit.assertEquals(1.0, result, 0.001); 100 101 result = comparator.getComponentValue(supportedComps, white, Component.RED); 102 AssertJUnit.assertEquals(1.0, result, 0.001); 103 } 104 105 @Test(expectedExceptions = IllegalStateException.class) 106 public void testAlphaOutOfBounds() { 107 double[] colors = new double[] { 0.0, 0.0, 0.1, 1.1 }; 108 comparator.getComponentValue(supportedComps, colors, Component.RED); 109 } 110 111 @Test(expectedExceptions = IllegalStateException.class) 112 public void testColorComponentOutOfBounds() { 113 double[] colors = new double[] { 1.1, 1.1, 1.1, 1.0 }; 114 comparator.getComponentValue(supportedComps, colors, Component.RED); 115 } 116 }