< prev index next >

core/JemmyAWTInput/test/org/jemmy/image/awt/comparator/ComparatorTest.java

Print this page




   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.comparator;
  26 
  27 import java.awt.Color;
  28 import java.io.File;
  29 import java.awt.image.BufferedImage;
  30 import java.io.FileNotFoundException;
  31 import java.io.IOException;
  32 import org.jemmy.image.*;

  33 import org.testng.annotations.AfterClass;
  34 import org.testng.annotations.AfterMethod;
  35 import org.testng.annotations.BeforeClass;
  36 import org.testng.annotations.BeforeMethod;
  37 import org.testng.annotations.Test;
  38 
  39 import static org.testng.Assert.assertNotNull;
  40 import static org.testng.Assert.fail;
  41 
  42 /**
  43  *
  44  * @author shura
  45  */
  46 public class ComparatorTest {
  47 
  48     public ComparatorTest() {
  49     }
  50 
  51     @BeforeClass
  52     public static void setUpClass() throws Exception {


  54 
  55     @AfterClass
  56     public static void tearDownClass() throws Exception {
  57     }
  58 
  59     @BeforeMethod
  60     public void setUp() {
  61     }
  62 
  63     @AfterMethod
  64     public void tearDown() {
  65     }
  66 
  67     // TODO add test methods here.
  68     // The methods must be annotated with annotation @Test. For example:
  69     //
  70     @Test
  71     public void average() {
  72         BufferedImage golden =
  73                 PNGDecoder.decode(getClass().getClassLoader().
  74                 getResourceAsStream("org/jemmy/image/comparator/golden-averagedistance.png"), true);
  75         BufferedImage actual =
  76                 PNGDecoder.decode(getClass().getClassLoader().
  77                 getResourceAsStream("org/jemmy/image/comparator/actual-averagedistance.png"), true);
  78         assertNotNull(new AverageDistanceImageComparator(.001).compare(new AWTImage(golden), new AWTImage(actual)));
  79     }
  80 
  81     @Test
  82     public void strict() {
  83         BufferedImage golden =
  84                 PNGDecoder.decode(getClass().getClassLoader().
  85                 getResourceAsStream("org/jemmy/image/comparator/golden-strict.png"), true);
  86         BufferedImage actual =
  87                 PNGDecoder.decode(getClass().getClassLoader().
  88                 getResourceAsStream("org/jemmy/image/comparator/actual-strict.png"), true);
  89         assertNotNull(new StrictImageComparator().compare(new AWTImage(golden), new AWTImage(actual)));
  90     }
  91 
  92     @Test
  93     public void strict_hyperlink() throws FileNotFoundException, IOException {
  94         BufferedImage golden =
  95                 PNGDecoder.decode(getClass().getClassLoader().
  96                 getResourceAsStream("org/jemmy/image/comparator/golden-hyperlink.png"), true);
  97         BufferedImage actual =
  98                 PNGDecoder.decode(getClass().getClassLoader().
  99                 getResourceAsStream("org/jemmy/image/comparator/actual-hyperlink.png"), true);
 100         BufferedImage diff = ((AWTImage)new StrictImageComparator().compare(new AWTImage(golden), new AWTImage(actual))).getTheImage();
 101         //assertNull(diff);
 102         //barbashov sucks!
 103         //he submits similar images
 104         new PNGEncoder(new File("/tmp/aaa.png")).encode(diff);
 105         assertNotNull(diff);
 106         for (int x = 0; x < diff.getWidth(); x++) {
 107             for (int y = 0; y < diff.getHeight(); y++) {
 108                 /*
 109                 if(new Color(golden.getRGB(x, y)).getAlpha() != 255) {
 110                     System.out.println("Haha!");
 111                 }
 112                 if(new Color(actual.getRGB(x, y)).getAlpha() != 255) {
 113                     System.out.println("Haha!");
 114                 }
 115                  *
 116                  */
 117                 Color color = new Color(diff.getRGB(x, y));
 118                 if (color.getRed() != 0 || color.getGreen() != 0 || color.getBlue() != 0) {
 119                     return;


   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.comparator;
  26 
  27 import java.awt.Color;
  28 import java.io.File;
  29 import java.awt.image.BufferedImage;
  30 import java.io.FileNotFoundException;
  31 import java.io.IOException;
  32 
  33 import org.jemmy.image.awt.*;
  34 import org.testng.annotations.AfterClass;
  35 import org.testng.annotations.AfterMethod;
  36 import org.testng.annotations.BeforeClass;
  37 import org.testng.annotations.BeforeMethod;
  38 import org.testng.annotations.Test;
  39 
  40 import static org.testng.Assert.assertNotNull;
  41 import static org.testng.Assert.fail;
  42 
  43 /**
  44  *
  45  * @author shura
  46  */
  47 public class ComparatorTest {
  48 
  49     public ComparatorTest() {
  50     }
  51 
  52     @BeforeClass
  53     public static void setUpClass() throws Exception {


  55 
  56     @AfterClass
  57     public static void tearDownClass() throws Exception {
  58     }
  59 
  60     @BeforeMethod
  61     public void setUp() {
  62     }
  63 
  64     @AfterMethod
  65     public void tearDown() {
  66     }
  67 
  68     // TODO add test methods here.
  69     // The methods must be annotated with annotation @Test. For example:
  70     //
  71     @Test
  72     public void average() {
  73         BufferedImage golden =
  74                 PNGDecoder.decode(getClass().getClassLoader().
  75                 getResourceAsStream("org/jemmy/image/awt/comparator/golden-averagedistance.png"), true);
  76         BufferedImage actual =
  77                 PNGDecoder.decode(getClass().getClassLoader().
  78                 getResourceAsStream("org/jemmy/image/awt/comparator/actual-averagedistance.png"), true);
  79         assertNotNull(new AverageDistanceImageComparator(.001).compare(new AWTImage(golden), new AWTImage(actual)));
  80     }
  81 
  82     @Test
  83     public void strict() {
  84         BufferedImage golden =
  85                 PNGDecoder.decode(getClass().getClassLoader().
  86                 getResourceAsStream("org/jemmy/image/awt/comparator/golden-strict.png"), true);
  87         BufferedImage actual =
  88                 PNGDecoder.decode(getClass().getClassLoader().
  89                 getResourceAsStream("org/jemmy/image/awt/comparator/actual-strict.png"), true);
  90         assertNotNull(new StrictImageComparator().compare(new AWTImage(golden), new AWTImage(actual)));
  91     }
  92 
  93     @Test
  94     public void strict_hyperlink() throws FileNotFoundException, IOException {
  95         BufferedImage golden =
  96                 PNGDecoder.decode(getClass().getClassLoader().
  97                 getResourceAsStream("org/jemmy/image/awt/comparator/golden-hyperlink.png"), true);
  98         BufferedImage actual =
  99                 PNGDecoder.decode(getClass().getClassLoader().
 100                 getResourceAsStream("org/jemmy/image/awt/comparator/actual-hyperlink.png"), true);
 101         BufferedImage diff = ((AWTImage)new StrictImageComparator().compare(new AWTImage(golden), new AWTImage(actual))).getTheImage();
 102         //assertNull(diff);
 103         //barbashov sucks!
 104         //he submits similar images
 105         new PNGEncoder(new File("/tmp/aaa.png")).encode(diff);
 106         assertNotNull(diff);
 107         for (int x = 0; x < diff.getWidth(); x++) {
 108             for (int y = 0; y < diff.getHeight(); y++) {
 109                 /*
 110                 if(new Color(golden.getRGB(x, y)).getAlpha() != 255) {
 111                     System.out.println("Haha!");
 112                 }
 113                 if(new Color(actual.getRGB(x, y)).getAlpha() != 255) {
 114                     System.out.println("Haha!");
 115                 }
 116                  *
 117                  */
 118                 Color color = new Color(diff.getRGB(x, y));
 119                 if (color.getRed() != 0 || color.getGreen() != 0 || color.getBlue() != 0) {
 120                     return;
< prev index next >