jdk/test/java/awt/Multiscreen/UpdateGCTest/UpdateGCTest.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 5506 202f599c92aa
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
     2
 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
    26
  @key headful
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @bug 4452373 6567564
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @summary Tests that all the child and toplevel components have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
their GraphicsConfiguration updated when the window moves from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
one screen to another, on Windows or Linux/Solaris + Xinerama
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  @author artem.ananiev: area=awt.multiscreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  @library ../../regtesthelpers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  @build Util
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  @run main UpdateGCTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import test.java.awt.regtesthelpers.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class UpdateGCTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public static void main(String[] args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        GraphicsDevice[] gds = ge.getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        if (gds.length < 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            System.out.println("The test should be run in multi-screen configuration. Test PASSED/skipped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        boolean virtualConfig = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        for (GraphicsDevice gd : gds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            GraphicsConfiguration gc = gd.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            if ((gc.getBounds().x != 0) || (gc.getBounds().y != 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                virtualConfig = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if (!virtualConfig)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            System.out.println("The test should be run in virtual multi-screen mode. Test PASSED/skipped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            Robot robot = new Robot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            for (GraphicsDevice gdOrig : gds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                GraphicsConfiguration gcOrig = gdOrig.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                // test Frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                Frame f = new Frame("F", gcOrig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                f.setSize(200, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                f.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                // test Canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                f.add(new Canvas(gcOrig), BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                // test lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                Container c = new Container() {};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                c.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                // test hw inside lw
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                c.add(new Panel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                c.add(new Canvas(gcOrig));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                f.add(c, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                // test Panel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                Panel p = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                p.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                // test nested Canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                p.add(new Canvas(gcOrig), BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                // test nested lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                p.add(new Component() {}, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                // test nested panel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                p.add(new Panel(), BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                f.add(p, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                f.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                for (GraphicsDevice gd : gds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    GraphicsConfiguration gc = gd.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    f.setLocation(gc.getBounds().x + 100, gc.getBounds().y + 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                    Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    checkGC(f, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        catch (Exception z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            System.err.println("Unknown exception caught");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            z.printStackTrace(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new RuntimeException("Test FAILED: " + z.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        System.out.println("Test PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private static void checkGC(Component c, GraphicsConfiguration gc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (c.getGraphicsConfiguration() != gc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            System.err.println("GC for component (" + c + ") is not updated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            System.err.println("Right GC: " + gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            System.err.println("Component GC: " + c.getGraphicsConfiguration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            throw new RuntimeException("Test FAILED: component GC is not updated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        System.out.println("Checked GC for component (" + c + "): OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (c instanceof Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            Container cc = (Container)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            Component[] children = cc.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            for (Component child : children)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                checkGC(child, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}