1 /*
2 * Copyright (c) 2014, 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 */
69
70
71 public class InterJVMGetDropSuccessTest extends Applet {
72
73 private int returnCode = Util.CODE_NOT_RETURNED;
74 private boolean successCodes[] = { true, false };
75 private int dropCount = 0;
76
77 final Frame frame = new Frame("Target Frame");
78
79 final DropTargetListener dropTargetListener = new DropTargetAdapter() {
80 public void drop(DropTargetDropEvent dtde) {
81 dtde.acceptDrop(DnDConstants.ACTION_COPY);
82 dtde.dropComplete(successCodes[dropCount]);
83 dropCount++;
84 }
85 };
86 final DropTarget dropTarget = new DropTarget(frame, dropTargetListener);
87
88 public void init() {
89 //Create instructions for the user here, as well as set up
90 // the environment -- set the layout manager, add buttons,
91 // etc.
92
93 String[] instructions =
94 {
95 "This is an AUTOMATIC test",
96 "simply wait until it is done"
97 };
98 Sysout.createDialog( );
99 Sysout.printInstructions( instructions );
100
101 frame.setTitle("Test frame");
102 frame.setBounds(100, 100, 150, 150);
103 } // init()
104
105 public void start() {
106
107 frame.setVisible(true);
108
109 try {
110 Thread.sleep(Util.FRAME_ACTIVATION_TIMEOUT);
111
112 Point p = frame.getLocationOnScreen();
113 Dimension d = frame.getSize();
114
115 String javaPath = System.getProperty("java.home", "");
116 String command = javaPath + File.separator + "bin" +
117 File.separator + "java -cp " + System.getProperty("test.classes", ".") +
118 " Child " +
119 p.x + " " + p.y + " " + d.width + " " + d.height;
120
344 }
345
346 boolean success2 = dragSourceListener.getDropSuccess();
347 int retCode = 0;
348
349 if (success1) {
350 retCode |= Util.CODE_FIRST_SUCCESS;
351 }
352 if (success2) {
353 retCode |= Util.CODE_SECOND_SUCCESS;
354 }
355 // This returns the diagnostic code from the child VM
356 System.exit(retCode);
357 } catch (Throwable e) {
358 e.printStackTrace();
359 // This returns the diagnostic code from the child VM
360 System.exit(Util.CODE_FAILURE);
361 }
362 } // run()
363 } // class child
364
365 /****************************************************
366 Standard Test Machinery
367 DO NOT modify anything below -- it's a standard
368 chunk of code whose purpose is to make user
369 interaction uniform, and thereby make it simpler
370 to read and understand someone else's test.
371 ****************************************************/
372
373 /**
374 This is part of the standard test machinery.
375 It creates a dialog (with the instructions), and is the interface
376 for sending text messages to the user.
377 To print the instructions, send an array of strings to Sysout.createDialog
378 WithInstructions method. Put one line of instructions per array entry.
379 To display a message for the tester to see, simply call Sysout.println
380 with the string to be displayed.
381 This mimics System.out.println but works within the test harness as well
382 as standalone.
383 */
384
385 class Sysout
386 {
387 private static TestDialog dialog;
388
389 public static void createDialogWithInstructions( String[] instructions )
390 {
391 dialog = new TestDialog( new Frame(), "Instructions" );
392 dialog.printInstructions( instructions );
393 dialog.show();
394 println( "Any messages for the tester will display here." );
395 }
396
397 public static void createDialog( )
398 {
399 dialog = new TestDialog( new Frame(), "Instructions" );
400 String[] defInstr = { "Instructions will appear here. ", "" } ;
401 dialog.printInstructions( defInstr );
402 dialog.show();
403 println( "Any messages for the tester will display here." );
404 }
405
406
407 public static void printInstructions( String[] instructions )
408 {
409 dialog.printInstructions( instructions );
410 }
411
412
413 public static void println( String messageIn )
414 {
415 dialog.displayMessage( messageIn );
416 }
417
418 }// Sysout class
419
420 /**
421 This is part of the standard test machinery. It provides a place for the
422 test instructions to be displayed, and a place for interactive messages
423 to the user to be displayed.
424 To have the test instructions displayed, see Sysout.
425 To have a message to the user be displayed, see Sysout.
426 Do not call anything in this dialog directly.
427 */
428 class TestDialog extends Dialog
429 {
430
431 TextArea instructionsText;
432 TextArea messageText;
433 int maxStringLength = 80;
434
435 //DO NOT call this directly, go through Sysout
436 public TestDialog( Frame frame, String name )
437 {
438 super( frame, name );
439 int scrollBoth = TextArea.SCROLLBARS_BOTH;
440 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
441 add( "North", instructionsText );
442
443 messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
444 add("South", messageText);
445
446 pack();
447
448 show();
449 }// TestDialog()
450
451 //DO NOT call this directly, go through Sysout
452 public void printInstructions( String[] instructions )
453 {
454 //Clear out any current instructions
455 instructionsText.setText( "" );
456
457 //Go down array of instruction strings
458
459 String printStr, remainingStr;
460 for( int i=0; i < instructions.length; i++ )
461 {
462 //chop up each into pieces maxSringLength long
463 remainingStr = instructions[ i ];
464 while( remainingStr.length() > 0 )
465 {
466 //if longer than max then chop off first max chars to print
467 if( remainingStr.length() >= maxStringLength )
468 {
469 //Try to chop on a word boundary
470 int posOfSpace = remainingStr.
471 lastIndexOf( ' ', maxStringLength - 1 );
472
473 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
474
475 printStr = remainingStr.substring( 0, posOfSpace + 1 );
476 remainingStr = remainingStr.substring( posOfSpace + 1 );
477 }
478 //else just print
479 else
480 {
481 printStr = remainingStr;
482 remainingStr = "";
483 }
484
485 instructionsText.append( printStr + "\n" );
486
487 }// while
488
489 }// for
490
491 }//printInstructions()
492
493 //DO NOT call this directly, go through Sysout
494 public void displayMessage( String messageIn )
495 {
496 messageText.append( messageIn + "\n" );
497 }
498
499 }// TestDialog class
|
1 /*
2 * Copyright (c) 2014, 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 */
69
70
71 public class InterJVMGetDropSuccessTest extends Applet {
72
73 private int returnCode = Util.CODE_NOT_RETURNED;
74 private boolean successCodes[] = { true, false };
75 private int dropCount = 0;
76
77 final Frame frame = new Frame("Target Frame");
78
79 final DropTargetListener dropTargetListener = new DropTargetAdapter() {
80 public void drop(DropTargetDropEvent dtde) {
81 dtde.acceptDrop(DnDConstants.ACTION_COPY);
82 dtde.dropComplete(successCodes[dropCount]);
83 dropCount++;
84 }
85 };
86 final DropTarget dropTarget = new DropTarget(frame, dropTargetListener);
87
88 public void init() {
89 frame.setTitle("Test frame");
90 frame.setBounds(100, 100, 150, 150);
91 } // init()
92
93 public void start() {
94
95 frame.setVisible(true);
96
97 try {
98 Thread.sleep(Util.FRAME_ACTIVATION_TIMEOUT);
99
100 Point p = frame.getLocationOnScreen();
101 Dimension d = frame.getSize();
102
103 String javaPath = System.getProperty("java.home", "");
104 String command = javaPath + File.separator + "bin" +
105 File.separator + "java -cp " + System.getProperty("test.classes", ".") +
106 " Child " +
107 p.x + " " + p.y + " " + d.width + " " + d.height;
108
332 }
333
334 boolean success2 = dragSourceListener.getDropSuccess();
335 int retCode = 0;
336
337 if (success1) {
338 retCode |= Util.CODE_FIRST_SUCCESS;
339 }
340 if (success2) {
341 retCode |= Util.CODE_SECOND_SUCCESS;
342 }
343 // This returns the diagnostic code from the child VM
344 System.exit(retCode);
345 } catch (Throwable e) {
346 e.printStackTrace();
347 // This returns the diagnostic code from the child VM
348 System.exit(Util.CODE_FAILURE);
349 }
350 } // run()
351 } // class child
|