ColorModel
implementation.
- *
- * @author Alexandre Iline (alexandre.iline@sun.com)
- * @deprecated Use classes form org.jemmy.image.pixel instead.
- */
-@Deprecated
-public class ColorImageComparator implements ImageComparator {
-
- ColorMap leftMap, rightMap;
- ImageComparator comparator = null;
-
- /**
- * Creates a comparator with a color maps. Object created by this
- * constructor behaves like
- * StrictImageComparator
. Object created works faster because
- * it does not create intermediate images for another comparator.
- *
- * @param map Map applied to both left and right images during comparision.
- */
- public ColorImageComparator(ColorMap map) {
- this(map, new StrictImageComparator());
- }
-
- /**
- * Creates a comparator with
- * map
color mapping. Actual comparision perfomed by
- * comparator
parameter.
- *
- * @param map Map applied to both left and right images during comparision.
- * @param subComparator comporator to perform a comparision of to images
- * with mapped colors.
- */
- public ColorImageComparator(ColorMap map, ImageComparator subComparator) {
- this(map, map, subComparator);
- }
-
- /**
- * Creates a comparator with two color maps. Object created by this
- * constructor behaves like
- * StrictImageComparator
. Object created works faster because
- * it does not create intermediate images for another comparator.
- *
- * @param leftMap Map applied to the left image during comparision.
- * @param rightMap Map applied to the right image during comparision.
- */
- public ColorImageComparator(ColorMap leftMap, ColorMap rightMap) {
- this(leftMap, rightMap, new BufferedImageComparator(new PixelEqualityRasterComparator(0)));
- }
-
- /**
- * Creates a comparator with two color maps. Actual comparision perfomed by
- * comparator
parameter.
- *
- * @param leftMap Map applied to the left image during comparision.
- * @param rightMap Map applied to the right image during comparision.
- * @param subComparator comporator to perform a comparision of to images
- * with mapped colors.
- */
- public ColorImageComparator(ColorMap leftMap, ColorMap rightMap, ImageComparator subComparator) {
- this.leftMap = leftMap;
- this.rightMap = rightMap;
- this.comparator = subComparator;
- }
-
- /**
- * Compares images by
- * ImageComparator
passed into constructor, or itself if no
- * ImageComparator
was passed, processing both images by
- * ColorMap
instance before comparision.
- */
- @Override
- public Image compare(Image image1, Image image2) {
- return (comparator.compare(
- recolor((AWTImage)image1, leftMap),
- recolor((AWTImage)image2, rightMap)));
- }
-
- private AWTImage recolor(AWTImage isrc, ColorMap map) {
- BufferedImage src = isrc.getTheImage();
- BufferedImage result = new BufferedImage(src.getWidth(), src.getHeight(), src.getType());
- for (int x = 0; x < src.getWidth(); x++) {
- for (int y = 0; y < src.getWidth(); y++) {
- result.setRGB(x, y, map.mapColor(src.getRGB(x, y)));
- }
- }
- return new AWTImage(result);
- }
-
- protected final boolean compareColors(int rgb1, int rgb2) {
- return (leftMap.mapColor(rgb1) == rightMap.mapColor(rgb2));
- }
-
- public String getID() {
- return ColorImageComparator.class.getName();
- }
-
- /**
- * Interface to map colors during the comparision.
- */
- public static interface ColorMap {
-
- /**
- * Maps one color into another.
- *
- * @param rgb an original color.
- * @return a converted color.
- */
- public int mapColor(int rgb);
- }
-
- /**
- * Turns
- * foreground
color to white, other - to black.
- */
- public static class ForegroundColorMap implements ColorMap {
-
- int foreground;
-
- /**
- * Constructs a ColorImageComparator$ForegroundColorMap object.
- *
- * @param foreground Foreground color.
- */
- public ForegroundColorMap(int foreground) {
- this.foreground = foreground;
- }
-
- public int mapColor(int rgb) {
- return ((rgb == foreground) ? 0xffffff : 0);
- }
- }
-
- /**
- * Turns
- * background
color to black, left others unchanged.
- */
- public static class BackgroundColorMap implements ColorMap {
-
- int background;
-
- /**
- * Constructs a ColorImageComparator$BackgroundColorMap object.
- *
- * @param background Background color.
- */
- public BackgroundColorMap(int background) {
- this.background = background;
- }
-
- public int mapColor(int rgb) {
- return ((rgb == background) ? 0 : rgb);
- }
- }
-}
--- /dev/null 2019-03-06 17:23:07.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/image/awt/ColorImageComparator.java 2019-03-06 17:23:07.000000000 -0800
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+import java.awt.image.BufferedImage;
+
+import org.jemmy.image.Image;
+import org.jemmy.image.ImageComparator;
+import org.jemmy.image.pixel.PixelEqualityRasterComparator;
+
+/**
+ * Compares two images with color mapping defined by
+ * ColorModel
implementation.
+ *
+ * @author Alexandre Iline (alexandre.iline@sun.com)
+ * @deprecated Use classes form org.jemmy.image.pixel instead.
+ */
+@Deprecated
+public class ColorImageComparator implements ImageComparator {
+
+ ColorMap leftMap, rightMap;
+ ImageComparator comparator = null;
+
+ /**
+ * Creates a comparator with a color maps. Object created by this
+ * constructor behaves like
+ * StrictImageComparator
. Object created works faster because
+ * it does not create intermediate images for another comparator.
+ *
+ * @param map Map applied to both left and right images during comparision.
+ */
+ public ColorImageComparator(ColorMap map) {
+ this(map, new StrictImageComparator());
+ }
+
+ /**
+ * Creates a comparator with
+ * map
color mapping. Actual comparision perfomed by
+ * comparator
parameter.
+ *
+ * @param map Map applied to both left and right images during comparision.
+ * @param subComparator comporator to perform a comparision of to images
+ * with mapped colors.
+ */
+ public ColorImageComparator(ColorMap map, ImageComparator subComparator) {
+ this(map, map, subComparator);
+ }
+
+ /**
+ * Creates a comparator with two color maps. Object created by this
+ * constructor behaves like
+ * StrictImageComparator
. Object created works faster because
+ * it does not create intermediate images for another comparator.
+ *
+ * @param leftMap Map applied to the left image during comparision.
+ * @param rightMap Map applied to the right image during comparision.
+ */
+ public ColorImageComparator(ColorMap leftMap, ColorMap rightMap) {
+ this(leftMap, rightMap, new BufferedImageComparator(new PixelEqualityRasterComparator(0)));
+ }
+
+ /**
+ * Creates a comparator with two color maps. Actual comparision perfomed by
+ * comparator
parameter.
+ *
+ * @param leftMap Map applied to the left image during comparision.
+ * @param rightMap Map applied to the right image during comparision.
+ * @param subComparator comporator to perform a comparision of to images
+ * with mapped colors.
+ */
+ public ColorImageComparator(ColorMap leftMap, ColorMap rightMap, ImageComparator subComparator) {
+ this.leftMap = leftMap;
+ this.rightMap = rightMap;
+ this.comparator = subComparator;
+ }
+
+ /**
+ * Compares images by
+ * ImageComparator
passed into constructor, or itself if no
+ * ImageComparator
was passed, processing both images by
+ * ColorMap
instance before comparision.
+ */
+ @Override
+ public Image compare(Image image1, Image image2) {
+ return (comparator.compare(
+ recolor((AWTImage)image1, leftMap),
+ recolor((AWTImage)image2, rightMap)));
+ }
+
+ private AWTImage recolor(AWTImage isrc, ColorMap map) {
+ BufferedImage src = isrc.getTheImage();
+ BufferedImage result = new BufferedImage(src.getWidth(), src.getHeight(), src.getType());
+ for (int x = 0; x < src.getWidth(); x++) {
+ for (int y = 0; y < src.getWidth(); y++) {
+ result.setRGB(x, y, map.mapColor(src.getRGB(x, y)));
+ }
+ }
+ return new AWTImage(result);
+ }
+
+ protected final boolean compareColors(int rgb1, int rgb2) {
+ return (leftMap.mapColor(rgb1) == rightMap.mapColor(rgb2));
+ }
+
+ public String getID() {
+ return ColorImageComparator.class.getName();
+ }
+
+ /**
+ * Interface to map colors during the comparision.
+ */
+ public static interface ColorMap {
+
+ /**
+ * Maps one color into another.
+ *
+ * @param rgb an original color.
+ * @return a converted color.
+ */
+ public int mapColor(int rgb);
+ }
+
+ /**
+ * Turns
+ * foreground
color to white, other - to black.
+ */
+ public static class ForegroundColorMap implements ColorMap {
+
+ int foreground;
+
+ /**
+ * Constructs a ColorImageComparator$ForegroundColorMap object.
+ *
+ * @param foreground Foreground color.
+ */
+ public ForegroundColorMap(int foreground) {
+ this.foreground = foreground;
+ }
+
+ public int mapColor(int rgb) {
+ return ((rgb == foreground) ? 0xffffff : 0);
+ }
+ }
+
+ /**
+ * Turns
+ * background
color to black, left others unchanged.
+ */
+ public static class BackgroundColorMap implements ColorMap {
+
+ int background;
+
+ /**
+ * Constructs a ColorImageComparator$BackgroundColorMap object.
+ *
+ * @param background Background color.
+ */
+ public BackgroundColorMap(int background) {
+ this.background = background;
+ }
+
+ public int mapColor(int rgb) {
+ return ((rgb == background) ? 0 : rgb);
+ }
+ }
+}
--- old/core/JemmyAWTInput/src/org/jemmy/image/DiffDialog.form 2019-03-06 17:23:08.000000000 -0800
+++ /dev/null 2019-03-06 17:23:08.000000000 -0800
@@ -1,259 +0,0 @@
-
-
-
-
--- /dev/null 2019-03-06 17:23:08.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/image/awt/DiffDialog.form 2019-03-06 17:23:08.000000000 -0800
@@ -0,0 +1,259 @@
+
+
+
+
--- old/core/JemmyAWTInput/src/org/jemmy/image/DiffDialog.java 2019-03-06 17:23:08.000000000 -0800
+++ /dev/null 2019-03-06 17:23:08.000000000 -0800
@@ -1,395 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Toolkit;
-import java.awt.event.ComponentEvent;
-import java.awt.event.ComponentListener;
-import java.awt.image.BufferedImage;
-import javax.swing.JDialog;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-
-/**
- *
- * @author shura
- */
-public class DiffDialog extends javax.swing.JDialog {
-
- private final static StrictImageComparator comparator = new StrictImageComparator();
- private double scale = 1.0;
- private int imageWidth, imageHeight, scaledWidth, scaledHeight;
- private ImagePane left = null, right = null, diff = null;
- int status = 0;
-
- /** Creates new form ImageDiff */
- DiffDialog() {
- super((JDialog)null, true);
- initComponents();
- leftPane.setLayout(new BorderLayout());
- leftPane.add(new JLabel("Golden"), BorderLayout.NORTH);
- rightPane.setLayout(new BorderLayout());
- rightPane.add(new JLabel("Result"), BorderLayout.NORTH);
- diffPane.setLayout(new BorderLayout());
- diffPane.add(new JLabel("Diff"), BorderLayout.NORTH);
- getContentPane().addComponentListener(new ComponentListener() {
-
- public void componentResized(ComponentEvent e) {
- lrSplit.setDividerLocation(.5);
- dcSplit.setDividerLocation(.5);
- tbSplit.setDividerLocation(.5);
- }
-
- public void componentMoved(ComponentEvent e) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public void componentShown(ComponentEvent e) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public void componentHidden(ComponentEvent e) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
- });
- setSize(400, 300);
-
- // Get the size of the screen
- Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
-
- // Determine the new location of the window
- int w = getSize().width;
- int h = getSize().height;
- int x = (dim.width - w) / 2;
- int y = (dim.height - h) / 2;
-
- // Move the window
- setLocation(x, y);
- }
-
- void setImages(BufferedImage leftImage, BufferedImage rightImage) {
- if (leftImage != null && rightImage != null) {
- copyBtn.setEnabled(true);
- removeBtn.setEnabled(false);
- imageWidth = leftImage.getWidth();
- imageHeight = leftImage.getHeight();
- } else {
- if (leftImage == null) {
- copyBtn.setEnabled(true);
- removeBtn.setEnabled(false);
- imageWidth = rightImage.getWidth();
- imageHeight = rightImage.getHeight();
- } else if (rightImage == null) {
- copyBtn.setEnabled(false);
- removeBtn.setEnabled(true);
- imageWidth = leftImage.getWidth();
- imageHeight = leftImage.getHeight();
- }
- }
- if (left == null) {
- left = new ImagePane(leftImage);
- } else {
- left.setImage(leftImage);
- }
- leftPane.add(left, BorderLayout.CENTER);
- if (right == null) {
- right = new ImagePane(rightImage);
- } else {
- right.setImage(rightImage);
- }
- rightPane.add(right, BorderLayout.CENTER);
- if (diff == null) {
- diff = new ImagePane(subtract(leftImage, rightImage));
- } else {
- diff.setImage(subtract(leftImage, rightImage));
- }
- diffPane.add(diff, BorderLayout.CENTER);
- rescaleAll();
- }
-
- private BufferedImage subtract(BufferedImage left, BufferedImage right) {
- if(left != null && right != null) {
- return ImageTool.subtractImage(left, right);
- } else {
- return null;
- }
- }
-
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // - * Resize Mode - defines way of resizing images that are being compared. One of the following constants: - *
- * Threshold value is applied in the following way: {@code Math.abs(image.getSize() * scale - * - size) / image.getSize() > PROPORTION_DISTORTION_THRESHOLD}, where {@code image.getSize()} - * is both image dimensions and {@code size} is target width and height (which - * is defined as mininum of sizes of two images) and scale is the scale factor - * that scales the particular image to fit the width and height. - *
- * Default value is 0.02 so as much as 2% of width/height could differ (around 5 - * in 0-255 color component values).
+ * Resize Mode - defines way of resizing images that are being compared. One of the following constants: + *
+ * Threshold value is applied in the following way: {@code Math.abs(image.getSize() * scale + * - size) / image.getSize() > PROPORTION_DISTORTION_THRESHOLD}, where {@code image.getSize()} + * is both image dimensions and {@code size} is target width and height (which + * is defined as mininum of sizes of two images) and scale is the scale factor + * that scales the particular image to fit the width and height. + *
+ * Default value is 0.02 so as much as 2% of width/height could differ (around 5 + * in 0-255 color component values).
roughness
allowed roughness.
- *
- * @param roughness Allowed comparision roughness.
- */
- public RoughImageComparator(double roughness) {
- super(new PixelEqualityRasterComparator(roughness));
- }
- public void setRoughness(double roughness) {
- ((PixelEqualityRasterComparator)getRasterComparator()).setThreshold(roughness);
- }
- public double getRoughness() {
- return ((PixelEqualityRasterComparator)getRasterComparator()).getThreshold();
- }
-}
--- /dev/null 2019-03-06 17:23:15.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/image/awt/RoughImageComparator.java 2019-03-06 17:23:15.000000000 -0800
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+import org.jemmy.image.pixel.PixelEqualityRasterComparator;
+
+/**
+ * Compares two images roughly (i.e. not all of the pixel colors should match).
+ *
+ * @author shura
+ * @author mrkam
+ */
+public class RoughImageComparator extends BufferedImageComparator {
+
+ /**
+ * Creates a comparator with
+ * roughness
allowed roughness.
+ *
+ * @param roughness Allowed comparision roughness.
+ */
+ public RoughImageComparator(double roughness) {
+ super(new PixelEqualityRasterComparator(roughness));
+ }
+ public void setRoughness(double roughness) {
+ ((PixelEqualityRasterComparator)getRasterComparator()).setThreshold(roughness);
+ }
+ public double getRoughness() {
+ return ((PixelEqualityRasterComparator)getRasterComparator()).getThreshold();
+ }
+}
--- old/core/JemmyAWTInput/src/org/jemmy/image/RoughImageFinder.java 2019-03-06 17:23:16.000000000 -0800
+++ /dev/null 2019-03-06 17:23:16.000000000 -0800
@@ -1,102 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-import org.jemmy.Point;
-import java.awt.image.BufferedImage;
-
-/**
- * Performs "rough" image search.
- *
- * @author shura
- */
-public class RoughImageFinder implements ImageFinder {
- double roughness = .0;
- int bigWidth, bigHeight;
- int[][] bigPixels;
-
- /**
- * Creates an instance allowing to find an image inside the one
- * passed as parameter with some "roughness".
- * @param area - Image to search in.
- * @param roughness - Allowed
- */
- public RoughImageFinder(BufferedImage area, double roughness) {
- this.roughness = roughness;
- bigWidth = area.getWidth();
- bigHeight = area.getHeight();
- bigPixels = new int[bigWidth][bigHeight];
- for(int x = 0; x < bigWidth; x++) {
- for(int y = 0; y < bigHeight; y++) {
- bigPixels[x][y] = area.getRGB(x, y);
- }
- }
- }
-
- /**
- * Performs "rough" search.
- * @param image an image to search.
- * @param index an ordinal image location index.
- * @return Point where number of unmatching pixels less or equal to
- * image1.getWidth() * image1.getHeight() * roughness
- */
- public Point findImage(BufferedImage image, int index) {
- int smallWidth = image.getWidth();
- int smallHeight = image.getHeight();
- int[][] smallPixels = new int[smallWidth][smallHeight];
- for(int x = 0; x < smallWidth; x++) {
- for(int y = 0; y < smallHeight; y++) {
- smallPixels[x][y] = image.getRGB(x, y);
- }
- }
- double maxRoughPixels = (double)(smallWidth * smallHeight) * roughness;
- int count = 0;
- for(int X = 0; X <= bigWidth - smallWidth; X++) {
- for(int Y = 0; Y <= bigHeight - smallHeight; Y++) {
- int roughPixels = 0;
- for(int x = 0; x < smallWidth; x++) {
- for(int y = 0; y < smallHeight; y++) {
- if(smallPixels[x][y] != bigPixels[X + x][Y + y]) {
- roughPixels++;
- if(roughPixels > maxRoughPixels) {
- break;
- }
- }
- }
- if(roughPixels > maxRoughPixels) {
- break;
- }
- }
- if(roughPixels <= maxRoughPixels) {
- if(count == index) {
- return(new Point(X, Y));
- }
- count++;
- }
- }
- }
- return(null);
- }
-}
--- /dev/null 2019-03-06 17:23:16.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/image/awt/RoughImageFinder.java 2019-03-06 17:23:16.000000000 -0800
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+import org.jemmy.Point;
+import java.awt.image.BufferedImage;
+
+/**
+ * Performs "rough" image search.
+ *
+ * @author shura
+ */
+public class RoughImageFinder implements ImageFinder {
+ double roughness = .0;
+ int bigWidth, bigHeight;
+ int[][] bigPixels;
+
+ /**
+ * Creates an instance allowing to find an image inside the one
+ * passed as parameter with some "roughness".
+ * @param area - Image to search in.
+ * @param roughness - Allowed
+ */
+ public RoughImageFinder(BufferedImage area, double roughness) {
+ this.roughness = roughness;
+ bigWidth = area.getWidth();
+ bigHeight = area.getHeight();
+ bigPixels = new int[bigWidth][bigHeight];
+ for(int x = 0; x < bigWidth; x++) {
+ for(int y = 0; y < bigHeight; y++) {
+ bigPixels[x][y] = area.getRGB(x, y);
+ }
+ }
+ }
+
+ /**
+ * Performs "rough" search.
+ * @param image an image to search.
+ * @param index an ordinal image location index.
+ * @return Point where number of unmatching pixels less or equal to
+ * image1.getWidth() * image1.getHeight() * roughness
+ */
+ public Point findImage(BufferedImage image, int index) {
+ int smallWidth = image.getWidth();
+ int smallHeight = image.getHeight();
+ int[][] smallPixels = new int[smallWidth][smallHeight];
+ for(int x = 0; x < smallWidth; x++) {
+ for(int y = 0; y < smallHeight; y++) {
+ smallPixels[x][y] = image.getRGB(x, y);
+ }
+ }
+ double maxRoughPixels = (double)(smallWidth * smallHeight) * roughness;
+ int count = 0;
+ for(int X = 0; X <= bigWidth - smallWidth; X++) {
+ for(int Y = 0; Y <= bigHeight - smallHeight; Y++) {
+ int roughPixels = 0;
+ for(int x = 0; x < smallWidth; x++) {
+ for(int y = 0; y < smallHeight; y++) {
+ if(smallPixels[x][y] != bigPixels[X + x][Y + y]) {
+ roughPixels++;
+ if(roughPixels > maxRoughPixels) {
+ break;
+ }
+ }
+ }
+ if(roughPixels > maxRoughPixels) {
+ break;
+ }
+ }
+ if(roughPixels <= maxRoughPixels) {
+ if(count == index) {
+ return(new Point(X, Y));
+ }
+ count++;
+ }
+ }
+ }
+ return(null);
+ }
+}
--- old/core/JemmyAWTInput/src/org/jemmy/image/StrictImageComparator.java 2019-03-06 17:23:17.000000000 -0800
+++ /dev/null 2019-03-06 17:23:17.000000000 -0800
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-import org.jemmy.image.pixel.PixelEqualityRasterComparator;
-
-/**
- * Compares two images strictly (i.e. all the pixel colors should match).
- *
- * @author shura
- * @author mrkam
- */
-public class StrictImageComparator extends BufferedImageComparator {
-
- public StrictImageComparator() {
- super(new PixelEqualityRasterComparator(0));
- }
-
-}
--- /dev/null 2019-03-06 17:23:17.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/image/awt/StrictImageComparator.java 2019-03-06 17:23:17.000000000 -0800
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+import org.jemmy.image.pixel.PixelEqualityRasterComparator;
+
+/**
+ * Compares two images strictly (i.e. all the pixel colors should match).
+ *
+ * @author shura
+ * @author mrkam
+ */
+public class StrictImageComparator extends BufferedImageComparator {
+
+ public StrictImageComparator() {
+ super(new PixelEqualityRasterComparator(0));
+ }
+
+}
--- old/core/JemmyAWTInput/src/org/jemmy/image/StrictImageFinder.java 2019-03-06 17:23:17.000000000 -0800
+++ /dev/null 2019-03-06 17:23:18.000000000 -0800
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-import org.jemmy.Point;
-import java.awt.image.BufferedImage;
-
-/**
- * Performs "strict" (i.e. based on all pixels matching) image search.
- *
- * @author Alexandre Iline (alexandre.iline@sun.com)
- */
-public class StrictImageFinder implements ImageFinder {
- int bigWidth, bigHeight;
- int[][] bigPixels;
-
- /**
- * Creates an instance searching subimages insige a parameter image.
- * @param area - Image to search in.
- */
- public StrictImageFinder(BufferedImage area) {
- bigWidth = area.getWidth();
- bigHeight = area.getHeight();
- bigPixels = new int[bigWidth][bigHeight];
- for(int x = 0; x < bigWidth; x++) {
- for(int y = 0; y < bigHeight; y++) {
- bigPixels[x][y] = area.getRGB(x, y);
- }
- }
- }
-
- /**
- * Searchs for an image inside image passed into constructor.
- * @param image an image to search.
- * @param index an ordinal image location index. If equal to 1, for example,
- * second appropriate location will be found.
- * @return Left-up corner coordinates of image location.
- */
- public Point findImage(BufferedImage image, int index) {
- int smallWidth = image.getWidth();
- int smallHeight = image.getHeight();
- int[][] smallPixels = new int[smallWidth][smallHeight];
- for(int x = 0; x < smallWidth; x++) {
- for(int y = 0; y < smallHeight; y++) {
- smallPixels[x][y] = image.getRGB(x, y);
- }
- }
- boolean good;
- int count = 0;
- for(int X = 0; X <= bigWidth - smallWidth; X++) {
- for(int Y = 0; Y <= bigHeight - smallHeight; Y++) {
- good = true;
- for(int x = 0; x < smallWidth; x++) {
- for(int y = 0; y < smallHeight; y++) {
- if(smallPixels[x][y] != bigPixels[X + x][Y + y]) {
- good = false;
- break;
- }
- }
- if(!good) {
- break;
- }
- }
- if(good) {
- if(count == index) {
- return(new Point(X, Y));
- }
- count++;
- }
- }
- }
- return(null);
- }
-}
--- /dev/null 2019-03-06 17:23:18.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/image/awt/StrictImageFinder.java 2019-03-06 17:23:17.000000000 -0800
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+import org.jemmy.Point;
+import java.awt.image.BufferedImage;
+
+/**
+ * Performs "strict" (i.e. based on all pixels matching) image search.
+ *
+ * @author Alexandre Iline (alexandre.iline@sun.com)
+ */
+public class StrictImageFinder implements ImageFinder {
+ int bigWidth, bigHeight;
+ int[][] bigPixels;
+
+ /**
+ * Creates an instance searching subimages insige a parameter image.
+ * @param area - Image to search in.
+ */
+ public StrictImageFinder(BufferedImage area) {
+ bigWidth = area.getWidth();
+ bigHeight = area.getHeight();
+ bigPixels = new int[bigWidth][bigHeight];
+ for(int x = 0; x < bigWidth; x++) {
+ for(int y = 0; y < bigHeight; y++) {
+ bigPixels[x][y] = area.getRGB(x, y);
+ }
+ }
+ }
+
+ /**
+ * Searchs for an image inside image passed into constructor.
+ * @param image an image to search.
+ * @param index an ordinal image location index. If equal to 1, for example,
+ * second appropriate location will be found.
+ * @return Left-up corner coordinates of image location.
+ */
+ public Point findImage(BufferedImage image, int index) {
+ int smallWidth = image.getWidth();
+ int smallHeight = image.getHeight();
+ int[][] smallPixels = new int[smallWidth][smallHeight];
+ for(int x = 0; x < smallWidth; x++) {
+ for(int y = 0; y < smallHeight; y++) {
+ smallPixels[x][y] = image.getRGB(x, y);
+ }
+ }
+ boolean good;
+ int count = 0;
+ for(int X = 0; X <= bigWidth - smallWidth; X++) {
+ for(int Y = 0; Y <= bigHeight - smallHeight; Y++) {
+ good = true;
+ for(int x = 0; x < smallWidth; x++) {
+ for(int y = 0; y < smallHeight; y++) {
+ if(smallPixels[x][y] != bigPixels[X + x][Y + y]) {
+ good = false;
+ break;
+ }
+ }
+ if(!good) {
+ break;
+ }
+ }
+ if(good) {
+ if(count == index) {
+ return(new Point(X, Y));
+ }
+ count++;
+ }
+ }
+ }
+ return(null);
+ }
+}
--- old/core/JemmyAWTInput/src/org/jemmy/image/Utils.java 2019-03-06 17:23:18.000000000 -0800
+++ /dev/null 2019-03-06 17:23:18.000000000 -0800
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-
-import org.jemmy.Dimension;
-import org.jemmy.Point;
-import org.jemmy.Rectangle;
-
-
-/**
- *
- * @author mrkam
- */
-public class Utils {
-
- public static java.awt.Rectangle convert(Rectangle r) {
- return new java.awt.Rectangle(r.x, r.y, r.width, r.height);
- }
-
- public static Rectangle convert(java.awt.Rectangle r) {
- return new Rectangle(r.x, r.y, r.width, r.height);
- }
-
- public static java.awt.Point convert(Point p) {
- return new java.awt.Point(p.x, p.y);
- }
-
- public static Point convert(java.awt.Point p) {
- return new Point(p.x, p.y);
- }
-
- public static java.awt.Dimension convert(Dimension d) {
- return new java.awt.Dimension(d.width, d.height);
- }
-
- public static Dimension convert(java.awt.Dimension d) {
- return new Dimension(d.width, d.height);
- }
-
-}
--- /dev/null 2019-03-06 17:23:18.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/image/awt/Utils.java 2019-03-06 17:23:18.000000000 -0800
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+
+import org.jemmy.Dimension;
+import org.jemmy.Point;
+import org.jemmy.Rectangle;
+
+
+/**
+ *
+ * @author mrkam
+ */
+public class Utils {
+
+ public static java.awt.Rectangle convert(Rectangle r) {
+ return new java.awt.Rectangle(r.x, r.y, r.width, r.height);
+ }
+
+ public static Rectangle convert(java.awt.Rectangle r) {
+ return new Rectangle(r.x, r.y, r.width, r.height);
+ }
+
+ public static java.awt.Point convert(Point p) {
+ return new java.awt.Point(p.x, p.y);
+ }
+
+ public static Point convert(java.awt.Point p) {
+ return new Point(p.x, p.y);
+ }
+
+ public static java.awt.Dimension convert(Dimension d) {
+ return new java.awt.Dimension(d.width, d.height);
+ }
+
+ public static Dimension convert(java.awt.Dimension d) {
+ return new Dimension(d.width, d.height);
+ }
+
+}
--- old/core/JemmyAWTInput/src/org/jemmy/image/package.html 2019-03-06 17:23:19.000000000 -0800
+++ /dev/null 2019-03-06 17:23:19.000000000 -0800
@@ -1,17 +0,0 @@
-
-
-
- main(java.lang.String[])
method
- * with a zero-length java.lang.String
array
- * as a parameter.
- *
- * @throws NoSuchMethodException when the method cannot be found.
- * @throws InvocationTargetException when the invoked method throws an exception.
- */
- public void startApplication()
- throws InvocationTargetException, NoSuchMethodException {
- String[] params = new String[0];
- startApplication(params);
- }
-
- /**
- * Executes class's main(java.lang.String[])
method.
- *
- * @param params The java.lang.String
array to pass
- * to main(java.lang.String[])
.
- * @throws NoSuchMethodException when the method cannot be found.
- * @throws InvocationTargetException when the invoked method throws an exception.
- */
- public void startApplication(String[] params)
- throws InvocationTargetException, NoSuchMethodException {
- String[] real_params;
- if (params == null) {
- real_params = new String[0];
- } else {
- real_params = params;
- }
- String[][] methodParams = {real_params};
- Class[] classes = {real_params.getClass()};
- try {
- invokeMethod("main", methodParams, classes);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (IllegalStateException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Locates method by name and parameter types and executes it.
- *
- * @param method_name Name of method.
- * @param params Method parameters.
- * @param params_classes Method parameters types.
- * @return the return value from an invocation of the Method.method_name
method is void, null
is returned.method_name
method returns a primitive type, then
- * return wrapper class instance.
- * @throws InvocationTargetException when the invoked method throws an exception.
- * @throws NoSuchMethodException when the method cannot be found.
- * @throws IllegalAccessException when access to the class or method is lacking.
- * @throws SecurityException if access to the package or method is denied.
- */
- public Object invokeMethod(String method_name, Object[] params, Class>[] params_classes)
- throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
- if (params == null) {
- params = new Object[0];
- }
- if (params_classes == null) {
- params_classes = new Class>[0];
- }
- Method method = cl.getMethod(method_name,
- params_classes);
- return (method.invoke(instance, params));
- }
-
- /**
- * Locates constructor by parameter types and creates an instance.
- *
- * @param params An array of Method parameters.
- * @param params_classes An array of Method parameter types.
- * @return a new class instance.
- * @throws InvocationTargetException when the invoked constructor throws an exception.
- * @throws NoSuchMethodException when the constructor cannot be found.
- * @throws IllegalAccessException when access to the class or constructor is lacking.
- * @throws InstantiationException when the constructor is for an abstract class.
- * @throws SecurityException if access to the package or constructor is denied.
- */
- public Object newInstance(Object[] params, Class[] params_classes)
- throws InvocationTargetException, NoSuchMethodException,
- IllegalAccessException, InstantiationException {
- if (params == null) {
- params = new Object[0];
- }
- if (params_classes == null) {
- params_classes = new Class[0];
- }
- Constructor constructor = cl.getConstructor(params_classes);
- return (constructor.newInstance(params));
- }
-
- /**
- * Returns the field value.
- * @param field_name The name of the field.
- * @return the field value
- * @see #setField
- * @throws NoSuchFieldException when the field cannot be found.
- * @throws IllegalAccessException when access to the class or constructor is lacking.
- * @throws SecurityException if access to the package or field is denied.
- */
- public Object getField(String field_name)
- throws NoSuchFieldException, IllegalAccessException {
- return (cl.getField(field_name).get(instance));
- }
-
- /**
- * Change a field's value.
- *
- * @param field_name The name of the field.
- * @param newValue The fields new value.
- * @see #getField
- * @throws NoSuchFieldException when the field cannot be found.
- * @throws IllegalAccessException when access to the class or constructor is lacking.
- * @throws SecurityException if access to the package or field is denied.
- */
- public void setField(String field_name, Object newValue)
- throws NoSuchFieldException, IllegalAccessException {
- cl.getField(field_name).set(instance, newValue);
- }
-
- /**
- * Returns all superclasses.
- * @return an array of superclasses, starting with the reference class
- * and ending with java.lang.Object
.
- */
- public Class[] getClasses() {
- Class cls = cl;
- int count = 0;
- do {
- count++;
- cls = cls.getSuperclass();
- } while (cls != null);
- Class[] result = new Class[count];
- cls = cl;
- for (int i = 0; i < count; i++) {
- result[i] = cls;
- cls = cls.getSuperclass();
- }
- return (result);
- }
-}
--- /dev/null 2019-03-06 17:23:21.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/input/awt/ClassReference.java 2019-03-06 17:23:21.000000000 -0800
@@ -0,0 +1,210 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.input.awt;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+/**
+ *
+ * Allows access to classes by reflection.
+ *
+ * @author Alexandre Iline (alexandre.iline@sun.com)
+ */
+public class ClassReference {
+
+ private Class> cl;
+ private Object instance;
+
+ /**
+ * Constructor.
+ * @param o Object to work with.
+ */
+ public ClassReference(Object o) {
+ super();
+ instance = o;
+ cl = o.getClass();
+ }
+
+ /**
+ * Contructor.
+ * The object created by this constructor can be used
+ * to access static methods and fields only.
+ *
+ * @param className name of class
+ * @throws ClassNotFoundException todo document
+ */
+ public ClassReference(String className)
+ throws ClassNotFoundException {
+ super();
+ cl = Class.forName(className);
+ instance = null;
+ }
+
+ /**
+ * Executes class's main(java.lang.String[])
method
+ * with a zero-length java.lang.String
array
+ * as a parameter.
+ *
+ * @throws NoSuchMethodException when the method cannot be found.
+ * @throws InvocationTargetException when the invoked method throws an exception.
+ */
+ public void startApplication()
+ throws InvocationTargetException, NoSuchMethodException {
+ String[] params = new String[0];
+ startApplication(params);
+ }
+
+ /**
+ * Executes class's main(java.lang.String[])
method.
+ *
+ * @param params The java.lang.String
array to pass
+ * to main(java.lang.String[])
.
+ * @throws NoSuchMethodException when the method cannot be found.
+ * @throws InvocationTargetException when the invoked method throws an exception.
+ */
+ public void startApplication(String[] params)
+ throws InvocationTargetException, NoSuchMethodException {
+ String[] real_params;
+ if (params == null) {
+ real_params = new String[0];
+ } else {
+ real_params = params;
+ }
+ String[][] methodParams = {real_params};
+ Class[] classes = {real_params.getClass()};
+ try {
+ invokeMethod("main", methodParams, classes);
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Locates method by name and parameter types and executes it.
+ *
+ * @param method_name Name of method.
+ * @param params Method parameters.
+ * @param params_classes Method parameters types.
+ * @return the return value from an invocation of the Method.method_name
method is void, null
is returned.method_name
method returns a primitive type, then
+ * return wrapper class instance.
+ * @throws InvocationTargetException when the invoked method throws an exception.
+ * @throws NoSuchMethodException when the method cannot be found.
+ * @throws IllegalAccessException when access to the class or method is lacking.
+ * @throws SecurityException if access to the package or method is denied.
+ */
+ public Object invokeMethod(String method_name, Object[] params, Class>[] params_classes)
+ throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
+ if (params == null) {
+ params = new Object[0];
+ }
+ if (params_classes == null) {
+ params_classes = new Class>[0];
+ }
+ Method method = cl.getMethod(method_name,
+ params_classes);
+ return (method.invoke(instance, params));
+ }
+
+ /**
+ * Locates constructor by parameter types and creates an instance.
+ *
+ * @param params An array of Method parameters.
+ * @param params_classes An array of Method parameter types.
+ * @return a new class instance.
+ * @throws InvocationTargetException when the invoked constructor throws an exception.
+ * @throws NoSuchMethodException when the constructor cannot be found.
+ * @throws IllegalAccessException when access to the class or constructor is lacking.
+ * @throws InstantiationException when the constructor is for an abstract class.
+ * @throws SecurityException if access to the package or constructor is denied.
+ */
+ public Object newInstance(Object[] params, Class[] params_classes)
+ throws InvocationTargetException, NoSuchMethodException,
+ IllegalAccessException, InstantiationException {
+ if (params == null) {
+ params = new Object[0];
+ }
+ if (params_classes == null) {
+ params_classes = new Class[0];
+ }
+ Constructor constructor = cl.getConstructor(params_classes);
+ return (constructor.newInstance(params));
+ }
+
+ /**
+ * Returns the field value.
+ * @param field_name The name of the field.
+ * @return the field value
+ * @see #setField
+ * @throws NoSuchFieldException when the field cannot be found.
+ * @throws IllegalAccessException when access to the class or constructor is lacking.
+ * @throws SecurityException if access to the package or field is denied.
+ */
+ public Object getField(String field_name)
+ throws NoSuchFieldException, IllegalAccessException {
+ return (cl.getField(field_name).get(instance));
+ }
+
+ /**
+ * Change a field's value.
+ *
+ * @param field_name The name of the field.
+ * @param newValue The fields new value.
+ * @see #getField
+ * @throws NoSuchFieldException when the field cannot be found.
+ * @throws IllegalAccessException when access to the class or constructor is lacking.
+ * @throws SecurityException if access to the package or field is denied.
+ */
+ public void setField(String field_name, Object newValue)
+ throws NoSuchFieldException, IllegalAccessException {
+ cl.getField(field_name).set(instance, newValue);
+ }
+
+ /**
+ * Returns all superclasses.
+ * @return an array of superclasses, starting with the reference class
+ * and ending with java.lang.Object
.
+ */
+ public Class[] getClasses() {
+ Class cls = cl;
+ int count = 0;
+ do {
+ count++;
+ cls = cls.getSuperclass();
+ } while (cls != null);
+ Class[] result = new Class[count];
+ cls = cl;
+ for (int i = 0; i < count; i++) {
+ result[i] = cls;
+ cls = cls.getSuperclass();
+ }
+ return (result);
+ }
+}
--- old/core/JemmyAWTInput/src/org/jemmy/input/DragImpl.java 2019-03-06 17:23:22.000000000 -0800
+++ /dev/null 2019-03-06 17:23:22.000000000 -0800
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.input;
-
-
-import java.awt.event.InputEvent;
-import org.jemmy.control.*;
-import org.jemmy.Point;
-import org.jemmy.action.Action;
-import org.jemmy.env.Environment;
-import org.jemmy.env.Timeout;
-import org.jemmy.interfaces.Mouse.MouseButton;
-import org.jemmy.interfaces.Drag;
-import org.jemmy.interfaces.Modifier;
-import org.jemmy.interfaces.Mouse;
-import org.jemmy.interfaces.Mouse.MouseButtons;
-import org.jemmy.interfaces.Showable;
-
-
-/**
- * @author shura
- */
-public class DragImpl implements Drag {
-
- public static final int DND_POINTS = 10;
-
- static {
- Environment.getEnvironment().setTimeout(BEFORE_DRAG_TIMEOUT);
- Environment.getEnvironment().setTimeout(BEFORE_DROP_TIMEOUT);
- Environment.getEnvironment().setTimeout(IN_DRAG_TIMEOUT);
- }
-
- private Wrap> source;
-
- public DragImpl(Wrap> source) {
- this.source = source;
- }
-
- public void dnd(Point targetPoint) {
- dnd(source, targetPoint);
- }
-
- public void dnd(Wrap target, Point targetPoint) {
- dnd(source.getClickPoint(), target, targetPoint);
- }
-
- public void dnd(Point point, Wrap target, Point targetPoint) {
- dnd(point, target, targetPoint, MouseButtons.BUTTON1);
- }
-
- public void dnd(Point point, Wrap target, Point targetPoint, MouseButton button) {
- dnd(point, target, targetPoint, button, new Modifier[]{});
- }
-
- public void dnd(Point pointParam, final Wrap target, final Point targetPoint, final MouseButton button, final Modifier... modifiers) {
- final Point point = pointParam == null ? source.getClickPoint() : pointParam;
- source.getEnvironment().getExecutor().execute(target.getEnvironment(), false, new Action() {
- public void run(Object... parameters) {
- if(source.is(Showable.class)) ((Showable)source.as(Showable.class)).shower().show();
- source.mouse().move(point);
- source.mouse().press(button, modifiers);
- source.getEnvironment().getTimeout(BEFORE_DRAG_TIMEOUT.getName()).sleep();
- Point intermediatePoint = new Point();
- int xDistance = target.getScreenBounds().x + targetPoint.x - source.getScreenBounds().x - point.x;
- int yDistance = target.getScreenBounds().y + targetPoint.y - source.getScreenBounds().y - point.y;
- int startX = point.x + source.getScreenBounds().x;
- int startY = point.y + source.getScreenBounds().y;
- int endX = startX + xDistance;
- int endY = startY + yDistance;
- for(int i = 0; i < DND_POINTS + 1; i++) {
- intermediatePoint.x = startX + xDistance * i / DND_POINTS - source.getScreenBounds().x;
- intermediatePoint.y = startY + yDistance * i / DND_POINTS - source.getScreenBounds().y;
- source.mouse().move(intermediatePoint);
- source.getEnvironment().getTimeout(IN_DRAG_TIMEOUT.getName()).sleep();
- }
- source.mouse().move(new Point(endX - source.getScreenBounds().x, endY - source.getScreenBounds().y));
- //target.mouse().move(targetPoint);
- source.getEnvironment().getTimeout(BEFORE_DROP_TIMEOUT.getName()).sleep();
- target.mouse().release(button, modifiers);
- }
-
- @Override
- public String toString() {
- return "grag'n'drop from " + point + " to " + targetPoint + " of " + target.getClass() + " with mouse button " + button + " with " + modifiers + " modifiers";
- }
-
- }, button, modifiers);
- }
-}
--- /dev/null 2019-03-06 17:23:22.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/input/awt/DragImpl.java 2019-03-06 17:23:21.000000000 -0800
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.input.awt;
+
+
+import java.awt.event.InputEvent;
+import org.jemmy.control.*;
+import org.jemmy.Point;
+import org.jemmy.action.Action;
+import org.jemmy.env.Environment;
+import org.jemmy.env.Timeout;
+import org.jemmy.interfaces.Mouse.MouseButton;
+import org.jemmy.interfaces.Drag;
+import org.jemmy.interfaces.Modifier;
+import org.jemmy.interfaces.Mouse;
+import org.jemmy.interfaces.Mouse.MouseButtons;
+import org.jemmy.interfaces.Showable;
+
+
+/**
+ * @author shura
+ */
+public class DragImpl implements Drag {
+
+ public static final int DND_POINTS = 10;
+
+ static {
+ Environment.getEnvironment().setTimeout(BEFORE_DRAG_TIMEOUT);
+ Environment.getEnvironment().setTimeout(BEFORE_DROP_TIMEOUT);
+ Environment.getEnvironment().setTimeout(IN_DRAG_TIMEOUT);
+ }
+
+ private Wrap> source;
+
+ public DragImpl(Wrap> source) {
+ this.source = source;
+ }
+
+ public void dnd(Point targetPoint) {
+ dnd(source, targetPoint);
+ }
+
+ public void dnd(Wrap target, Point targetPoint) {
+ dnd(source.getClickPoint(), target, targetPoint);
+ }
+
+ public void dnd(Point point, Wrap target, Point targetPoint) {
+ dnd(point, target, targetPoint, MouseButtons.BUTTON1);
+ }
+
+ public void dnd(Point point, Wrap target, Point targetPoint, MouseButton button) {
+ dnd(point, target, targetPoint, button, new Modifier[]{});
+ }
+
+ public void dnd(Point pointParam, final Wrap target, final Point targetPoint, final MouseButton button, final Modifier... modifiers) {
+ final Point point = pointParam == null ? source.getClickPoint() : pointParam;
+ source.getEnvironment().getExecutor().execute(target.getEnvironment(), false, new Action() {
+ public void run(Object... parameters) {
+ if(source.is(Showable.class)) ((Showable)source.as(Showable.class)).shower().show();
+ source.mouse().move(point);
+ source.mouse().press(button, modifiers);
+ source.getEnvironment().getTimeout(BEFORE_DRAG_TIMEOUT.getName()).sleep();
+ Point intermediatePoint = new Point();
+ int xDistance = target.getScreenBounds().x + targetPoint.x - source.getScreenBounds().x - point.x;
+ int yDistance = target.getScreenBounds().y + targetPoint.y - source.getScreenBounds().y - point.y;
+ int startX = point.x + source.getScreenBounds().x;
+ int startY = point.y + source.getScreenBounds().y;
+ int endX = startX + xDistance;
+ int endY = startY + yDistance;
+ for(int i = 0; i < DND_POINTS + 1; i++) {
+ intermediatePoint.x = startX + xDistance * i / DND_POINTS - source.getScreenBounds().x;
+ intermediatePoint.y = startY + yDistance * i / DND_POINTS - source.getScreenBounds().y;
+ source.mouse().move(intermediatePoint);
+ source.getEnvironment().getTimeout(IN_DRAG_TIMEOUT.getName()).sleep();
+ }
+ source.mouse().move(new Point(endX - source.getScreenBounds().x, endY - source.getScreenBounds().y));
+ //target.mouse().move(targetPoint);
+ source.getEnvironment().getTimeout(BEFORE_DROP_TIMEOUT.getName()).sleep();
+ target.mouse().release(button, modifiers);
+ }
+
+ @Override
+ public String toString() {
+ return "grag'n'drop from " + point + " to " + targetPoint + " of " + target.getClass() + " with mouse button " + button + " with " + modifiers + " modifiers";
+ }
+
+ }, button, modifiers);
+ }
+}
--- old/core/JemmyAWTInput/src/org/jemmy/input/KeyboardImpl.java 2019-03-06 17:23:22.000000000 -0800
+++ /dev/null 2019-03-06 17:23:22.000000000 -0800
@@ -1,173 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.input;
-
-import org.jemmy.action.Action;
-import org.jemmy.control.Wrap;
-import org.jemmy.interfaces.Keyboard.KeyboardButton;
-import org.jemmy.interfaces.Keyboard.KeyboardModifier;
-import org.jemmy.interfaces.Keyboard;
-import org.jemmy.env.Environment;
-import org.jemmy.env.Timeout;
-import org.jemmy.interfaces.Focusable;
-import org.jemmy.interfaces.Modifier;
-
-/**
- * KeyDriver
- *
- * @author Alexandre Iline(alexandre.iline@sun.com)
- */
-public class KeyboardImpl implements Keyboard {
-
- CharBindingMapRobot.setAutoDelay(long)
method.
- */
- public RobotDriver(Timeout autoDelay) {
- RobotExecutor.get().setAutoDelay(autoDelay);
- }
-
- /**
- * Constructs a RobotDriver object.
- * @param env Environment with ROBOT_DELAY_TIMEOUT_NAME timeout
- * @see AWTRobotInputFactory#ROBOT_DELAY_TIMEOUT_NAME
- */
- public RobotDriver(Environment env) {
- this(env.getTimeout(ROBOT_DELAY_TIMEOUT_NAME));
- }
-
- /**
- * Capture an image of specified rectangular area of screen
- * @param screenRect area on screen that will be captured
- * @return image of specified rectangular area of screen
- */
- public static Image createScreenCapture(Rectangle screenRect) {
- return RobotExecutor.get().createScreenCapture(screenRect);
- }
-
- /**
- * Presses mouse button specified by mouseButton preceding pressing of
- * modifier keys or buttons specified by modifiers
- * @param mouseButton One of MouseEvent.BUTTON*_MASK
- * @param modifiers Combination of InputEvent.*_DOWN_MASK
- * @see java.awt.event.InputEvent
- * @see java.awt.event.MouseEvent
- */
- public void pressMouse(MouseButton mouseButton, Modifier... modifiers) {
- pressModifiers(modifiers);
- makeAnOperation("mousePress",
- new Object[]{mouseButton},
- new Class[]{MouseButton.class});
- }
-
- /**
- * Releases mouse button specified by mouseButton then releasing
- * modifier keys or buttons specified by modifiers
- * @param mouseButton One of MouseEvent.BUTTON*_MASK
- * @param modifiers Combination of InputEvent.*_DOWN_MASK
- * @see java.awt.event.InputEvent
- * @see java.awt.event.MouseEvent
- */
- public void releaseMouse(MouseButton mouseButton, Modifier... modifiers) {
- makeAnOperation("mouseRelease",
- new Object[]{mouseButton},
- new Class[]{MouseButton.class});
- releaseModifiers(modifiers);
- }
-
- /**
- * Moves mouse to the specified mouse. When previous mouse location is
- * remembered mouse moved smoothly between the points according to
- * mouse smoothness parameter. Otherwise it jumps to the specified point
- * @param point Position on the screen where to move mouse
- * @see #setMouseSmoothness(int)
- * @see #getMouseSmoothness()
- */
- public void moveMouse(Point point) {
- double targetX = point.x;
- double targetY = point.y;
- if (haveOldPos && (oldX != targetX || oldY != targetY)) {
- double currX = oldX;
- double currY = oldY;
- double hyp = Math.sqrt((targetX - currX) * (targetX - currX) +
- (targetY - currY) * (targetY - currY));
- double steps = Math.ceil(hyp / Math.min(hyp, smoothness));
- double vx = (targetX - currX) / steps;
- double vy = (targetY - currY) / steps;
- assert (long)vx * vx + (long)vy * vy <= (long)smoothness * smoothness;
- while (Math.round(currX) != Math.round(targetX) ||
- Math.round(currY) != Math.round(targetY)) {
- currX += vx;
- currY += vy;
- makeAnOperation("mouseMove", new Object[]{
- new Integer((int) Math.round(currX)),
- new Integer((int) Math.round(currY))},
- new Class[]{Integer.TYPE, Integer.TYPE});
- }
- } else {
- makeAnOperation("mouseMove",
- new Object[]{new Integer(point.x), new Integer(point.y)},
- new Class[]{Integer.TYPE, Integer.TYPE});
- }
- haveOldPos = true;
- oldX = targetX;
- oldY = targetY;
- }
-
- /**
- * Clicks the mouse button specified by mouseButton at the specified point
- * specified number of times preceding it by pressing the modifiers key or
- * buttons and ending by releasing them. The last click is as long as
- * mouseClick timeout
- * @param point Screen location where to click mouse
- * @param clickCount Number of clicks
- * @param mouseButton One of MouseEvent.BUTTON*_MASK
- * @param modifiers Combination of InputEvent.*_DOWN_MASK
- * @param mouseClick Timeout of the last click
- * @see java.awt.event.InputEvent
- * @see java.awt.event.MouseEvent
- */
- public void clickMouse(Point point, int clickCount, MouseButton mouseButton, Timeout mouseClick, Modifier... modifiers) {
- pressModifiers(modifiers);
- moveMouse(point);
- makeAnOperation("mousePress", new Object[]{mouseButton}, new Class[]{MouseButton.class});
- for (int i = 1; i < clickCount; i++) {
- makeAnOperation("mouseRelease", new Object[]{mouseButton}, new Class[]{MouseButton.class});
- makeAnOperation("mousePress", new Object[]{mouseButton}, new Class[]{MouseButton.class});
- }
- mouseClick.sleep();
- makeAnOperation("mouseRelease", new Object[]{mouseButton}, new Class[]{MouseButton.class});
- releaseModifiers(modifiers);
- }
-
- /**
- * @deprecated Implementation doesn't seem to be correct as it ignores mouseButton and modifiers
- * @param point todo document
- * @param mouseButton One of MouseEvent.BUTTON*_MASK
- * @param modifiers todo document
- */
- public void dragMouse(Point point, int mouseButton, int modifiers) {
- moveMouse(point);
- }
-
- /**
- * Performs drag and drop from startPoint to endPoint using specified
- * mouseButton and modifiers to perform it.
- * @param startPoint Screen coordinates of drag start point
- * @param endPoint Screen coordinates of drag end point
- * @param mouseButton One of MouseEvent.BUTTON*_MASK
- * @param modifiers Combination of InputEvent.*_DOWN_MASK
- * @param before Timeout between pressing mouse at the startPoint and
- * mouse move
- * @param after Timeout between mouse move to the endPoint and mouse
- * release
- */
- public void dragNDrop(Point startPoint, Point endPoint, MouseButton mouseButton, Modifier modifiers[], Timeout before, Timeout after) {
- moveMouse(startPoint);
- pressMouse(mouseButton, modifiers);
- before.sleep();
- moveMouse(endPoint);
- after.sleep();
- releaseMouse(mouseButton, modifiers);
- }
-
- /**
- * Presses a key.
- * @param kbdButton Key code (KeyEventVK_*
field.
- * @param modifiers a combination of InputEvent.*_MASK
fields.
- */
- public void pressKey(KeyboardButton kbdButton, Modifier... modifiers) {
- pressModifiers(modifiers);
- makeAnOperation("keyPress",
- new Object[]{kbdButton},
- new Class[]{KeyboardButton.class});
- }
-
- /**
- * Releases a key.
- * @param kbdButton Key code (KeyEventVK_*
field.
- * @param modifiers a combination of InputEvent.*_MASK
fields.
- */
- public void releaseKey(KeyboardButton kbdButton, Modifier... modifiers) {
- makeAnOperation("keyRelease",
- new Object[]{kbdButton},
- new Class[]{KeyboardButton.class});
- releaseModifiers(modifiers);
- }
-
- /**
- * Turns the wheel.
- * @param p todo document
- * @param amount Either positive or negative
- * @param modifiers a combination of InputEvent.*_MASK
fields.
- */
- public void turnWheel(Point p, int amount, Modifier... modifiers) {
- pressModifiers(modifiers);
- moveMouse(p);
- java.awt.Robot r = null;
- makeAnOperation("mouseWheel",
- new Object[]{amount},
- new Class[]{Integer.TYPE});
- releaseModifiers(modifiers);
- }
-
- /**
- * Performs a single operation.
- * @param method a name of java.awt.Robot
method.
- * @param params method parameters
- * @param paramClasses method parameters classes
- */
- public void makeAnOperation(final String method, final Object[] params, final Class[] paramClasses) {
- RobotExecutor.get().makeAnOperation(method, params, paramClasses);
- }
-
- final static int SHIFT_MASK = InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK;
- final static int ALT_GRAPH_MASK = InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.ALT_GRAPH_MASK;
- final static int ALT_MASK = InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK;
- final static int META_MASK = InputEvent.META_DOWN_MASK | InputEvent.META_MASK;
- final static int CTRL_MASK = InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK;
-
- /**
- * Presses modifiers keys by robot.
- * @param modifiers a combination of InputEvent.*_MASK
fields.
- */
- protected void pressModifiers(Modifier... modifiers) {
- for (Modifier modifier : modifiers) { // TODO: ALT_GRAPH_MASK?
- if (modifier == KeyboardModifiers.ALT_DOWN_MASK) {
- pressKey(KeyboardButtons.ALT);
- } else if (modifier == KeyboardModifiers.CTRL_DOWN_MASK) {
- pressKey(KeyboardButtons.CONTROL);
- } else if (modifier == KeyboardModifiers.META_DOWN_MASK) {
- pressKey(KeyboardButtons.META);
- } else if (modifier == KeyboardModifiers.SHIFT_DOWN_MASK) {
- pressKey(KeyboardButtons.SHIFT);
- }
- }
- }
-
- /**
- * Releases modifiers keys by robot.
- * @param modifiers a combination of InputEvent.*_MASK
fields.
- */
- protected void releaseModifiers(Modifier... modifiers) {
- for (Modifier modifier : modifiers) { // TODO: ALT_GRAPH_MASK?
- if (modifier == KeyboardModifiers.ALT_DOWN_MASK) {
- releaseKey(KeyboardButtons.ALT);
- } else if (modifier == KeyboardModifiers.CTRL_DOWN_MASK) {
- releaseKey(KeyboardButtons.CONTROL);
- } else if (modifier == KeyboardModifiers.META_DOWN_MASK) {
- releaseKey(KeyboardButtons.META);
- } else if (modifier == KeyboardModifiers.SHIFT_DOWN_MASK) {
- releaseKey(KeyboardButtons.SHIFT);
- }
- }
- }
- /**
- * If java.awt.Robot is running in other JVM, it shutdowns that JVM
- * @see AWTRobotInputFactory#runInOtherJVM(boolean)
- */
- public static void exit() {
- RobotExecutor.get().exit();
- }
-}
--- /dev/null 2019-03-06 17:23:24.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/input/awt/RobotDriver.java 2019-03-06 17:23:23.000000000 -0800
@@ -0,0 +1,338 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.input.awt;
+
+
+import org.jemmy.Point;
+import java.awt.event.InputEvent;
+
+import org.jemmy.Rectangle;
+import org.jemmy.env.Timeout;
+import org.jemmy.env.Environment;
+import org.jemmy.image.Image;
+import static org.jemmy.input.awt.AWTRobotInputFactory.*;
+
+import org.jemmy.interfaces.Keyboard.KeyboardButton;
+import org.jemmy.interfaces.Keyboard.KeyboardButtons;
+import org.jemmy.interfaces.Keyboard.KeyboardModifiers;
+import org.jemmy.interfaces.Modifier;
+import org.jemmy.interfaces.Mouse.MouseButton;
+
+
+/**
+ * @author shura
+ * @author mrkam
+ *
+ */
+public class RobotDriver {
+
+ private static boolean haveOldPos = false;
+ private static int smoothness;
+ private static double oldX;
+ private static double oldY;
+
+ static {
+ Environment.getEnvironment().setTimeout(
+ new Timeout(ROBOT_DELAY_TIMEOUT_NAME, 10));
+ Environment.getEnvironment().setPropertyIfNotSet(
+ AWTRobotInputFactory.ROBOT_MOUSE_SMOOTHNESS_PROPERTY,
+ Integer.toString(Integer.MAX_VALUE));
+ smoothness = Integer.parseInt(
+ (String)Environment.getEnvironment().getProperty(
+ AWTRobotInputFactory.ROBOT_MOUSE_SMOOTHNESS_PROPERTY));
+ }
+
+ /**
+ * Sets mouse smoothness
+ * @param mouseSmoothness the maximum distance in pixels between
+ * mouse positions during movement
+ * @see #moveMouse(Point)
+ */
+ public static void setMouseSmoothness(int mouseSmoothness) {
+ smoothness = mouseSmoothness;
+ }
+
+ /**
+ * Gets mouse smoothness
+ * @return the maximum distance in pixels between
+ * mouse positions during movement
+ * @see #setMouseSmoothness(int)
+ * @see #moveMouse(Point)
+ */
+ public static int getMouseSmoothness() {
+ return smoothness;
+ }
+
+ /**
+ * Constructs a RobotDriver object.
+ * @param autoDelay Time for Robot.setAutoDelay(long)
method.
+ */
+ public RobotDriver(Timeout autoDelay) {
+ RobotExecutor.get().setAutoDelay(autoDelay);
+ }
+
+ /**
+ * Constructs a RobotDriver object.
+ * @param env Environment with ROBOT_DELAY_TIMEOUT_NAME timeout
+ * @see AWTRobotInputFactory#ROBOT_DELAY_TIMEOUT_NAME
+ */
+ public RobotDriver(Environment env) {
+ this(env.getTimeout(ROBOT_DELAY_TIMEOUT_NAME));
+ }
+
+ /**
+ * Capture an image of specified rectangular area of screen
+ * @param screenRect area on screen that will be captured
+ * @return image of specified rectangular area of screen
+ */
+ public static Image createScreenCapture(Rectangle screenRect) {
+ return RobotExecutor.get().createScreenCapture(screenRect);
+ }
+
+ /**
+ * Presses mouse button specified by mouseButton preceding pressing of
+ * modifier keys or buttons specified by modifiers
+ * @param mouseButton One of MouseEvent.BUTTON*_MASK
+ * @param modifiers Combination of InputEvent.*_DOWN_MASK
+ * @see java.awt.event.InputEvent
+ * @see java.awt.event.MouseEvent
+ */
+ public void pressMouse(MouseButton mouseButton, Modifier... modifiers) {
+ pressModifiers(modifiers);
+ makeAnOperation("mousePress",
+ new Object[]{mouseButton},
+ new Class[]{MouseButton.class});
+ }
+
+ /**
+ * Releases mouse button specified by mouseButton then releasing
+ * modifier keys or buttons specified by modifiers
+ * @param mouseButton One of MouseEvent.BUTTON*_MASK
+ * @param modifiers Combination of InputEvent.*_DOWN_MASK
+ * @see java.awt.event.InputEvent
+ * @see java.awt.event.MouseEvent
+ */
+ public void releaseMouse(MouseButton mouseButton, Modifier... modifiers) {
+ makeAnOperation("mouseRelease",
+ new Object[]{mouseButton},
+ new Class[]{MouseButton.class});
+ releaseModifiers(modifiers);
+ }
+
+ /**
+ * Moves mouse to the specified mouse. When previous mouse location is
+ * remembered mouse moved smoothly between the points according to
+ * mouse smoothness parameter. Otherwise it jumps to the specified point
+ * @param point Position on the screen where to move mouse
+ * @see #setMouseSmoothness(int)
+ * @see #getMouseSmoothness()
+ */
+ public void moveMouse(Point point) {
+ double targetX = point.x;
+ double targetY = point.y;
+ if (haveOldPos && (oldX != targetX || oldY != targetY)) {
+ double currX = oldX;
+ double currY = oldY;
+ double hyp = Math.sqrt((targetX - currX) * (targetX - currX) +
+ (targetY - currY) * (targetY - currY));
+ double steps = Math.ceil(hyp / Math.min(hyp, smoothness));
+ double vx = (targetX - currX) / steps;
+ double vy = (targetY - currY) / steps;
+ assert (long)vx * vx + (long)vy * vy <= (long)smoothness * smoothness;
+ while (Math.round(currX) != Math.round(targetX) ||
+ Math.round(currY) != Math.round(targetY)) {
+ currX += vx;
+ currY += vy;
+ makeAnOperation("mouseMove", new Object[]{
+ new Integer((int) Math.round(currX)),
+ new Integer((int) Math.round(currY))},
+ new Class[]{Integer.TYPE, Integer.TYPE});
+ }
+ } else {
+ makeAnOperation("mouseMove",
+ new Object[]{new Integer(point.x), new Integer(point.y)},
+ new Class[]{Integer.TYPE, Integer.TYPE});
+ }
+ haveOldPos = true;
+ oldX = targetX;
+ oldY = targetY;
+ }
+
+ /**
+ * Clicks the mouse button specified by mouseButton at the specified point
+ * specified number of times preceding it by pressing the modifiers key or
+ * buttons and ending by releasing them. The last click is as long as
+ * mouseClick timeout
+ * @param point Screen location where to click mouse
+ * @param clickCount Number of clicks
+ * @param mouseButton One of MouseEvent.BUTTON*_MASK
+ * @param modifiers Combination of InputEvent.*_DOWN_MASK
+ * @param mouseClick Timeout of the last click
+ * @see java.awt.event.InputEvent
+ * @see java.awt.event.MouseEvent
+ */
+ public void clickMouse(Point point, int clickCount, MouseButton mouseButton, Timeout mouseClick, Modifier... modifiers) {
+ pressModifiers(modifiers);
+ moveMouse(point);
+ makeAnOperation("mousePress", new Object[]{mouseButton}, new Class[]{MouseButton.class});
+ for (int i = 1; i < clickCount; i++) {
+ makeAnOperation("mouseRelease", new Object[]{mouseButton}, new Class[]{MouseButton.class});
+ makeAnOperation("mousePress", new Object[]{mouseButton}, new Class[]{MouseButton.class});
+ }
+ mouseClick.sleep();
+ makeAnOperation("mouseRelease", new Object[]{mouseButton}, new Class[]{MouseButton.class});
+ releaseModifiers(modifiers);
+ }
+
+ /**
+ * @deprecated Implementation doesn't seem to be correct as it ignores mouseButton and modifiers
+ * @param point todo document
+ * @param mouseButton One of MouseEvent.BUTTON*_MASK
+ * @param modifiers todo document
+ */
+ public void dragMouse(Point point, int mouseButton, int modifiers) {
+ moveMouse(point);
+ }
+
+ /**
+ * Performs drag and drop from startPoint to endPoint using specified
+ * mouseButton and modifiers to perform it.
+ * @param startPoint Screen coordinates of drag start point
+ * @param endPoint Screen coordinates of drag end point
+ * @param mouseButton One of MouseEvent.BUTTON*_MASK
+ * @param modifiers Combination of InputEvent.*_DOWN_MASK
+ * @param before Timeout between pressing mouse at the startPoint and
+ * mouse move
+ * @param after Timeout between mouse move to the endPoint and mouse
+ * release
+ */
+ public void dragNDrop(Point startPoint, Point endPoint, MouseButton mouseButton, Modifier modifiers[], Timeout before, Timeout after) {
+ moveMouse(startPoint);
+ pressMouse(mouseButton, modifiers);
+ before.sleep();
+ moveMouse(endPoint);
+ after.sleep();
+ releaseMouse(mouseButton, modifiers);
+ }
+
+ /**
+ * Presses a key.
+ * @param kbdButton Key code (KeyEventVK_*
field.
+ * @param modifiers a combination of InputEvent.*_MASK
fields.
+ */
+ public void pressKey(KeyboardButton kbdButton, Modifier... modifiers) {
+ pressModifiers(modifiers);
+ makeAnOperation("keyPress",
+ new Object[]{kbdButton},
+ new Class[]{KeyboardButton.class});
+ }
+
+ /**
+ * Releases a key.
+ * @param kbdButton Key code (KeyEventVK_*
field.
+ * @param modifiers a combination of InputEvent.*_MASK
fields.
+ */
+ public void releaseKey(KeyboardButton kbdButton, Modifier... modifiers) {
+ makeAnOperation("keyRelease",
+ new Object[]{kbdButton},
+ new Class[]{KeyboardButton.class});
+ releaseModifiers(modifiers);
+ }
+
+ /**
+ * Turns the wheel.
+ * @param p todo document
+ * @param amount Either positive or negative
+ * @param modifiers a combination of InputEvent.*_MASK
fields.
+ */
+ public void turnWheel(Point p, int amount, Modifier... modifiers) {
+ pressModifiers(modifiers);
+ moveMouse(p);
+ java.awt.Robot r = null;
+ makeAnOperation("mouseWheel",
+ new Object[]{amount},
+ new Class[]{Integer.TYPE});
+ releaseModifiers(modifiers);
+ }
+
+ /**
+ * Performs a single operation.
+ * @param method a name of java.awt.Robot
method.
+ * @param params method parameters
+ * @param paramClasses method parameters classes
+ */
+ public void makeAnOperation(final String method, final Object[] params, final Class[] paramClasses) {
+ RobotExecutor.get().makeAnOperation(method, params, paramClasses);
+ }
+
+ final static int SHIFT_MASK = InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK;
+ final static int ALT_GRAPH_MASK = InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.ALT_GRAPH_MASK;
+ final static int ALT_MASK = InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK;
+ final static int META_MASK = InputEvent.META_DOWN_MASK | InputEvent.META_MASK;
+ final static int CTRL_MASK = InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK;
+
+ /**
+ * Presses modifiers keys by robot.
+ * @param modifiers a combination of InputEvent.*_MASK
fields.
+ */
+ protected void pressModifiers(Modifier... modifiers) {
+ for (Modifier modifier : modifiers) { // TODO: ALT_GRAPH_MASK?
+ if (modifier == KeyboardModifiers.ALT_DOWN_MASK) {
+ pressKey(KeyboardButtons.ALT);
+ } else if (modifier == KeyboardModifiers.CTRL_DOWN_MASK) {
+ pressKey(KeyboardButtons.CONTROL);
+ } else if (modifier == KeyboardModifiers.META_DOWN_MASK) {
+ pressKey(KeyboardButtons.META);
+ } else if (modifier == KeyboardModifiers.SHIFT_DOWN_MASK) {
+ pressKey(KeyboardButtons.SHIFT);
+ }
+ }
+ }
+
+ /**
+ * Releases modifiers keys by robot.
+ * @param modifiers a combination of InputEvent.*_MASK
fields.
+ */
+ protected void releaseModifiers(Modifier... modifiers) {
+ for (Modifier modifier : modifiers) { // TODO: ALT_GRAPH_MASK?
+ if (modifier == KeyboardModifiers.ALT_DOWN_MASK) {
+ releaseKey(KeyboardButtons.ALT);
+ } else if (modifier == KeyboardModifiers.CTRL_DOWN_MASK) {
+ releaseKey(KeyboardButtons.CONTROL);
+ } else if (modifier == KeyboardModifiers.META_DOWN_MASK) {
+ releaseKey(KeyboardButtons.META);
+ } else if (modifier == KeyboardModifiers.SHIFT_DOWN_MASK) {
+ releaseKey(KeyboardButtons.SHIFT);
+ }
+ }
+ }
+ /**
+ * If java.awt.Robot is running in other JVM, it shutdowns that JVM
+ * @see AWTRobotInputFactory#runInOtherJVM(boolean)
+ */
+ public static void exit() {
+ RobotExecutor.get().exit();
+ }
+}
--- old/core/JemmyAWTInput/src/org/jemmy/input/RobotExecutor.java 2019-03-06 17:23:24.000000000 -0800
+++ /dev/null 2019-03-06 17:23:24.000000000 -0800
@@ -1,603 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.input;
-
-
-import java.awt.EventQueue;
-import java.awt.image.BufferedImage;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OptionalDataException;
-import java.io.PrintWriter;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Modifier;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.jemmy.JemmyException;
-import org.jemmy.Rectangle;
-import org.jemmy.env.Environment;
-import org.jemmy.env.Timeout;
-import org.jemmy.image.AWTImage;
-import org.jemmy.image.Image;
-import org.jemmy.image.PNGDecoder;
-import org.jemmy.image.PNGEncoder;
-import org.jemmy.timing.State;
-import org.jemmy.timing.Waiter;
-import org.jemmy.interfaces.Keyboard.KeyboardButton;
-import org.jemmy.interfaces.Mouse.MouseButton;
-
-/**
- *
- * @author КАМ
- */
-class RobotExecutor {
-
- private static RobotExecutor instance;
- private AWTMap awtMap = null;
-
- public static RobotExecutor get() {
- if (instance == null) {
- instance = new RobotExecutor();
- }
- return instance;
- }
-
- /**
- * A reference to the robot instance.
- */
- protected ClassReference robotReference = null;
- protected Timeout autoDelay;
- private boolean inited = false;
- private boolean runInOtherJVM = false;
- private boolean ready = false;
- private boolean connectionEstablished = false;
- private ObjectOutputStream outputStream;
- private ObjectInputStream inputStream;
- private Socket socket;
- private int connectionPort;
- private String connectionHost;
- public static final int CONNECTION_TIMEOUT = Integer.parseInt(
- (String)Environment.getEnvironment().getProperty(
- AWTRobotInputFactory.OTHER_VM_CONNECTION_TIMEOUT_PROPERTY,
- Integer.toString(60000 * 15))); // 15 min
-
- public RobotExecutor() {
- }
-
- void setAWTMap(AWTMap awtMap) {
- this.awtMap = awtMap;
- }
-
- AWTMap getAWTMap() {
- if (awtMap == null) {
- awtMap = new AWTMap();
- }
- return awtMap;
- }
-
- private void ensureInited() {
- if (!inited) {
- runInOtherJVM = Boolean.parseBoolean((String)Environment.getEnvironment()
- .getProperty(AWTRobotInputFactory.OTHER_VM_PROPERTY,
- Boolean.toString(runInOtherJVM)));
- inited = true;
- }
- }
-
- public Image createScreenCapture(Rectangle screenRect) {
- Object result = makeAnOperation("createScreenCapture", new Object[] {
- new java.awt.Rectangle(screenRect.x, screenRect.y, screenRect.width,
- screenRect.height) },
- new Class[] { java.awt.Rectangle.class });
- if (result.getClass().isAssignableFrom(BufferedImage.class)) {
- return new AWTImage(BufferedImage.class.cast(result));
- } else {
- throw new JemmyException("Screen capture (" + result
- + ") is not a BufferedImage");
- }
- }
-
- public Object makeAnOperation(String method, Object[] params, Class[] paramClasses) {
- ensureInited();
- if (runInOtherJVM) {
- return makeAnOperationRemotely(method, params, paramClasses);
- } else {
- return makeAnOperationLocally(method, params, paramClasses);
- }
- }
-
- public void exit() {
- ensureInited();
- if (runInOtherJVM) {
- ensureConnection();
- try {
- outputStream.writeObject("exit");
- connectionEstablished = false;
- deleteProperties();
- } catch (IOException ex) {
- throw new JemmyException("Failed to invoke exit", ex);
- }
- }
- }
-
- private Object makeAnOperationLocally(String method, Object[] params, Class[] paramClasses) {
- if (robotReference == null) {
- initRobot();
- }
- try {
- convert(method, params, paramClasses);
- Object result = robotReference.invokeMethod(method, params, paramClasses);
- synchronizeRobot();
- return result;
- } catch (InvocationTargetException e) {
- throw (new JemmyException("Exception during java.awt.Robot accessing", e));
- } catch (IllegalStateException e) {
- throw (new JemmyException("Exception during java.awt.Robot accessing", e));
- } catch (NoSuchMethodException e) {
- throw (new JemmyException("Exception during java.awt.Robot accessing", e));
- } catch (IllegalAccessException e) {
- throw (new JemmyException("Exception during java.awt.Robot accessing", e));
- }
- }
-
- private int convert(Object obj) {
- if (MouseButton.class.isAssignableFrom(obj.getClass())) {
- return awtMap.convert((MouseButton)obj);
- } else if (KeyboardButton.class.isAssignableFrom(obj.getClass())) {
- return awtMap.convert((KeyboardButton)obj);
- } else {
- throw new JemmyException("Unable to recognize object", obj);
- }
- }
-
- private static final Setjava.awt.Robot.waitForIdle()
method.
- */
- protected void synchronizeRobot() {
- ensureInited();
- if (!runInOtherJVM) {
- // TODO: It looks like this method is rudimentary
- if (!EventQueue.isDispatchThread()) {
- if (robotReference == null) {
- initRobot();
- }
- try {
- robotReference.invokeMethod("waitForIdle", null, null);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- public void setAutoDelay(Timeout autoDelay) {
- this.autoDelay = autoDelay;
- if (ready) {
- makeAnOperation("setAutoDelay", new Object[]{new Integer((int) ((autoDelay != null) ? autoDelay.getValue() : 0))}, new Class[]{Integer.TYPE});
- }
- }
-
- public boolean isRunInOtherJVM() {
- ensureInited();
- return runInOtherJVM;
- }
-
- public void setRunInOtherJVM(boolean runInOtherJVM) {
- if (inited && this.runInOtherJVM && this.connectionEstablished && !runInOtherJVM) {
- shutdownConnection();
- }
- this.runInOtherJVM = runInOtherJVM;
- inited = true;
- ready = false;
- }
-
- private void shutdownConnection() {
- try {
- outputStream.writeObject("exit");
- socket.close();
- connectionEstablished = false;
- } catch (IOException ex) {
- throw new JemmyException("Failed to shutdown connection", ex);
- }
- }
-}
--- /dev/null 2019-03-06 17:23:24.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/input/awt/RobotExecutor.java 2019-03-06 17:23:24.000000000 -0800
@@ -0,0 +1,603 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.input.awt;
+
+
+import java.awt.EventQueue;
+import java.awt.image.BufferedImage;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OptionalDataException;
+import java.io.PrintWriter;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.jemmy.JemmyException;
+import org.jemmy.Rectangle;
+import org.jemmy.env.Environment;
+import org.jemmy.env.Timeout;
+import org.jemmy.image.awt.AWTImage;
+import org.jemmy.image.Image;
+import org.jemmy.image.awt.PNGDecoder;
+import org.jemmy.image.awt.PNGEncoder;
+import org.jemmy.timing.State;
+import org.jemmy.timing.Waiter;
+import org.jemmy.interfaces.Keyboard.KeyboardButton;
+import org.jemmy.interfaces.Mouse.MouseButton;
+
+/**
+ *
+ * @author КАМ
+ */
+class RobotExecutor {
+
+ private static RobotExecutor instance;
+ private AWTMap awtMap = null;
+
+ public static RobotExecutor get() {
+ if (instance == null) {
+ instance = new RobotExecutor();
+ }
+ return instance;
+ }
+
+ /**
+ * A reference to the robot instance.
+ */
+ protected ClassReference robotReference = null;
+ protected Timeout autoDelay;
+ private boolean inited = false;
+ private boolean runInOtherJVM = false;
+ private boolean ready = false;
+ private boolean connectionEstablished = false;
+ private ObjectOutputStream outputStream;
+ private ObjectInputStream inputStream;
+ private Socket socket;
+ private int connectionPort;
+ private String connectionHost;
+ public static final int CONNECTION_TIMEOUT = Integer.parseInt(
+ (String)Environment.getEnvironment().getProperty(
+ AWTRobotInputFactory.OTHER_VM_CONNECTION_TIMEOUT_PROPERTY,
+ Integer.toString(60000 * 15))); // 15 min
+
+ public RobotExecutor() {
+ }
+
+ void setAWTMap(AWTMap awtMap) {
+ this.awtMap = awtMap;
+ }
+
+ AWTMap getAWTMap() {
+ if (awtMap == null) {
+ awtMap = new AWTMap();
+ }
+ return awtMap;
+ }
+
+ private void ensureInited() {
+ if (!inited) {
+ runInOtherJVM = Boolean.parseBoolean((String)Environment.getEnvironment()
+ .getProperty(AWTRobotInputFactory.OTHER_VM_PROPERTY,
+ Boolean.toString(runInOtherJVM)));
+ inited = true;
+ }
+ }
+
+ public Image createScreenCapture(Rectangle screenRect) {
+ Object result = makeAnOperation("createScreenCapture", new Object[] {
+ new java.awt.Rectangle(screenRect.x, screenRect.y, screenRect.width,
+ screenRect.height) },
+ new Class[] { java.awt.Rectangle.class });
+ if (result.getClass().isAssignableFrom(BufferedImage.class)) {
+ return new AWTImage(BufferedImage.class.cast(result));
+ } else {
+ throw new JemmyException("Screen capture (" + result
+ + ") is not a BufferedImage");
+ }
+ }
+
+ public Object makeAnOperation(String method, Object[] params, Class[] paramClasses) {
+ ensureInited();
+ if (runInOtherJVM) {
+ return makeAnOperationRemotely(method, params, paramClasses);
+ } else {
+ return makeAnOperationLocally(method, params, paramClasses);
+ }
+ }
+
+ public void exit() {
+ ensureInited();
+ if (runInOtherJVM) {
+ ensureConnection();
+ try {
+ outputStream.writeObject("exit");
+ connectionEstablished = false;
+ deleteProperties();
+ } catch (IOException ex) {
+ throw new JemmyException("Failed to invoke exit", ex);
+ }
+ }
+ }
+
+ private Object makeAnOperationLocally(String method, Object[] params, Class[] paramClasses) {
+ if (robotReference == null) {
+ initRobot();
+ }
+ try {
+ convert(method, params, paramClasses);
+ Object result = robotReference.invokeMethod(method, params, paramClasses);
+ synchronizeRobot();
+ return result;
+ } catch (InvocationTargetException e) {
+ throw (new JemmyException("Exception during java.awt.Robot accessing", e));
+ } catch (IllegalStateException e) {
+ throw (new JemmyException("Exception during java.awt.Robot accessing", e));
+ } catch (NoSuchMethodException e) {
+ throw (new JemmyException("Exception during java.awt.Robot accessing", e));
+ } catch (IllegalAccessException e) {
+ throw (new JemmyException("Exception during java.awt.Robot accessing", e));
+ }
+ }
+
+ private int convert(Object obj) {
+ if (MouseButton.class.isAssignableFrom(obj.getClass())) {
+ return awtMap.convert((MouseButton)obj);
+ } else if (KeyboardButton.class.isAssignableFrom(obj.getClass())) {
+ return awtMap.convert((KeyboardButton)obj);
+ } else {
+ throw new JemmyException("Unable to recognize object", obj);
+ }
+ }
+
+ private static final Setjava.awt.Robot.waitForIdle()
method.
+ */
+ protected void synchronizeRobot() {
+ ensureInited();
+ if (!runInOtherJVM) {
+ // TODO: It looks like this method is rudimentary
+ if (!EventQueue.isDispatchThread()) {
+ if (robotReference == null) {
+ initRobot();
+ }
+ try {
+ robotReference.invokeMethod("waitForIdle", null, null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public void setAutoDelay(Timeout autoDelay) {
+ this.autoDelay = autoDelay;
+ if (ready) {
+ makeAnOperation("setAutoDelay", new Object[]{new Integer((int) ((autoDelay != null) ? autoDelay.getValue() : 0))}, new Class[]{Integer.TYPE});
+ }
+ }
+
+ public boolean isRunInOtherJVM() {
+ ensureInited();
+ return runInOtherJVM;
+ }
+
+ public void setRunInOtherJVM(boolean runInOtherJVM) {
+ if (inited && this.runInOtherJVM && this.connectionEstablished && !runInOtherJVM) {
+ shutdownConnection();
+ }
+ this.runInOtherJVM = runInOtherJVM;
+ inited = true;
+ ready = false;
+ }
+
+ private void shutdownConnection() {
+ try {
+ outputStream.writeObject("exit");
+ socket.close();
+ connectionEstablished = false;
+ } catch (IOException ex) {
+ throw new JemmyException("Failed to shutdown connection", ex);
+ }
+ }
+}
--- old/core/JemmyAWTInput/src/org/jemmy/input/Version.java 2019-03-06 17:23:25.000000000 -0800
+++ /dev/null 2019-03-06 17:23:25.000000000 -0800
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.input;
-
-/**
- *
- * @author shura
- */
-public class Version extends org.jemmy.Version {
-
- public static final Version VERSION = new Version();
-
- public Version() {
- super(Version.class.getPackage().getName());
- }
-
- public static void main(String[] args) {
- System.out.println("JemmyAWTInput version: " + VERSION.getVersion());
- }
-}
--- /dev/null 2019-03-06 17:23:25.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/input/awt/Version.java 2019-03-06 17:23:25.000000000 -0800
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.input.awt;
+
+/**
+ *
+ * @author shura
+ */
+public class Version extends org.jemmy.Version {
+
+ public static final Version VERSION = new Version();
+
+ public Version() {
+ super(Version.class.getPackage().getName());
+ }
+
+ public static void main(String[] args) {
+ System.out.println("JemmyAWTInput version: " + VERSION.getVersion());
+ }
+}
--- old/core/JemmyAWTInput/src/org/jemmy/input/jemmy.properties 2019-03-06 17:23:26.000000000 -0800
+++ /dev/null 2019-03-06 17:23:26.000000000 -0800
@@ -1,4 +0,0 @@
-version.major=1
-version.minor=0
-version.mini=2
-build=${buildnumber}
--- /dev/null 2019-03-06 17:23:26.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/input/awt/jemmy.properties 2019-03-06 17:23:26.000000000 -0800
@@ -0,0 +1,4 @@
+version.major=1
+version.minor=0
+version.mini=2
+build=${buildnumber}
--- old/core/JemmyAWTInput/src/org/jemmy/operators/AWTScreen.java 2019-03-06 17:23:26.000000000 -0800
+++ /dev/null 2019-03-06 17:23:26.000000000 -0800
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.operators;
-
-
-import java.awt.Toolkit;
-import org.jemmy.Rectangle;
-import org.jemmy.env.Environment;
-
-/**
- * @author shura
- */
-public class AWTScreen extends Screen {
-
- public AWTScreen() {
- this(Environment.getEnvironment());
- }
-
- public AWTScreen(Environment env) {
- super(env);
- }
-
- @Override
- public Rectangle getScreenBounds() {
- java.awt.Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
- return new Rectangle(0, 0, size.width, size.height);
- }
-
-}
--- /dev/null 2019-03-06 17:23:26.000000000 -0800
+++ new/core/JemmyAWTInput/src/org/jemmy/operators/awt/AWTScreen.java 2019-03-06 17:23:26.000000000 -0800
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.operators.awt;
+
+
+import java.awt.Toolkit;
+
+import org.jemmy.Rectangle;
+import org.jemmy.env.Environment;
+import org.jemmy.operators.Screen;
+
+/**
+ * @author shura
+ */
+public class AWTScreen extends Screen {
+
+ public AWTScreen() {
+ this(Environment.getEnvironment());
+ }
+
+ public AWTScreen(Environment env) {
+ super(env);
+ }
+
+ @Override
+ public Rectangle getScreenBounds() {
+ java.awt.Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
+ return new Rectangle(0, 0, size.width, size.height);
+ }
+
+}
Binary files old/core/JemmyAWTInput/test/org/jemmy/image/AreaChart_a.png and /dev/null differ
Binary files /dev/null and new/core/JemmyAWTInput/test/org/jemmy/image/awt/AreaChart_a.png differ
Binary files old/core/JemmyAWTInput/test/org/jemmy/image/AreaChart_a_res.png and /dev/null differ
Binary files /dev/null and new/core/JemmyAWTInput/test/org/jemmy/image/awt/AreaChart_a_res.png differ
--- old/core/JemmyAWTInput/test/org/jemmy/image/AverageDistanceImageComparatorTest.java 2019-03-06 17:23:28.000000000 -0800
+++ /dev/null 2019-03-06 17:23:28.000000000 -0800
@@ -1,318 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import javax.imageio.ImageIO;
-
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.AssertJUnit.assertEquals;
-
-
-/**
- *
- * @author KAM
- */
-public class AverageDistanceImageComparatorTest {
-
- public AverageDistanceImageComparatorTest() {
- }
-
- static final int NUMBER_OF_IMAGES = 3;
- static BufferedImage[] images;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- images = new BufferedImage[NUMBER_OF_IMAGES];
- for(int i = 0; i < NUMBER_OF_IMAGES; i++) {
- images[i] = ImageIO.read(AverageDistanceImageComparatorTest.class
- .getResource("image" + (i + 1) + ".jpg"));
- }
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
-
- @BeforeMethod
- public void setUp() {
- }
-
- @AfterMethod
- public void tearDown() {
- }
-
- /**
- * Test of compare method, of class AverageDistanceImageComparator.
- */
- @Test
- public void testCompare1() {
- System.out.println("compare1");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image1.createGraphics();
- g.setColor(new Color(0.5f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- BufferedImage image2 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image2.createGraphics();
- g.setColor(new Color(0.52f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
- assertNull(instance.compare(new AWTImage(image1), new AWTImage(image2)));
- }
-
- /**
- * Test of compare method, of class AverageDistanceImageComparator.
- */
- @Test
- public void testCompare2() {
- System.out.println("compare2");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image1.createGraphics();
- g.setColor(new Color(0.5f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image3.createGraphics();
- g.setColor(new Color(0.51f, 0.51f, 0.51f));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
- assertNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
- }
-
- /**
- * Test of compare method, of class AverageDistanceImageComparator.
- */
- @Test
- public void testCompare3Pos() {
- System.out.println("compare3Pos");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image1.createGraphics();
- g.setColor(new Color(0.5f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image3.createGraphics();
- g.setColor(new Color(0.5f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.setColor(new Color(0.6f, 0.6f, 0.6f));
- g.fillRect(3, 3, 3, 3);
- g.dispose();
-
- AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
- assertNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
- }
-
- /**
- * Test of compare method, of class AverageDistanceImageComparator.
- */
- @Test
- public void testCompare3Neg() {
- System.out.println("compare3Neg");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image1.createGraphics();
- g.setColor(new Color(0.5f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image3.createGraphics();
- g.setColor(new Color(0.5f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.setColor(new Color(0.6f, 0.6f, 0.6f));
- g.fillRect(3, 3, 3, 4);
- g.dispose();
-
- AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
- assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
- }
-
- /**
- * Test of compare method, of class AverageDistanceImageComparator.
- */
- @Test
- public void testCompare4() {
- System.out.println("compare4");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 11, BufferedImage.TYPE_INT_RGB);
- BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
-
- AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
- assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
- }
-
- /**
- * Test of compare method, of class AverageDistanceImageComparator.
- */
- @Test
- public void testCompare5() {
- System.out.println("compare5");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- BufferedImage image3 = new BufferedImage(11, 10, BufferedImage.TYPE_INT_RGB);
-
- AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
- assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
- }
-
- /**
- * Test of compare method, of class AverageDistanceImageComparator.
- */
- @Test
- public void testCompare6() {
- System.out.println("compare6");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image1.createGraphics();
- g.setColor(new Color(0, 0, 0));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image3.createGraphics();
- g.setColor(new Color(255, 255, 255));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
- assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
- }
-
- /**
- * Test of compare method, of class AverageDistanceImageComparator.
- */
- @Test
- public void testCompare7() {
- System.out.println("compare7");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image1.createGraphics();
- g.setColor(new Color(0.51f, 0.51f, 0.51f));
- g.fillRect(0, 0, 10, 5);
- g.setColor(new Color(0.49f, 0.49f, 0.49f));
- g.fillRect(0, 5, 10, 5);
- g.dispose();
-
- BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image3.createGraphics();
- g.setColor(new Color(0.49f, 0.49f, 0.49f));
- g.fillRect(0, 5, 10, 5);
- g.setColor(new Color(0.51f, 0.51f, 0.51f));
- g.fillRect(0, 0, 10, 5);
- g.dispose();
-
- AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
- assertNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
- }
-
- /**
- * Test of compare method, of class AverageDistanceImageComparator.
- * @throws IOException
- */
- @Test
- public void testCompare() throws IOException {
- System.out.println("compare");
- boolean[][][] expected = {
- // NO_RESIZE
- {
- { true, false, false },
- { false, true, false },
- { false, false, true }
- },
- // PROPORTIONAL_RESIZE
- {
- { true, true, false },
- { true, true, false },
- { false, false, true }
- },
- // ARBITRARY_RESIZE
- {
- { true, true, true },
- { true, true, true },
- { true, true, true }
- }
- };
- for(int i = 0; i < NUMBER_OF_IMAGES; i++) {
- BufferedImage image1 = images[i];
- for(int j = i; j < NUMBER_OF_IMAGES; j++) {
- System.out.println("Comparing " + i + " to " + j);
- BufferedImage image2 = images[j];
- System.out.println("\nimage " + i + " " + image1.getWidth() +
- "x" + image1.getHeight());
- System.out.println("image " + j + " " + image2.getWidth() + "x"
- + image2.getHeight());
- for(ResizeImageComparator.ResizeMode resizeMode :
- ResizeImageComparator.ResizeMode.values()) {
-
- System.out.println("\n " + resizeMode);
- AWTImage.setComparator(new ResizeImageComparator(resizeMode,
- new AverageDistanceImageComparator(0.024)));
- Image awtImage1 = new AWTImage(image1);
- Image awtImage2 = new AWTImage(image2);
- boolean expResult = expected[resizeMode.ordinal()][i][j];
- Image diff = awtImage1.compareTo(awtImage2);
- boolean result = diff == null;
- if (diff != null) {
- diff.save("diff" + i + j + resizeMode + ".png");
- }
- assertEquals("Failed comparison for image " + i + " with " +
- "image " + j + ", resizeMode = " + resizeMode,
- expResult, result);
- }
- }
- }
- }
-
-}
--- /dev/null 2019-03-06 17:23:28.000000000 -0800
+++ new/core/JemmyAWTInput/test/org/jemmy/image/awt/AverageDistanceImageComparatorTest.java 2019-03-06 17:23:28.000000000 -0800
@@ -0,0 +1,319 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+
+import org.jemmy.image.Image;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import javax.imageio.ImageIO;
+
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.AssertJUnit.assertEquals;
+
+
+/**
+ *
+ * @author KAM
+ */
+public class AverageDistanceImageComparatorTest {
+
+ public AverageDistanceImageComparatorTest() {
+ }
+
+ static final int NUMBER_OF_IMAGES = 3;
+ static BufferedImage[] images;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ images = new BufferedImage[NUMBER_OF_IMAGES];
+ for(int i = 0; i < NUMBER_OF_IMAGES; i++) {
+ images[i] = ImageIO.read(AverageDistanceImageComparatorTest.class
+ .getResource("image" + (i + 1) + ".jpg"));
+ }
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @BeforeMethod
+ public void setUp() {
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ }
+
+ /**
+ * Test of compare method, of class AverageDistanceImageComparator.
+ */
+ @Test
+ public void testCompare1() {
+ System.out.println("compare1");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image1.createGraphics();
+ g.setColor(new Color(0.5f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ BufferedImage image2 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image2.createGraphics();
+ g.setColor(new Color(0.52f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
+ assertNull(instance.compare(new AWTImage(image1), new AWTImage(image2)));
+ }
+
+ /**
+ * Test of compare method, of class AverageDistanceImageComparator.
+ */
+ @Test
+ public void testCompare2() {
+ System.out.println("compare2");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image1.createGraphics();
+ g.setColor(new Color(0.5f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image3.createGraphics();
+ g.setColor(new Color(0.51f, 0.51f, 0.51f));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
+ assertNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
+ }
+
+ /**
+ * Test of compare method, of class AverageDistanceImageComparator.
+ */
+ @Test
+ public void testCompare3Pos() {
+ System.out.println("compare3Pos");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image1.createGraphics();
+ g.setColor(new Color(0.5f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image3.createGraphics();
+ g.setColor(new Color(0.5f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.setColor(new Color(0.6f, 0.6f, 0.6f));
+ g.fillRect(3, 3, 3, 3);
+ g.dispose();
+
+ AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
+ assertNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
+ }
+
+ /**
+ * Test of compare method, of class AverageDistanceImageComparator.
+ */
+ @Test
+ public void testCompare3Neg() {
+ System.out.println("compare3Neg");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image1.createGraphics();
+ g.setColor(new Color(0.5f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image3.createGraphics();
+ g.setColor(new Color(0.5f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.setColor(new Color(0.6f, 0.6f, 0.6f));
+ g.fillRect(3, 3, 3, 4);
+ g.dispose();
+
+ AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
+ assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
+ }
+
+ /**
+ * Test of compare method, of class AverageDistanceImageComparator.
+ */
+ @Test
+ public void testCompare4() {
+ System.out.println("compare4");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 11, BufferedImage.TYPE_INT_RGB);
+ BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+
+ AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
+ assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
+ }
+
+ /**
+ * Test of compare method, of class AverageDistanceImageComparator.
+ */
+ @Test
+ public void testCompare5() {
+ System.out.println("compare5");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ BufferedImage image3 = new BufferedImage(11, 10, BufferedImage.TYPE_INT_RGB);
+
+ AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
+ assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
+ }
+
+ /**
+ * Test of compare method, of class AverageDistanceImageComparator.
+ */
+ @Test
+ public void testCompare6() {
+ System.out.println("compare6");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image1.createGraphics();
+ g.setColor(new Color(0, 0, 0));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image3.createGraphics();
+ g.setColor(new Color(255, 255, 255));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
+ assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
+ }
+
+ /**
+ * Test of compare method, of class AverageDistanceImageComparator.
+ */
+ @Test
+ public void testCompare7() {
+ System.out.println("compare7");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image1.createGraphics();
+ g.setColor(new Color(0.51f, 0.51f, 0.51f));
+ g.fillRect(0, 0, 10, 5);
+ g.setColor(new Color(0.49f, 0.49f, 0.49f));
+ g.fillRect(0, 5, 10, 5);
+ g.dispose();
+
+ BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image3.createGraphics();
+ g.setColor(new Color(0.49f, 0.49f, 0.49f));
+ g.fillRect(0, 5, 10, 5);
+ g.setColor(new Color(0.51f, 0.51f, 0.51f));
+ g.fillRect(0, 0, 10, 5);
+ g.dispose();
+
+ AverageDistanceImageComparator instance = new AverageDistanceImageComparator();
+ assertNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
+ }
+
+ /**
+ * Test of compare method, of class AverageDistanceImageComparator.
+ * @throws IOException
+ */
+ @Test
+ public void testCompare() throws IOException {
+ System.out.println("compare");
+ boolean[][][] expected = {
+ // NO_RESIZE
+ {
+ { true, false, false },
+ { false, true, false },
+ { false, false, true }
+ },
+ // PROPORTIONAL_RESIZE
+ {
+ { true, true, false },
+ { true, true, false },
+ { false, false, true }
+ },
+ // ARBITRARY_RESIZE
+ {
+ { true, true, true },
+ { true, true, true },
+ { true, true, true }
+ }
+ };
+ for(int i = 0; i < NUMBER_OF_IMAGES; i++) {
+ BufferedImage image1 = images[i];
+ for(int j = i; j < NUMBER_OF_IMAGES; j++) {
+ System.out.println("Comparing " + i + " to " + j);
+ BufferedImage image2 = images[j];
+ System.out.println("\nimage " + i + " " + image1.getWidth() +
+ "x" + image1.getHeight());
+ System.out.println("image " + j + " " + image2.getWidth() + "x"
+ + image2.getHeight());
+ for(ResizeImageComparator.ResizeMode resizeMode :
+ ResizeImageComparator.ResizeMode.values()) {
+
+ System.out.println("\n " + resizeMode);
+ AWTImage.setComparator(new ResizeImageComparator(resizeMode,
+ new AverageDistanceImageComparator(0.024)));
+ Image awtImage1 = new AWTImage(image1);
+ Image awtImage2 = new AWTImage(image2);
+ boolean expResult = expected[resizeMode.ordinal()][i][j];
+ Image diff = awtImage1.compareTo(awtImage2);
+ boolean result = diff == null;
+ if (diff != null) {
+ diff.save("diff" + i + j + resizeMode + ".png");
+ }
+ assertEquals("Failed comparison for image " + i + " with " +
+ "image " + j + ", resizeMode = " + resizeMode,
+ expResult, result);
+ }
+ }
+ }
+ }
+
+}
Binary files old/core/JemmyAWTInput/test/org/jemmy/image/CheckBox_a_start.png and /dev/null differ
Binary files /dev/null and new/core/JemmyAWTInput/test/org/jemmy/image/awt/CheckBox_a_start.png differ
Binary files old/core/JemmyAWTInput/test/org/jemmy/image/CheckBox_a_start_res.png and /dev/null differ
Binary files /dev/null and new/core/JemmyAWTInput/test/org/jemmy/image/awt/CheckBox_a_start_res.png differ
--- old/core/JemmyAWTInput/test/org/jemmy/image/EnvTest.java 2019-03-06 17:23:30.000000000 -0800
+++ /dev/null 2019-03-06 17:23:30.000000000 -0800
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-import org.jemmy.env.Environment;
-import org.jemmy.image.pixel.PixelEqualityRasterComparator;
-import org.jemmy.image.pixel.RasterComparator;
-import org.testng.annotations.Test;
-
-import static org.testng.AssertJUnit.assertTrue;
-
-/**
- *
- * @author shura
- */
-public class EnvTest {
-
- public EnvTest() {
- }
-
- @Test
- public void testRaster() {
- Environment.getEnvironment().setProperty(RasterComparator.class, new PixelEqualityRasterComparator(1));
- Environment.getEnvironment().setProperty(ImageCapturer.class, new AWTRobotCapturer());
- ImageComparator comp = Environment.getEnvironment().getProperty(ImageComparator.class);
- assertTrue(comp instanceof BufferedImageComparator);
- assertTrue(((BufferedImageComparator)comp).getRasterComparator() instanceof PixelEqualityRasterComparator);
- }
-}
--- /dev/null 2019-03-06 17:23:30.000000000 -0800
+++ new/core/JemmyAWTInput/test/org/jemmy/image/awt/EnvTest.java 2019-03-06 17:23:29.000000000 -0800
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+import org.jemmy.env.Environment;
+import org.jemmy.image.ImageCapturer;
+import org.jemmy.image.ImageComparator;
+import org.jemmy.image.awt.AWTRobotCapturer;
+import org.jemmy.image.awt.BufferedImageComparator;
+import org.jemmy.image.pixel.PixelEqualityRasterComparator;
+import org.jemmy.image.pixel.RasterComparator;
+import org.testng.annotations.Test;
+
+import static org.testng.AssertJUnit.assertTrue;
+
+/**
+ *
+ * @author shura
+ */
+public class EnvTest {
+
+ public EnvTest() {
+ }
+
+ @Test
+ public void testRaster() {
+ Environment.getEnvironment().setProperty(RasterComparator.class, new PixelEqualityRasterComparator(1));
+ Environment.getEnvironment().setProperty(ImageCapturer.class, new AWTRobotCapturer());
+ ImageComparator comp = Environment.getEnvironment().getProperty(ImageComparator.class);
+ assertTrue(comp instanceof BufferedImageComparator);
+ assertTrue(((BufferedImageComparator)comp).getRasterComparator() instanceof PixelEqualityRasterComparator);
+ }
+}
--- old/core/JemmyAWTInput/test/org/jemmy/image/ImageResizerTest.java 2019-03-06 17:23:30.000000000 -0800
+++ /dev/null 2019-03-06 17:23:30.000000000 -0800
@@ -1,218 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-import java.awt.image.BufferedImage;
-import org.jemmy.image.ResizeImageComparator.ResizeMode;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertNull;
-import static org.testng.AssertJUnit.assertEquals;
-
-/**
- *
- * @author mrkam
- */
-public class ImageResizerTest {
-
- public ImageResizerTest() {
- }
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
-
- @BeforeMethod
- public void setUp() {
- }
-
- @AfterMethod
- public void tearDown() {
- }
-
- /**
- * Test of default value of ResizeMode, of class ImageResizer.
- */
- @Test
- public void testDefaultResizeMode() {
- System.out.println("testDefaultResizeMode");
- ResizeMode expResult = ResizeMode.PROPORTIONAL_RESIZE;
- ResizeMode result = new ResizeImageComparator(null).resizeMode;
- assertEquals(expResult, result);
- }
-
- /**
- * Test of setDefaultResizeMode method, of class ImageResizer.
- */
- @Test
- public void testProportionalResizeMode() {
- System.out.println("testProportionalResizeMode");
-
- new ResizeImageComparator(new ImageComparator() {
-
- public Image compare(Image image1,
- Image image2) {
- assertEquals(50, ((AWTImage) image2).getSize().width);
- assertEquals(50, ((AWTImage) image2).getSize().height);
- return null;
- }
-
- public String getID() {
- return "test";
- }
- }).compare(new AWTImage(new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB)),
- new AWTImage(new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB)));
- }
-
- /**
- * Test of getResized method, of class ImageResizer.
- */
- @Test
- public void testGetResizedNoResize() {
- System.out.println("getResizedNoResize");
- final AWTImage image1 =
- new AWTImage(new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB));
- final AWTImage image2 =
- new AWTImage(new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB));
-
- new ResizeImageComparator(ResizeMode.NO_RESIZE, new ImageComparator() {
-
- public Image compare(Image im1,
- Image im2) {
- assertEquals(image1, im1);
- assertEquals(image2, im2);
- return null;
- }
-
- public String getID() {
- return "test";
- }
- }).compare(image1, image2);
- }
-
- /**
- * Test of getResized method, of class ImageResizer.
- */
- @Test
- public void testGetResizedProportional1() {
- System.out.println("getResizedProportional1");
- BufferedImage image1 =
- new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- BufferedImage image2 =
- new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- assertNull(new ResizeImageComparator(ResizeMode.PROPORTIONAL_RESIZE,
- new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2)));
- }
-
- /**
- * Test of getResized method, of class ImageResizer.
- */
- @Test
- public void testGetResizedProportional2() {
- System.out.println("getResizedProportional2");
- BufferedImage image1 =
- new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- BufferedImage image2 =
- new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB);
- assertNull(new ResizeImageComparator(ResizeMode.PROPORTIONAL_RESIZE,
- new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2)));
- }
-
- /**
- * Test of getResized method, of class ImageResizer.
- */
- @Test
- public void testGetResizedProportional3() {
- System.out.println("getResizedProportional3");
- final AWTImage image1 =
- new AWTImage(new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB));
- final AWTImage image2 =
- new AWTImage(new BufferedImage(10, 15, BufferedImage.TYPE_INT_RGB));
- new ResizeImageComparator(ResizeMode.PROPORTIONAL_RESIZE,
- new ImageComparator() {
-
- public Image compare(Image im1,
- Image im2) {
- assertEquals(image1, im1);
- assertEquals(image2, im2);
- return null;
- }
-
- public String getID() {
- return "test";
- }
- }).compare(image1, image2);
- }
-
- /**
- * Test of getResized method, of class ImageResizer.
- */
- @Test
- public void testGetResizedArbitrary1() {
- System.out.println("getResizedArbitrary1");
- BufferedImage image1 =
- new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- BufferedImage image2 =
- new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- assertNull(new ResizeImageComparator(ResizeMode.ARBITRARY_RESIZE,
- new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2)));
- }
-
- /**
- * Test of getResized method, of class ImageResizer.
- */
- @Test
- public void testGetResizedArbitrary2() {
- System.out.println("getResizedArbitrary2");
- BufferedImage image1 =
- new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- BufferedImage image2 =
- new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB);
- assertNull(new ResizeImageComparator(ResizeMode.ARBITRARY_RESIZE,
- new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2)));
- }
-
- /**
- * Test of getResized method, of class ImageResizer.
- */
- @Test
- public void testGetResizedArbitrary3() {
- System.out.println("getResizedArbitrary3");
- BufferedImage image1 =
- new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- BufferedImage image2 =
- new BufferedImage(10, 15, BufferedImage.TYPE_INT_RGB);
- assertNull(new ResizeImageComparator(ResizeMode.ARBITRARY_RESIZE,
- new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2)));
- }
-}
--- /dev/null 2019-03-06 17:23:30.000000000 -0800
+++ new/core/JemmyAWTInput/test/org/jemmy/image/awt/ImageResizerTest.java 2019-03-06 17:23:30.000000000 -0800
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+import java.awt.image.BufferedImage;
+
+import org.jemmy.image.Image;
+import org.jemmy.image.ImageComparator;
+import org.jemmy.image.awt.AWTImage;
+import org.jemmy.image.awt.ResizeImageComparator;
+import org.jemmy.image.awt.ResizeImageComparator.ResizeMode;
+import org.jemmy.image.awt.StrictImageComparator;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertNull;
+import static org.testng.AssertJUnit.assertEquals;
+
+/**
+ *
+ * @author mrkam
+ */
+public class ImageResizerTest {
+
+ public ImageResizerTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @BeforeMethod
+ public void setUp() {
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ }
+
+ /**
+ * Test of default value of ResizeMode, of class ImageResizer.
+ */
+ @Test
+ public void testDefaultResizeMode() {
+ System.out.println("testDefaultResizeMode");
+ ResizeMode expResult = ResizeMode.PROPORTIONAL_RESIZE;
+ ResizeMode result = new ResizeImageComparator(null).resizeMode;
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of setDefaultResizeMode method, of class ImageResizer.
+ */
+ @Test
+ public void testProportionalResizeMode() {
+ System.out.println("testProportionalResizeMode");
+
+ new ResizeImageComparator(new ImageComparator() {
+
+ public Image compare(Image image1,
+ Image image2) {
+ assertEquals(50, ((AWTImage) image2).getSize().width);
+ assertEquals(50, ((AWTImage) image2).getSize().height);
+ return null;
+ }
+
+ public String getID() {
+ return "test";
+ }
+ }).compare(new AWTImage(new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB)),
+ new AWTImage(new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB)));
+ }
+
+ /**
+ * Test of getResized method, of class ImageResizer.
+ */
+ @Test
+ public void testGetResizedNoResize() {
+ System.out.println("getResizedNoResize");
+ final AWTImage image1 =
+ new AWTImage(new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB));
+ final AWTImage image2 =
+ new AWTImage(new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB));
+
+ new ResizeImageComparator(ResizeMode.NO_RESIZE, new ImageComparator() {
+
+ public Image compare(Image im1,
+ Image im2) {
+ assertEquals(image1, im1);
+ assertEquals(image2, im2);
+ return null;
+ }
+
+ public String getID() {
+ return "test";
+ }
+ }).compare(image1, image2);
+ }
+
+ /**
+ * Test of getResized method, of class ImageResizer.
+ */
+ @Test
+ public void testGetResizedProportional1() {
+ System.out.println("getResizedProportional1");
+ BufferedImage image1 =
+ new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ BufferedImage image2 =
+ new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ assertNull(new ResizeImageComparator(ResizeMode.PROPORTIONAL_RESIZE,
+ new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2)));
+ }
+
+ /**
+ * Test of getResized method, of class ImageResizer.
+ */
+ @Test
+ public void testGetResizedProportional2() {
+ System.out.println("getResizedProportional2");
+ BufferedImage image1 =
+ new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ BufferedImage image2 =
+ new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB);
+ assertNull(new ResizeImageComparator(ResizeMode.PROPORTIONAL_RESIZE,
+ new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2)));
+ }
+
+ /**
+ * Test of getResized method, of class ImageResizer.
+ */
+ @Test
+ public void testGetResizedProportional3() {
+ System.out.println("getResizedProportional3");
+ final AWTImage image1 =
+ new AWTImage(new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB));
+ final AWTImage image2 =
+ new AWTImage(new BufferedImage(10, 15, BufferedImage.TYPE_INT_RGB));
+ new ResizeImageComparator(ResizeMode.PROPORTIONAL_RESIZE,
+ new ImageComparator() {
+
+ public Image compare(Image im1,
+ Image im2) {
+ assertEquals(image1, im1);
+ assertEquals(image2, im2);
+ return null;
+ }
+
+ public String getID() {
+ return "test";
+ }
+ }).compare(image1, image2);
+ }
+
+ /**
+ * Test of getResized method, of class ImageResizer.
+ */
+ @Test
+ public void testGetResizedArbitrary1() {
+ System.out.println("getResizedArbitrary1");
+ BufferedImage image1 =
+ new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ BufferedImage image2 =
+ new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ assertNull(new ResizeImageComparator(ResizeMode.ARBITRARY_RESIZE,
+ new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2)));
+ }
+
+ /**
+ * Test of getResized method, of class ImageResizer.
+ */
+ @Test
+ public void testGetResizedArbitrary2() {
+ System.out.println("getResizedArbitrary2");
+ BufferedImage image1 =
+ new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ BufferedImage image2 =
+ new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB);
+ assertNull(new ResizeImageComparator(ResizeMode.ARBITRARY_RESIZE,
+ new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2)));
+ }
+
+ /**
+ * Test of getResized method, of class ImageResizer.
+ */
+ @Test
+ public void testGetResizedArbitrary3() {
+ System.out.println("getResizedArbitrary3");
+ BufferedImage image1 =
+ new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ BufferedImage image2 =
+ new BufferedImage(10, 15, BufferedImage.TYPE_INT_RGB);
+ assertNull(new ResizeImageComparator(ResizeMode.ARBITRARY_RESIZE,
+ new StrictImageComparator()).compare(new AWTImage(image1), new AWTImage(image2)));
+ }
+}
--- old/core/JemmyAWTInput/test/org/jemmy/image/InitTest.java 2019-03-06 17:23:31.000000000 -0800
+++ /dev/null 2019-03-06 17:23:31.000000000 -0800
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-import java.io.IOException;
-import org.jemmy.env.Environment;
-import org.jemmy.image.pixel.MaxDistanceComparator;
-import org.jemmy.image.pixel.PixelEqualityRasterComparator;
-import org.jemmy.operators.AWTScreen;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-
-/**
- *
- * @author shura
- */
-public class InitTest {
-
- public InitTest() {
- }
-
- @BeforeClass
- public static void setup() throws InterruptedException, IOException {
- }
-
- @Test
- public void testImage() {
- Environment.getEnvironment().setProperty(ImageCapturer.class, new AWTRobotCapturer());
- Image i = new AWTScreen().getScreenImage();
- assertTrue(i instanceof AWTImage);
- assertNull(i.compareTo(i));
- }
-
- @Test
- public void testComparator() {
- Environment.getEnvironment().setProperty(ImageCapturer.class, new AWTRobotCapturer());
- ImageComparator comp = Environment.getEnvironment().getProperty(ImageComparator.class);
- System.out.println("comp = " + comp);
- assertTrue(comp instanceof BufferedImageComparator);
- assertTrue(((BufferedImageComparator)comp).getRasterComparator() instanceof PixelEqualityRasterComparator);
- }
-
-}
--- /dev/null 2019-03-06 17:23:31.000000000 -0800
+++ new/core/JemmyAWTInput/test/org/jemmy/image/awt/InitTest.java 2019-03-06 17:23:31.000000000 -0800
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+import java.io.IOException;
+import org.jemmy.env.Environment;
+import org.jemmy.image.Image;
+import org.jemmy.image.ImageCapturer;
+import org.jemmy.image.ImageComparator;
+import org.jemmy.image.awt.AWTImage;
+import org.jemmy.image.awt.AWTRobotCapturer;
+import org.jemmy.image.awt.BufferedImageComparator;
+import org.jemmy.image.pixel.PixelEqualityRasterComparator;
+import org.jemmy.operators.awt.AWTScreen;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+/**
+ *
+ * @author shura
+ */
+public class InitTest {
+
+ public InitTest() {
+ }
+
+ @BeforeClass
+ public static void setup() throws InterruptedException, IOException {
+ }
+
+ @Test
+ public void testImage() {
+ Environment.getEnvironment().setProperty(ImageCapturer.class, new AWTRobotCapturer());
+ Image i = new AWTScreen().getScreenImage();
+ assertTrue(i instanceof AWTImage);
+ assertNull(i.compareTo(i));
+ }
+
+ @Test
+ public void testComparator() {
+ Environment.getEnvironment().setProperty(ImageCapturer.class, new AWTRobotCapturer());
+ ImageComparator comp = Environment.getEnvironment().getProperty(ImageComparator.class);
+ System.out.println("comp = " + comp);
+ assertTrue(comp instanceof BufferedImageComparator);
+ assertTrue(((BufferedImageComparator)comp).getRasterComparator() instanceof PixelEqualityRasterComparator);
+ }
+
+}
--- old/core/JemmyAWTInput/test/org/jemmy/image/NaturalImageComparatorTest.java 2019-03-06 17:23:32.000000000 -0800
+++ /dev/null 2019-03-06 17:23:32.000000000 -0800
@@ -1,312 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.image.BufferedImage;
-import java.awt.image.DataBufferInt;
-import java.io.IOException;
-import javax.imageio.ImageIO;
-
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.fail;
-import static org.testng.AssertJUnit.assertEquals;
-
-/**
- *
- * @author KAM
- */
-public class NaturalImageComparatorTest {
-
- public NaturalImageComparatorTest() {
- }
- static final int NUMBER_OF_IMAGES = 3;
- static BufferedImage[] images;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- images = new BufferedImage[NUMBER_OF_IMAGES];
- for (int i = 0; i < NUMBER_OF_IMAGES; i++) {
- images[i] = ImageIO.read(NaturalImageComparatorTest.class.getResource("image" + (i + 1) + ".jpg"));
- }
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
-
- @BeforeMethod
- public void setUp() {
- }
-
- @AfterMethod
- public void tearDown() {
- }
-
- /**
- * Test of compare method, of class NaturalImageComparator.
- */
- @Test
- public void testCompare1() {
- System.out.println("compare1");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image1.createGraphics();
- g.setColor(new Color(0.5f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- BufferedImage image2 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image2.createGraphics();
- g.setColor(new Color(0.52f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- NaturalImageComparator instance = new NaturalImageComparator();
- assertNull(instance.compare(new AWTImage(image1), new AWTImage(image2)));
- }
-
- /**
- * Test of compare method, of class NaturalImageComparator.
- */
- @Test
- public void testCompare2() {
- System.out.println("compare2");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image1.createGraphics();
- g.setColor(new Color(0.5f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image3.createGraphics();
- g.setColor(new Color(0.51f, 0.51f, 0.51f));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- NaturalImageComparator instance = new NaturalImageComparator();
- assertNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
- }
-
- /**
- * Test of compare method, of class NaturalImageComparator.
- */
- @Test
- public void testCompare3() {
- System.out.println("compare3");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image1.createGraphics();
- g.setColor(new Color(0.5f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.dispose();
-
- BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- g = image3.createGraphics();
- g.setColor(new Color(0.5f, 0.5f, 0.5f));
- g.fillRect(0, 0, 10, 10);
- g.setColor(new Color(0.53f, 0.5f, 0.5f));
- g.fillRect(3, 3, 1, 1);
- g.dispose();
-
- NaturalImageComparator instance = new NaturalImageComparator();
- assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
- }
-
- /**
- * Test of compare method, of class NaturalImageComparator.
- */
- @Test
- public void testCompare4() {
- System.out.println("compare4");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 11, BufferedImage.TYPE_INT_RGB);
- BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
-
- NaturalImageComparator instance = new NaturalImageComparator();
- assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
- }
-
- /**
- * Test of compare method, of class NaturalImageComparator.
- */
- @Test
- public void testCompare5() {
- System.out.println("compare5");
- Graphics2D g;
-
- BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
- BufferedImage image3 = new BufferedImage(11, 10, BufferedImage.TYPE_INT_RGB);
-
- NaturalImageComparator instance = new NaturalImageComparator();
- assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
- }
-
- /**
- * Test of compare method, of class NaturalImageComparator.
- *
- * @throws IOException
- */
- @Test
- public void testCompare() throws IOException {
- System.out.println("compare");
- boolean[][][] expected = {
- // NO_RESIZE
- {
- {true, false, false},
- {false, true, false},
- {false, false, true}
- },
- // PROPORTIONAL_RESIZE
- {
- {true, true, false},
- {true, true, false},
- {false, false, true}
- },
- // ARBITRARY_RESIZE
- {
- {true, true, true},
- {true, true, true},
- {true, true, true}
- }
- };
- for (int i = 0; i < NUMBER_OF_IMAGES; i++) {
- BufferedImage image1 = images[i];
- for (int j = i; j < NUMBER_OF_IMAGES; j++) {
- BufferedImage image2 = images[j];
- System.out.println("\nimage " + i + " " + image1.getWidth()
- + "x" + image1.getHeight());
- System.out.println("image " + j + " " + image2.getWidth() + "x"
- + image2.getHeight());
- for (ResizeImageComparator.ResizeMode resizeMode :
- ResizeImageComparator.ResizeMode.values()) {
-
- System.out.println("\n " + resizeMode);
- AWTImage.setComparator(new ResizeImageComparator(resizeMode,
- new NaturalImageComparator(1.1)));
- Image awtImage1 = new AWTImage(image1);
- Image awtImage2 = new AWTImage(image2);
- boolean expResult = expected[resizeMode.ordinal()][i][j];
- Image diff = awtImage1.compareTo(awtImage2);
- boolean result = diff == null;
- if (diff != null) {
- diff.save("diff" + i + j + resizeMode + ".png");
- }
- assertEquals("Failed comparison for image " + i + " with "
- + "image " + j + ", resizeMode = " + resizeMode,
- expResult, result);
- }
- }
- }
- }
-
- @Test
- public void testFXDiff() {
- System.out.println("fxDiff");
- AWTImage.setComparator(new NaturalImageComparator());
- ClasspathImageLoader cil = new ClasspathImageLoader();
- cil.setClassLoader(this.getClass().getClassLoader());
- cil.setRootPackage(this.getClass().getPackage());
- Image im1 = cil.load("AreaChart_a.png");
- Image im2 = cil.load("AreaChart_a_res.png");
- Image diff = im1.compareTo(im2);
- if (diff != null) {
- diff.save("testFXDiff_1to2.png");
- checkDiff(diff);
- }
- assertNotNull("Images has to be different", diff);
-
- diff = im2.compareTo(im1);
- if (diff != null) {
- diff.save("testFXDiff_2to1.png");
- checkDiff(diff);
- }
- assertNotNull("Images has to be different", diff);
- }
-
- /**
- * http://javafx-jira.kenai.com/browse/JMY-202
- * Jemmy produces completely black diffs in some cases
- */
- @Test
- public void testFXDiff2() {
- System.out.println("fxDiff2");
- AWTImage.setComparator(new NaturalImageComparator());
- ClasspathImageLoader cil = new ClasspathImageLoader();
- cil.setClassLoader(this.getClass().getClassLoader());
- cil.setRootPackage(this.getClass().getPackage());
-
- BufferedImage img1 = ((AWTImage) cil.load("AreaChart_a.png")).getTheImage();
- BufferedImage img3 = new BufferedImage(img1.getWidth(), img1.getHeight(), 3);
- for (int x = 0; x < img1.getWidth(); x++) {
- for (int y = 0; y < img1.getHeight(); y++) {
- img3.setRGB(x, y, img1.getRGB(x, y));
- }
- }
- Image im1 = new AWTImage(img3);
- Image im2 = cil.load("AreaChart_a_res.png");
- Image diff = im1.compareTo(im2);
- if (diff != null) {
- diff.save("testFXDiff2_1to2.png");
- checkDiff(diff);
- }
- assertNotNull("Images has to be different", diff);
-
- diff = im2.compareTo(im1);
- if (diff != null) {
- diff.save("testFXDiff2_2to1.png");
- checkDiff(diff);
- }
- assertNotNull("Images has to be different", diff);
- }
-
- private void checkDiff(Image diff) {
- BufferedImage im = ((AWTImage) diff).getTheImage();
- int[] data = ((DataBufferInt) im.getRaster().getDataBuffer()).getData();
- for (int d : data) {
- if ((d & 0xffffff) != 0) {
- System.out.println("d = " + Integer.toBinaryString(d));
- return;
- }
- if (d != 0) {
- System.out.println("d = " + Integer.toBinaryString(d));
- }
- }
- fail("Diff is completely black");
- }
-}
--- /dev/null 2019-03-06 17:23:32.000000000 -0800
+++ new/core/JemmyAWTInput/test/org/jemmy/image/awt/NaturalImageComparatorTest.java 2019-03-06 17:23:32.000000000 -0800
@@ -0,0 +1,313 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+import org.jemmy.image.Image;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferInt;
+import java.io.IOException;
+import javax.imageio.ImageIO;
+
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.fail;
+import static org.testng.AssertJUnit.assertEquals;
+
+/**
+ *
+ * @author KAM
+ */
+public class NaturalImageComparatorTest {
+
+ public NaturalImageComparatorTest() {
+ }
+ static final int NUMBER_OF_IMAGES = 3;
+ static BufferedImage[] images;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ images = new BufferedImage[NUMBER_OF_IMAGES];
+ for (int i = 0; i < NUMBER_OF_IMAGES; i++) {
+ images[i] = ImageIO.read(NaturalImageComparatorTest.class.getResource("image" + (i + 1) + ".jpg"));
+ }
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @BeforeMethod
+ public void setUp() {
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ }
+
+ /**
+ * Test of compare method, of class NaturalImageComparator.
+ */
+ @Test
+ public void testCompare1() {
+ System.out.println("compare1");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image1.createGraphics();
+ g.setColor(new Color(0.5f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ BufferedImage image2 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image2.createGraphics();
+ g.setColor(new Color(0.52f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ NaturalImageComparator instance = new NaturalImageComparator();
+ assertNull(instance.compare(new AWTImage(image1), new AWTImage(image2)));
+ }
+
+ /**
+ * Test of compare method, of class NaturalImageComparator.
+ */
+ @Test
+ public void testCompare2() {
+ System.out.println("compare2");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image1.createGraphics();
+ g.setColor(new Color(0.5f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image3.createGraphics();
+ g.setColor(new Color(0.51f, 0.51f, 0.51f));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ NaturalImageComparator instance = new NaturalImageComparator();
+ assertNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
+ }
+
+ /**
+ * Test of compare method, of class NaturalImageComparator.
+ */
+ @Test
+ public void testCompare3() {
+ System.out.println("compare3");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image1.createGraphics();
+ g.setColor(new Color(0.5f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.dispose();
+
+ BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ g = image3.createGraphics();
+ g.setColor(new Color(0.5f, 0.5f, 0.5f));
+ g.fillRect(0, 0, 10, 10);
+ g.setColor(new Color(0.53f, 0.5f, 0.5f));
+ g.fillRect(3, 3, 1, 1);
+ g.dispose();
+
+ NaturalImageComparator instance = new NaturalImageComparator();
+ assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
+ }
+
+ /**
+ * Test of compare method, of class NaturalImageComparator.
+ */
+ @Test
+ public void testCompare4() {
+ System.out.println("compare4");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 11, BufferedImage.TYPE_INT_RGB);
+ BufferedImage image3 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+
+ NaturalImageComparator instance = new NaturalImageComparator();
+ assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
+ }
+
+ /**
+ * Test of compare method, of class NaturalImageComparator.
+ */
+ @Test
+ public void testCompare5() {
+ System.out.println("compare5");
+ Graphics2D g;
+
+ BufferedImage image1 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
+ BufferedImage image3 = new BufferedImage(11, 10, BufferedImage.TYPE_INT_RGB);
+
+ NaturalImageComparator instance = new NaturalImageComparator();
+ assertNotNull(instance.compare(new AWTImage(image1), new AWTImage(image3)));
+ }
+
+ /**
+ * Test of compare method, of class NaturalImageComparator.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testCompare() throws IOException {
+ System.out.println("compare");
+ boolean[][][] expected = {
+ // NO_RESIZE
+ {
+ {true, false, false},
+ {false, true, false},
+ {false, false, true}
+ },
+ // PROPORTIONAL_RESIZE
+ {
+ {true, true, false},
+ {true, true, false},
+ {false, false, true}
+ },
+ // ARBITRARY_RESIZE
+ {
+ {true, true, true},
+ {true, true, true},
+ {true, true, true}
+ }
+ };
+ for (int i = 0; i < NUMBER_OF_IMAGES; i++) {
+ BufferedImage image1 = images[i];
+ for (int j = i; j < NUMBER_OF_IMAGES; j++) {
+ BufferedImage image2 = images[j];
+ System.out.println("\nimage " + i + " " + image1.getWidth()
+ + "x" + image1.getHeight());
+ System.out.println("image " + j + " " + image2.getWidth() + "x"
+ + image2.getHeight());
+ for (ResizeImageComparator.ResizeMode resizeMode :
+ ResizeImageComparator.ResizeMode.values()) {
+
+ System.out.println("\n " + resizeMode);
+ AWTImage.setComparator(new ResizeImageComparator(resizeMode,
+ new NaturalImageComparator(1.1)));
+ Image awtImage1 = new AWTImage(image1);
+ Image awtImage2 = new AWTImage(image2);
+ boolean expResult = expected[resizeMode.ordinal()][i][j];
+ Image diff = awtImage1.compareTo(awtImage2);
+ boolean result = diff == null;
+ if (diff != null) {
+ diff.save("diff" + i + j + resizeMode + ".png");
+ }
+ assertEquals("Failed comparison for image " + i + " with "
+ + "image " + j + ", resizeMode = " + resizeMode,
+ expResult, result);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testFXDiff() {
+ System.out.println("fxDiff");
+ AWTImage.setComparator(new NaturalImageComparator());
+ ClasspathImageLoader cil = new ClasspathImageLoader();
+ cil.setClassLoader(this.getClass().getClassLoader());
+ cil.setRootPackage(this.getClass().getPackage());
+ Image im1 = cil.load("AreaChart_a.png");
+ Image im2 = cil.load("AreaChart_a_res.png");
+ Image diff = im1.compareTo(im2);
+ if (diff != null) {
+ diff.save("testFXDiff_1to2.png");
+ checkDiff(diff);
+ }
+ assertNotNull("Images has to be different", diff);
+
+ diff = im2.compareTo(im1);
+ if (diff != null) {
+ diff.save("testFXDiff_2to1.png");
+ checkDiff(diff);
+ }
+ assertNotNull("Images has to be different", diff);
+ }
+
+ /**
+ * http://javafx-jira.kenai.com/browse/JMY-202
+ * Jemmy produces completely black diffs in some cases
+ */
+ @Test
+ public void testFXDiff2() {
+ System.out.println("fxDiff2");
+ AWTImage.setComparator(new NaturalImageComparator());
+ ClasspathImageLoader cil = new ClasspathImageLoader();
+ cil.setClassLoader(this.getClass().getClassLoader());
+ cil.setRootPackage(this.getClass().getPackage());
+
+ BufferedImage img1 = ((AWTImage) cil.load("AreaChart_a.png")).getTheImage();
+ BufferedImage img3 = new BufferedImage(img1.getWidth(), img1.getHeight(), 3);
+ for (int x = 0; x < img1.getWidth(); x++) {
+ for (int y = 0; y < img1.getHeight(); y++) {
+ img3.setRGB(x, y, img1.getRGB(x, y));
+ }
+ }
+ Image im1 = new AWTImage(img3);
+ Image im2 = cil.load("AreaChart_a_res.png");
+ Image diff = im1.compareTo(im2);
+ if (diff != null) {
+ diff.save("testFXDiff2_1to2.png");
+ checkDiff(diff);
+ }
+ assertNotNull("Images has to be different", diff);
+
+ diff = im2.compareTo(im1);
+ if (diff != null) {
+ diff.save("testFXDiff2_2to1.png");
+ checkDiff(diff);
+ }
+ assertNotNull("Images has to be different", diff);
+ }
+
+ private void checkDiff(Image diff) {
+ BufferedImage im = ((AWTImage) diff).getTheImage();
+ int[] data = ((DataBufferInt) im.getRaster().getDataBuffer()).getData();
+ for (int d : data) {
+ if ((d & 0xffffff) != 0) {
+ System.out.println("d = " + Integer.toBinaryString(d));
+ return;
+ }
+ if (d != 0) {
+ System.out.println("d = " + Integer.toBinaryString(d));
+ }
+ }
+ fail("Diff is completely black");
+ }
+}
--- old/core/JemmyAWTInput/test/org/jemmy/image/SaveLoadTest.java 2019-03-06 17:23:32.000000000 -0800
+++ /dev/null 2019-03-06 17:23:33.000000000 -0800
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-import java.io.*;
-import org.jemmy.Rectangle;
-import org.jemmy.control.Wrap;
-import org.jemmy.env.Environment;
-import org.jemmy.image.pixel.PNGSaver;
-import org.jemmy.operators.ScreenRectangle;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertNull;
-
-/**
- *
- * @author shura
- */
-public class SaveLoadTest {
-
- public SaveLoadTest() {
- }
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
-
- @BeforeClass
- public void setUp() {
- }
-
- @AfterClass
- public void tearDown() {
- }
-
- @Test
- public void hello() throws FileNotFoundException, IOException {
- Wrap> wrap = new ScreenRectangle(Environment.getEnvironment(), new Rectangle(0, 0, 220, 220));
- AWTImage img = (AWTImage) new AWTRobotCapturer().capture(wrap, new Rectangle(0, 0, 200, 200));
- File imgFile = new File(System.getProperty("user.dir") + File.separator + "out.png");
- new PNGSaver(new FileOutputStream(imgFile), PNGSaver.COLOR_MODE).encode(img);
- AWTImage loaded = new AWTImage(new PNGImageLoader().load(new FileInputStream(imgFile)));
- new PNGSaver(new FileOutputStream(new File(System.getProperty("user.dir") + File.separator + "loaded.png")), PNGSaver.COLOR_MODE).encode(loaded);
- AWTImage diff = (AWTImage) img.compareTo(loaded);
- if(diff != null) {
- new PNGSaver(new FileOutputStream(new File(System.getProperty("user.dir") + File.separator + "diff.png")), PNGSaver.COLOR_MODE).encode(diff);
- }
- assertNull(diff);
- }
-}
--- /dev/null 2019-03-06 17:23:33.000000000 -0800
+++ new/core/JemmyAWTInput/test/org/jemmy/image/awt/SaveLoadTest.java 2019-03-06 17:23:32.000000000 -0800
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.jemmy.image.awt;
+
+import java.io.*;
+import org.jemmy.Rectangle;
+import org.jemmy.control.Wrap;
+import org.jemmy.env.Environment;
+import org.jemmy.image.awt.AWTImage;
+import org.jemmy.image.awt.AWTRobotCapturer;
+import org.jemmy.image.awt.PNGImageLoader;
+import org.jemmy.image.pixel.PNGSaver;
+import org.jemmy.operators.ScreenRectangle;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertNull;
+
+/**
+ *
+ * @author shura
+ */
+public class SaveLoadTest {
+
+ public SaveLoadTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @BeforeClass
+ public void setUp() {
+ }
+
+ @AfterClass
+ public void tearDown() {
+ }
+
+ @Test
+ public void hello() throws FileNotFoundException, IOException {
+ Wrap> wrap = new ScreenRectangle(Environment.getEnvironment(), new Rectangle(0, 0, 220, 220));
+ AWTImage img = (AWTImage) new AWTRobotCapturer().capture(wrap, new Rectangle(0, 0, 200, 200));
+ File imgFile = new File(System.getProperty("user.dir") + File.separator + "out.png");
+ new PNGSaver(new FileOutputStream(imgFile), PNGSaver.COLOR_MODE).encode(img);
+ AWTImage loaded = new AWTImage(new PNGImageLoader().load(new FileInputStream(imgFile)));
+ new PNGSaver(new FileOutputStream(new File(System.getProperty("user.dir") + File.separator + "loaded.png")), PNGSaver.COLOR_MODE).encode(loaded);
+ AWTImage diff = (AWTImage) img.compareTo(loaded);
+ if(diff != null) {
+ new PNGSaver(new FileOutputStream(new File(System.getProperty("user.dir") + File.separator + "diff.png")), PNGSaver.COLOR_MODE).encode(diff);
+ }
+ assertNull(diff);
+ }
+}
--- old/core/JemmyAWTInput/test/org/jemmy/image/ScreenAreaImageTest.java 2019-03-06 17:23:33.000000000 -0800
+++ /dev/null 2019-03-06 17:23:33.000000000 -0800
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.jemmy.image;
-
-import java.awt.EventQueue;
-import java.awt.Frame;
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.jemmy.Rectangle;
-import org.jemmy.TimeoutExpiredException;
-import org.jemmy.control.Wrap;
-import org.jemmy.env.Environment;
-import org.jemmy.operators.AWTScreen;
-import org.jemmy.operators.Screen;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.fail;
-
-/**
- *
- * @author shura
- */
-public class ScreenAreaImageTest {
-
- public ScreenAreaImageTest() {
- }
-
- static ImageLoader loader;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- Screen.setSCREEN(new AWTScreen());
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
- File tmpDump = null;
- File tmpDumpPart = null;
- Wrap