test/jdk/java/awt/TrayIcon/GetTrayIconsTest/GetTrayIcons.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25137 jdk/test/java/awt/TrayIcon/GetTrayIconsTest/GetTrayIcons.java@43055e2deee9
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:
25137
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     1
/*
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     2
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     4
 *
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     8
 *
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    13
 * accompanied this code).
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    14
 *
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    18
 *
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    21
 * questions.
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    22
 */
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    23
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    24
import java.awt.*;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    25
import java.awt.image.BufferedImage;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    26
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    27
/*
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    28
 * @test
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    29
 * @summary Check the getTrayIcons method of the SystemTray
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    30
 * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    31
 * @run main GetTrayIcons
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    32
 */
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    33
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    34
public class GetTrayIcons {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    35
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    36
    Image image;
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    37
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    38
    public static void main(String[] args) throws Exception {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    39
        if (! SystemTray.isSupported())
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    40
            System.out.println("SystemTray not supported on the platform under test. " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    41
                    "Marking the test passed");
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    42
        else
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    43
            new GetTrayIcons().doTest();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    44
    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    45
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    46
    GetTrayIcons() {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    47
        image = new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    48
    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    49
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    50
    void doTest() throws Exception {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    51
        SystemTray tray = SystemTray.getSystemTray();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    52
        TrayIcon[] icons = tray.getTrayIcons();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    53
        if (icons == null || icons.length > 0)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    54
            throw new RuntimeException("FAIL: getTrayIcons() returned incorrect " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    55
                    "value when no icons are added " + icons);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    56
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    57
        TrayIcon icon = new TrayIcon(image);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    58
        tray.add(icon);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    59
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    60
        icons = tray.getTrayIcons();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    61
        if (icons == null || icons.length != 1)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    62
            throw new RuntimeException("FAIL: getTrayIcons() returned incorrect value " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    63
                    "when one icon present " + icons);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    64
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    65
        icon = new TrayIcon(image);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    66
        tray.add(icon);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    67
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    68
        icons = tray.getTrayIcons();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    69
        if (icons == null || icons.length != 2)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    70
            throw new RuntimeException("FAIL: getTrayIcons() returned incorrect value " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    71
                    "when two icons present " + icons);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    72
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    73
        icons = tray.getTrayIcons();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    74
        if (icons != null) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    75
            for (int i = 0; i < icons.length; i++) {
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    76
                tray.remove(icons[i]);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    77
            }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    78
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    79
            TrayIcon[] newList = tray.getTrayIcons();
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    80
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    81
            if (newList == null || newList.length != 0)
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    82
                throw new RuntimeException("FAIL: Incorrect value returned by getTrayIcons " +
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    83
                        "after icons are added and then removed " + newList);
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    84
        }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    85
    }
43055e2deee9 8044765: Move functional tests AWT_SystemTray/Automated to openjdk repository
yan
parents:
diff changeset
    86
}