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 05.07.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ClassType;
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 ClassType.SetValues command with incorrect types of 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 = "ClassType::SetValues command";
044: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ClassType/SetValues002Debuggee;";
045:
046: protected String getDebuggeeClassName() {
047: return "org.apache.harmony.jpda.tests.jdwp.ClassType.SetValues002Debuggee";
048: }
049:
050: /**
051: * The test checks ClassType.SetValues command for
052: * field of Debuggee class with value which has other
053: * referenceType than field to set.
054: * The test expects the field should not be set.
055: */
056: public void testSetValues002() {
057: String this TestName = "testSetValues002";
058: logWriter.println("==> " + this TestName + " for "
059: + this CommandName + ": START...");
060: synchronizer
061: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
062:
063: CommandPacket classesBySignatureCommand = new CommandPacket(
064: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
065: JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand);
066: classesBySignatureCommand
067: .setNextValueAsString(debuggeeSignature);
068: ReplyPacket classesBySignatureReply = debuggeeWrapper.vmMirror
069: .performCommand(classesBySignatureCommand);
070: classesBySignatureCommand = null;
071: checkReplyPacket(classesBySignatureReply,
072: "VirtualMachine::ClassesBySignature command");
073:
074: classesBySignatureReply.getNextValueAsInt();
075: // Number of returned reference types - is NOt used here
076:
077: classesBySignatureReply.getNextValueAsByte();
078: // refTypeTag of class - is NOt used here
079:
080: long refTypeID = classesBySignatureReply
081: .getNextValueAsReferenceTypeID();
082: classesBySignatureReply = null;
083:
084: logWriter.println("=> Debuggee class = "
085: + getDebuggeeClassName());
086: logWriter.println("=> referenceTypeID for Debuggee class = "
087: + refTypeID);
088:
089: String checkedFieldNames[] = { "SetValues002DebuggeeObject",
090: "objectField", };
091: long checkedFieldIDs[] = checkFields(refTypeID,
092: checkedFieldNames);
093: int checkedFieldsNumber = checkedFieldNames.length;
094:
095: logWriter
096: .println("=> Send ReferenceType::GetValues command and get ObjectID for value to set...");
097:
098: CommandPacket getValuesCommand = new CommandPacket(
099: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
100: JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
101: getValuesCommand.setNextValueAsReferenceTypeID(refTypeID);
102: getValuesCommand.setNextValueAsInt(1);
103: getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[0]);
104: ReplyPacket getValuesReply = debuggeeWrapper.vmMirror
105: .performCommand(getValuesCommand);
106: getValuesCommand = null;
107: checkReplyPacket(getValuesReply,
108: "ReferenceType::GetValues command");
109:
110: int returnedValuesNumber = getValuesReply.getNextValueAsInt();
111: logWriter.println("=> Returned values number = "
112: + returnedValuesNumber);
113: assertEquals(
114: "ReferenceType::GetValues returned invalid values number,",
115: 1, returnedValuesNumber);
116:
117: Value objectFieldValueToSet = getValuesReply
118: .getNextValueAsValue();
119: byte objectFieldValueToSetTag = objectFieldValueToSet.getTag();
120: logWriter
121: .println("=> Returned field value tag for checked object= "
122: + objectFieldValueToSetTag
123: + "("
124: + JDWPConstants.Tag
125: .getName(objectFieldValueToSetTag)
126: + ")");
127: assertEquals(
128: "ReferenceType::GetValues returned invalid value tag,",
129: JDWPConstants.Tag.OBJECT_TAG,
130: objectFieldValueToSetTag,
131: JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
132: JDWPConstants.Tag.getName(objectFieldValueToSetTag));
133:
134: long objectFieldID = objectFieldValueToSet.getLongValue();
135: logWriter.println("=> Returned ObjectID = " + objectFieldID);
136: logWriter
137: .println("=> CHECK: send "
138: + this CommandName
139: + " for Debuggee class with value which has other referenceType than field to set...");
140:
141: CommandPacket checkedCommand = new CommandPacket(
142: JDWPCommands.ClassTypeCommandSet.CommandSetID,
143: JDWPCommands.ClassTypeCommandSet.SetValuesCommand);
144: checkedCommand.setNextValueAsClassID(refTypeID);
145: checkedCommand.setNextValueAsInt(checkedFieldsNumber - 1);
146: int fieldIndex = 1;
147: for (; fieldIndex < checkedFieldsNumber; fieldIndex++) {
148: checkedCommand
149: .setNextValueAsFieldID(checkedFieldIDs[fieldIndex]);
150: switch (fieldIndex) {
151: case 1: // objectField
152: checkedCommand.setNextValueAsObjectID(objectFieldID);
153: break;
154: }
155: }
156: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
157: .performCommand(checkedCommand);
158: checkedCommand = null;
159:
160: short errorCode = checkedReply.getErrorCode();
161: if (errorCode == JDWPConstants.Error.NONE) {
162: logWriter.println("=> " + this CommandName
163: + " run without any ERROR!");
164: } else {
165: logWriter.println("=> " + this CommandName
166: + " returns ERROR = " + errorCode + "("
167: + JDWPConstants.Error.getName(errorCode) + ")");
168: }
169:
170: logWriter
171: .println("=> Wait for Debuggee's status about check for set field...");
172: synchronizer
173: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
174: boolean debuggeeStatus = synchronizer.receiveMessage("PASSED");
175: if (!debuggeeStatus) {
176: logWriter.println("## " + this TestName
177: + ": Debuggee returned status FAILED");
178: fail("Debuggee returned status FAILED");
179: } else {
180: logWriter.println("=> " + this TestName
181: + ": Debuggee returned status PASSED");
182: }
183:
184: logWriter.println("==> " + this TestName + " for "
185: + this CommandName + ": OK");
186: }
187:
188: public static void main(String[] args) {
189: junit.textui.TestRunner.run(SetValues002Test.class);
190: }
191: }
|