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 Viacheslav G. Rybalov
021: * @version $Revision: 1.4 $
022: */
023:
024: /**
025: * Created on 10.03.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ArrayType;
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.JDWPConstants;
031: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032: import org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject;
033: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
034: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
035:
036: /**
037: * JDWP unit test for ArrayType.NewInstance command.
038: */
039:
040: public class NewInstanceTest extends JDWPSyncTestCase {
041:
042: /**
043: * Returns full name of debuggee class which is used by this test.
044: * @return full name of debuggee class.
045: */
046: protected String getDebuggeeClassName() {
047: return "org.apache.harmony.jpda.tests.jdwp.ArrayType.NewInstanceDebuggee";
048: }
049:
050: /**
051: * This testcase exercises ArrayType.NewInstance command.
052: * <BR>Starts <A HREF="../share/debuggee/HelloWorld.html">HelloWorld</A> debuggee.
053: * <BR>Creates new instance of array by ArrayType.NewInstance command,
054: * check it length by ArrayReference.Length command.
055: */
056: public void testNewInstance001() {
057: synchronizer
058: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
059: String[] testedArrayRefs = {
060: "[Lorg/apache/harmony/jpda/tests/jdwp/ArrayType/checkClass;",
061: "[Ljava/lang/String;",
062: "[I",
063: "[[Lorg/apache/harmony/jpda/tests/jdwp/ArrayType/checkClass;",
064: "[[Ljava/lang/String;", "[[I" };
065: for (int i = 0; i < testedArrayRefs.length; i++) {
066: logWriter.println("Checking reference "
067: + testedArrayRefs[i]);
068:
069: // Get referenceTypeID
070: CommandPacket packet = new CommandPacket(
071: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
072: JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand);
073: packet.setNextValueAsString(testedArrayRefs[i]);
074: ReplyPacket reply = debuggeeWrapper.vmMirror
075: .performCommand(packet);
076: checkReplyPacket(reply,
077: "VirtualMachine::ClassesBySignature command");
078:
079: int classes = reply.getNextValueAsInt();
080: if (classes <= 0) {
081: logWriter.println("## WARNING: class "
082: + testedArrayRefs[i] + " is not loadded ");
083: continue;
084: }
085:
086: byte refInitTypeTag = reply.getNextValueAsByte();
087: long typeArrayID = reply.getNextValueAsReferenceTypeID();
088: int status = reply.getNextValueAsInt();
089:
090: assertEquals(
091: "VirtualMachine::ClassesBySignature returned invalid TypeTag,",
092: JDWPConstants.TypeTag.ARRAY, refInitTypeTag,
093: JDWPConstants.TypeTag
094: .getName(JDWPConstants.TypeTag.ARRAY),
095: JDWPConstants.TypeTag.getName(refInitTypeTag));
096:
097: logWriter
098: .println(" VirtualMachine.ClassesBySignature: classes="
099: + classes
100: + " refTypeTag="
101: + refInitTypeTag
102: + " typeID= "
103: + typeArrayID
104: + " status="
105: + status);
106:
107: // Make NewInstance
108: packet = new CommandPacket(
109: JDWPCommands.ArrayTypeCommandSet.CommandSetID,
110: JDWPCommands.ArrayTypeCommandSet.NewInstanceCommand);
111: packet.setNextValueAsReferenceTypeID(typeArrayID);
112: packet.setNextValueAsInt(10);
113: reply = debuggeeWrapper.vmMirror.performCommand(packet);
114: checkReplyPacket(reply, "ArrayType::NewInstance command");
115:
116: TaggedObject newArray = reply.getNextValueAsTaggedObject();
117: assertAllDataRead(reply);
118: assertNotNull(
119: "ArrayType::NewInstance returned null newArray",
120: newArray);
121:
122: logWriter.println("ArrayType.NewInstance: newArray.tag="
123: + newArray.tag + " newArray.objectID="
124: + newArray.objectID);
125:
126: if (newArray.tag != JDWPConstants.Tag.ARRAY_TAG) {
127: logWriter
128: .println("##FAILURE: typeTag is not ARRAY_TAG");
129: fail("Returned tag "
130: + JDWPConstants.Tag.getName(newArray.tag) + "("
131: + newArray.tag + ") is not ARRAY_TAG");
132: }
133:
134: // Let's check array length
135: packet = new CommandPacket(
136: JDWPCommands.ArrayReferenceCommandSet.CommandSetID,
137: JDWPCommands.ArrayReferenceCommandSet.LengthCommand);
138: packet.setNextValueAsObjectID(newArray.objectID);
139: reply = debuggeeWrapper.vmMirror.performCommand(packet);
140: checkReplyPacket(reply, "ArrayReference::Length command");
141:
142: int arrayLength = reply.getNextValueAsInt();
143: logWriter.println("ArrayReference.Length: arrayLength="
144: + arrayLength);
145: assertEquals(
146: "ArrayReference::Length command returned ivalid array length,",
147: 10, arrayLength);
148: assertAllDataRead(reply);
149: }
150: synchronizer
151: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
152: }
153:
154: /**
155: * Starts this test by junit.textui.TestRunner.run() method.
156: */
157: public static void main(String[] args) {
158: junit.textui.TestRunner.run(NewInstanceTest.class);
159: }
160:
161: }
|