10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @key headful
27 * @bug 4397404 4720930 8197926
28 * @summary tests that images of all supported native image formats are
29 * transferred properly
30 * @library ../../../../lib/testlibrary
31 * @library ../../regtesthelpers/process/
32 * @build jdk.testlibrary.OSInfo ProcessResults ProcessCommunicator
33 * @author gas@sparc.spb.su area=Clipboard
34 * @run main/timeout=240 ImageTransferTest
35 */
36
37 import test.java.awt.regtesthelpers.process.ProcessCommunicator;
38 import test.java.awt.regtesthelpers.process.ProcessResults;
39 import jdk.testlibrary.OSInfo;
40
41 import java.awt.*;
42 import java.awt.datatransfer.DataFlavor;
43 import java.awt.datatransfer.SystemFlavorMap;
44 import java.awt.datatransfer.Transferable;
45 import java.awt.datatransfer.UnsupportedFlavorException;
46 import java.awt.dnd.DnDConstants;
47 import java.awt.dnd.DragSource;
48 import java.awt.dnd.DragSourceAdapter;
49 import java.awt.dnd.DragSourceDropEvent;
50 import java.awt.dnd.DragSourceListener;
51 import java.awt.dnd.DropTarget;
52 import java.awt.dnd.DropTargetAdapter;
53 import java.awt.dnd.DropTargetDropEvent;
54 import java.awt.event.InputEvent;
55 import java.awt.image.BufferedImage;
56 import java.awt.image.MemoryImageSource;
57 import java.util.stream.Stream;
58
59 public class ImageTransferTest {
157 int blue = y > h / 2 ? 127 : 0;
158 int alpha = 255;
159 if (x < w / 4 && y < h / 4) {
160 alpha = 0;
161 red = 0;
162 }
163 pix[index++] =
164 (alpha << 24) | (red << 16) | (green << 8) | blue;
165 }
166 }
167 return Toolkit.getDefaultToolkit().
168 createImage(new MemoryImageSource(w, h, pix, 0, w));
169 }
170
171
172 static String[] retrieveFormatsToTest() {
173 SystemFlavorMap sfm =
174 (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
175 java.util.List<String> ln =
176 sfm.getNativesForFlavor(DataFlavor.imageFlavor);
177 if (OSInfo.OSType.WINDOWS.equals(OSInfo.getOSType()) &&
178 !ln.contains("METAFILEPICT"))
179 {
180 // for test failing on JDK without this fix
181 ln.add("METAFILEPICT");
182 }
183 return ln.toArray(new String[ln.size()]);
184 }
185
186 static void leaveFormat(String format) {
187 SystemFlavorMap sfm =
188 (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
189 sfm.setFlavorsForNative(format,
190 new DataFlavor[]{DataFlavor.imageFlavor});
191 sfm.setNativesForFlavor(DataFlavor.imageFlavor, new String[]{format});
192 }
193
194
195 boolean areImagesIdentical(Image im1, Image im2) {
196 if (formats[fi].equals("JFIF") || formats[fi].equals("image/jpeg") ||
197 formats[fi].equals("GIF") || formats[fi].equals("image/gif")) {
198 // JFIF and GIF are lossy formats
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @key headful
27 * @bug 4397404 4720930 8197926
28 * @summary tests that images of all supported native image formats are
29 * transferred properly
30 * @library /test/lib
31 * @library ../../regtesthelpers/process/
32 * @build jdk.test.lib.Platform ProcessResults ProcessCommunicator
33 * @author gas@sparc.spb.su area=Clipboard
34 * @run main/timeout=240 ImageTransferTest
35 */
36
37 import jdk.test.lib.Platform;
38 import test.java.awt.regtesthelpers.process.ProcessCommunicator;
39 import test.java.awt.regtesthelpers.process.ProcessResults;
40
41 import java.awt.*;
42 import java.awt.datatransfer.DataFlavor;
43 import java.awt.datatransfer.SystemFlavorMap;
44 import java.awt.datatransfer.Transferable;
45 import java.awt.datatransfer.UnsupportedFlavorException;
46 import java.awt.dnd.DnDConstants;
47 import java.awt.dnd.DragSource;
48 import java.awt.dnd.DragSourceAdapter;
49 import java.awt.dnd.DragSourceDropEvent;
50 import java.awt.dnd.DragSourceListener;
51 import java.awt.dnd.DropTarget;
52 import java.awt.dnd.DropTargetAdapter;
53 import java.awt.dnd.DropTargetDropEvent;
54 import java.awt.event.InputEvent;
55 import java.awt.image.BufferedImage;
56 import java.awt.image.MemoryImageSource;
57 import java.util.stream.Stream;
58
59 public class ImageTransferTest {
157 int blue = y > h / 2 ? 127 : 0;
158 int alpha = 255;
159 if (x < w / 4 && y < h / 4) {
160 alpha = 0;
161 red = 0;
162 }
163 pix[index++] =
164 (alpha << 24) | (red << 16) | (green << 8) | blue;
165 }
166 }
167 return Toolkit.getDefaultToolkit().
168 createImage(new MemoryImageSource(w, h, pix, 0, w));
169 }
170
171
172 static String[] retrieveFormatsToTest() {
173 SystemFlavorMap sfm =
174 (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
175 java.util.List<String> ln =
176 sfm.getNativesForFlavor(DataFlavor.imageFlavor);
177 if (Platform.isWindows() && !ln.contains("METAFILEPICT"))
178 {
179 // for test failing on JDK without this fix
180 ln.add("METAFILEPICT");
181 }
182 return ln.toArray(new String[ln.size()]);
183 }
184
185 static void leaveFormat(String format) {
186 SystemFlavorMap sfm =
187 (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
188 sfm.setFlavorsForNative(format,
189 new DataFlavor[]{DataFlavor.imageFlavor});
190 sfm.setNativesForFlavor(DataFlavor.imageFlavor, new String[]{format});
191 }
192
193
194 boolean areImagesIdentical(Image im1, Image im2) {
195 if (formats[fi].equals("JFIF") || formats[fi].equals("image/jpeg") ||
196 formats[fi].equals("GIF") || formats[fi].equals("image/gif")) {
197 // JFIF and GIF are lossy formats
|