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 Anatoly F. Bondarenko
021: * @version $Revision: 1.6 $
022: */
023:
024: /**
025: * Created on 24.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
031: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
032: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
033:
034: /**
035: * JDWP Unit test for ReferenceType.ClassObject command.
036: */
037: public class ClassObjectTest extends JDWPSyncTestCase {
038:
039: static final int testStatusPassed = 0;
040: static final int testStatusFailed = -1;
041: static final String this CommandName = "ReferenceType.ClassObject command";
042: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/ClassObjectDebuggee;";
043:
044: protected String getDebuggeeClassName() {
045: return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.ClassObjectDebuggee";
046: }
047:
048: /**
049: * This testcase exercises ReferenceType.ClassObject command.
050: * <BR>The test starts ClassObjectDebuggee class, requests referenceTypeId
051: * for this class by VirtualMachine.ClassesBySignature command, then
052: * performs ReferenceType.ClassObject command and checks that returned
053: * class object is object of reference type 'java/lang/Class'.
054: */
055: public void testClassObject001() {
056: String this TestName = "testClassObject001";
057: logWriter.println("==> " + this TestName + " for "
058: + this CommandName + ": START...");
059: //int testStatus = testStatusPassed;
060: synchronizer
061: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
062:
063: long refTypeID = getClassIDBySignature(debuggeeSignature);
064:
065: logWriter.println("=> Debuggee class = "
066: + getDebuggeeClassName());
067: logWriter.println("=> referenceTypeID for Debuggee class = "
068: + refTypeID);
069:
070: String debuggeeExtraClassSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/ClassObjectDebuggee_ExtraClass;";
071:
072: long debuggeeExtraClassRefTypeID = getClassIDBySignature(debuggeeExtraClassSignature);
073:
074: logWriter
075: .println("=> referenceTypeID for Debuggee extra class = "
076: + debuggeeExtraClassRefTypeID);
077: logWriter.println("=> CHECK: send " + this CommandName
078: + " and check reply...");
079:
080: CommandPacket checkedCommand = new CommandPacket(
081: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
082: JDWPCommands.ReferenceTypeCommandSet.ClassObjectCommand);
083: checkedCommand.setNextValueAsReferenceTypeID(refTypeID);
084:
085: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
086: .performCommand(checkedCommand);
087: checkedCommand = null;
088: checkReplyPacket(checkedReply, this CommandName);
089:
090: long classObjectID = checkedReply.getNextValueAsObjectID();
091: logWriter.println("=> Returned class ObjectID = "
092: + classObjectID);
093: logWriter
094: .println("=> Get reference type for returned class Object...");
095:
096: CommandPacket referenceTypeCommand = new CommandPacket(
097: JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
098: JDWPCommands.ObjectReferenceCommandSet.ReferenceTypeCommand);
099: referenceTypeCommand.setNextValueAsObjectID(classObjectID);
100:
101: ReplyPacket referenceTypeReply = debuggeeWrapper.vmMirror
102: .performCommand(referenceTypeCommand);
103: referenceTypeCommand = null;
104:
105: checkReplyPacket(referenceTypeReply,
106: "ObjectReference::ReferenceType command");
107:
108: referenceTypeReply.getNextValueAsByte();
109: // refTypeTag of class - is NOT used here
110:
111: long refTypeIDOfClassObject = referenceTypeReply
112: .getNextValueAsReferenceTypeID();
113: referenceTypeReply = null;
114:
115: logWriter.println("=> ReferenceTypeID of ClassObject = "
116: + refTypeIDOfClassObject);
117: logWriter
118: .println("=> Get signature for reference type of ClassObject...");
119:
120: CommandPacket signatureCommand = new CommandPacket(
121: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
122: JDWPCommands.ReferenceTypeCommandSet.SignatureCommand);
123: signatureCommand
124: .setNextValueAsReferenceTypeID(refTypeIDOfClassObject);
125:
126: ReplyPacket signatureReply = debuggeeWrapper.vmMirror
127: .performCommand(signatureCommand);
128: signatureCommand = null;
129: checkReplyPacket(signatureReply,
130: "ReferenceType::Signature command");
131:
132: String returnedSignature = signatureReply
133: .getNextValueAsString();
134: signatureReply = null;
135: logWriter
136: .println("=> Signature of reference type of ClassObject = "
137: + returnedSignature);
138:
139: String expectedSignature = "Ljava/lang/Class;";
140: assertString(
141: "Invalid signature of reference type of ClassObject,",
142: expectedSignature, returnedSignature);
143: logWriter
144: .println("=> CHECK: PASSED: expected signature is returned");
145:
146: assertAllDataRead(checkedReply);
147:
148: CommandPacket classLoaderCommand = new CommandPacket(
149: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
150: JDWPCommands.ReferenceTypeCommandSet.ClassLoaderCommand);
151: classLoaderCommand.setNextValueAsReferenceTypeID(refTypeID);
152:
153: ReplyPacket classLoaderReply = debuggeeWrapper.vmMirror
154: .performCommand(classLoaderCommand);
155: classLoaderCommand = null;
156: checkReplyPacket(classLoaderReply,
157: "ReferenceType::ClassLoader command");
158:
159: long classLoaderID = classLoaderReply.getNextValueAsObjectID();
160: logWriter.println("=> ClassLoaderID of debuggee = "
161: + classLoaderID);
162: synchronizer
163: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
164: logWriter.println("==> " + this TestName + " for "
165: + this CommandName + ": FINISH");
166: }
167:
168: public static void main(String[] args) {
169: junit.textui.TestRunner.run(ClassObjectTest.class);
170: }
171: }
|