test/jdk/tools/jpackage/share/IconTest.java
author herrick
Mon, 01 Jul 2019 18:31:16 -0400
branchJDK-8200758-branch
changeset 57446 5a5b85f00a63
parent 57445 test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageIconTest.java@405ddd80496e
child 58114 42df7de58e39
permissions -rw-r--r--
8226891: rename and re-layout jpackage tests. Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57307
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     1
/*
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     4
 *
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     8
 *
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    13
 * accompanied this code).
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    14
 *
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    18
 *
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    21
 * questions.
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    22
 */
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    23
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    24
import java.io.File;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    25
import java.nio.file.Files;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    26
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    27
/*
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    28
 * @test
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    29
 * @summary jpackage create image to verify --icon
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    30
 * @library ../helpers
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    31
 * @build JPackageHelper
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    32
 * @build JPackagePath
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    33
 * @modules jdk.jpackage
57446
5a5b85f00a63 8226891: rename and re-layout jpackage tests.
herrick
parents: 57445
diff changeset
    34
 * @run main/othervm -Xmx512m IconTest
57307
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    35
 */
57446
5a5b85f00a63 8226891: rename and re-layout jpackage tests.
herrick
parents: 57445
diff changeset
    36
public class IconTest {
57307
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    37
    private static final String OUTPUT = "output";
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    38
    private static final String app = JPackagePath.getApp();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    39
    private static final String appOutput = JPackagePath.getAppOutputFile();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    40
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    41
    private static final String[] CMD = {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    42
        "--input", "input",
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    43
        "--name", "test",
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    44
        "--main-jar", "hello.jar",
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    45
        "--main-class", "Hello",
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    46
        "--icon", getIconPath(),
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    47
        "--output", OUTPUT};
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    48
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    49
    private static void validateResult(String[] result) throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    50
        if (result.length != 2) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    51
            throw new AssertionError(
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    52
                   "Unexpected number of lines: " + result.length);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    53
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    54
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    55
        if (!result[0].trim().equals("jpackage test application")) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    56
            throw new AssertionError("Unexpected result[0]: " + result[0]);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    57
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    58
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    59
        if (!result[1].trim().equals("args.length: 0")) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    60
            throw new AssertionError("Unexpected result[1]: " + result[1]);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    61
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    62
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    63
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    64
    private static void validate() throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    65
        int retVal = JPackageHelper.execute(null, app);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    66
        if (retVal != 0) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    67
            throw new AssertionError(
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    68
                   "Test application exited with error: " + retVal);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    69
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    70
57445
405ddd80496e 8226904: current working directory wrong running jpackage app
herrick
parents: 57414
diff changeset
    71
        File outfile = new File(appOutput);
57307
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    72
        if (!outfile.exists()) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    73
            throw new AssertionError(appOutput + " was not created");
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    74
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    75
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    76
        String output = Files.readString(outfile.toPath());
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    77
        String[] result = output.split("\n");
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    78
        validateResult(result);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    79
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    80
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    81
    private static void validateIcon() throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    82
        File origIcon = new File(getIconPath());
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    83
        File icon = new File(JPackagePath.getAppIcon());
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    84
        if (origIcon.length() != icon.length()) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    85
            System.err.println("origIcon.length(): " + origIcon.length());
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    86
            System.err.println("icon.length(): " + icon.length());
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    87
            throw new AssertionError("Icons size does not match");
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    88
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    89
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    90
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    91
    private static void testIcon() throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    92
        JPackageHelper.executeCLI(true, CMD);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    93
        validate();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    94
        validateIcon();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    95
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    96
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    97
    private static void testIconToolProvider() throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    98
        JPackageHelper.deleteOutputFolder(OUTPUT);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    99
        JPackageHelper.executeToolProvider(true, CMD);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   100
        validate();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   101
        validateIcon();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   102
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   103
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   104
    private static String getIconPath() {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   105
        String ext = ".ico";
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   106
        if (JPackageHelper.isOSX()) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   107
            ext = ".icns";
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   108
        } else if (JPackageHelper.isLinux()) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   109
            ext = ".png";
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   110
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   111
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   112
        String path = JPackagePath.getTestSrcRoot() + File.separator + "resources"
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   113
                + File.separator + "icon" + ext;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   114
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   115
        return path;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   116
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   117
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   118
    public static void main(String[] args) throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   119
        JPackageHelper.createHelloImageJar();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   120
        testIcon();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   121
        testIconToolProvider();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   122
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   123
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   124
}