jdk/test/java/awt/Mixing/AWT_Mixing/OverlappingTestBase.java
author yan
Wed, 04 Jun 2014 17:24:13 +0400
changeset 25129 3961e8fcb668
parent 24539 f0250a79028b
child 28087 622b2f420bc3
permissions -rw-r--r--
8044157: [TEST_BUG] Improve recently submitted AWT_Mixing tests Reviewed-by: pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     1
/*
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     4
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     8
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    13
 * accompanied this code).
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    14
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    18
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    21
 * questions.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    22
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    23
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    24
import java.awt.*;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    25
import java.awt.event.*;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    26
import java.awt.peer.ComponentPeer;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    27
import java.lang.reflect.Constructor;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    28
import java.lang.reflect.InvocationTargetException;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    29
import java.lang.reflect.Method;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    30
import java.util.ArrayList;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    31
import javax.swing.*;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    32
import sun.awt.*;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    33
import java.io.*;
25129
3961e8fcb668 8044157: [TEST_BUG] Improve recently submitted AWT_Mixing tests
yan
parents: 24539
diff changeset
    34
import test.java.awt.regtesthelpers.Util;
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    35
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    36
/**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    37
 * <p>This class provides basis for AWT Mixing testing.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    38
 * <p>It provides all standard test machinery and should be used by
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    39
 * extending and overriding next methods:
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    40
 * <li> {@link OverlappingTestBase#prepareControls()} - setup UI components
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    41
 * <li> {@link OverlappingTestBase#performTest()} -  run particular test
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    42
 * Those methods would be run in the loop for each AWT component.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    43
 * <p>Current AWT component should be added to the tested UI by {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) ()}.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    44
 * There AWT components are prepared to be tested as being overlayed by other (e.g. Swing) components - they are colored to
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    45
 * {@link OverlappingTestBase#AWT_BACKGROUND_COLOR} and throws failure on catching mouse event.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    46
 * <p> Validation of component being overlayed should be tested by {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    47
 * See each method javadoc for more details.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    48
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    49
 * <p>Due to test machinery limitations all test should be run from their own main() by calling next coe
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    50
 * <code>
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    51
 *     public static void main(String args[]) throws InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    52
 *        instance = new YourTestInstance();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    53
 *        OverlappingTestBase.doMain(args);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    54
 *     }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    55
 * </code>
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    56
 *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    57
 * @author Sergey Grinev
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    58
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    59
public abstract class OverlappingTestBase {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    60
    // working variables
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    61
    private static volatile boolean wasHWClicked = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    62
    private static volatile boolean passed = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    63
    // constants
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    64
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    65
     * Default color for AWT component used for validate correct drawing of overlapping. <b>Never</b> use it for lightweight components.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    66
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    67
    protected static final Color AWT_BACKGROUND_COLOR = new Color(21, 244, 54);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    68
    protected static Color AWT_VERIFY_COLOR = AWT_BACKGROUND_COLOR;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    69
    protected static final int ROBOT_DELAY = 500;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    70
    private static final String[] simpleAwtControls = {"Button", "Checkbox", "Label", "TextArea"};
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    71
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    72
     * Generic strings array. To be used for population of List based controls.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    73
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    74
    protected static final String[] petStrings = {"Bird", "Cat", "Dog", "Rabbit", "Rhynocephalia Granda", "Bear", "Tiger", "Mustang"};
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    75
    // "properties"
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    76
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    77
     * Tests customization. Set this variable to test only control from java.awt
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    78
     * <p>Usage of this variable should be marked with CR being the reason.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    79
     * <p>Do not use this variable simultaneously with {@link OverlappingTestBase#skipClassNames}
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    80
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    81
    protected String onlyClassName = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    82
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    83
     * For customizing tests. List classes' simple names to skip them from testings.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    84
     * <p>Usage of this variable should be marked with CR being the reason.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    85
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    86
    protected String[] skipClassNames = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    87
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    88
     * Set to false to avoid event delivery validation
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    89
     * @see OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean)
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    90
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    91
    protected boolean useClickValidation = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    92
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    93
     * Set to false if test doesn't supposed to verify EmbeddedFrame
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    94
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    95
    protected boolean testEmbeddedFrame = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    96
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    97
     * Set this variable to true if testing embedded frame is impossible (on Mac, for instance, for now).
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    98
     * The testEmbeddedFrame is explicitly set to true in dozen places.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
    99
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   100
    protected boolean skipTestingEmbeddedFrame = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   101
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   102
    public static final boolean isMac = System.getProperty("os.name").toLowerCase().contains("os x");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   103
    private boolean isFrameBorderCalculated;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   104
    private int borderShift;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   105
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   106
    {    if (Toolkit.getDefaultToolkit().getClass().getName().matches(".*L.*Toolkit")) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   107
             // No EmbeddedFrame in LWToolkit/LWCToolkit, yet
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   108
             // And it should be programmed some other way, too, in any case
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   109
             System.err.println("skipTestingEmbeddedFrame");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   110
             skipTestingEmbeddedFrame = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   111
         }else {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   112
             System.err.println("do not skipTestingEmbeddedFrame");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   113
         }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   114
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   115
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   116
    protected int frameBorderCounter() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   117
        if (!isFrameBorderCalculated) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   118
            try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   119
                new FrameBorderCounter(); // force compilation by jtreg
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   120
                String JAVA_HOME = System.getProperty("java.home");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   121
                Process p = Runtime.getRuntime().exec(JAVA_HOME + "/bin/java FrameBorderCounter");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   122
                try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   123
                    p.waitFor();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   124
                } catch (InterruptedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   125
                    e.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   126
                    throw new RuntimeException(e);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   127
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   128
                if (p.exitValue() != 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   129
                    throw new RuntimeException("FrameBorderCounter exited with not null code!\n" + readInputStream(p.getErrorStream()));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   130
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   131
                borderShift = Integer.parseInt(readInputStream(p.getInputStream()).trim());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   132
                isFrameBorderCalculated = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   133
            } catch (IOException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   134
                e.printStackTrace();
25129
3961e8fcb668 8044157: [TEST_BUG] Improve recently submitted AWT_Mixing tests
yan
parents: 24539
diff changeset
   135
                throw new RuntimeException("Problem calculating a native border size");
24539
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   136
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   137
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   138
        return borderShift;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   139
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   140
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   141
    public void getVerifyColor() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   142
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   143
            final int size = 200;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   144
            final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   145
            final Point[] p = new Point[1];
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   146
            SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   147
                public void run(){
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   148
                    JFrame frame = new JFrame("set back");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   149
                    frame.getContentPane().setBackground(AWT_BACKGROUND_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   150
                    frame.setSize(size, size);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   151
                    frame.setUndecorated(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   152
                    frame.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   153
                    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   154
                    p[0] = frame.getLocation();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   155
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   156
            });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   157
            Robot robot = new Robot();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   158
            toolkit.realSync();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   159
            Thread.sleep(ROBOT_DELAY);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   160
            AWT_VERIFY_COLOR = robot.getPixelColor(p[0].x+size/2, p[0].y+size/2);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   161
            System.out.println("Color will be compared with " + AWT_VERIFY_COLOR + " instead of " + AWT_BACKGROUND_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   162
        } catch (Exception e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   163
            System.err.println("Cannot get verify color: "+e.getMessage());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   164
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   165
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   166
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   167
    private String readInputStream(InputStream is) throws IOException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   168
        byte[] buffer = new byte[4096];
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   169
        int len = 0;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   170
        StringBuilder sb = new StringBuilder();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   171
        try (InputStreamReader isr = new InputStreamReader(is)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   172
            while ((len = is.read(buffer)) > 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   173
                sb.append(new String(buffer, 0, len));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   174
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   175
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   176
        return sb.toString();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   177
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   178
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   179
    private void setupControl(final Component control) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   180
        if (useClickValidation) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   181
            control.addMouseListener(new MouseAdapter() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   182
                @Override
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   183
                public void mouseClicked(MouseEvent e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   184
                    System.err.println("ERROR: " + control.getClass() + " received mouse click.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   185
                    wasHWClicked = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   186
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   187
            });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   188
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   189
        control.setBackground(AWT_BACKGROUND_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   190
        control.setForeground(AWT_BACKGROUND_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   191
        control.setPreferredSize(new Dimension(150, 150));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   192
        control.setFocusable(false);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   193
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   194
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   195
    private void addAwtControl(java.util.List<Component> container, final Component control) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   196
        String simpleName = control.getClass().getSimpleName();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   197
        if (onlyClassName != null && !simpleName.equals(onlyClassName)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   198
            return;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   199
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   200
        if (skipClassNames != null) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   201
            for (String skipMe : skipClassNames) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   202
                if (simpleName.equals(skipMe)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   203
                    return;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   204
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   205
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   206
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   207
        setupControl(control);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   208
        container.add(control);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   209
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   210
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   211
    private void addSimpleAwtControl(java.util.List<Component> container, String className) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   212
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   213
            Class definition = Class.forName("java.awt." + className);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   214
            Constructor constructor = definition.getConstructor(new Class[]{String.class});
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   215
            java.awt.Component component = (java.awt.Component) constructor.newInstance(new Object[]{"AWT Component " + className});
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   216
            addAwtControl(container, component);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   217
        } catch (Exception ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   218
            System.err.println(ex.getMessage());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   219
            fail("Setup error, this jdk doesn't have awt conrol " + className);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   220
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   221
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   222
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   223
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   224
     * Adds current AWT control to container
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   225
     * <p>N.B.: if testEmbeddedFrame == true this method will also add EmbeddedFrame over Canvas
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   226
     * and it should be called <b>after</b> Frame.setVisible(true) call
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   227
     * @param container container to hold AWT component
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   228
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   229
    protected final void propagateAWTControls(Container container) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   230
        if (currentAwtControl != null) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   231
            container.add(currentAwtControl);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   232
        } else { // embedded frame
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   233
            try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   234
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   235
                //create embedder
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   236
                Canvas embedder = new Canvas();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   237
                embedder.setBackground(Color.RED);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   238
                embedder.setPreferredSize(new Dimension(150, 150));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   239
                container.add(embedder);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   240
                container.setVisible(true); // create peer
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   241
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   242
                long frameWindow = 0;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   243
                String getWindowMethodName = "getHWnd";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   244
                if (Toolkit.getDefaultToolkit().getClass().getName().contains("XToolkit")) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   245
                    getWindowMethodName = "getWindow";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   246
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   247
                ComponentPeer peer = embedder.getPeer();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   248
//                System.err.println("Peer: " + peer);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   249
                Method getWindowMethod = peer.getClass().getMethod(getWindowMethodName);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   250
                frameWindow = (Long) getWindowMethod.invoke(peer);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   251
//                System.err.println("frame peer ID: " + frameWindow);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   252
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   253
                String eframeClassName = "sun.awt.windows.WEmbeddedFrame";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   254
                if (Toolkit.getDefaultToolkit().getClass().getName().contains("XToolkit")) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   255
                    eframeClassName = "sun.awt.X11.XEmbeddedFrame";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   256
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   257
                Class eframeClass = Class.forName(eframeClassName);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   258
                Constructor eframeCtor = eframeClass.getConstructor(long.class);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   259
                EmbeddedFrame eframe = (EmbeddedFrame) eframeCtor.newInstance(frameWindow);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   260
                setupControl(eframe);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   261
                eframe.setSize(new Dimension(150, 150));
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   262
                eframe.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   263
//                System.err.println(eframe.getSize());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   264
            } catch (Exception ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   265
                ex.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   266
                fail("Failed to instantiate EmbeddedFrame: " + ex.getMessage());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   267
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   268
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   269
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   270
    private static final Font hugeFont = new Font("Arial", Font.BOLD, 70);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   271
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   272
    private java.util.List<Component> getAWTControls() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   273
        java.util.List<Component> components = new ArrayList<Component>();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   274
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   275
        for (String clazz : simpleAwtControls) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   276
            addSimpleAwtControl(components, clazz);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   277
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   278
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   279
        TextField tf = new TextField();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   280
        tf.setFont(hugeFont);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   281
        addAwtControl(components, tf);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   282
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   283
        // more complex controls
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   284
        Choice c = new Choice();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   285
        for (int i = 0; i < petStrings.length; i++) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   286
            c.add(petStrings[i]);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   287
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   288
        addAwtControl(components, c);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   289
        c.setPreferredSize(null);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   290
        c.setFont(hugeFont); // to make control bigger as setPrefferedSize don't do his job here
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   291
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   292
        List l = new List(petStrings.length);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   293
        for (int i = 0; i < petStrings.length; i++) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   294
            l.add(petStrings[i]);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   295
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   296
        addAwtControl(components, l);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   297
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   298
        Canvas canvas = new Canvas();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   299
        canvas.setSize(100, 200);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   300
        addAwtControl(components, canvas);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   301
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   302
        Scrollbar sb = new Scrollbar(Scrollbar.VERTICAL, 500, 1, 0, 500);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   303
        addAwtControl(components, sb);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   304
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   305
        Scrollbar sb2 = new Scrollbar(Scrollbar.HORIZONTAL, 500, 1, 0, 500);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   306
        addAwtControl(components, sb2);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   307
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   308
        return components;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   309
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   310
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   311
     * Default shift for {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   312
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   313
    protected static Point shift = new Point(16, 16);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   314
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   315
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   316
     * Verifies point using specified AWT Robot. Supposes <code>defaultShift == true</code> for {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean) }.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   317
     * This method is used to verify controls by providing just their plain screen coordinates.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   318
     * @param robot AWT Robot. Usually created by {@link Util#createRobot() }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   319
     * @param lLoc point to verify
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   320
     * @see OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point, boolean)
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   321
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   322
    protected void clickAndBlink(Robot robot, Point lLoc) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   323
        clickAndBlink(robot, lLoc, true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   324
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   325
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   326
     * Default failure message for color check
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   327
     * @see OverlappingTestBase#performTest()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   328
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   329
    protected String failMessageColorCheck = "The LW component did not pass pixel color check and is overlapped";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   330
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   331
     * Default failure message event check
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   332
     * @see OverlappingTestBase#performTest()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   333
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   334
    protected String failMessage = "The LW component did not received the click.";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   335
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   336
    private static boolean isValidForPixelCheck(Component component) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   337
        if ((component instanceof java.awt.Scrollbar) || isMac && (component instanceof java.awt.Button)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   338
            return false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   339
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   340
        return true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   341
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   342
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   343
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   344
     * Preliminary validation - should be run <b>before</b> overlapping happens to ensure test is correct.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   345
     * @param robot AWT Robot. Usually created by {@link Util#createRobot() }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   346
     * @param lLoc point to validate to be <b>of</b> {@link OverlappingTestBase#AWT_BACKGROUND_COLOR}
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   347
     * @param component tested component, should be pointed out as not all components are valid for pixel check.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   348
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   349
    protected void pixelPreCheck(Robot robot, Point lLoc, Component component) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   350
        if (isValidForPixelCheck(component)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   351
            int tries = 10;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   352
            Color c = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   353
            while (tries-- > 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   354
                c = robot.getPixelColor(lLoc.x, lLoc.y);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   355
                System.out.println("Precheck. color: "+c+" compare with "+AWT_VERIFY_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   356
                if (c.equals(AWT_VERIFY_COLOR)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   357
                    return;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   358
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   359
                try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   360
                    Thread.sleep(100);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   361
                } catch (InterruptedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   362
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   363
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   364
            System.err.println(lLoc + ": " + c);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   365
            fail("Dropdown test setup failure, colored part of AWT component is not located at click area");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   366
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   367
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   368
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   369
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   370
     * Verifies point using specified AWT Robot.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   371
     * <p>Firstly, verifies point by color pixel check
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   372
     * <p>Secondly, verifies event delivery by mouse click
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   373
     * @param robot AWT Robot. Usually created by {@link Util#createRobot() }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   374
     * @param lLoc point to verify
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   375
     * @param defaultShift if true verified position will be shifted by {@link OverlappingTestBase#shift }.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   376
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   377
    protected void clickAndBlink(Robot robot, Point lLoc, boolean defaultShift) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   378
        Point loc = lLoc.getLocation();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   379
        //check color
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   380
        Util.waitForIdle(robot);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   381
        try{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   382
            Thread.sleep(500);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   383
        }catch(Exception exx){
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   384
            exx.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   385
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   386
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   387
        if (defaultShift) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   388
            loc.translate(shift.x, shift.y);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   389
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   390
        if (!(System.getProperty("os.name").toLowerCase().contains("os x"))) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   391
            Color c = robot.getPixelColor(loc.x, loc.y);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   392
            System.out.println("C&B. color: "+c+" compare with "+AWT_VERIFY_COLOR);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   393
            if (c.equals(AWT_VERIFY_COLOR)) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   394
                fail(failMessageColorCheck);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   395
                passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   396
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   397
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   398
            // perform click
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   399
            Util.waitForIdle(robot);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   400
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   401
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   402
        robot.mouseMove(loc.x, loc.y);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   403
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   404
        robot.mousePress(InputEvent.BUTTON1_MASK);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   405
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   406
        Util.waitForIdle(robot);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   407
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   408
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   409
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   410
     * This method should be overriden with code which setups UI for testing.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   411
     * Code in this method <b>will</b> be called only from AWT thread so Swing operations can be called directly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   412
     *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   413
     * @see {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) } for instructions about adding tested AWT control to UI
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   414
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   415
    protected abstract void prepareControls();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   416
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   417
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   418
     * This method should be overriden with test execution. It will <b>not</b> be called from AWT thread so all Swing operations should be treated accordingly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   419
     * @return true if test passed. Otherwise fail with default fail message.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   420
     * @see {@link OverlappingTestBase#failMessage} default fail message
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   421
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   422
    protected abstract boolean performTest();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   423
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   424
     * This method can be overriden with cleanup routines. It will be called from AWT thread so all Swing operations should be treated accordingly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   425
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   426
    protected void cleanup() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   427
        // intentionally do nothing
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   428
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   429
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   430
     * Currect tested AWT Control. Usually shouldn't be accessed directly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   431
     *
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   432
     * @see {@link OverlappingTestBase#propagateAWTControls(java.awt.Container) } for instructions about adding tested AWT control to UI
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   433
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   434
    protected Component currentAwtControl;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   435
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   436
    private void testComponent(Component component) throws InterruptedException, InvocationTargetException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   437
        currentAwtControl = component;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   438
        System.out.println("Testing " + currentAwtControl.getClass().getSimpleName());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   439
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   440
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   441
                prepareControls();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   442
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   443
        });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   444
        if (component != null) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   445
            Util.waitTillShown(component);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   446
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   447
        Util.waitForIdle(null);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   448
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   449
            Thread.sleep(500); // wait for graphic effects on systems like Win7
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   450
        } catch (InterruptedException ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   451
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   452
        if (!instance.performTest()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   453
            fail(failMessage);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   454
            passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   455
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   456
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   457
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   458
                cleanup();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   459
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   460
        });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   461
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   462
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   463
    private void testEmbeddedFrame() throws InvocationTargetException, InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   464
        System.out.println("Testing EmbeddedFrame");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   465
        currentAwtControl = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   466
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   467
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   468
                prepareControls();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   469
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   470
        });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   471
        Util.waitForIdle(null);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   472
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   473
            Thread.sleep(500); // wait for graphic effects on systems like Win7
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   474
        } catch (InterruptedException ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   475
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   476
        if (!instance.performTest()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   477
            fail(failMessage);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   478
            passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   479
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   480
        SwingUtilities.invokeAndWait(new Runnable() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   481
            public void run() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   482
                cleanup();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   483
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   484
        });
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   485
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   486
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   487
    private void testAwtControls() throws InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   488
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   489
            for (Component component : getAWTControls()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   490
                testComponent(component);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   491
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   492
            if (testEmbeddedFrame && !skipTestingEmbeddedFrame) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   493
                testEmbeddedFrame();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   494
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   495
        } catch (InvocationTargetException ex) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   496
            ex.printStackTrace();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   497
            fail(ex.getMessage());
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   498
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   499
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   500
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   501
     * Used by standard test machinery. See usage at {@link OverlappingTestBase }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   502
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   503
    protected static OverlappingTestBase instance;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   504
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   505
    protected OverlappingTestBase() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   506
        getVerifyColor();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   507
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   508
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   509
    /*****************************************************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   510
     * Standard Test Machinery Section
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   511
     * DO NOT modify anything in this section -- it's a
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   512
     * standard chunk of code which has all of the
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   513
     * synchronisation necessary for the test harness.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   514
     * By keeping it the same in all tests, it is easier
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   515
     * to read and understand someone else's test, as
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   516
     * well as insuring that all tests behave correctly
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   517
     * with the test harness.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   518
     * There is a section following this for test-
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   519
     * classes
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   520
     ******************************************************/
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   521
    private static void init() throws InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   522
        //*** Create instructions for the user here ***
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   523
        //System.setProperty("sun.awt.disableMixing", "true");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   524
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   525
        String[] instructions = {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   526
            "This is an AUTOMATIC test, simply wait until it is done.",
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   527
            "The result (passed or failed) will be shown in the",
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   528
            "message window below."
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   529
        };
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   530
        Sysout.createDialog();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   531
        Sysout.printInstructions(instructions);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   532
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   533
        instance.testAwtControls();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   534
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   535
        if (wasHWClicked) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   536
            fail("HW component received the click.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   537
            passed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   538
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   539
        if (passed) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   540
            pass();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   541
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   542
    }//End  init()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   543
    private static boolean theTestPassed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   544
    private static boolean testGeneratedInterrupt = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   545
    private static String failureMessage = "";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   546
    private static Thread mainThread = null;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   547
    private static int sleepTime = 300000;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   548
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   549
    // Not sure about what happens if multiple of this test are
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   550
    //  instantiated in the same VM.  Being static (and using
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   551
    //  static vars), it aint gonna work.  Not worrying about
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   552
    //  it for now.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   553
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   554
     * Starting point for test runs. See usage at {@link OverlappingTestBase }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   555
     * @param args regular main args, not used.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   556
     * @throws InterruptedException
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   557
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   558
    public static void doMain(String args[]) throws InterruptedException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   559
        mainThread = Thread.currentThread();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   560
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   561
            init();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   562
        } catch (TestPassedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   563
            //The test passed, so just return from main and harness will
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   564
            // interepret this return as a pass
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   565
            return;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   566
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   567
        //At this point, neither test pass nor test fail has been
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   568
        // called -- either would have thrown an exception and ended the
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   569
        // test, so we know we have multiple threads.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   570
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   571
        //Test involves other threads, so sleep and wait for them to
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   572
        // called pass() or fail()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   573
        try {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   574
            Thread.sleep(sleepTime);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   575
            //Timed out, so fail the test
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   576
            throw new RuntimeException("Timed out after " + sleepTime / 1000 + " seconds");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   577
        } catch (InterruptedException e) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   578
            //The test harness may have interrupted the test.  If so, rethrow the exception
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   579
            // so that the harness gets it and deals with it.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   580
            if (!testGeneratedInterrupt) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   581
                throw e;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   582
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   583
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   584
            //reset flag in case hit this code more than once for some reason (just safety)
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   585
            testGeneratedInterrupt = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   586
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   587
            if (theTestPassed == false) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   588
                throw new RuntimeException(failureMessage);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   589
            }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   590
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   591
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   592
    }//main
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   593
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   594
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   595
     * Test will fail if not passed after this timeout. Default timeout is 300 seconds.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   596
     * @param seconds timeout in seconds
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   597
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   598
    public static synchronized void setTimeoutTo(int seconds) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   599
        sleepTime = seconds * 1000;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   600
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   601
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   602
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   603
     * Set test as passed. Usually shoudn't be called directly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   604
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   605
    public static synchronized void pass() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   606
        Sysout.println("The test passed.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   607
        Sysout.println("The test is over, hit  Ctl-C to stop Java VM");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   608
        //first check if this is executing in main thread
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   609
        if (mainThread == Thread.currentThread()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   610
            //Still in the main thread, so set the flag just for kicks,
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   611
            // and throw a test passed exception which will be caught
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   612
            // and end the test.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   613
            theTestPassed = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   614
            throw new TestPassedException();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   615
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   616
        theTestPassed = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   617
        testGeneratedInterrupt = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   618
        mainThread.interrupt();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   619
    }//pass()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   620
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   621
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   622
     * Fail test generic message.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   623
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   624
    public static synchronized void fail() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   625
        //test writer didn't specify why test failed, so give generic
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   626
        fail("it just plain failed! :-)");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   627
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   628
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   629
    /**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   630
     * Fail test providing specific reason.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   631
     * @param whyFailed reason
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   632
     */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   633
    public static synchronized void fail(String whyFailed) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   634
        Sysout.println("The test failed: " + whyFailed);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   635
        Sysout.println("The test is over, hit  Ctl-C to stop Java VM");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   636
        //check if this called from main thread
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   637
        if (mainThread == Thread.currentThread()) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   638
            //If main thread, fail now 'cause not sleeping
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   639
            throw new RuntimeException(whyFailed);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   640
        }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   641
        theTestPassed = false;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   642
        testGeneratedInterrupt = true;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   643
        failureMessage = whyFailed;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   644
        mainThread.interrupt();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   645
    }//fail()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   646
}// class LWComboBox
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   647
class TestPassedException extends RuntimeException {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   648
}
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   649
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   650
//*********** End Standard Test Machinery Section **********
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   651
//************ Begin classes defined for the test ****************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   652
// if want to make listeners, here is the recommended place for them, then instantiate
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   653
//  them in init()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   654
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   655
/* Example of a class which may be written as part of a test
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   656
class NewClass implements anInterface
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   657
{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   658
static int newVar = 0;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   659
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   660
public void eventDispatched(AWTEvent e)
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   661
{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   662
//Counting events to see if we get enough
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   663
eventCount++;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   664
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   665
if( eventCount == 20 )
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   666
{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   667
//got enough events, so pass
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   668
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   669
LWComboBox.pass();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   670
}
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   671
else if( tries == 20 )
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   672
{
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   673
//tried too many times without getting enough events so fail
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   674
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   675
LWComboBox.fail();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   676
}
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   677
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   678
}// eventDispatched()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   679
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   680
}// NewClass class
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   681
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   682
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   683
//************** End classes defined for the test *******************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   684
/****************************************************
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   685
Standard Test Machinery
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   686
DO NOT modify anything below -- it's a standard
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   687
chunk of code whose purpose is to make user
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   688
interaction uniform, and thereby make it simpler
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   689
to read and understand someone else's test.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   690
 ****************************************************/
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   691
/**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   692
This is part of the standard test machinery.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   693
It creates a dialog (with the instructions), and is the interface
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   694
for sending text messages to the user.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   695
To print the instructions, send an array of strings to Sysout.createDialog
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   696
WithInstructions method.  Put one line of instructions per array entry.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   697
To display a message for the tester to see, simply call Sysout.println
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   698
with the string to be displayed.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   699
This mimics System.out.println but works within the test harness as well
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   700
as standalone.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   701
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   702
class Sysout {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   703
    private static TestDialog dialog;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   704
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   705
    public static void createDialogWithInstructions(String[] instructions) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   706
        dialog = new TestDialog(new Frame(), "Instructions");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   707
        dialog.printInstructions(instructions);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   708
        //dialog.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   709
        println("Any messages for the tester will display here.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   710
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   711
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   712
    public static void createDialog() {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   713
        dialog = new TestDialog(new Frame(), "Instructions");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   714
        String[] defInstr = {"Instructions will appear here. ", ""};
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   715
        dialog.printInstructions(defInstr);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   716
        //dialog.setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   717
        println("Any messages for the tester will display here.");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   718
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   719
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   720
    public static void printInstructions(String[] instructions) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   721
        dialog.printInstructions(instructions);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   722
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   723
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   724
    public static void println(String messageIn) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   725
        dialog.displayMessage(messageIn);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   726
        System.out.println(messageIn);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   727
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   728
}// Sysout  class
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   729
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   730
/**
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   731
This is part of the standard test machinery.  It provides a place for the
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   732
test instructions to be displayed, and a place for interactive messages
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   733
to the user to be displayed.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   734
To have the test instructions displayed, see Sysout.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   735
To have a message to the user be displayed, see Sysout.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   736
Do not call anything in this dialog directly.
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   737
 */
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   738
class TestDialog extends Dialog {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   739
    TextArea instructionsText;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   740
    TextArea messageText;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   741
    int maxStringLength = 80;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   742
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   743
    //DO NOT call this directly, go through Sysout
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   744
    public TestDialog(Frame frame, String name) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   745
        super(frame, name);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   746
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   747
        instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   748
        add("North", instructionsText);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   749
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   750
        messageText = new TextArea("", 5, maxStringLength, scrollBoth);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   751
        add("Center", messageText);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   752
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   753
        pack();
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   754
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   755
       //setVisible(true);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   756
    }// TestDialog()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   757
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   758
    //DO NOT call this directly, go through Sysout
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   759
    public void printInstructions(String[] instructions) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   760
        //Clear out any current instructions
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   761
        instructionsText.setText("");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   762
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   763
        //Go down array of instruction strings
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   764
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   765
        String printStr, remainingStr;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   766
        for (int i = 0; i < instructions.length; i++) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   767
            //chop up each into pieces maxSringLength long
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   768
            remainingStr = instructions[i];
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   769
            while (remainingStr.length() > 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   770
                //if longer than max then chop off first max chars to print
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   771
                if (remainingStr.length() >= maxStringLength) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   772
                    //Try to chop on a word boundary
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   773
                    int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   774
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   775
                    if (posOfSpace <= 0) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   776
                        posOfSpace = maxStringLength - 1;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   777
                    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   778
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   779
                    printStr = remainingStr.substring(0, posOfSpace + 1);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   780
                    remainingStr = remainingStr.substring(posOfSpace + 1);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   781
                } //else just print
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   782
                else {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   783
                    printStr = remainingStr;
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   784
                    remainingStr = "";
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   785
                }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   786
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   787
                instructionsText.append(printStr + "\n");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   788
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   789
            }// while
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   790
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   791
        }// for
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   792
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   793
    }//printInstructions()
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   794
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   795
    //DO NOT call this directly, go through Sysout
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   796
    public void displayMessage(String messageIn) {
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   797
        messageText.append(messageIn + "\n");
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   798
        System.out.println(messageIn);
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   799
    }
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   800
}// TestDialog  class
f0250a79028b 8041592: [TEST_BUG] Move 42 AWT hw/lw mixing tests to jdk
yan
parents:
diff changeset
   801