jdk/test/java/awt/Component/NoUpdateUponShow/NoUpdateUponShow.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 27763 1fba965925e8
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2467
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 27763
diff changeset
     2
 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
2467
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
     4
 *
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
     8
 *
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    13
 * accompanied this code).
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    14
 *
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2467
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2467
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2467
diff changeset
    21
 * questions.
2467
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    22
 */
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    23
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    24
/*
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 27763
diff changeset
    26
  @key headful
2467
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    27
  @bug 6774258
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    28
  @summary  api/java_awt/Component/index.html#PaintUpdate fails randomly
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    29
  @author dmitry.cherepanov@...: area=awt.painting
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    30
  @run main NoUpdateUponShow
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    31
*/
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    32
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    33
/**
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    34
 * NoUpdateUponShow.java
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    35
 *
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    36
 * summary:  System-level painting operations shouldn't make call to update()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    37
 */
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    38
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    39
import java.awt.*;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    40
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    41
public class NoUpdateUponShow
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    42
{
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    43
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    44
    static volatile boolean wasUpdate = false;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    45
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    46
    private static void init()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    47
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    48
        //*** Create instructions for the user here ***
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    49
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    50
        String[] instructions =
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    51
        {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    52
            "This is an AUTOMATIC test, simply wait until it is done.",
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    53
            "The result (passed or failed) will be shown in the",
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    54
            "message window below."
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    55
        };
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    56
        Sysout.createDialog( );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    57
        Sysout.printInstructions( instructions );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    58
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    59
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    60
        // Create the frame and the button
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    61
        Frame f = new Frame();
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    62
        f.setBounds(100, 100, 200, 200);
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    63
        f.setLayout(new FlowLayout());
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    64
        f.add(new Button() {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    65
            @Override
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    66
            public void update(Graphics g) {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    67
                wasUpdate = true;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    68
                super.update(g);
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    69
            }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    70
        });
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    71
        f.setVisible(true);
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    72
27763
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 5506
diff changeset
    73
        try {
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 5506
diff changeset
    74
            Robot robot = new Robot();
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 5506
diff changeset
    75
            robot.waitForIdle();
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 5506
diff changeset
    76
        }catch(Exception ex) {
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 5506
diff changeset
    77
            ex.printStackTrace();
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 5506
diff changeset
    78
            throw new RuntimeException("Unexpected failure");
1fba965925e8 8063102: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents: 5506
diff changeset
    79
        }
2467
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    80
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    81
        if (wasUpdate) {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    82
            fail(" Unexpected update. ");
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    83
        } else {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    84
            pass();
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    85
        }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    86
    }//End  init()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    87
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    88
    /*****************************************************
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    89
     * Standard Test Machinery Section
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    90
     * DO NOT modify anything in this section -- it's a
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    91
     * standard chunk of code which has all of the
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    92
     * synchronisation necessary for the test harness.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    93
     * By keeping it the same in all tests, it is easier
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    94
     * to read and understand someone else's test, as
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    95
     * well as insuring that all tests behave correctly
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    96
     * with the test harness.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    97
     * There is a section following this for test-
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    98
     * classes
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
    99
     ******************************************************/
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   100
    private static boolean theTestPassed = false;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   101
    private static boolean testGeneratedInterrupt = false;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   102
    private static String failureMessage = "";
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   103
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   104
    private static Thread mainThread = null;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   105
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   106
    private static int sleepTime = 300000;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   107
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   108
    // Not sure about what happens if multiple of this test are
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   109
    //  instantiated in the same VM.  Being static (and using
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   110
    //  static vars), it aint gonna work.  Not worrying about
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   111
    //  it for now.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   112
    public static void main( String args[] ) throws InterruptedException
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   113
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   114
        mainThread = Thread.currentThread();
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   115
        try
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   116
        {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   117
            init();
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   118
        }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   119
        catch( TestPassedException e )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   120
        {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   121
            //The test passed, so just return from main and harness will
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   122
            // interepret this return as a pass
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   123
            return;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   124
        }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   125
        //At this point, neither test pass nor test fail has been
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   126
        // called -- either would have thrown an exception and ended the
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   127
        // test, so we know we have multiple threads.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   128
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   129
        //Test involves other threads, so sleep and wait for them to
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   130
        // called pass() or fail()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   131
        try
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   132
        {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   133
            Thread.sleep( sleepTime );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   134
            //Timed out, so fail the test
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   135
            throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   136
        }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   137
        catch (InterruptedException e)
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   138
        {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   139
            //The test harness may have interrupted the test.  If so, rethrow the exception
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   140
            // so that the harness gets it and deals with it.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   141
            if( ! testGeneratedInterrupt ) throw e;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   142
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   143
            //reset flag in case hit this code more than once for some reason (just safety)
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   144
            testGeneratedInterrupt = false;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   145
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   146
            if ( theTestPassed == false )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   147
            {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   148
                throw new RuntimeException( failureMessage );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   149
            }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   150
        }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   151
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   152
    }//main
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   153
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   154
    public static synchronized void setTimeoutTo( int seconds )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   155
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   156
        sleepTime = seconds * 1000;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   157
    }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   158
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   159
    public static synchronized void pass()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   160
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   161
        Sysout.println( "The test passed." );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   162
        Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   163
        //first check if this is executing in main thread
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   164
        if ( mainThread == Thread.currentThread() )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   165
        {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   166
            //Still in the main thread, so set the flag just for kicks,
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   167
            // and throw a test passed exception which will be caught
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   168
            // and end the test.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   169
            theTestPassed = true;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   170
            throw new TestPassedException();
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   171
        }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   172
        theTestPassed = true;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   173
        testGeneratedInterrupt = true;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   174
        mainThread.interrupt();
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   175
    }//pass()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   176
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   177
    public static synchronized void fail()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   178
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   179
        //test writer didn't specify why test failed, so give generic
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   180
        fail( "it just plain failed! :-)" );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   181
    }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   182
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   183
    public static synchronized void fail( String whyFailed )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   184
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   185
        Sysout.println( "The test failed: " + whyFailed );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   186
        Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   187
        //check if this called from main thread
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   188
        if ( mainThread == Thread.currentThread() )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   189
        {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   190
            //If main thread, fail now 'cause not sleeping
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   191
            throw new RuntimeException( whyFailed );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   192
        }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   193
        theTestPassed = false;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   194
        testGeneratedInterrupt = true;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   195
        failureMessage = whyFailed;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   196
        mainThread.interrupt();
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   197
    }//fail()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   198
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   199
}// class ValidBounds
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   200
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   201
//This exception is used to exit from any level of call nesting
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   202
// when it's determined that the test has passed, and immediately
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   203
// end the test.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   204
class TestPassedException extends RuntimeException
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   205
{
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   206
}
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   207
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   208
//*********** End Standard Test Machinery Section **********
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   209
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   210
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   211
//************ Begin classes defined for the test ****************
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   212
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   213
// if want to make listeners, here is the recommended place for them, then instantiate
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   214
//  them in init()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   215
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   216
/* Example of a class which may be written as part of a test
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   217
class NewClass implements anInterface
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   218
 {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   219
   static int newVar = 0;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   220
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   221
   public void eventDispatched(AWTEvent e)
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   222
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   223
      //Counting events to see if we get enough
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   224
      eventCount++;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   225
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   226
      if( eventCount == 20 )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   227
       {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   228
         //got enough events, so pass
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   229
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   230
         ValidBounds.pass();
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   231
       }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   232
      else if( tries == 20 )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   233
       {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   234
         //tried too many times without getting enough events so fail
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   235
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   236
         ValidBounds.fail();
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   237
       }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   238
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   239
    }// eventDispatched()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   240
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   241
 }// NewClass class
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   242
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   243
*/
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   244
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   245
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   246
//************** End classes defined for the test *******************
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   247
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   248
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   249
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   250
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   251
/****************************************************
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   252
 Standard Test Machinery
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   253
 DO NOT modify anything below -- it's a standard
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   254
  chunk of code whose purpose is to make user
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   255
  interaction uniform, and thereby make it simpler
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   256
  to read and understand someone else's test.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   257
 ****************************************************/
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   258
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   259
/**
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   260
 This is part of the standard test machinery.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   261
 It creates a dialog (with the instructions), and is the interface
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   262
  for sending text messages to the user.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   263
 To print the instructions, send an array of strings to Sysout.createDialog
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   264
  WithInstructions method.  Put one line of instructions per array entry.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   265
 To display a message for the tester to see, simply call Sysout.println
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   266
  with the string to be displayed.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   267
 This mimics System.out.println but works within the test harness as well
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   268
  as standalone.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   269
 */
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   270
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   271
class Sysout
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   272
{
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   273
    private static TestDialog dialog;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   274
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   275
    public static void createDialogWithInstructions( String[] instructions )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   276
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   277
        dialog = new TestDialog( new Frame(), "Instructions" );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   278
        dialog.printInstructions( instructions );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   279
        dialog.setVisible(true);
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   280
        println( "Any messages for the tester will display here." );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   281
    }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   282
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   283
    public static void createDialog( )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   284
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   285
        dialog = new TestDialog( new Frame(), "Instructions" );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   286
        String[] defInstr = { "Instructions will appear here. ", "" } ;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   287
        dialog.printInstructions( defInstr );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   288
        dialog.setVisible(true);
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   289
        println( "Any messages for the tester will display here." );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   290
    }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   291
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   292
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   293
    public static void printInstructions( String[] instructions )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   294
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   295
        dialog.printInstructions( instructions );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   296
    }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   297
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   298
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   299
    public static void println( String messageIn )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   300
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   301
        dialog.displayMessage( messageIn );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   302
        System.out.println(messageIn);
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   303
    }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   304
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   305
}// Sysout  class
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   306
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   307
/**
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   308
  This is part of the standard test machinery.  It provides a place for the
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   309
   test instructions to be displayed, and a place for interactive messages
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   310
   to the user to be displayed.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   311
  To have the test instructions displayed, see Sysout.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   312
  To have a message to the user be displayed, see Sysout.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   313
  Do not call anything in this dialog directly.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   314
  */
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   315
class TestDialog extends Dialog
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   316
{
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   317
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   318
    TextArea instructionsText;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   319
    TextArea messageText;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   320
    int maxStringLength = 80;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   321
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   322
    //DO NOT call this directly, go through Sysout
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   323
    public TestDialog( Frame frame, String name )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   324
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   325
        super( frame, name );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   326
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   327
        instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   328
        add( "North", instructionsText );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   329
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   330
        messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   331
        add("Center", messageText);
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   332
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   333
        pack();
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   334
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   335
        setVisible(true);
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   336
    }// TestDialog()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   337
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   338
    //DO NOT call this directly, go through Sysout
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   339
    public void printInstructions( String[] instructions )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   340
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   341
        //Clear out any current instructions
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   342
        instructionsText.setText( "" );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   343
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   344
        //Go down array of instruction strings
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   345
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   346
        String printStr, remainingStr;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   347
        for( int i=0; i < instructions.length; i++ )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   348
        {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   349
            //chop up each into pieces maxSringLength long
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   350
            remainingStr = instructions[ i ];
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   351
            while( remainingStr.length() > 0 )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   352
            {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   353
                //if longer than max then chop off first max chars to print
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   354
                if( remainingStr.length() >= maxStringLength )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   355
                {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   356
                    //Try to chop on a word boundary
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   357
                    int posOfSpace = remainingStr.
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   358
                        lastIndexOf( ' ', maxStringLength - 1 );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   359
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   360
                    if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   361
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   362
                    printStr = remainingStr.substring( 0, posOfSpace + 1 );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   363
                    remainingStr = remainingStr.substring( posOfSpace + 1 );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   364
                }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   365
                //else just print
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   366
                else
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   367
                {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   368
                    printStr = remainingStr;
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   369
                    remainingStr = "";
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   370
                }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   371
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   372
                instructionsText.append( printStr + "\n" );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   373
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   374
            }// while
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   375
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   376
        }// for
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   377
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   378
    }//printInstructions()
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   379
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   380
    //DO NOT call this directly, go through Sysout
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   381
    public void displayMessage( String messageIn )
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   382
    {
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   383
        messageText.append( messageIn + "\n" );
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   384
        System.out.println(messageIn);
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   385
    }
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   386
6f07b02fe2c0 6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
diff changeset
   387
}// TestDialog  class