1 /*
   2  * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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 5098433
  28   @summary REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
  29   @library ../../regtesthelpers
  30   @library ../../regtesthelpers/process
  31   @build Util
  32   @build ProcessResults ProcessCommunicator
  33   @run main/othervm DragUnicodeBetweenJVMTest main
  34 */
  35 
  36 import java.awt.*;
  37 import java.awt.event.*;
  38 
  39 import test.java.awt.regtesthelpers.process.ProcessCommunicator;
  40 import test.java.awt.regtesthelpers.process.ProcessResults;
  41 import test.java.awt.regtesthelpers.Util;
  42 import static java.lang.Thread.sleep;
  43 
  44 public class DragUnicodeBetweenJVMTest {
  45 
  46     public void start() {
  47 
  48         String toolkit = Toolkit.getDefaultToolkit().getClass().getName();
  49         if (!toolkit.equals("sun.awt.windows.WToolkit")){
  50             System.out.println("This test is for Windows only. Passed.");
  51             return;
  52         }
  53         else{
  54             System.out.println("Toolkit = " + toolkit);
  55         }
  56 
  57         final Frame sourceFrame = new Frame("Source frame");
  58         final SourcePanel sourcePanel = new SourcePanel();
  59         sourceFrame.add(sourcePanel);
  60         sourceFrame.pack();
  61         sourceFrame.addWindowListener( new WindowAdapter() {
  62             @Override
  63             public void windowClosing(WindowEvent e) {
  64                 sourceFrame.dispose();
  65             }
  66         });
  67         sourceFrame.setVisible(true);
  68 
  69         Util.waitForIdle(null);
  70 
  71         NextFramePositionCalculator positionCalculator = new NextFramePositionCalculator(sourceFrame);
  72 
  73         String [] args = new String [] {
  74                 String.valueOf(positionCalculator.getNextLocationX()),
  75                 String.valueOf(positionCalculator.getNextLocationY()),
  76                 String.valueOf(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(sourcePanel)),
  77                 String.valueOf(AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(sourcePanel)),
  78         };
  79 
  80 
  81        ProcessResults processResults =
  82                 // ProcessCommunicator.executeChildProcess(this.getClass()," -cp \"C:\\Documents and Settings\\df153228\\IdeaProjects\\UnicodeTestDebug\\out\\production\\UnicodeTestDebug\" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 ", args);
  83                 ProcessCommunicator.executeChildProcess(this.getClass(), args);
  84 
  85         verifyTestResults(processResults);
  86 
  87     }// start()
  88 
  89 
  90 
  91     private static void verifyTestResults(ProcessResults processResults) {
  92         if ( InterprocessMessages.FILES_ON_TARGET_ARE_CORRUPTED ==
  93                 processResults.getExitValue())
  94         {
  95             processResults.printProcessErrorOutput(System.err);
  96             throw new RuntimeException("TEST IS FAILED: Target has recieved" +
  97                     " broken file list.");
  98         }
  99         processResults.verifyStdErr(System.err);
 100         processResults.verifyProcessExitValue(System.err);
 101         processResults.printProcessStandartOutput(System.out);
 102     }
 103 
 104     //We cannot make an instance of the applet without the default constructor
 105     public DragUnicodeBetweenJVMTest () {
 106         super();
 107     }
 108 
 109     //We need in this constructor to pass frame position between JVMs
 110     public DragUnicodeBetweenJVMTest (Point targetFrameLocation, Point dragSourcePoint)
 111             throws InterruptedException
 112     {
 113         final Frame targetFrame = new Frame("Target frame");
 114         final TargetPanel targetPanel = new TargetPanel(targetFrame);
 115         targetFrame.add(targetPanel);
 116         targetFrame.addWindowListener( new WindowAdapter() {
 117             @Override
 118             public void windowClosing(WindowEvent e) {
 119                 targetFrame.dispose();
 120             }
 121         });
 122         targetFrame.setLocation(targetFrameLocation);
 123         targetFrame.pack();
 124         targetFrame.setVisible(true);
 125 
 126         doTest(dragSourcePoint, targetPanel);
 127     }
 128 
 129     private void doTest(Point dragSourcePoint, TargetPanel targetPanel) {
 130         Util.waitForIdle(null);
 131 
 132         final Robot robot = Util.createRobot();
 133 
 134         robot.mouseMove((int)dragSourcePoint.getX(),(int)dragSourcePoint.getY());
 135         try {
 136             sleep(100);
 137             robot.mousePress(InputEvent.BUTTON1_MASK);
 138             sleep(100);
 139             robot.mouseRelease(InputEvent.BUTTON1_MASK);
 140             sleep(100);
 141         } catch (InterruptedException e) {
 142             e.printStackTrace();
 143         }
 144 
 145         Util.drag(robot, dragSourcePoint, new Point (AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(targetPanel),
 146                 AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(targetPanel)),
 147                 InputEvent.BUTTON1_MASK);
 148     }
 149 
 150 
 151     enum InterprocessArguments {
 152         TARGET_FRAME_X_POSITION_ARGUMENT,
 153         TARGET_FRAME_Y_POSITION_ARGUMENT,
 154         DRAG_SOURCE_POINT_X_ARGUMENT,
 155         DRAG_SOURCE_POINT_Y_ARGUMENT;
 156 
 157         int extract (String [] args) {
 158             return Integer.parseInt(args[this.ordinal()]);
 159         }
 160     }
 161 
 162     public static void main(final String [] args) {
 163         if (args.length > 0 && args[0].equals("main")) {
 164             new DragUnicodeBetweenJVMTest().start();
 165             return;
 166         }
 167         Point dragSourcePoint = new Point(InterprocessArguments.DRAG_SOURCE_POINT_X_ARGUMENT.extract(args),
 168                 InterprocessArguments.DRAG_SOURCE_POINT_Y_ARGUMENT.extract(args));
 169         Point targetFrameLocation = new Point(InterprocessArguments.TARGET_FRAME_X_POSITION_ARGUMENT.extract(args),
 170                 InterprocessArguments.TARGET_FRAME_Y_POSITION_ARGUMENT.extract(args));
 171 
 172         try {
 173             new DragUnicodeBetweenJVMTest(targetFrameLocation, dragSourcePoint);
 174         } catch (InterruptedException e) {
 175             e.printStackTrace();
 176         }
 177     }
 178 }