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 10.03.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.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 ReferenceType.GetValues command.
038: */
039: public class GetValuesTest extends JDWPSyncTestCase {
040:
041: static final int testStatusPassed = 0;
042: static final int testStatusFailed = -1;
043: static final String this CommandName = "ReferenceType.GetValues command";
044: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValuesDebuggee;";
045:
046: protected String getDebuggeeClassName() {
047: return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.GetValuesDebuggee";
048: }
049:
050: /**
051: * This testcase exercises ReferenceType.GetValues command.
052: * <BR>The test starts GetValuesDebuggee class, requests referenceTypeId
053: * for this class by VirtualMachine.ClassesBySignature command, then
054: * performs ReferenceType.Fields command and gets fieldIDs for checked fields.
055: * <BR>Then test performs ReferenceType.GetValues command for checked fields and checks
056: * that returned field values are expected.
057: */
058: public void testGetValues001() {
059: String this TestName = "testGetValues001";
060: logWriter.println("==> " + this TestName + " for "
061: + this CommandName + ": START...");
062: synchronizer
063: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
064:
065: long refTypeID = getClassIDBySignature(debuggeeSignature);
066:
067: logWriter.println("=> Debuggee class = "
068: + getDebuggeeClassName());
069: logWriter.println("=> referenceTypeID for Debuggee class = "
070: + refTypeID);
071:
072: String checkedFieldNames[] = { "staticIntField",
073: "staticLongField", "getValuesDebuggeeField",
074: "staticStringField", "staticArrayField", };
075:
076: String checkedFieldSignatures[] = {
077: "I",
078: "J",
079: "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValuesDebuggee;",
080: "Ljava/lang/String;", "[I", };
081:
082: long checkedFieldIDs[] = checkFields(refTypeID,
083: checkedFieldNames, checkedFieldSignatures, null);
084: int checkedFieldsNumber = checkedFieldNames.length;
085:
086: logWriter.println("=> CHECK: send " + this CommandName
087: + " and check reply...");
088: CommandPacket getValuesCommand = new CommandPacket(
089: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
090: JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
091: getValuesCommand.setNextValueAsReferenceTypeID(refTypeID);
092: getValuesCommand.setNextValueAsInt(checkedFieldsNumber);
093: for (int k = 0; k < checkedFieldsNumber; k++) {
094: getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[k]);
095: }
096:
097: ReplyPacket getValuesReply = debuggeeWrapper.vmMirror
098: .performCommand(getValuesCommand);
099: getValuesCommand = null;
100: checkReplyPacket(getValuesReply, this CommandName);
101:
102: int returnedValuesNumber = getValuesReply.getNextValueAsInt();
103: logWriter.println("=> Returned values number = "
104: + returnedValuesNumber);
105: assertEquals("Invalid number of values,", checkedFieldsNumber,
106: returnedValuesNumber);
107:
108: logWriter.println("=> CHECK for returned values...");
109: byte expectedFieldTags[] = { JDWPConstants.Tag.INT_TAG,
110: JDWPConstants.Tag.LONG_TAG,
111: JDWPConstants.Tag.OBJECT_TAG,
112: JDWPConstants.Tag.STRING_TAG,
113: JDWPConstants.Tag.ARRAY_TAG, };
114: for (int k = 0; k < checkedFieldsNumber; k++) {
115: Value fieldValue = getValuesReply.getNextValueAsValue();
116: byte fieldTag = fieldValue.getTag();
117: logWriter
118: .println("\n=> Check for returned value for field: "
119: + checkedFieldNames[k] + " ...");
120: logWriter.println("=> Returned value tag = " + fieldTag
121: + "(" + JDWPConstants.Tag.getName(fieldTag) + ")");
122:
123: assertEquals("Invalid value tag is returned,",
124: expectedFieldTags[k], fieldTag, JDWPConstants.Tag
125: .getName(expectedFieldTags[k]),
126: JDWPConstants.Tag.getName(fieldTag));
127:
128: switch (fieldTag) {
129: case JDWPConstants.Tag.INT_TAG:
130: int intValue = fieldValue.getIntValue();
131: logWriter.println("=> Int value = " + intValue);
132: // here expected value = 99 (staticIntField)
133: int expectedIntValue = 99;
134: assertEquals("Invalid int value,", expectedIntValue,
135: intValue);
136: break;
137: case JDWPConstants.Tag.LONG_TAG:
138: long longValue = fieldValue.getLongValue();
139: logWriter.println("=> Long value = " + longValue);
140: // here expected value = 2147483647 (staticLongField)
141: long expectedLongValue = 2147483647;
142: assertEquals("Invalid Long value,", expectedLongValue,
143: longValue);
144: break;
145: case JDWPConstants.Tag.OBJECT_TAG:
146: long objectIdValue = fieldValue.getLongValue();
147: logWriter.println("=> ObjectID value = "
148: + objectIdValue);
149: break;
150: case JDWPConstants.Tag.STRING_TAG:
151: long stringIDValue = fieldValue.getLongValue();
152: logWriter.println("=> StringID value = "
153: + stringIDValue);
154: break;
155: case JDWPConstants.Tag.ARRAY_TAG:
156: long arrayIDValue = fieldValue.getLongValue();
157: logWriter.println("=> ArrayID value = " + arrayIDValue);
158: break;
159: }
160: }
161:
162: assertAllDataRead(getValuesReply);
163:
164: logWriter
165: .println("=> CHECK PASSED: All expected field values are got and have expected attributes");
166:
167: synchronizer
168: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
169: logWriter.println("==> " + this TestName + " for "
170: + this CommandName + ": FINISH");
171: }
172:
173: public static void main(String[] args) {
174: junit.textui.TestRunner.run(GetValuesTest.class);
175: }
176: }
|