test/jdk/java/awt/List/SetBackgroundTest/SetBackgroundTest.java
author serb
Wed, 21 Feb 2018 12:49:00 -0800
changeset 49096 eaef201ec301
parent 47216 71c04702a3d5
child 52739 7199c4da1a6f
permissions -rw-r--r--
8198333: ProblemList should be updated for headless mode Reviewed-by: psadhukhan, prr
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
49096
eaef201ec301 8198333: ProblemList should be updated for headless mode
serb
parents: 47216
diff changeset
    27
  @key headful
eaef201ec301 8198333: ProblemList should be updated for headless mode
serb
parents: 47216
diff changeset
    28
  @requires (os.family == "linux") | (os.family == "solaris")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
  @summary List does not honor user specified background, foreground colors on XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  @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
    31
  @library ../../../../lib/testlibrary
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    32
  @build ExtendedRobot
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  @run main SetBackgroundTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * SetBackgroundTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * summary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class SetBackgroundTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    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
    49
    private static ExtendedRobot robot = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static Frame frame = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static final Color color = Color.red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static Color roughColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static void initRoughColor(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        Canvas canvas = new Canvas();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        canvas.setBackground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        frame.add(canvas, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        frame.validate();
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    61
        robot.waitForIdle(500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        Point loc = canvas.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        Color robotColor = robot.getPixelColor(loc.x + canvas.getWidth()/2, loc.y + canvas.getHeight()/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        roughColor = robotColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    67
        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
    68
        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
    69
        System.out.println("     roughColor = "+roughColor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        frame.remove(canvas);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    72
        robot.waitForIdle(500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static void test() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (!isXAWT){
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    78
            System.out.println(" this is XAWT-only test. ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        frame = new Frame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        frame.setBounds(400,400,200,200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        frame.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        try{
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    89
            robot = new ExtendedRobot();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }catch(AWTException e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            throw new RuntimeException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    94
        robot.waitForIdle(500);
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
    95
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        initRoughColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        Component[] components = new Component[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            new Button(), new Checkbox(), new Label(), new List(3, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            new TextArea(), new TextField(), new Choice()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        for (Component component : components) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            testComponent(new Panel(), component, color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   106
        robot.waitForIdle(1500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        frame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static void testComponent(Container container, Component component, Color color){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        component.setBackground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        container.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        container.add(component, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        frame.add(container, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        frame.add("Center", container);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        frame.validate();
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   119
        robot.waitForIdle(500);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        Point loc = component.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        Color robotColor = robot.getPixelColor(loc.x + component.getWidth()/2, loc.y + component.getHeight()/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   124
        System.out.println(" --- test ... ");
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   125
        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
   126
        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
   127
        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
   128
        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
   129
        System.out.println("     robotColor = "+robotColor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if(robotColor.getRGB() != roughColor.getRGB()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            throw new RuntimeException(" the case failed. ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        } else {
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   134
            System.out.println(" the case passed. ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        container.remove(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        frame.remove(container);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   139
        robot.waitForIdle(500);
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
    public static void main( String args[] ) throws Exception
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    {
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 5506
diff changeset
   143
        test();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146