test/jdk/java/awt/Frame/NonEDT_GUI_DeadlockTest/NonEDT_GUI_Deadlock.java
changeset 50834 9cf279436b9d
parent 47216 71c04702a3d5
child 54231 e4813eded7cb
equal deleted inserted replaced
50833:97852c0a7a91 50834:9cf279436b9d
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 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.
    73     boolean bOK = false;
    73     boolean bOK = false;
    74     Thread badThread = null;
    74     Thread badThread = null;
    75 
    75 
    76     public void init()
    76     public void init()
    77     {
    77     {
    78         //Create instructions for the user here, as well as set up
       
    79         // the environment -- set the layout manager, add buttons,
       
    80         // etc.
       
    81 
       
    82 
       
    83         String[] instructions =
       
    84         {
       
    85             "This is an AUTOMATIC test",
       
    86             "simply wait until it is done"
       
    87         };
       
    88         Sysout.createDialog( );
       
    89         Sysout.printInstructions( instructions );
       
    90 
       
    91     }//End  init()
    78     }//End  init()
    92 
    79 
    93     public void start ()
    80     public void start ()
    94     {
    81     {
    95         //Get things going.  Request focus, set size, et cetera
    82         //Get things going.  Request focus, set size, et cetera
   107                  Thread.sleep( 9000 );
    94                  Thread.sleep( 9000 );
   108               }catch( Exception ex ) {
    95               }catch( Exception ex ) {
   109               }
    96               }
   110               if( !bOK ) {
    97               if( !bOK ) {
   111                  // oops,
    98                  // oops,
   112                  //Sysout.println("Deadlock!");
    99                  //System.out.println("Deadlock!");
   113                  Runtime.getRuntime().halt(0);
   100                  Runtime.getRuntime().halt(0);
   114               }else{
   101               }else{
   115                  //Sysout.println("Passed ok.");
   102                  //System.out.println("Passed ok.");
   116               }
   103               }
   117            }
   104            }
   118         };
   105         };
   119         thKiller.setName("Killer thread");
   106         thKiller.setName("Killer thread");
   120         thKiller.start();
   107         thKiller.start();
   181        imt.start();
   168        imt.start();
   182     }
   169     }
   183 
   170 
   184 
   171 
   185 }// class NonEDT_GUI_Deadlock
   172 }// class NonEDT_GUI_Deadlock
   186 
       
   187 
       
   188 /****************************************************
       
   189  Standard Test Machinery
       
   190  DO NOT modify anything below -- it's a standard
       
   191   chunk of code whose purpose is to make user
       
   192   interaction uniform, and thereby make it simpler
       
   193   to read and understand someone else's test.
       
   194  ****************************************************/
       
   195 
       
   196 /**
       
   197  This is part of the standard test machinery.
       
   198  It creates a dialog (with the instructions), and is the interface
       
   199   for sending text messages to the user.
       
   200  To print the instructions, send an array of strings to Sysout.createDialog
       
   201   WithInstructions method.  Put one line of instructions per array entry.
       
   202  To display a message for the tester to see, simply call Sysout.println
       
   203   with the string to be displayed.
       
   204  This mimics System.out.println but works within the test harness as well
       
   205   as standalone.
       
   206  */
       
   207 
       
   208 class Sysout
       
   209 {
       
   210     private static TestDialog dialog;
       
   211 
       
   212     public static void createDialogWithInstructions( String[] instructions )
       
   213     {
       
   214         dialog = new TestDialog( new Frame(), "Instructions" );
       
   215         dialog.printInstructions( instructions );
       
   216         dialog.setVisible(true);
       
   217         println( "Any messages for the tester will display here." );
       
   218     }
       
   219 
       
   220     public static void createDialog( )
       
   221     {
       
   222         dialog = new TestDialog( new Frame(), "Instructions" );
       
   223         String[] defInstr = { "Instructions will appear here. ", "" } ;
       
   224         dialog.printInstructions( defInstr );
       
   225         dialog.setVisible(true);
       
   226         println( "Any messages for the tester will display here." );
       
   227     }
       
   228 
       
   229 
       
   230     public static void printInstructions( String[] instructions )
       
   231     {
       
   232         dialog.printInstructions( instructions );
       
   233     }
       
   234 
       
   235 
       
   236     public static void println( String messageIn )
       
   237     {
       
   238         dialog.displayMessage( messageIn );
       
   239     }
       
   240 
       
   241 }// Sysout  class
       
   242 
       
   243 /**
       
   244   This is part of the standard test machinery.  It provides a place for the
       
   245    test instructions to be displayed, and a place for interactive messages
       
   246    to the user to be displayed.
       
   247   To have the test instructions displayed, see Sysout.
       
   248   To have a message to the user be displayed, see Sysout.
       
   249   Do not call anything in this dialog directly.
       
   250   */
       
   251 class TestDialog extends Dialog
       
   252 {
       
   253 
       
   254     TextArea instructionsText;
       
   255     TextArea messageText;
       
   256     int maxStringLength = 80;
       
   257 
       
   258     //DO NOT call this directly, go through Sysout
       
   259     public TestDialog( Frame frame, String name )
       
   260     {
       
   261         super( frame, name );
       
   262         int scrollBoth = TextArea.SCROLLBARS_BOTH;
       
   263         instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
       
   264         add( "North", instructionsText );
       
   265 
       
   266         messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
       
   267         add("Center", messageText);
       
   268 
       
   269         pack();
       
   270 
       
   271         show();
       
   272     }// TestDialog()
       
   273 
       
   274     //DO NOT call this directly, go through Sysout
       
   275     public void printInstructions( String[] instructions )
       
   276     {
       
   277         //Clear out any current instructions
       
   278         instructionsText.setText( "" );
       
   279 
       
   280         //Go down array of instruction strings
       
   281 
       
   282         String printStr, remainingStr;
       
   283         for( int i=0; i < instructions.length; i++ )
       
   284         {
       
   285             //chop up each into pieces maxSringLength long
       
   286             remainingStr = instructions[ i ];
       
   287             while( remainingStr.length() > 0 )
       
   288             {
       
   289                 //if longer than max then chop off first max chars to print
       
   290                 if( remainingStr.length() >= maxStringLength )
       
   291                 {
       
   292                     //Try to chop on a word boundary
       
   293                     int posOfSpace = remainingStr.
       
   294                         lastIndexOf( ' ', maxStringLength - 1 );
       
   295 
       
   296                     if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
       
   297 
       
   298                     printStr = remainingStr.substring( 0, posOfSpace + 1 );
       
   299                     remainingStr = remainingStr.substring( posOfSpace + 1 );
       
   300                 }
       
   301                 //else just print
       
   302                 else
       
   303                 {
       
   304                     printStr = remainingStr;
       
   305                     remainingStr = "";
       
   306                 }
       
   307 
       
   308                 instructionsText.append( printStr + "\n" );
       
   309 
       
   310             }// while
       
   311 
       
   312         }// for
       
   313 
       
   314     }//printInstructions()
       
   315 
       
   316     //DO NOT call this directly, go through Sysout
       
   317     public void displayMessage( String messageIn )
       
   318     {
       
   319         messageText.append( messageIn + "\n" );
       
   320         System.out.println(messageIn);
       
   321     }
       
   322 
       
   323 }// TestDialog  class