test/jdk/java/awt/List/SetBackgroundTest/SetBackgroundTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 28087 jdk/test/java/awt/List/SetBackgroundTest/SetBackgroundTest.java@622b2f420bc3
child 49096 eaef201ec301
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2007, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
  @bug 6246467
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @summary List does not honor user specified background, foreground colors on XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @author Dmitry Cherepanov  area=awt.list
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    29
  @library ../../../../lib/testlibrary
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    30
  @build ExtendedRobot
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  @run main SetBackgroundTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * SetBackgroundTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * summary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class SetBackgroundTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static boolean isXAWT = (Toolkit.getDefaultToolkit().getClass().getName().equals("sun.awt.X11.XToolkit"));
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    47
    private static ExtendedRobot robot = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static Frame frame = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final Color color = Color.red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static Color roughColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static void initRoughColor(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        Canvas canvas = new Canvas();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        canvas.setBackground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        frame.add(canvas, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        frame.validate();
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    59
        robot.waitForIdle(500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        Point loc = canvas.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        Color robotColor = robot.getPixelColor(loc.x + canvas.getWidth()/2, loc.y + canvas.getHeight()/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        roughColor = robotColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    65
        System.out.println(" --- init rough color ... ");
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    66
        System.out.println("     color = "+color);
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    67
        System.out.println("     roughColor = "+roughColor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        frame.remove(canvas);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    70
        robot.waitForIdle(500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static void test() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (!isXAWT){
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    76
            System.out.println(" this is XAWT-only test. ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        frame = new Frame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        frame.setBounds(400,400,200,200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        frame.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        try{
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    87
            robot = new ExtendedRobot();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }catch(AWTException e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            throw new RuntimeException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    92
        robot.waitForIdle(500);
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    93
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        initRoughColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        Component[] components = new Component[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            new Button(), new Checkbox(), new Label(), new List(3, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            new TextArea(), new TextField(), new Choice()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        for (Component component : components) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            testComponent(new Panel(), component, color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   104
        robot.waitForIdle(1500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        frame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private static void testComponent(Container container, Component component, Color color){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        component.setBackground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        container.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        container.add(component, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        frame.add(container, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        frame.add("Center", container);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        frame.validate();
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   117
        robot.waitForIdle(500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        Point loc = component.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        Color robotColor = robot.getPixelColor(loc.x + component.getWidth()/2, loc.y + component.getHeight()/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   122
        System.out.println(" --- test ... ");
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   123
        System.out.println("     container = "+container);
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   124
        System.out.println("     component = "+component);
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   125
        System.out.println("     color = "+color);
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   126
        System.out.println("     roughColor = "+roughColor);
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   127
        System.out.println("     robotColor = "+robotColor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if(robotColor.getRGB() != roughColor.getRGB()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            throw new RuntimeException(" the case failed. ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } else {
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   132
            System.out.println(" the case passed. ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        container.remove(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        frame.remove(container);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   137
        robot.waitForIdle(500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   139
    public static void main( String args[] ) throws Exception
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    {
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   141
        test();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144