1 /*
2  * Copyright (c) 2003, 2018, 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 4870984
27  * @summary JPDA: Add support for RFE 4856541 - varargs
28  * @comment converted from test/jdk/com/sun/jdi/JdbVarargsTest.sh
29  *
30  * @library /test/lib
31  * @run main/othervm JdbVarargsTest
32  */
33 
34 import jdk.test.lib.process.OutputAnalyzer;
35 import lib.jdb.JdbCommand;
36 import lib.jdb.JdbTest;
37 
38 class JdbVarargsTestTarg {
39 
main(String args[])40     public static void main(String args[]) {
41         int ii = 0; // @1 breakpoint
42 
43         // Call the varargs method so the bkpt will be hit
44         varString(new String[] {"a", "b"});
45     }
46 
varString(String... ss)47     static String varString(String... ss) {
48         if (ss == null) {
49             return "-null-";
50         }
51         if (ss.length == 0) {
52             return "NONE";
53         }
54         String retVal = "";
55         for (int ii = 0; ii < ss.length; ii++) {
56             retVal += ss[ii];
57         }
58         return retVal;
59     }
60 
61 }
62 
63 public class JdbVarargsTest extends JdbTest {
main(String argv[])64     public static void main(String argv[]) {
65         new JdbVarargsTest().run();
66     }
67 
JdbVarargsTest()68     private JdbVarargsTest() {
69         super(DEBUGGEE_CLASS);
70     }
71 
72     private static final String DEBUGGEE_CLASS = JdbVarargsTestTarg.class.getName();
73 
74     @Override
runCases()75     protected void runCases() {
76         setBreakpointsFromTestSource("JdbVarargsTest.java", 1);
77         // Run to breakpoint #1
78         jdb.command(JdbCommand.run());
79 
80         // check that 'methods' shows the ...
81         jdb.command(JdbCommand.methods(DEBUGGEE_CLASS));
82 
83         // check that we can call with no args
84         jdb.command(JdbCommand.eval(DEBUGGEE_CLASS + ".varString();"));
85 
86         // check that we can call with var args
87         jdb.command(JdbCommand.eval(DEBUGGEE_CLASS + ".varString(\"aa\", \"bb\");"));
88 
89         // check that we can stop in ...
90         jdb.command(JdbCommand.stopIn(DEBUGGEE_CLASS, "varString(java.lang.String...)"));
91 
92         jdb.command(JdbCommand.cont());
93 
94         new OutputAnalyzer(jdb.getJdbOutput())
95                 .shouldContain("NONE")
96                 .shouldContain("aabb")
97                 .shouldContain(DEBUGGEE_CLASS + " varString(java.lang.String...)")
98                 .shouldMatch("Breakpoint hit:.*varString\\(\\)");
99     }
100 }
101