|
1 /* |
|
2 * Copyright (c) 2016, 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 /* |
|
25 * @test |
|
26 * @library /testlibrary /test/lib /compiler/whitebox .. |
|
27 * @build sun.hotspot.WhiteBox |
|
28 * @compile/module=java.base java/lang/reflect/ModuleHelper.java |
|
29 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
|
30 * sun.hotspot.WhiteBox$WhiteBoxPermission |
|
31 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI JVMAddModulePackage |
|
32 */ |
|
33 |
|
34 import static jdk.test.lib.Asserts.*; |
|
35 |
|
36 public class JVMAddModulePackage { |
|
37 |
|
38 public static void main(String args[]) throws Throwable { |
|
39 MyClassLoader cl1 = new MyClassLoader(); |
|
40 MyClassLoader cl3 = new MyClassLoader(); |
|
41 Object module1, module2, module3; |
|
42 boolean result; |
|
43 |
|
44 module1 = ModuleHelper.ModuleObject("module1", cl1, new String[] { "mypackage" }); |
|
45 assertNotNull(module1, "Module should not be null"); |
|
46 ModuleHelper.DefineModule(module1, "9.0", "module1/here", new String[] { "mypackage" }); |
|
47 module2 = ModuleHelper.ModuleObject("module2", cl1, new String[] { "yourpackage" }); |
|
48 assertNotNull(module2, "Module should not be null"); |
|
49 ModuleHelper.DefineModule(module2, "9.0", "module2/here", new String[] { "yourpackage" }); |
|
50 module3 = ModuleHelper.ModuleObject("module3", cl3, new String[] { "package/num3" }); |
|
51 assertNotNull(module3, "Module should not be null"); |
|
52 ModuleHelper.DefineModule(module3, "9.0", "module3/here", new String[] { "package/num3" }); |
|
53 |
|
54 // Simple call |
|
55 ModuleHelper.AddModulePackage(module1, "new_package"); |
|
56 |
|
57 // Add a package and export it |
|
58 ModuleHelper.AddModulePackage(module1, "package/num3"); |
|
59 ModuleHelper.AddModuleExportsToAll(module1, "package/num3"); |
|
60 |
|
61 // Null module argument, expect an NPE |
|
62 try { |
|
63 ModuleHelper.AddModulePackage(null, "new_package"); |
|
64 throw new RuntimeException("Failed to get the expected NPE"); |
|
65 } catch(NullPointerException e) { |
|
66 // Expected |
|
67 } |
|
68 |
|
69 // Bad module argument, expect an IAE |
|
70 try { |
|
71 ModuleHelper.AddModulePackage(cl1, "new_package"); |
|
72 throw new RuntimeException("Failed to get the expected IAE"); |
|
73 } catch(IllegalArgumentException e) { |
|
74 // Expected |
|
75 } |
|
76 |
|
77 // Null package argument, expect an NPE |
|
78 try { |
|
79 ModuleHelper.AddModulePackage(module1, null); |
|
80 throw new RuntimeException("Failed to get the expected NPE"); |
|
81 } catch(NullPointerException e) { |
|
82 // Expected |
|
83 } |
|
84 |
|
85 // Existing package, expect an IAE |
|
86 try { |
|
87 ModuleHelper.AddModulePackage(module1, "yourpackage"); |
|
88 throw new RuntimeException("Failed to get the expected IAE"); |
|
89 } catch(IllegalArgumentException e) { |
|
90 // Expected |
|
91 } |
|
92 |
|
93 // Invalid package name, expect an IAE |
|
94 try { |
|
95 ModuleHelper.AddModulePackage(module1, "your.package"); |
|
96 throw new RuntimeException("Failed to get the expected IAE"); |
|
97 } catch(IllegalArgumentException e) { |
|
98 // Expected |
|
99 } |
|
100 |
|
101 // Invalid package name, expect an IAE |
|
102 try { |
|
103 ModuleHelper.AddModulePackage(module1, ";your/package"); |
|
104 throw new RuntimeException("Failed to get the expected IAE"); |
|
105 } catch(IllegalArgumentException e) { |
|
106 // Expected |
|
107 } |
|
108 |
|
109 // Invalid package name, expect an IAE |
|
110 try { |
|
111 ModuleHelper.AddModulePackage(module1, "7[743"); |
|
112 throw new RuntimeException("Failed to get the expected IAE"); |
|
113 } catch(IllegalArgumentException e) { |
|
114 // Expected |
|
115 } |
|
116 |
|
117 // Empty package name, expect an IAE |
|
118 try { |
|
119 ModuleHelper.AddModulePackage(module1, ""); |
|
120 throw new RuntimeException("Failed to get the expected IAE"); |
|
121 } catch(IllegalArgumentException e) { |
|
122 // Expected |
|
123 } |
|
124 |
|
125 } |
|
126 |
|
127 static class MyClassLoader extends ClassLoader { } |
|
128 } |
|
129 |