1 /* 2 * Copyright (c) 2009, 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 @bug 5098433 27 @summary REG: DnD of File-List between JVM is broken for non ASCII file names - Win32 28 @author Denis Fokin: area=dnd 29 @library ../../regtesthelpers 30 @library ../../regtesthelpers/process 31 @build Util 32 @build ProcessResults ProcessCommunicator 33 34 35 @run applet/othervm DragUnicodeBetweenJVMTest.html 36 */ 37 38 /** 39 * DragUnicodeBetweenJVMTest.java 40 * 41 * summary: The test drags a list of files (DataFlavor.javaFileListFlavor) from one jvm to another. 42 * The files have Unicode names. The list on target side must be equal to 43 * the list on the source side. 44 */ 45 46 47 import java.awt.*; 48 import java.awt.event.*; 49 import java.applet.Applet; 50 51 import test.java.awt.regtesthelpers.process.ProcessCommunicator; 52 import test.java.awt.regtesthelpers.process.ProcessResults; 53 import test.java.awt.regtesthelpers.Util; 54 import static java.lang.Thread.sleep; 55 56 public class DragUnicodeBetweenJVMTest extends Applet 57 { 58 59 public void init() { 60 setLayout(new BorderLayout()); 61 }//End init() 62 63 public void start() { 64 65 String toolkit = Toolkit.getDefaultToolkit().getClass().getName(); 66 if (!toolkit.equals("sun.awt.windows.WToolkit")){ 67 System.out.println("This test is for Windows only. Passed."); 68 return; 69 } 70 else{ 71 System.out.println("Toolkit = " + toolkit); 72 } 73 74 final Frame sourceFrame = new Frame("Source frame"); 75 final SourcePanel sourcePanel = new SourcePanel(); 76 sourceFrame.add(sourcePanel); 77 sourceFrame.pack(); 78 sourceFrame.addWindowListener( new WindowAdapter() { 79 @Override 80 public void windowClosing(WindowEvent e) { 81 sourceFrame.dispose(); 82 } 83 }); 84 sourceFrame.setVisible(true); 85 86 Util.waitForIdle(null); 87 88 NextFramePositionCalculator positionCalculator = new NextFramePositionCalculator(sourceFrame); 89 90 String [] args = new String [] { 91 String.valueOf(positionCalculator.getNextLocationX()), 92 String.valueOf(positionCalculator.getNextLocationY()), 93 String.valueOf(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(sourcePanel)), 94 String.valueOf(AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(sourcePanel)), 95 }; 96 97 98 ProcessResults processResults = 99 // 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); 100 ProcessCommunicator.executeChildProcess(this.getClass(), args); 101 102 verifyTestResults(processResults); 103 104 }// start() 105 106 107 108 private static void verifyTestResults(ProcessResults processResults) { 109 if ( InterprocessMessages.FILES_ON_TARGET_ARE_CORRUPTED == 110 processResults.getExitValue()) 111 { 112 processResults.printProcessErrorOutput(System.err); 113 throw new RuntimeException("TEST IS FAILED: Target has recieved" + 114 " broken file list."); 115 } 116 processResults.verifyStdErr(System.err); 117 processResults.verifyProcessExitValue(System.err); 118 processResults.printProcessStandartOutput(System.out); 119 } 120 121 //We cannot make an instance of the applet without the default constructor 122 public DragUnicodeBetweenJVMTest () { 123 super(); 124 } 125 126 //We need in this constructor to pass frame position between JVMs 127 public DragUnicodeBetweenJVMTest (Point targetFrameLocation, Point dragSourcePoint) 128 throws InterruptedException 129 { 130 final Frame targetFrame = new Frame("Target frame"); 131 final TargetPanel targetPanel = new TargetPanel(targetFrame); 132 targetFrame.add(targetPanel); 133 targetFrame.addWindowListener( new WindowAdapter() { 134 @Override 135 public void windowClosing(WindowEvent e) { 136 targetFrame.dispose(); 137 } 138 }); 139 targetFrame.setLocation(targetFrameLocation); 140 targetFrame.pack(); 141 targetFrame.setVisible(true); 142 143 doTest(dragSourcePoint, targetPanel); 144 } 145 146 private void doTest(Point dragSourcePoint, TargetPanel targetPanel) { 147 Util.waitForIdle(null); 148 149 final Robot robot = Util.createRobot(); 150 151 robot.mouseMove((int)dragSourcePoint.getX(),(int)dragSourcePoint.getY()); 152 try { 153 sleep(100); 154 robot.mousePress(InputEvent.BUTTON1_MASK); 155 sleep(100); 156 robot.mouseRelease(InputEvent.BUTTON1_MASK); 157 sleep(100); 158 } catch (InterruptedException e) { 159 e.printStackTrace(); 160 } 161 162 Util.drag(robot, dragSourcePoint, new Point (AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(targetPanel), 163 AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(targetPanel)), 164 InputEvent.BUTTON1_MASK); 165 } 166 167 168 enum InterprocessArguments { 169 TARGET_FRAME_X_POSITION_ARGUMENT, 170 TARGET_FRAME_Y_POSITION_ARGUMENT, 171 DRAG_SOURCE_POINT_X_ARGUMENT, 172 DRAG_SOURCE_POINT_Y_ARGUMENT; 173 174 int extract (String [] args) { 175 return Integer.parseInt(args[this.ordinal()]); 176 } 177 } 178 179 public static void main (String [] args) { 180 Point dragSourcePoint = new Point(InterprocessArguments.DRAG_SOURCE_POINT_X_ARGUMENT.extract(args), 181 InterprocessArguments.DRAG_SOURCE_POINT_Y_ARGUMENT.extract(args)); 182 Point targetFrameLocation = new Point(InterprocessArguments.TARGET_FRAME_X_POSITION_ARGUMENT.extract(args), 183 InterprocessArguments.TARGET_FRAME_Y_POSITION_ARGUMENT.extract(args)); 184 185 try { 186 new DragUnicodeBetweenJVMTest(targetFrameLocation, dragSourcePoint); 187 } catch (InterruptedException e) { 188 e.printStackTrace(); 189 } 190 } 191 192 193 }