< prev index next >

test/jdk/java/lang/invoke/findSpecial/FindSpecialTest.java

Print this page

 1 /*
 2  * Copyright (c) 2019, 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  * @bug 8209005 8209078
27  * @library /test/lib
28  * @build m1/* FindSpecialTest
29  * @run testng/othervm FindSpecialTest
30  * @summary Test findSpecial and unreflectSpecial of the declaring class
31  *          of the method and the special caller are not in the same module
32  *          as the lookup class.
33  */
34 
35 import java.io.File;
36 import java.nio.file.Files;
37 import java.nio.file.Path;
38 import java.nio.file.Paths;
39 
40 import jdk.test.lib.JDKToolFinder;
41 import jdk.test.lib.process.ProcessTools;
42 
43 import org.testng.annotations.Test;
44 
45 public class FindSpecialTest {
46     static final String JAVA_LAUNCHER = JDKToolFinder.getJDKTool("java");
47     static final String TEST_CLASSES = System.getProperty("test.classes", ".");
48     static final String TEST_CLASS_PATH = System.getProperty("test.class.path");
49     static final String TEST_MAIN_CLASS = "test.FindSpecial";
50     static final String TEST_MODULE = "m1";
51 
52     /*
53      * Run test.FindSpecial in unnamed module
54      */
55     @Test
56     public static void callerInUnnamedModule() throws Throwable {
57         Path m1 = Paths.get(TEST_CLASSES, "modules", TEST_MODULE);
58         if (Files.notExists(m1)) {
59             throw new Error(m1 + " not exist");
60         }
61         String classpath = m1.toString() + File.pathSeparator + TEST_CLASS_PATH;
62         ProcessTools.executeCommand(JAVA_LAUNCHER, "-cp", classpath, TEST_MAIN_CLASS)
63                     .shouldHaveExitValue(0);

64     }
65 
66     /*
67      * Run test.FindSpecial in a named module
68      */
69     @Test
70     public static void callerInNamedModule() throws Throwable {
71         Path modules = Paths.get(TEST_CLASSES, "modules");
72         if (Files.notExists(modules)) {
73             throw new Error(modules + " not exist");
74         }
75         ProcessTools.executeCommand(JAVA_LAUNCHER,
76                                     "-cp", TEST_CLASS_PATH,
77                                     "-p", modules.toString(),
78                                     "-m", TEST_MODULE + "/" + TEST_MAIN_CLASS)
79                     .shouldHaveExitValue(0);
80     }
81 }

 1 /*
 2  * Copyright (c) 2019, 2023, 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  * @bug 8209005 8209078
27  * @library /test/lib
28  * @build m1/* FindSpecialTest
29  * @run testng/othervm FindSpecialTest
30  * @summary Test findSpecial and unreflectSpecial of the declaring class
31  *          of the method and the special caller are not in the same module
32  *          as the lookup class.
33  */
34 
35 import java.io.File;
36 import java.nio.file.Files;
37 import java.nio.file.Path;
38 import java.nio.file.Paths;
39 
40 import static jdk.test.lib.process.ProcessTools.*;

41 
42 import org.testng.annotations.Test;
43 
44 public class FindSpecialTest {

45     static final String TEST_CLASSES = System.getProperty("test.classes", ".");
46     static final String TEST_CLASS_PATH = System.getProperty("test.class.path");
47     static final String TEST_MAIN_CLASS = "test.FindSpecial";
48     static final String TEST_MODULE = "m1";
49 
50     /*
51      * Run test.FindSpecial in unnamed module
52      */
53     @Test
54     public static void callerInUnnamedModule() throws Throwable {
55         Path m1 = Paths.get(TEST_CLASSES, "modules", TEST_MODULE);
56         if (Files.notExists(m1)) {
57             throw new Error(m1 + " not exist");
58         }
59         String classpath = m1.toString() + File.pathSeparator + TEST_CLASS_PATH;
60         executeCommand(createTestJavaProcessBuilder("-cp", classpath,
61                                                     TEST_MAIN_CLASS))
62                 .shouldHaveExitValue(0);
63     }
64 
65     /*
66      * Run test.FindSpecial in a named module
67      */
68     @Test
69     public static void callerInNamedModule() throws Throwable {
70         Path modules = Paths.get(TEST_CLASSES, "modules");
71         if (Files.notExists(modules)) {
72             throw new Error(modules + " not exist");
73         }
74         executeCommand(createTestJavaProcessBuilder("-cp", TEST_CLASS_PATH,
75                                                     "-p", modules.toString(),
76                                                     "-m", TEST_MODULE + "/" + TEST_MAIN_CLASS))
77                 .shouldHaveExitValue(0);

78     }
79 }
< prev index next >