RFR: 8342098: Write a test to compare the images [v3]

Manukumar V S mvs at openjdk.org
Mon Oct 21 08:30:31 UTC 2024


On Fri, 18 Oct 2024 15:54:24 GMT, Naveen Narayanan <duke at openjdk.org> wrote:

>> This testcase checks for the following:
>> 
>> 1. An image is drawn on the screen and a portion of it is captured using a Robot. It is tested by comparing whether the captured image is same as the source image. 
>> 
>> Testing:
>> Tested using Mach5(20 times per platform) in MacOS, Linux and Windows. Seen all tests passing.
>
> Naveen Narayanan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8342098: Updated review comments

test/jdk/java/awt/Robot/ScreenCaptureRobotTest.java line 103:

> 101:                     + "the actual image";
> 102:             System.err.println("Test failed");
> 103:             throw new RuntimeException(errorMessage);

Suggestion:

            System.err.println("Test failed");
            saveImage(capturedImage,"robotCapture.png");
            saveImage(realImage,"realImage.png");
            throw new RuntimeException(errorMessage);

test/jdk/java/awt/Robot/ScreenCaptureRobotTest.java line 125:

> 123:                 capturedPixel = capturedImg.getRGB(i, j);
> 124:                 realPixel = realImg.getRGB(i, j);
> 125:                 if (capturedPixel != realPixel) {

Suggestion:

               if (capturedPixel != realPixel) {
                    System.out.println("Captured pixel ("+capturedPixel+") at (" + i + ", " + j + ") is not equal to real pixel (" + realPixel + ")");

test/jdk/java/awt/Robot/ScreenCaptureRobotTest.java line 133:

> 131:         return result;
> 132:     }
> 133: 

Suggestion:

//Save BufferedImage to PNG file
    private static void saveImage(BufferedImage image, String fileName) {
        if (image != null) {
            try {
                File file = new File(fileName);
                System.out.println("Saving button image to " + file.getAbsolutePath());
                ImageIO.write(image, "PNG", file);
            } catch (Exception e) {
                throw new RuntimeException("Could not write image file");
            }
        } else {
            throw new RuntimeException("BufferedImage was set to null");
        }
    }

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21524#discussion_r1808318925
PR Review Comment: https://git.openjdk.org/jdk/pull/21524#discussion_r1808324098
PR Review Comment: https://git.openjdk.org/jdk/pull/21524#discussion_r1808321103


More information about the client-libs-dev mailing list