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.5 $
022: */
023:
024: /**
025: * Created on 13.07.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ArrayReference;
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.Value;
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 ArrayReference.SetValues command with specific values.
038: */
039: public class SetValues002Test extends JDWPSyncTestCase {
040:
041: static final int testStatusPassed = 0;
042: static final int testStatusFailed = -1;
043: static final String this CommandName = "ArrayReference::SetValues command";
044: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ArrayReference/SetValues002Debuggee;";
045:
046: /**
047: * Returns full name of debuggee class which is used by this test.
048: * @return full name of debuggee class.
049: */
050: protected String getDebuggeeClassName() {
051: return "org.apache.harmony.jpda.tests.jdwp.ArrayReference.SetValues002Debuggee";
052: }
053:
054: /**
055: * This testcase exercises ArrayReference.SetValues command for
056: * array of elements of referenceType with value=null.
057: * <BR>The test expects array element should be set by null value.
058: */
059: public void testSetValues002() {
060: String this TestName = "testSetValues002";
061: logWriter.println("==> " + this TestName + " for "
062: + this CommandName + ": START...");
063: synchronizer
064: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
065:
066: CommandPacket classesBySignatureCommand = new CommandPacket(
067: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
068: JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand);
069: classesBySignatureCommand
070: .setNextValueAsString(debuggeeSignature);
071: ReplyPacket classesBySignatureReply = debuggeeWrapper.vmMirror
072: .performCommand(classesBySignatureCommand);
073: classesBySignatureCommand = null;
074: checkReplyPacket(classesBySignatureReply,
075: "VirtualMachine::ClassesBySignature command");
076:
077: classesBySignatureReply.getNextValueAsInt();
078: // Number of returned reference types - is NOT used here
079:
080: classesBySignatureReply.getNextValueAsByte();
081: // refTypeTag of class - is NOT used here
082:
083: long refTypeID = classesBySignatureReply
084: .getNextValueAsReferenceTypeID();
085: classesBySignatureReply = null;
086:
087: logWriter.println("=> Debuggee class = "
088: + getDebuggeeClassName());
089: logWriter.println("=> referenceTypeID for Debuggee class = "
090: + refTypeID);
091:
092: String checkedFieldNames[] = { "objectArrayField", };
093: long checkedFieldIDs[] = checkFields(refTypeID,
094: checkedFieldNames);
095:
096: logWriter
097: .println("=> Send ReferenceType::GetValues command and get ArrayID to check...");
098:
099: CommandPacket getValuesCommand = new CommandPacket(
100: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
101: JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
102: getValuesCommand.setNextValueAsReferenceTypeID(refTypeID);
103: getValuesCommand.setNextValueAsInt(1);
104: getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[0]);
105: ReplyPacket getValuesReply = debuggeeWrapper.vmMirror
106: .performCommand(getValuesCommand);
107: getValuesCommand = null;
108: checkReplyPacket(getValuesReply,
109: "ReferenceType::GetValues command");
110:
111: int returnedValuesNumber = getValuesReply.getNextValueAsInt();
112: assertEquals(
113: "ReferenceType::GetValues returned invalid number of values,",
114: 1, returnedValuesNumber);
115: logWriter.println("=> Returned values number = "
116: + returnedValuesNumber);
117:
118: Value checkedObjectFieldValue = getValuesReply
119: .getNextValueAsValue();
120: byte checkedObjectFieldTag = checkedObjectFieldValue.getTag();
121: logWriter
122: .println("=> Returned field value tag for checked object= "
123: + checkedObjectFieldTag
124: + "("
125: + JDWPConstants.Tag
126: .getName(checkedObjectFieldTag) + ")");
127:
128: assertEquals(
129: "ReferenceType::GetValues returned invalid object field tag,",
130: JDWPConstants.Tag.ARRAY_TAG, checkedObjectFieldTag,
131: JDWPConstants.Tag.getName(JDWPConstants.Tag.ARRAY_TAG),
132: JDWPConstants.Tag.getName(checkedObjectFieldTag));
133:
134: long checkedObjectID = checkedObjectFieldValue.getLongValue();
135: logWriter.println("=> Returned checked ArrayID = "
136: + checkedObjectID);
137: logWriter
138: .println("=> CHECK: send "
139: + this CommandName
140: + " for this ArrayID for element of referenceType with null values...");
141:
142: CommandPacket checkedCommand = new CommandPacket(
143: JDWPCommands.ArrayReferenceCommandSet.CommandSetID,
144: JDWPCommands.ArrayReferenceCommandSet.SetValuesCommand);
145: checkedCommand.setNextValueAsObjectID(checkedObjectID);
146: checkedCommand.setNextValueAsInt(0); // first index
147: checkedCommand.setNextValueAsInt(1); // elements' number
148: checkedCommand.setNextValueAsObjectID(0); // null value
149: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
150: .performCommand(checkedCommand);
151: checkedCommand = null;
152: checkReplyPacket(checkedReply,
153: "ArrayReference::SetValues command");
154:
155: logWriter
156: .println("=> Wait for Debuggee's status about check for set field...");
157: synchronizer
158: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
159: boolean debuggeeStatus = synchronizer.receiveMessage("PASSED");
160: if (!debuggeeStatus) {
161: logWriter.println("## " + this TestName
162: + ": Debuggee returned status FAILED");
163: //logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FAILED");
164: fail("Debuggee returned status FAILED");
165: } else {
166: logWriter.println("=> " + this TestName
167: + ": Debuggee returned status PASSED");
168: }
169:
170: logWriter.println("==> " + this TestName + " for "
171: + this CommandName + ": OK.");
172: }
173:
174: /**
175: * Starts this test by junit.textui.TestRunner.run() method.
176: */
177: public static void main(String[] args) {
178: junit.textui.TestRunner.run(SetValues002Test.class);
179: }
180: }
|