< prev index next >

test/java/awt/SplashScreen/MultiResolutionSplash/unix/UnixMultiResolutionSplashTest.java

Print this page




  27 import java.awt.Graphics;
  28 import java.awt.Graphics2D;
  29 import java.awt.Panel;
  30 import java.awt.Rectangle;
  31 import java.awt.Robot;
  32 import java.awt.SplashScreen;
  33 import java.awt.TextField;
  34 import java.awt.Window;
  35 import java.awt.event.KeyEvent;
  36 import java.awt.image.BufferedImage;
  37 import java.io.BufferedReader;
  38 import java.io.File;
  39 import java.io.InputStreamReader;
  40 import java.util.ArrayList;
  41 import java.util.HashMap;
  42 import java.util.List;
  43 import java.util.Map;
  44 import javax.imageio.ImageIO;
  45 
  46 /**
  47  * @test @bug 8145174
  48  * @summary HiDPI splash screen support on Linux
  49  * @modules java.desktop/sun.java2d
  50  * @run main UnixMultiResolutionSplashTest
  51  */
  52 public class UnixMultiResolutionSplashTest {
  53 
  54     private static final int IMAGE_WIDTH = 300;
  55     private static final int IMAGE_HEIGHT = 200;
  56     private static int inx = 0;
  57     private static final ImageInfo[] tests = {
  58         new ImageInfo("splash1.png", "splash1.java-scale2x.png", Color.BLUE, Color.GREEN),
  59         new ImageInfo("splash2", "splash2.java-scale2x", Color.WHITE, Color.BLACK),
  60         new ImageInfo("splash3.", "splash3.java-scale2x.", Color.YELLOW, Color.RED)
  61     };
  62 
  63     public static void main(String[] args) throws Exception {
  64 
  65         if (args.length == 0) {
  66             generateImages();
  67             for (ImageInfo test : tests) {
  68                 createChildProcess(test);
  69             }
  70         } else {
  71             int index = Integer.parseInt(args[0]);
  72             testSplash(tests[index]);
  73         }
  74     }
  75 
  76     static void createChildProcess(ImageInfo test) {
  77         String javaPath = System.getProperty("java.home");
  78         File file = new File(test.name1x);
  79         String classPathDir = System.getProperty("java.class.path");
  80         Map<String, String> env = new HashMap<String, String>();
  81         env.put("GDK_SCALE", "2");
  82         int exitValue = doExec(env, javaPath + File.separator + "bin" + File.separator
  83                 + "java", "-splash:" + file.getAbsolutePath(), "-cp",
  84                 classPathDir, "UnixMultiResolutionSplashTest", String.valueOf(inx++));
  85         if (exitValue != 0) {
  86             throw new RuntimeException("Test Failed");
  87         }
  88     }
  89 
  90     static void testSplash(ImageInfo test) throws Exception {
  91         SplashScreen splashScreen = SplashScreen.getSplashScreen();
  92         if (splashScreen == null) {
  93             throw new RuntimeException("Splash screen is not shown!");
  94         }
  95         Graphics2D g = splashScreen.createGraphics();
  96         Rectangle splashBounds = splashScreen.getBounds();
  97         int screenX = (int) splashBounds.getCenterX();
  98         int screenY = (int) splashBounds.getCenterY();
  99         System.out.println(screenX);
 100         System.out.println(screenY);
 101         Robot robot = new Robot();
 102         Color splashScreenColor = robot.getPixelColor(screenX, screenY);
 103 
 104         float scaleFactor = getScaleFactor();
 105         Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;
 106         if (!compare(testColor, splashScreenColor)) {
 107             throw new RuntimeException(
 108                     "Image with wrong resolution is used for splash screen!");
 109         }
 110     }
 111 
 112     static int doExec(Map<String, String> envToSet, String... cmds) {
 113         Process p = null;
 114         ProcessBuilder pb = new ProcessBuilder(cmds);
 115         Map<String, String> env = pb.environment();
 116         for (String cmd : cmds) {
 117             System.out.print(cmd + " ");
 118         }
 119         System.out.println();
 120         if (envToSet != null) {




  27 import java.awt.Graphics;
  28 import java.awt.Graphics2D;
  29 import java.awt.Panel;
  30 import java.awt.Rectangle;
  31 import java.awt.Robot;
  32 import java.awt.SplashScreen;
  33 import java.awt.TextField;
  34 import java.awt.Window;
  35 import java.awt.event.KeyEvent;
  36 import java.awt.image.BufferedImage;
  37 import java.io.BufferedReader;
  38 import java.io.File;
  39 import java.io.InputStreamReader;
  40 import java.util.ArrayList;
  41 import java.util.HashMap;
  42 import java.util.List;
  43 import java.util.Map;
  44 import javax.imageio.ImageIO;
  45 
  46 /**
  47  * @test @bug 8145174 8151787
  48  * @summary HiDPI splash screen support on Linux
  49  * @modules java.desktop/sun.java2d
  50  * @run main UnixMultiResolutionSplashTest
  51  */
  52 public class UnixMultiResolutionSplashTest {
  53 
  54     private static final int IMAGE_WIDTH = 300;
  55     private static final int IMAGE_HEIGHT = 200;
  56     private static int inx = 0;
  57     private static final ImageInfo[] tests = {
  58         new ImageInfo("splash1.png", "splash1@200pct.png", Color.BLUE, Color.GREEN),
  59         new ImageInfo("splash2", "splash2@2x", Color.WHITE, Color.BLACK),
  60         new ImageInfo("splash3.", "splash3@200pct.", Color.YELLOW, Color.RED)
  61     };
  62 
  63     public static void main(String[] args) throws Exception {
  64 
  65         if (args.length == 0) {
  66             generateImages();
  67             for (ImageInfo test : tests) {
  68                 createChildProcess(test);
  69             }
  70         } else {
  71             int index = Integer.parseInt(args[0]);
  72             testSplash(tests[index]);
  73         }
  74     }
  75 
  76     static void createChildProcess(ImageInfo test) {
  77         String javaPath = System.getProperty("java.home");
  78         File file = new File(test.name1x);
  79         String classPathDir = System.getProperty("java.class.path");
  80         Map<String, String> env = new HashMap<String, String>();
  81         env.put("GDK_SCALE", "2");
  82         int exitValue = doExec(env, javaPath + File.separator + "bin" + File.separator
  83                 + "java", "-splash:" + file.getAbsolutePath(), "-cp",
  84                 classPathDir, "UnixMultiResolutionSplashTest", String.valueOf(inx++));
  85         if (exitValue != 0) {
  86             throw new RuntimeException("Test Failed");
  87         }
  88     }
  89 
  90     static void testSplash(ImageInfo test) throws Exception {
  91         SplashScreen splashScreen = SplashScreen.getSplashScreen();
  92         if (splashScreen == null) {
  93             throw new RuntimeException("Splash screen is not shown!");
  94         }
  95         Graphics2D g = splashScreen.createGraphics();
  96         Rectangle splashBounds = splashScreen.getBounds();
  97         int screenX = (int) splashBounds.getCenterX();
  98         int screenY = (int) splashBounds.getCenterY();


  99         Robot robot = new Robot();
 100         Color splashScreenColor = robot.getPixelColor(screenX, screenY);
 101 
 102         float scaleFactor = getScaleFactor();
 103         Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;
 104         if (!compare(testColor, splashScreenColor)) {
 105             throw new RuntimeException(
 106                     "Image with wrong resolution is used for splash screen!");
 107         }
 108     }
 109 
 110     static int doExec(Map<String, String> envToSet, String... cmds) {
 111         Process p = null;
 112         ProcessBuilder pb = new ProcessBuilder(cmds);
 113         Map<String, String> env = pb.environment();
 114         for (String cmd : cmds) {
 115             System.out.print(cmd + " ");
 116         }
 117         System.out.println();
 118         if (envToSet != null) {


< prev index next >