< prev index next >

test/jdk/java/awt/Menu/OpensWithNoGrab/OpensWithNoGrab.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2016, 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  */


  29   @author andrei.dmitriev: area=awt.menu
  30   @library ../../regtesthelpers
  31   @library ../../../../lib/testlibrary
  32   @modules java.desktop/sun.awt
  33   @build jdk.testlibrary.OSInfo
  34   @build Util
  35   @run main OpensWithNoGrab
  36 */
  37 
  38 import java.awt.*;
  39 import java.awt.event.*;
  40 
  41 import jdk.testlibrary.OSInfo;
  42 import test.java.awt.regtesthelpers.Util;
  43 
  44 public class OpensWithNoGrab
  45 {
  46     final static int delay = 50;
  47     private static void init()
  48     {
  49         String[] instructions =
  50         {
  51             "This is an AUTOMATIC test, simply wait until it is done.",
  52             "The result (passed or failed) will be shown in the",
  53             "message window below."
  54         };
  55         Sysout.createDialog( );
  56         Sysout.printInstructions( instructions );
  57 
  58         if (!(OSInfo.getOSType().equals(OSInfo.OSType.LINUX)
  59                 || OSInfo.getOSType().equals(OSInfo.OSType.SOLARIS))) {
  60             System.out.println("This test is for XAWT/Motif only");
  61             OpensWithNoGrab.pass();
  62         }
  63 
  64         Choice ch = new Choice ();
  65         Frame f = new Frame ("OpensWithNoGrab");
  66         Robot robot;
  67         Point framePt, choicePt;
  68 
  69         ch.add("line 1");
  70         ch.add("line 2");
  71         ch.add("line 3");
  72         ch.add("line 4");
  73         ch.setBackground(Color.red);
  74         f.add(ch);
  75 
  76         Menu file = new Menu ("file");
  77         MenuBar mb = new MenuBar();


 188                 if( ! testGeneratedInterrupt ) throw e;
 189 
 190                 //reset flag in case hit this code more than once for some reason (just safety)
 191                 testGeneratedInterrupt = false;
 192 
 193                 if ( theTestPassed == false )
 194                     {
 195                         throw new RuntimeException( failureMessage );
 196                     }
 197             }
 198 
 199     }//main
 200 
 201     public static synchronized void setTimeoutTo( int seconds )
 202     {
 203         sleepTime = seconds * 1000;
 204     }
 205 
 206     public static synchronized void pass()
 207     {
 208         Sysout.println( "The test passed." );
 209         Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
 210         //first check if this is executing in main thread
 211         if ( mainThread == Thread.currentThread() )
 212             {
 213                 //Still in the main thread, so set the flag just for kicks,
 214                 // and throw a test passed exception which will be caught
 215                 // and end the test.
 216                 theTestPassed = true;
 217                 throw new TestPassedException();
 218             }
 219         theTestPassed = true;
 220         testGeneratedInterrupt = true;
 221         mainThread.interrupt();
 222     }//pass()
 223 
 224     public static synchronized void fail()
 225     {
 226         //test writer didn't specify why test failed, so give generic
 227         fail( "it just plain failed! :-)" );
 228     }
 229 
 230     public static synchronized void fail( String whyFailed )
 231     {
 232         Sysout.println( "The test failed: " + whyFailed );
 233         Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
 234         //check if this called from main thread
 235         if ( mainThread == Thread.currentThread() )
 236             {
 237                 //If main thread, fail now 'cause not sleeping
 238                 throw new RuntimeException( whyFailed );
 239             }
 240         theTestPassed = false;
 241         testGeneratedInterrupt = true;
 242         failureMessage = whyFailed;
 243         mainThread.interrupt();
 244     }//fail()
 245 
 246 }// class OpensWithNoGrab
 247 
 248 //This exception is used to exit from any level of call nesting
 249 // when it's determined that the test has passed, and immediately
 250 // end the test.
 251 class TestPassedException extends RuntimeException
 252 {
 253 }
 254 
 255 //*********** End Standard Test Machinery Section **********
 256 
 257 
 258 //************ Begin classes defined for the test ****************
 259 
 260 // if want to make listeners, here is the recommended place for them, then instantiate
 261 //  them in init()
 262 
 263 /* Example of a class which may be written as part of a test
 264 class NewClass implements anInterface
 265  {
 266    static int newVar = 0;
 267 
 268    public void eventDispatched(AWTEvent e)
 269     {
 270       //Counting events to see if we get enough
 271       eventCount++;
 272 
 273       if( eventCount == 20 )
 274        {
 275          //got enough events, so pass
 276 
 277          OpensWithNoGrab.pass();
 278        }
 279       else if( tries == 20 )
 280        {
 281          //tried too many times without getting enough events so fail
 282 
 283          OpensWithNoGrab.fail();
 284        }
 285 
 286     }// eventDispatched()
 287 
 288  }// NewClass class
 289 
 290 */
 291 
 292 
 293 //************** End classes defined for the test *******************
 294 
 295 
 296 
 297 
 298 /****************************************************
 299  Standard Test Machinery
 300  DO NOT modify anything below -- it's a standard
 301   chunk of code whose purpose is to make user
 302   interaction uniform, and thereby make it simpler
 303   to read and understand someone else's test.
 304  ****************************************************/
 305 
 306 /**
 307  This is part of the standard test machinery.
 308  It creates a dialog (with the instructions), and is the interface
 309   for sending text messages to the user.
 310  To print the instructions, send an array of strings to Sysout.createDialog
 311   WithInstructions method.  Put one line of instructions per array entry.
 312  To display a message for the tester to see, simply call Sysout.println
 313   with the string to be displayed.
 314  This mimics System.out.println but works within the test harness as well
 315   as standalone.
 316  */
 317 
 318     class Sysout
 319     {
 320         private static TestDialog dialog;
 321 
 322         public static void createDialogWithInstructions( String[] instructions )
 323         {
 324             dialog = new TestDialog( new Frame(), "Instructions" );
 325             dialog.printInstructions( instructions );
 326             dialog.setVisible(true);
 327             println( "Any messages for the tester will display here." );
 328         }
 329 
 330         public static void createDialog( )
 331         {
 332             dialog = new TestDialog( new Frame(), "Instructions" );
 333             String[] defInstr = { "Instructions will appear here. ", "" } ;
 334             dialog.printInstructions( defInstr );
 335             dialog.setVisible(true);
 336             println( "Any messages for the tester will display here." );
 337         }
 338 
 339 
 340         public static void printInstructions( String[] instructions )
 341         {
 342             dialog.printInstructions( instructions );
 343         }
 344 
 345 
 346         public static void println( String messageIn )
 347         {
 348             dialog.displayMessage( messageIn );
 349             System.out.println(messageIn);
 350         }
 351 
 352     }// Sysout  class
 353 
 354 /**
 355   This is part of the standard test machinery.  It provides a place for the
 356    test instructions to be displayed, and a place for interactive messages
 357    to the user to be displayed.
 358   To have the test instructions displayed, see Sysout.
 359   To have a message to the user be displayed, see Sysout.
 360   Do not call anything in this dialog directly.
 361   */
 362 class TestDialog extends Dialog
 363 {
 364 
 365     TextArea instructionsText;
 366     TextArea messageText;
 367     int maxStringLength = 80;
 368 
 369     //DO NOT call this directly, go through Sysout
 370     public TestDialog( Frame frame, String name )
 371     {
 372         super( frame, name );
 373         int scrollBoth = TextArea.SCROLLBARS_BOTH;
 374         instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
 375         add( "North", instructionsText );
 376 
 377         messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
 378         add("Center", messageText);
 379 
 380         pack();
 381 
 382         setVisible(true);
 383     }// TestDialog()
 384 
 385     //DO NOT call this directly, go through Sysout
 386     public void printInstructions( String[] instructions )
 387     {
 388         //Clear out any current instructions
 389         instructionsText.setText( "" );
 390 
 391         //Go down array of instruction strings
 392 
 393         String printStr, remainingStr;
 394         for( int i=0; i < instructions.length; i++ )
 395             {
 396                 //chop up each into pieces maxSringLength long
 397                 remainingStr = instructions[ i ];
 398                 while( remainingStr.length() > 0 )
 399                     {
 400                         //if longer than max then chop off first max chars to print
 401                         if( remainingStr.length() >= maxStringLength )
 402                             {
 403                                 //Try to chop on a word boundary
 404                                 int posOfSpace = remainingStr.
 405                                     lastIndexOf( ' ', maxStringLength - 1 );
 406 
 407                                 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
 408 
 409                                 printStr = remainingStr.substring( 0, posOfSpace + 1 );
 410                                 remainingStr = remainingStr.substring( posOfSpace + 1 );
 411                             }
 412                         //else just print
 413                         else
 414                             {
 415                                 printStr = remainingStr;
 416                                 remainingStr = "";
 417                             }
 418 
 419                         instructionsText.append( printStr + "\n" );
 420 
 421                     }// while
 422 
 423             }// for
 424 
 425     }//printInstructions()
 426 
 427     //DO NOT call this directly, go through Sysout
 428     public void displayMessage( String messageIn )
 429     {
 430         messageText.append( messageIn + "\n" );
 431         System.out.println(messageIn);
 432     }
 433 
 434 }// TestDialog  class
   1 /*
   2  * Copyright (c) 2005, 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  */


  29   @author andrei.dmitriev: area=awt.menu
  30   @library ../../regtesthelpers
  31   @library ../../../../lib/testlibrary
  32   @modules java.desktop/sun.awt
  33   @build jdk.testlibrary.OSInfo
  34   @build Util
  35   @run main OpensWithNoGrab
  36 */
  37 
  38 import java.awt.*;
  39 import java.awt.event.*;
  40 
  41 import jdk.testlibrary.OSInfo;
  42 import test.java.awt.regtesthelpers.Util;
  43 
  44 public class OpensWithNoGrab
  45 {
  46     final static int delay = 50;
  47     private static void init()
  48     {









  49         if (!(OSInfo.getOSType().equals(OSInfo.OSType.LINUX)
  50                 || OSInfo.getOSType().equals(OSInfo.OSType.SOLARIS))) {
  51             System.out.println("This test is for XAWT/Motif only");
  52             OpensWithNoGrab.pass();
  53         }
  54 
  55         Choice ch = new Choice ();
  56         Frame f = new Frame ("OpensWithNoGrab");
  57         Robot robot;
  58         Point framePt, choicePt;
  59 
  60         ch.add("line 1");
  61         ch.add("line 2");
  62         ch.add("line 3");
  63         ch.add("line 4");
  64         ch.setBackground(Color.red);
  65         f.add(ch);
  66 
  67         Menu file = new Menu ("file");
  68         MenuBar mb = new MenuBar();


 179                 if( ! testGeneratedInterrupt ) throw e;
 180 
 181                 //reset flag in case hit this code more than once for some reason (just safety)
 182                 testGeneratedInterrupt = false;
 183 
 184                 if ( theTestPassed == false )
 185                     {
 186                         throw new RuntimeException( failureMessage );
 187                     }
 188             }
 189 
 190     }//main
 191 
 192     public static synchronized void setTimeoutTo( int seconds )
 193     {
 194         sleepTime = seconds * 1000;
 195     }
 196 
 197     public static synchronized void pass()
 198     {
 199         System.out.println( "The test passed." );
 200         System.out.println( "The test is over, hit  Ctl-C to stop Java VM" );
 201         //first check if this is executing in main thread
 202         if ( mainThread == Thread.currentThread() )
 203             {
 204                 //Still in the main thread, so set the flag just for kicks,
 205                 // and throw a test passed exception which will be caught
 206                 // and end the test.
 207                 theTestPassed = true;
 208                 throw new TestPassedException();
 209             }
 210         theTestPassed = true;
 211         testGeneratedInterrupt = true;
 212         mainThread.interrupt();
 213     }//pass()
 214 
 215     public static synchronized void fail()
 216     {
 217         //test writer didn't specify why test failed, so give generic
 218         fail( "it just plain failed! :-)" );
 219     }
 220 
 221     public static synchronized void fail( String whyFailed )
 222     {
 223         System.out.println( "The test failed: " + whyFailed );
 224         System.out.println( "The test is over, hit  Ctl-C to stop Java VM" );
 225         //check if this called from main thread
 226         if ( mainThread == Thread.currentThread() )
 227             {
 228                 //If main thread, fail now 'cause not sleeping
 229                 throw new RuntimeException( whyFailed );
 230             }
 231         theTestPassed = false;
 232         testGeneratedInterrupt = true;
 233         failureMessage = whyFailed;
 234         mainThread.interrupt();
 235     }//fail()
 236 
 237 }// class OpensWithNoGrab
 238 
 239 //This exception is used to exit from any level of call nesting
 240 // when it's determined that the test has passed, and immediately
 241 // end the test.
 242 class TestPassedException extends RuntimeException
 243 {
 244 }





















































































































































































< prev index next >