20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8142406
27 * @author a.stepanov
28 * @summary [HiDPI] [macosx] check that for a pair of images
29 * (image.ext, image@2x.ext) the 1st one is loaded
30 * in case if the 2nd is corrupted
31 *
32 * @requires (os.family == "mac")
33 *
34 * @library ../../../../lib/testlibrary/
35 * @build ExtendedRobot
36 * @run main Corrupted2XImageTest
37 */
38
39 import java.awt.*;
40 import java.awt.geom.AffineTransform;
41 import java.awt.image.*;
42 import java.io.*;
43
44 import javax.imageio.ImageIO;
45
46 public class Corrupted2XImageTest extends Frame {
47
48 private static final int SZ = 200;
49 private static final Color C = Color.BLUE;
50
51 private final String format, name1x, name2x;
52
53 public Corrupted2XImageTest(String format) throws IOException {
54
55 this.format = format;
56 name1x = "test." + format;
57 name2x = "test@2x." + format;
58 createFiles();
59 }
60
99 Math.abs(c2.getRed() - c1.getRed() ) < tol &&
100 Math.abs(c2.getGreen() - c1.getGreen()) < tol &&
101 Math.abs(c2.getBlue() - c1.getBlue() ) < tol);
102 }
103
104 private void doTest() throws Exception {
105
106 ExtendedRobot r = new ExtendedRobot();
107 System.out.println("format: " + format);
108 r.waitForIdle(1000);
109 EventQueue.invokeAndWait(this::UI);
110 r.waitForIdle(1000);
111 Point loc = getLocationOnScreen();
112 Color c = r.getPixelColor(loc.x + SZ / 2, loc.y + SZ / 2);
113 if (!cmpColors(c, C)) {
114 throw new RuntimeException("test failed, color = " + c); }
115 System.out.println("ok");
116 dispose();
117 }
118
119 private static boolean is2x() {
120
121 AffineTransform tr = GraphicsEnvironment.getLocalGraphicsEnvironment().
122 getDefaultScreenDevice().getDefaultConfiguration().
123 getDefaultTransform();
124 return Math.min(tr.getScaleX(), tr.getScaleY()) > 1.001;
125 }
126
127 public static void main(String[] args) throws Exception {
128
129 // TODO: update the test with sun.java2d.uiScale option (remove is2x())
130 // after fix of JDK-8150844 enh. to run it on non-HiDPI machines as well
131 if (is2x()) {
132 // formats supported by Toolkit.getImage()
133 for (String format: new String[]{"gif", "jpg", "png"}) {
134 (new Corrupted2XImageTest(format)).doTest();
135 }
136 } else {
137 System.out.println("this test is for HiDPI only");
138 }
139 }
140 }
|
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8142406
27 * @author a.stepanov
28 * @summary [HiDPI] [macosx] check that for a pair of images
29 * (image.ext, image@2x.ext) the 1st one is loaded
30 * in case if the 2nd is corrupted
31 *
32 * @requires (os.family == "mac")
33 *
34 * @library ../../../../lib/testlibrary/
35 * @build ExtendedRobot
36 * @run main Corrupted2XImageTest
37 */
38
39 import java.awt.*;
40 import java.awt.image.*;
41 import java.io.*;
42
43 import javax.imageio.ImageIO;
44
45 public class Corrupted2XImageTest extends Frame {
46
47 private static final int SZ = 200;
48 private static final Color C = Color.BLUE;
49
50 private final String format, name1x, name2x;
51
52 public Corrupted2XImageTest(String format) throws IOException {
53
54 this.format = format;
55 name1x = "test." + format;
56 name2x = "test@2x." + format;
57 createFiles();
58 }
59
98 Math.abs(c2.getRed() - c1.getRed() ) < tol &&
99 Math.abs(c2.getGreen() - c1.getGreen()) < tol &&
100 Math.abs(c2.getBlue() - c1.getBlue() ) < tol);
101 }
102
103 private void doTest() throws Exception {
104
105 ExtendedRobot r = new ExtendedRobot();
106 System.out.println("format: " + format);
107 r.waitForIdle(1000);
108 EventQueue.invokeAndWait(this::UI);
109 r.waitForIdle(1000);
110 Point loc = getLocationOnScreen();
111 Color c = r.getPixelColor(loc.x + SZ / 2, loc.y + SZ / 2);
112 if (!cmpColors(c, C)) {
113 throw new RuntimeException("test failed, color = " + c); }
114 System.out.println("ok");
115 dispose();
116 }
117
118 public static void main(String[] args) throws Exception {
119
120 // formats supported by Toolkit.getImage()
121 for (String format : new String[]{"gif", "jpg", "png"}) {
122 (new Corrupted2XImageTest(format)).doTest();
123 }
124 }
125 }
|