001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Anton V. Karnachuk
021: * @version $Revision: 1.6 $
022: */
023:
024: /**
025: * Created on 14.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.Method;
027:
028: import java.io.UnsupportedEncodingException;
029:
030: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
031: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
032: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
033: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
034:
035: /**
036: * JDWP Unit test for Method.Bytecodes command.
037: */
038: public class BytecodesTest extends JDWPMethodTestCase {
039:
040: public static void main(String[] args) {
041: junit.textui.TestRunner.run(BytecodesTest.class);
042: }
043:
044: /**
045: * This testcase exercises Method.Bytecodes command.
046: * <BR>It runs MethodDebuggee. Gets methods with ReferenceType.Methods command,
047: * prints it's bytecodes received with Method.Bytecodes command.
048: */
049: public void testBytecodesTest001()
050: throws UnsupportedEncodingException {
051: logWriter.println("testBytecodesTest001 started");
052:
053: //check capability, relevant for this test
054: logWriter.println("=> Check capability: canGetBytecodes");
055: debuggeeWrapper.vmMirror.capabilities();
056: boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canGetBytecodes;
057: if (!isCapability) {
058: logWriter
059: .println("##WARNING: this VM doesn't possess capability: canGetBytecodes");
060: return;
061: }
062:
063: synchronizer
064: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
065:
066: long classID = getClassIDBySignature("L"
067: + getDebuggeeClassName().replace('.', '/') + ";");
068:
069: MethodInfo[] methodsInfo = jdwpGetMethodsInfo(classID);
070: assertFalse("Invalid number of methods",
071: methodsInfo.length == 0);
072:
073: for (int i = 0; i < methodsInfo.length; i++) {
074: logWriter.println(methodsInfo[i].toString());
075:
076: // get variable table for this class
077: CommandPacket packet = new CommandPacket(
078: JDWPCommands.MethodCommandSet.CommandSetID,
079: JDWPCommands.MethodCommandSet.BytecodesCommand);
080: packet.setNextValueAsClassID(classID);
081: packet.setNextValueAsMethodID(methodsInfo[i].getMethodID());
082: ReplyPacket reply = debuggeeWrapper.vmMirror
083: .performCommand(packet);
084: checkReplyPacket(reply, "Method::Bytecodes command");
085:
086: int bytes = reply.getNextValueAsInt();
087: logWriter.println("bytes = " + bytes);
088:
089: byte[] bytecode = new byte[bytes];
090: for (int j = 0; j < bytes; j++) {
091: bytecode[j] = reply.getNextValueAsByte();
092: }
093:
094: logWriter.println("Bytecode=" + new String(bytecode));
095: }
096:
097: synchronizer
098: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
099: }
100: }
|