/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 4870984
* @summary JPDA: Add support for RFE 4856541 - varargs
*
* @author jjh
*
* @run build TestScaffold VMConnection TargetListener TargetAdapter
* @run compile -g VarargsTest.java
* @run main VarargsTest
*/
/********** target program **********/
class VarargsTarg {
// These are args that will get passed
// We will pass these to a varargs instance method
iname = "";
}
}
/*
* This isn't really part of the test, it just shows
* the kinds of calls the debugger test will do and lets
* you verify how javac handles these calls.
*/
// Should be autoboxed: javac converts the ints to Integers
// Needs a new method in java.lang.Integer which is only
// in the generics workspace.
bkpt();
}
static void bkpt() {
}
/*
* Define the methods to be called from the debugger
*/
return "" + p1;
}
return "" + p1;
}
}
return retVal;
}
}
return retVal;
}
return "-null-";
}
}
return retVal;
}
}
return "-fixed-";
}
return "-null-";
}
//System.out.println("debugee: ss length = " + ss.length);
}
return retVal;
}
}
/********** test program **********/
super(args);
}
}
}
/*
* Call a method in the debuggee and verify the return value.
*/
try {
return;
}
}
}
/*
* Call a method in the debuggee.
*/
throws Exception {
} else {
}
return returnValue;
}
/********** test core **********/
/*
* Get to the top of main()
* to determine targetClass and mainThread
*/
/*
* Run past the calls the debuggee makes
* just to see what they do.
*/
/*
* Find Method objects for varString and varString2
* Both are tested just to show that the code works
* if there is just one param or if there is more than one.
*/
/*
* The test consists of calling the varargs static and instance methods
* (and constructor) passing primitives, Strings, and Objects, and also
* passing arrays of the above instead of individual args.
* The same code is used in the underlying JDI implementations
* for calling instance methods, static methods, and constructors
* so this test doesn't have to try all possible argument configurations
* with each type of method.
*/
fail("failure: varString is not flagged as being var args");
}
if (!varString2.isVarArgs()) {
fail("failure: varString2 is not flagged as being var args");
}
/*
* Setup arg lists for both varString and varString2 that
* have null in the varargs position.
*/
{
// call varString()
}
{
// call varString(null)
}
{
// call varString(9)
}
{
// call varString(9, null)
}
{
// call varString("1")
// call varString("1", "2")
}
{
// call varString2(9, "1");
// call varString2(9, "1", "2");
}
{
/*
* Passing an array of Strings should work too.
*/
// call varString(new String[] {"a", "b"})
/*
* But passing an array of Strings and another String
* should fail
*/
boolean isOk = false;
try {
// call varString(new String[] {"a", "b"}, "x")
/*
* Since the number of args passed is > than
* the number of params, JDI assumes they are var args
* and tries to put the array containing the "a" and
* "be" elements into a the first element of an array
* of Strings. This fails because you can't store
* an array into a String
*/
isOk = true;
//ee.printStackTrace();
}
if (!isOk) {
fail("failure: an array and a String didn't cause an exception");
}
}
{
/*
* Test calling instance method instead of static method,
* and passing non-String objects
*/
/* Create a new instance by calling the varargs
* ctor.
* call new VarargsTarg("vt3", "xx");
*/
{
fail("failure: Constructor is not varargs");
}
}
// call vt1.varStringInstance(vv1, vv2, vv3)
}
{
/*
* tests with primitive types
*/
// call fixedInt(21)
// autoboxing is not implemented in JDI.
// call fixedInteger(21)
//mlist = rt.methodsByName("fixedInteger");
//mm = (Method)mlist.get(0);
//doInvoke(targetClass, mm, ll, "21");
// call varInt( new int[] {1, 2});
// call varInt(21, 22)
// call varInteger(1, 2)
// autoboxing is not implemented.
//doInvoke(targetClass, mm, ll, "2122");
}
/*
* We don't really need this for the test, but
* but without it, we sometimes hit 4728096.
*/
/*
* deal with results of test
* if anything has called failure("foo") testFailed will be true
*/
if (!testFailed) {
println("VarargsTest: passed");
} else {
throw new Exception("VarargsTest: failed");
}
}
}