21 * questions.
22 */
23
24 import java.io.File;
25 import java.nio.file.Files;
26
27 /*
28 * @test
29 * @summary jpackage create image to verify --icon
30 * @library ../helpers
31 * @build JPackageHelper
32 * @build JPackagePath
33 * @requires ((os.family == "windows") | (os.family == "mac"))
34 * @modules jdk.jpackage
35 * @run main/othervm -Xmx512m JPackageCreateAppImageResourceTest
36 */
37 public class JPackageCreateAppImageResourceTest {
38 private static final String OUTPUT = "output";
39 private static final String app = JPackagePath.getApp("icon");
40 private static final String appOutput = JPackagePath.getAppOutputFile();
41 private static final String appWorkingDir =
42 JPackagePath.getAppWorkingDir("icon");
43 private static final String resourceDir =
44 JPackagePath.getTestSrcRoot() + File.separator + "resources";
45
46 private static final String[] CMD = {
47 "--input", "input",
48 "--name", "icon",
49 "--main-jar", "hello.jar",
50 "--main-class", "Hello",
51 "--resource-dir", resourceDir,
52 "--output", OUTPUT};
53
54 private static void validateResult(String[] result) throws Exception {
55 if (result.length != 2) {
56 throw new AssertionError(
57 "Unexpected number of lines: " + result.length);
58 }
59
60 if (!result[0].trim().equals("jpackage test application")) {
61 throw new AssertionError("Unexpected result[0]: " + result[0]);
62 }
63
64 if (!result[1].trim().equals("args.length: 0")) {
65 throw new AssertionError("Unexpected result[1]: " + result[1]);
66 }
67 }
68
69 private static void validate() throws Exception {
70 int retVal = JPackageHelper.execute(null, app);
71 if (retVal != 0) {
72 throw new AssertionError(
73 "Test application exited with error: " + retVal);
74 }
75
76 File outfile = new File(appWorkingDir + File.separator + appOutput);
77 if (!outfile.exists()) {
78 throw new AssertionError(appOutput + " was not created");
79 }
80
81 String output = Files.readString(outfile.toPath());
82 String[] result = output.split("\n");
83 validateResult(result);
84 }
85
86 private static void validateIcon() throws Exception {
87 File origIcon = new File(getIconPath());
88 File icon = new File(JPackagePath.getAppIcon("icon"));
89 if (origIcon.length() != icon.length()) {
90 System.err.println("file: " + origIcon + " - origIcon.length(): "
91 + origIcon.length());
92 System.err.println("file: " + icon + " - icon.length(): "
93 + icon.length());
94 throw new AssertionError("Icons size does not match");
95 }
96 }
|
21 * questions.
22 */
23
24 import java.io.File;
25 import java.nio.file.Files;
26
27 /*
28 * @test
29 * @summary jpackage create image to verify --icon
30 * @library ../helpers
31 * @build JPackageHelper
32 * @build JPackagePath
33 * @requires ((os.family == "windows") | (os.family == "mac"))
34 * @modules jdk.jpackage
35 * @run main/othervm -Xmx512m JPackageCreateAppImageResourceTest
36 */
37 public class JPackageCreateAppImageResourceTest {
38 private static final String OUTPUT = "output";
39 private static final String app = JPackagePath.getApp("icon");
40 private static final String appOutput = JPackagePath.getAppOutputFile();
41 private static final String resourceDir =
42 JPackagePath.getTestSrcRoot() + File.separator + "resources";
43
44 private static final String[] CMD = {
45 "--input", "input",
46 "--name", "icon",
47 "--main-jar", "hello.jar",
48 "--main-class", "Hello",
49 "--resource-dir", resourceDir,
50 "--output", OUTPUT};
51
52 private static void validateResult(String[] result) throws Exception {
53 if (result.length != 2) {
54 throw new AssertionError(
55 "Unexpected number of lines: " + result.length);
56 }
57
58 if (!result[0].trim().equals("jpackage test application")) {
59 throw new AssertionError("Unexpected result[0]: " + result[0]);
60 }
61
62 if (!result[1].trim().equals("args.length: 0")) {
63 throw new AssertionError("Unexpected result[1]: " + result[1]);
64 }
65 }
66
67 private static void validate() throws Exception {
68 int retVal = JPackageHelper.execute(null, app);
69 if (retVal != 0) {
70 throw new AssertionError(
71 "Test application exited with error: " + retVal);
72 }
73
74 File outfile = new File(appOutput);
75 if (!outfile.exists()) {
76 throw new AssertionError(appOutput + " was not created");
77 }
78
79 String output = Files.readString(outfile.toPath());
80 String[] result = output.split("\n");
81 validateResult(result);
82 }
83
84 private static void validateIcon() throws Exception {
85 File origIcon = new File(getIconPath());
86 File icon = new File(JPackagePath.getAppIcon("icon"));
87 if (origIcon.length() != icon.length()) {
88 System.err.println("file: " + origIcon + " - origIcon.length(): "
89 + origIcon.length());
90 System.err.println("file: " + icon + " - icon.length(): "
91 + icon.length());
92 throw new AssertionError("Icons size does not match");
93 }
94 }
|