--- /dev/null 2014-04-18 17:39:41.000000000 +0400 +++ new/test/java/awt/dnd/Win32TYMEDSelectionTest/Win32TYMEDSelectionTest.java 2014-04-18 17:39:40.740880800 +0400 @@ -0,0 +1,193 @@ +/* + test + @bug 4426805 4427837 + @summary tests that drag source provides data in the requested tymed + in java-to-native drag-and-drop operation on Win32 + @author das@sparc.spb.su area=dnd + @run applet Win32TYMEDSelectionTest.html +*/ + +/** + * Win32TYMEDSelectionTest.java + * + * summary: tests that drag source provides data in the requested tymed + * in java-to-native drag-and-drop operation on Win32 + */ + +import java.applet.Applet; +import java.awt.*; +import java.awt.datatransfer.*; +import java.awt.dnd.*; +import java.awt.event.*; +import java.io.*; + + +public class Win32TYMEDSelectionTest extends Applet implements Runnable { + + /* + * NOTE: These constants are duplicated in child.cpp. + * Be sure to keep them is sync. + */ + public static final int CODE_NOT_RETURNED = -1; + public static final int CODE_OK = 0; + public static final int CODE_INVALID_TYMED_FAILURE = 1; + public static final int CODE_INVALID_DATA_FAILURE = 2; + public static final String TEST_TEXT = "TEST TEXT"; + public static final int X = 300; + public static final int Y = 300; + public static final int WIDTH = 100; + public static final int HEIGHT = 100; + + public static final int ACTIVATION_TIMEOUT = 2000; + + private transient int retCode = CODE_NOT_RETURNED; + + final Frame frame = new Frame(); + final Button button = new DragSourceButton(); + private Process process; + + public void run() { + try { + Thread.sleep(ACTIVATION_TIMEOUT); + + final Point sourcePoint = button.getLocationOnScreen(); + final Dimension d = button.getSize(); + sourcePoint.translate(d.width / 2, d.height / 2); + final Point targetPoint = new Point(X + WIDTH / 2, Y + HEIGHT / 2); + + final Robot robot = new Robot(); + robot.mouseMove(sourcePoint.x, sourcePoint.y); + robot.keyPress(KeyEvent.VK_CONTROL); + robot.mousePress(InputEvent.BUTTON1_MASK); + for (;!sourcePoint.equals(targetPoint); + sourcePoint.translate(sign(targetPoint.x - sourcePoint.x), + sign(targetPoint.y - sourcePoint.y))) { + + robot.mouseMove(sourcePoint.x, sourcePoint.y); + Thread.sleep(10); + } + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.keyRelease(KeyEvent.VK_CONTROL); + + Thread.sleep(ACTIVATION_TIMEOUT); + + if (retCode == CODE_NOT_RETURNED) { + process.destroy(); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } // run() + + public static int sign(int n) { + return n < 0 ? -1 : n == 0 ? 0 : 1; + } + + public void start() { + + if (System.getProperty("os.name").startsWith("Windows")) { + frame.setTitle("DragSource frame"); + frame.setLocation(200, 200); + frame.add(button); + frame.pack(); + frame.setVisible(true); + + String testPath = System.getProperty("test.src", "."); + + try { + Process process = Runtime.getRuntime().exec("cp " + testPath + File.separator + "child.exe ."); + process.waitFor(); + process = Runtime.getRuntime().exec("chmod 755 child.exe"); + process.waitFor(); + }catch (InterruptedException ire) { + ire.printStackTrace(); + } catch (IOException ie) { + ie.printStackTrace(); + } + + String command = "./child.exe"; + try { + process = Runtime.getRuntime().exec(command); + new Thread(this).start(); + + retCode = process.waitFor(); + + InputStream errorStream = process.getErrorStream(); + int count = errorStream.available(); + if (count > 0) { + byte[] b = new byte[count]; + errorStream.read(b); + System.err.println("========= Child VM System.err ========"); + System.err.print(new String(b)); + System.err.println("======================================"); + } + + } catch (Exception e) { + e.printStackTrace(); + } + System.err.println("Child VM: returned: " + retCode); + switch (retCode) { + case CODE_NOT_RETURNED: + System.err.println("Child VM: failed to start"); + break; + case CODE_OK: + System.err.println("Child VM: normal termination"); + break; + default: + System.err.println("Child VM: other failure"); + break; + case CODE_INVALID_TYMED_FAILURE: + System.err.println("Child VM: invalid tymed detected"); + throw new RuntimeException("The test failed."); + case CODE_INVALID_DATA_FAILURE: + System.err.println("Child VM: invalid transfer data detected"); + throw new RuntimeException("The test failed."); + } + } + } // start() +} // class Win32TYMEDSelectionTest + +class DragSourceButton extends Button implements Serializable, + DragGestureListener, + Transferable { + static final DataFlavor[] flavors = + new DataFlavor[] { DataFlavor.stringFlavor, DataFlavor.imageFlavor }; + + public DragSourceButton() { + this("DragSourceButton"); + } + + public DragSourceButton(String str) { + super(str); + + DragSource ds = DragSource.getDefaultDragSource(); + ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, + this); + } + + public void dragGestureRecognized(DragGestureEvent dge) { + dge.startDrag(null, this, + new DragSourceAdapter() {}); + } + + public DataFlavor[] getTransferDataFlavors() { + return flavors; + } + + public boolean isDataFlavorSupported(DataFlavor flavor) { + return DataFlavor.stringFlavor.equals(flavor) || + DataFlavor.imageFlavor.equals(flavor); + } + + public Object getTransferData(DataFlavor flavor) + throws UnsupportedFlavorException, IOException { + if (DataFlavor.stringFlavor.equals(flavor)) { + return Win32TYMEDSelectionTest.TEST_TEXT; + } else if (DataFlavor.imageFlavor.equals(flavor)) { + return createImage(10, 10); + } else { + throw new UnsupportedFlavorException(flavor); + } + } +} +