test/jdk/java/awt/TrayIcon/8072769/bug8072769.java
changeset 47216 71c04702a3d5
parent 30783 e664daa546bb
child 49096 eaef201ec301
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /* @test
       
    25    @bug 8072769
       
    26    @summary System tray icon title freezes java
       
    27    @author Semyon Sadetsky
       
    28    @library ../../../../lib/testlibrary
       
    29    @build jdk.testlibrary.OSInfo
       
    30    @run main bug8072769
       
    31   */
       
    32 
       
    33 import jdk.testlibrary.OSInfo;
       
    34 
       
    35 import javax.swing.*;
       
    36 import java.awt.*;
       
    37 import java.util.Arrays;
       
    38 
       
    39 public class bug8072769 {
       
    40 
       
    41     public static void main(String[] args) throws Exception {
       
    42         if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
       
    43             if (SystemTray.isSupported()) {
       
    44                 test();
       
    45             } else {
       
    46                 System.out.println("SystemTray not supported. " +
       
    47                         "Test is skipped.");
       
    48             }
       
    49         } else {
       
    50             System.out.println("Test will only run on Windows platform. " +
       
    51                     "Test is skipped.");
       
    52         }
       
    53         System.out.println("ok");
       
    54     }
       
    55 
       
    56     private static void test() throws Exception {
       
    57         SwingUtilities.invokeAndWait(new Runnable() {
       
    58             public void run() {
       
    59                 final SystemTray tray = SystemTray.getSystemTray();
       
    60                 final TrayIcon trayIcon = new TrayIcon(icon.getImage());
       
    61                 try {
       
    62                     tray.add(trayIcon);
       
    63                 } catch (AWTException e) {
       
    64                     throw new RuntimeException(
       
    65                             "TrayIcon could not be added.");
       
    66                 }
       
    67 
       
    68 
       
    69                 try {
       
    70                     trayIcon.displayMessage(createString(63, 'A'),
       
    71                             createString(255, 'C'), TrayIcon.MessageType.ERROR);
       
    72 
       
    73                     trayIcon.setToolTip(createString(127, 'B'));
       
    74 
       
    75                     trayIcon.displayMessage(createString(64, 'A'),
       
    76                             createString(256, 'C'), TrayIcon.MessageType.ERROR);
       
    77 
       
    78                     trayIcon.setToolTip(createString(128, 'B'));
       
    79 
       
    80                     trayIcon.displayMessage(createString(65, 'A'),
       
    81                             createString(257, 'C'), TrayIcon.MessageType.ERROR);
       
    82 
       
    83                     trayIcon.setToolTip(createString(129, 'B'));
       
    84                 }
       
    85                 finally {
       
    86                     tray.remove(trayIcon);
       
    87                 }
       
    88             }
       
    89         });
       
    90     }
       
    91 
       
    92     private static String createString(int len, char letter) {
       
    93         char[] chars = new char[len];
       
    94         Arrays.fill(chars, letter);
       
    95         chars[len - 2] = '=';
       
    96         chars[len - 1] = '>';
       
    97         return new String(chars);
       
    98     }
       
    99 
       
   100     private static ImageIcon icon = new ImageIcon(
       
   101             new byte[]{71, 73, 70, 56, 57, 97, 32, 0, 35, 0, -43, 0, 0, -1, -1,
       
   102                     -1, -19, -101, 9, -18, -95, 24, -14, -76, 71, -4, -19, -46,
       
   103                     -3, -13, -31, -17, -88, 40, -12, -63, 102, -10, -51, -124,
       
   104                     -16, -82, 55, -11, -57, 117, -2, -7, -15, -7, -32, -77, -9,
       
   105                     -45, -108, -5, -26, -62, -13, -70, 86, -8, -39, -94, 83,
       
   106                     -126, -95, -8, -38, -93, -6, -26, -63, -9, -45, -109, -4,
       
   107                     -14, -32, -15, -76, 70, -12, -58, 116, -17, -89, 39, 77,
       
   108                     121, -106, -3, -8, -17, 104, -111, -84, 126, -95, -72, 93,
       
   109                     -119, -90, -14, -70, 85, -13, -64, 101, -16, -83, 55, -109,
       
   110                     -80, -60, -7, -33, -78, -100, -84, -85, 94, -127, -104, -32,
       
   111                     -99, 39, 127, -120, -114, 83, 113, -124, -12, -9, -7, -16,
       
   112                     -16, -16, -115, 108, 45, 57, 89, 110, -50, -41, -35, 104,
       
   113                     -111, -83, 41, 65, 80, 72, 113, -116, 115, -103, -78, 88,
       
   114                     106, 112, -82, -78, -82, -45, -38, -40, -5, -20, -48, -65,
       
   115                     -48, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       
   116                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, -7, 4, 0, 0, 0,
       
   117                     0, 0, 44, 0, 0, 0, 0, 32, 0, 35, 0, 0, 6, -1, 64, -128, 112,
       
   118                     72, 4, 16, 0, 14, -57, 2, 1, 96, 30, -117, -48, 40, -78,
       
   119                     -55, 96, 28, 28, -125, -62, 0, 96, 48, 74, -91, -116, 102,
       
   120                     3, 97, 64, 4, 20, -25, -128, 68, -80, 16, 24, 11, 95, 98,
       
   121                     -29, -64, 72, 11, 2, 120, -68, 96, -64, 39, 116, -29, 0, 12,
       
   122                     13, 5, 1, 3, 121, -121, -120, 9, 2, 7, 5, 15, 82, 11, 11,
       
   123                     92, 15, 6, -120, -107, -121, 7, 2, 18, 0, 112, 80, 3, 8,
       
   124                     104, -106, -95, 122, 88, 97, 68, 5, 11, 4, -95, 32, 8, 16,
       
   125                     19, 16, 8, 22, -106, -114, 79, 66, 5, 2, 15, 9, -120, 22,
       
   126                     19, 81, 21, 31, -120, 7, 6, 10, 67, 71, 4, 119, -121, 20,
       
   127                     -128, 16, -57, 120, 7, -101, -111, -58, 9, -108, 121, -55,
       
   128                     -128, 0, 16, 121, 123, -117, 67, 5, -71, 121, 30, -42, 67,
       
   129                     23, -121, 13, 66, 14, 6, 3, -34, 120, 21, -31, 66, 26, -39,
       
   130                     3, 6, -50, 11, -96, 120, 31, -19, 67, 30, 121, 9, 14, 0, 13,
       
   131                     124, -121, 68, -32, 19, 98, 6, 15, 58, 71, 18, 12, -27, 97,
       
   132                     55, 80, 68, 54, 5, 5, 24, 40, 80, 23, 96, -96, -112, 9, -39,
       
   133                     30, 52, -112, 72, -47, 34, 0, 10, 25, -53, 37, 60, -60, 16,
       
   134                     -33, 56, 61, 16, -1, 41, -60, 83, 13, 31, -122, 60, 7, 1,
       
   135                     -48, 59, -124, 65, 3, 62, -116, 48, -5, 57, 72, -112, -18,
       
   136                     -48, 5, -103, 124, 32, -32, 37, 112, -74, -119, 98, 0, 8,
       
   137                     -31, 64, -110, 35, 38, 64, 26, 34, -92, 113, 42, 48, -45,
       
   138                     70, -76, 24, -77, 60, 80, -91, -60, -70, -12, 76, -120, 49,
       
   139                     92, -120, 4, -40, -116, -126, 51, 79, -80, 97, -36, 80, 89,
       
   140                     -6, 25, -91, 96, -98, 89, -99, 62, 33, -62, 32, -59, -83, 0,
       
   141                     82, 80, 32, 1, -72, 53, 13, -113, -42, 102, -103, 54, -127,
       
   142                     25, 84, 40, 15, -115, 40, 37, 20, 49, 34, 26, 103, 78, 29,
       
   143                     52, 42, 88, 16, 65, 17, -94, -49, 31, 107, 97, 16, -116, 49,
       
   144                     32, 35, -61, 6, 14, 33, 56, 68, -120, -80, -96, 11, 1, 78,
       
   145                     -31, -6, 33, 96, 48, -93, -61, -122, 21, 46, 50, -116, -10,
       
   146                     -30, -47, -117, -125, 24, 29, 94, -100, -112, 61, -94, 54,
       
   147                     -108, 20, 38, 90, -112, -128, 81, -61, 90, 16, 0, 59},
       
   148             "try icon");
       
   149 
       
   150 }