Skip to content

Commit fcb35ed

Browse files
committed
8287743: javax/swing/text/CSSBorder/6796710/bug6796710.java failed
Reviewed-by: aivanov
1 parent bdd64d6 commit fcb35ed

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

test/jdk/javax/swing/text/CSSBorder/6796710/bug6796710.java

+39-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
3232
*/
3333

3434
import java.awt.BorderLayout;
35+
import java.awt.Color;
3536
import java.awt.Rectangle;
3637
import java.awt.Robot;
3738
import java.awt.image.BufferedImage;
@@ -72,6 +73,7 @@ public class bug6796710 {
7273
private static JFrame frame;
7374

7475
private static JPanel pnBottom;
76+
private static final int COLOR_TOLERANCE = 5;
7577

7678
public static void main(String[] args) throws Exception {
7779
robot = new Robot();
@@ -126,7 +128,7 @@ public void run() {
126128
Thread.sleep(1000);
127129

128130
BufferedImage pnBottomImage = getPnBottomImage();
129-
if (!Util.compareBufferedImages(bufferedImage, pnBottomImage)) {
131+
if (!compareBufferedImages(bufferedImage, pnBottomImage)) {
130132
ImageIO.write(bufferedImage, "png", new File("bufferedImage.png"));
131133
ImageIO.write(pnBottomImage, "png", new File("pnBottomImage.png"));
132134
throw new RuntimeException("The test failed");
@@ -135,6 +137,41 @@ public void run() {
135137
System.out.println("The test bug6796710 passed.");
136138
}
137139

140+
public static boolean compareBufferedImages(BufferedImage bufferedImage0, BufferedImage bufferedImage1) {
141+
int width = bufferedImage0.getWidth();
142+
int height = bufferedImage0.getHeight();
143+
144+
if (width != bufferedImage1.getWidth() || height != bufferedImage1.getHeight()) {
145+
return false;
146+
}
147+
148+
for (int y = 0; y < height; y++) {
149+
for (int x = 0; x < width; x++) {
150+
Color bufCol0 = new Color(bufferedImage0.getRGB(x, y));
151+
Color bufCol1 = new Color(bufferedImage1.getRGB(x, y));
152+
153+
int red1 = bufCol0.getRed();
154+
int blue1 = bufCol0.getBlue();
155+
int green1 = bufCol0.getGreen();
156+
157+
int red2 = bufCol1.getRed();
158+
int blue2 = bufCol1.getBlue();
159+
int green2 = bufCol1.getGreen();
160+
161+
if ((Math.abs(red1 - red2) > COLOR_TOLERANCE) ||
162+
(Math.abs(green1 - green2) > COLOR_TOLERANCE) ||
163+
(Math.abs(blue1 - blue2) > COLOR_TOLERANCE)) {
164+
System.out.println("x "+ x + " y " + y +
165+
" rgb1: " + bufCol0 +
166+
" rgb2: " + bufCol1);
167+
return false;
168+
}
169+
}
170+
}
171+
172+
return true;
173+
}
174+
138175
private static BufferedImage getPnBottomImage() {
139176
Rectangle rect = pnBottom.getBounds();
140177

0 commit comments

Comments
 (0)