test/jdk/java/awt/Dialog/NonResizableDialogSysMenuResize/NonResizableDialogSysMenuResize.java
changeset 50834 9cf279436b9d
parent 47216 71c04702a3d5
equal deleted inserted replaced
50833:97852c0a7a91 50834:9cf279436b9d
     1 /*
     1 /*
     2  * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    50     //*** test-writer defined static variables go here ***
    50     //*** test-writer defined static variables go here ***
    51 
    51 
    52 
    52 
    53     private static void init()
    53     private static void init()
    54     {
    54     {
    55         //*** Create instructions for the user here ***
       
    56 
       
    57         String[] instructions =
       
    58         {
       
    59             "This is an AUTOMATIC test, simply wait until it is done.",
       
    60             "The result (passed or failed) will be shown in the",
       
    61             "message window below."
       
    62         };
       
    63         Sysout.createDialog( );
       
    64         Sysout.printInstructions( instructions );
       
    65 
       
    66         // We must be sure that the Size system command has the S key as the shortcut one in the System menu.
    55         // We must be sure that the Size system command has the S key as the shortcut one in the System menu.
    67         Sysout.println("NOTE: The test is known to work correctly with English MS Windows only.");
    56         System.out.println("NOTE: The test is known to work correctly with English MS Windows only.");
    68 
    57 
    69         String s = Toolkit.getDefaultToolkit().getClass().getName();
    58         String s = Toolkit.getDefaultToolkit().getClass().getName();
    70 
    59 
    71         // This is Windows-only test
    60         // This is Windows-only test
    72         if (!s.contains("WToolkit")) {
    61         if (!s.contains("WToolkit")) {
   206         sleepTime = seconds * 1000;
   195         sleepTime = seconds * 1000;
   207     }
   196     }
   208 
   197 
   209     public static synchronized void pass()
   198     public static synchronized void pass()
   210     {
   199     {
   211         Sysout.println( "The test passed." );
   200         System.out.println( "The test passed." );
   212         Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
   201         System.out.println( "The test is over, hit  Ctl-C to stop Java VM" );
   213         //first check if this is executing in main thread
   202         //first check if this is executing in main thread
   214         if ( mainThread == Thread.currentThread() )
   203         if ( mainThread == Thread.currentThread() )
   215         {
   204         {
   216             //Still in the main thread, so set the flag just for kicks,
   205             //Still in the main thread, so set the flag just for kicks,
   217             // and throw a test passed exception which will be caught
   206             // and throw a test passed exception which will be caught
   230         fail( "it just plain failed! :-)" );
   219         fail( "it just plain failed! :-)" );
   231     }
   220     }
   232 
   221 
   233     public static synchronized void fail( String whyFailed )
   222     public static synchronized void fail( String whyFailed )
   234     {
   223     {
   235         Sysout.println( "The test failed: " + whyFailed );
   224         System.out.println( "The test failed: " + whyFailed );
   236         Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
   225         System.out.println( "The test is over, hit  Ctl-C to stop Java VM" );
   237         //check if this called from main thread
   226         //check if this called from main thread
   238         if ( mainThread == Thread.currentThread() )
   227         if ( mainThread == Thread.currentThread() )
   239         {
   228         {
   240             //If main thread, fail now 'cause not sleeping
   229             //If main thread, fail now 'cause not sleeping
   241             throw new RuntimeException( whyFailed );
   230             throw new RuntimeException( whyFailed );
   252 // when it's determined that the test has passed, and immediately
   241 // when it's determined that the test has passed, and immediately
   253 // end the test.
   242 // end the test.
   254 class TestPassedException extends RuntimeException
   243 class TestPassedException extends RuntimeException
   255 {
   244 {
   256 }
   245 }
   257 
       
   258 //*********** End Standard Test Machinery Section **********
       
   259 
       
   260 
       
   261 //************ Begin classes defined for the test ****************
       
   262 
       
   263 // if want to make listeners, here is the recommended place for them, then instantiate
       
   264 //  them in init()
       
   265 
       
   266 /* Example of a class which may be written as part of a test
       
   267 class NewClass implements anInterface
       
   268  {
       
   269    static int newVar = 0;
       
   270 
       
   271    public void eventDispatched(AWTEvent e)
       
   272     {
       
   273       //Counting events to see if we get enough
       
   274       eventCount++;
       
   275 
       
   276       if( eventCount == 20 )
       
   277        {
       
   278          //got enough events, so pass
       
   279 
       
   280          NonResizableDialogSysMenuResize.pass();
       
   281        }
       
   282       else if( tries == 20 )
       
   283        {
       
   284          //tried too many times without getting enough events so fail
       
   285 
       
   286          NonResizableDialogSysMenuResize.fail();
       
   287        }
       
   288 
       
   289     }// eventDispatched()
       
   290 
       
   291  }// NewClass class
       
   292 
       
   293 */
       
   294 
       
   295 
       
   296 //************** End classes defined for the test *******************
       
   297 
       
   298 
       
   299 
       
   300 
       
   301 /****************************************************
       
   302  Standard Test Machinery
       
   303  DO NOT modify anything below -- it's a standard
       
   304   chunk of code whose purpose is to make user
       
   305   interaction uniform, and thereby make it simpler
       
   306   to read and understand someone else's test.
       
   307  ****************************************************/
       
   308 
       
   309 /**
       
   310  This is part of the standard test machinery.
       
   311  It creates a dialog (with the instructions), and is the interface
       
   312   for sending text messages to the user.
       
   313  To print the instructions, send an array of strings to Sysout.createDialog
       
   314   WithInstructions method.  Put one line of instructions per array entry.
       
   315  To display a message for the tester to see, simply call Sysout.println
       
   316   with the string to be displayed.
       
   317  This mimics System.out.println but works within the test harness as well
       
   318   as standalone.
       
   319  */
       
   320 
       
   321 class Sysout
       
   322 {
       
   323     private static TestDialog dialog;
       
   324 
       
   325     public static void createDialogWithInstructions( String[] instructions )
       
   326     {
       
   327         dialog = new TestDialog( new Frame(), "Instructions" );
       
   328         dialog.printInstructions( instructions );
       
   329         dialog.setVisible(true);
       
   330         println( "Any messages for the tester will display here." );
       
   331     }
       
   332 
       
   333     public static void createDialog( )
       
   334     {
       
   335         dialog = new TestDialog( new Frame(), "Instructions" );
       
   336         String[] defInstr = { "Instructions will appear here. ", "" } ;
       
   337         dialog.printInstructions( defInstr );
       
   338         dialog.setVisible(true);
       
   339         println( "Any messages for the tester will display here." );
       
   340     }
       
   341 
       
   342 
       
   343     public static void printInstructions( String[] instructions )
       
   344     {
       
   345         dialog.printInstructions( instructions );
       
   346     }
       
   347 
       
   348 
       
   349     public static void println( String messageIn )
       
   350     {
       
   351         dialog.displayMessage( messageIn );
       
   352         System.out.println(messageIn);
       
   353     }
       
   354 
       
   355 }// Sysout  class
       
   356 
       
   357 /**
       
   358   This is part of the standard test machinery.  It provides a place for the
       
   359    test instructions to be displayed, and a place for interactive messages
       
   360    to the user to be displayed.
       
   361   To have the test instructions displayed, see Sysout.
       
   362   To have a message to the user be displayed, see Sysout.
       
   363   Do not call anything in this dialog directly.
       
   364   */
       
   365 class TestDialog extends Dialog
       
   366 {
       
   367 
       
   368     TextArea instructionsText;
       
   369     TextArea messageText;
       
   370     int maxStringLength = 80;
       
   371 
       
   372     //DO NOT call this directly, go through Sysout
       
   373     public TestDialog( Frame frame, String name )
       
   374     {
       
   375         super( frame, name );
       
   376         int scrollBoth = TextArea.SCROLLBARS_BOTH;
       
   377         instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
       
   378         add( "North", instructionsText );
       
   379 
       
   380         messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
       
   381         add("Center", messageText);
       
   382 
       
   383         pack();
       
   384 
       
   385         setVisible(true);
       
   386     }// TestDialog()
       
   387 
       
   388     //DO NOT call this directly, go through Sysout
       
   389     public void printInstructions( String[] instructions )
       
   390     {
       
   391         //Clear out any current instructions
       
   392         instructionsText.setText( "" );
       
   393 
       
   394         //Go down array of instruction strings
       
   395 
       
   396         String printStr, remainingStr;
       
   397         for( int i=0; i < instructions.length; i++ )
       
   398         {
       
   399             //chop up each into pieces maxSringLength long
       
   400             remainingStr = instructions[ i ];
       
   401             while( remainingStr.length() > 0 )
       
   402             {
       
   403                 //if longer than max then chop off first max chars to print
       
   404                 if( remainingStr.length() >= maxStringLength )
       
   405                 {
       
   406                     //Try to chop on a word boundary
       
   407                     int posOfSpace = remainingStr.
       
   408                         lastIndexOf( ' ', maxStringLength - 1 );
       
   409 
       
   410                     if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
       
   411 
       
   412                     printStr = remainingStr.substring( 0, posOfSpace + 1 );
       
   413                     remainingStr = remainingStr.substring( posOfSpace + 1 );
       
   414                 }
       
   415                 //else just print
       
   416                 else
       
   417                 {
       
   418                     printStr = remainingStr;
       
   419                     remainingStr = "";
       
   420                 }
       
   421 
       
   422                 instructionsText.append( printStr + "\n" );
       
   423 
       
   424             }// while
       
   425 
       
   426         }// for
       
   427 
       
   428     }//printInstructions()
       
   429 
       
   430     //DO NOT call this directly, go through Sysout
       
   431     public void displayMessage( String messageIn )
       
   432     {
       
   433         messageText.append( messageIn + "\n" );
       
   434         System.out.println(messageIn);
       
   435     }
       
   436 
       
   437 }// TestDialog  class