changeset 52895:4c436aab570a

8176556: java/awt/dnd/ImageTransferTest/ImageTransferTest.java fails for JFIF Reviewed-by: serb
author jdv
date Tue, 13 Nov 2018 09:39:57 +0530
parents e6753ace7f6d
children 7199c4da1a6f
files test/jdk/ProblemList.txt test/jdk/java/awt/dnd/ImageTransferTest/ImageTransferTest.java
diffstat 2 files changed, 39 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/ProblemList.txt	Mon Nov 12 22:28:08 2018 +0000
+++ b/test/jdk/ProblemList.txt	Tue Nov 13 09:39:57 2018 +0530
@@ -186,7 +186,6 @@
 java/awt/event/MouseEvent/MouseButtonsAndKeyMasksTest/MouseButtonsAndKeyMasksTest.java 8129778 generic-all
 
 java/awt/dnd/URIListToFileListBetweenJVMsTest/URIListToFileListBetweenJVMsTest.html 8194947 generic-all
-java/awt/dnd/ImageTransferTest/ImageTransferTest.java 8176556 generic-all
 java/awt/Frame/SetMaximizedBounds/SetMaximizedBounds.java 8196006 windows-all
 java/awt/Frame/FramesGC/FramesGC.java 8079069 macosx-all
 java/awt/FullScreen/AltTabCrashTest/AltTabCrashTest.java 8047218 generic-all
--- a/test/jdk/java/awt/dnd/ImageTransferTest/ImageTransferTest.java	Mon Nov 12 22:28:08 2018 +0000
+++ b/test/jdk/java/awt/dnd/ImageTransferTest/ImageTransferTest.java	Tue Nov 13 09:39:57 2018 +0530
@@ -24,7 +24,7 @@
 /*
  * @test
  * @key headful
- * @bug 4397404 4720930 8197926
+ * @bug 4397404 4720930 8197926 8176556
  * @summary tests that images of all supported native image formats are
  * transferred properly
  * @library /test/lib
@@ -134,21 +134,29 @@
 
 abstract class ImageTransferer {
     Image image;
+    Image imageForJpeg;
     String[] formats;
     int fi; // current format index
     Frame frame = new Frame();
 
 
     ImageTransferer() {
-        image = createImage();
+        image = createImage(false);
+        imageForJpeg = createImage(true);
         frame.setSize(100, 100);
     }
 
-    private static Image createImage() {
+    private static Image createImage(boolean forJpeg) {
         int w = 100;
         int h = 100;
         int[] pix = new int[w * h];
 
+        BufferedImage img;
+        if (!forJpeg) {
+            img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
+        } else {
+            img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
+        }
         int index = 0;
         for (int y = 0; y < h; y++) {
             for (int x = 0; x < w; x++) {
@@ -160,12 +168,18 @@
                     alpha = 0;
                     red = 0;
                 }
-                pix[index++] =
-                        (alpha << 24) | (red << 16) | (green << 8) | blue;
+                if (!forJpeg) {
+                    pix[index] =
+                        (alpha <<24) | (red << 16) | (green << 8) | blue;
+                } else {
+                    pix[index] =
+                        (red << 16) | (green << 8) | blue;
+                }
+                img.setRGB(x, y, pix[index]);
+                index++;
             }
         }
-        return Toolkit.getDefaultToolkit().
-                createImage(new MemoryImageSource(w, h, pix, 0, w));
+        return (Image)img;
     }
 
 
@@ -193,7 +207,7 @@
 
     boolean areImagesIdentical(Image im1, Image im2) {
         if (formats[fi].equals("JFIF") || formats[fi].equals("image/jpeg") ||
-        formats[fi].equals("GIF") || formats[fi].equals("image/gif")) {
+            formats[fi].equals("GIF") || formats[fi].equals("image/gif")) {
             // JFIF and GIF are lossy formats
             return true;
         }
@@ -205,8 +219,8 @@
         }
 
         if (formats[fi].equals("PNG") ||
-        formats[fi].equals("image/png") ||
-        formats[fi].equals("image/x-png")) {
+            formats[fi].equals("image/png") ||
+            formats[fi].equals("image/x-png")) {
             // check alpha as well
             for (int i = 0; i < ib1.length; i++) {
                 if (ib1[i] != ib2[i]) {
@@ -268,7 +282,13 @@
 
         new DragSource().createDefaultDragGestureRecognizer(frame,
         DnDConstants.ACTION_COPY,
-        dge -> dge.startDrag(null, new ImageSelection(image), dsl));
+        dge -> {
+            if (formats[fi].equals("JFIF") || formats[fi].equals("image/jpeg")) {
+                dge.startDrag(null, new ImageSelection(imageForJpeg), dsl);
+            } else {
+                dge.startDrag(null, new ImageSelection(image), dsl);
+            }
+        });
         leaveFormat(formats[fi]);
     }
 
@@ -314,6 +334,14 @@
                 return;
             }
 
+            /*
+             * We are using RGB source image for jpeg
+             * because there is no support for alpha channel.
+             * Also we are not verifying pixel data for jpeg
+             * in areImagesIdentical() since it is a lossy format.
+             * So after image drop we are not handling any needed
+             * special cases for jpeg.
+             */
             if (im == null) {
                 System.err.println("getTransferData returned null");
                 dtde.dropComplete(false);