/* * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * 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.
*/
publicclass InvokeTest extends TestScaffold {
ReferenceType targetClass;
ThreadReference mainThread;
ObjectReference thisObject;
Field longCheckField;
Field booleanCheckField;
Field voidCheckField;
Field objectCheckField;
Value longValue;
Value booleanValue;
Value objectValue;
Value voidValue;
InvokeTest (String args[]) { super(args);
}
publicstaticvoid main(String[] args) throws Exception { new InvokeTest(args).startTests();
}
/********** event handlers **********/
// not use now publicvoid breakpointReached(BreakpointEvent event) {
println("Got BreakpointEvent");
longValue = thisObject.getValue(longCheckField);
booleanValue = thisObject.getValue(booleanCheckField);
objectValue = thisObject.getValue(objectCheckField);
voidValue = thisObject.getValue(voidCheckField);
}
/********** test assist **********/
void invoke(Method method, List args, Value value) {
Value returnValue = null;
try {
returnValue = thisObject.invokeMethod(mainThread,
method, args, 0);
} catch ( Exception ee) {
println("Got Exception: " + ee);
ee.printStackTrace();
}
println(" return val = " + returnValue); // It has to be the same value as what we passed in! if (returnValue.equals(value)) {
println(" " + method.name() + " return value matches: "
+ value);
} else { if (value != null) {
failure("FAIL: " + method.name() + " returned: " + returnValue + " expected: " + value );
} else {
println(" " + method.name() + " return value : " + returnValue);
}
// We have to find it. First find java.lang.Object
List myClasses = vm().allClasses();
Iterator iter = myClasses.iterator();
ReferenceType objectMirror = null; while (iter.hasNext()) {
ReferenceType xx = (ReferenceType)iter.next(); if (xx.name().equals("java.lang.Object")) {
objectMirror = xx; break;
}
}
if (objectMirror == null) { returnnull;
}
// Then find toString
List meths = objectMirror.methods();
iter = meths.iterator(); while (iter.hasNext()) {
toStringMethod = (Method)iter.next(); if (toStringMethod.name().equals("toString")) { return toStringMethod;
}
}
toStringMethod = null; returnnull;
}
// This calls toString on a field protectedvoid callToString(String fieldName) throws Exception { // Sorry for this kludgy use of global vars.
ObjectReference saveObject = thisObject;
Method toStringMethod = gettoStringMethod();
Field theField = targetClass.fieldByName(fieldName);
thisObject = (ObjectReference)thisObject.getValue( theField);
invoke(toStringMethod, new ArrayList(0), null);
thisObject = saveObject;
}
Value fieldValue(String fieldName) {
Field field = targetClass.fieldByName(fieldName); return thisObject.getValue(field);
}
/********** test core **********/
protectedvoid runTests() throws Exception { /* * Get to the top of sayHi() * to determine targetClass and mainThread
*/
BreakpointEvent bpe = startTo("InvokeTarg", "sayHi", "()V");
targetClass = bpe.location().declaringType();
Value i2 = fieldValue("aInt2DArray");
Value str = vm().mirrorOf("Later");
List args = new ArrayList(2);
args.add(i2);
args.add(str);
invoke("invokeCombo", "([[ILjava/lang/String;)Ljava/lang/String;",
args, str);
invoke("invokeCombo2", "([[ILjava/lang/String;)[[I",
args, i2); /* * resume the target listening for events
*/
listenUntilVMDisconnect();
/* * deal with results of test * if anything has called failure("foo") testFailed will be true
*/ if (!testFailed) {
println("InvokeTest: passed");
} else { thrownew Exception("InvokeTest: failed");
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.