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 28.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ObjectReference;
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 ObjectReference.GetValues command .
038: */
039: public class GetValuesTest extends JDWPSyncTestCase {
040:
041: static final String this CommandName = "ObjectReference::GetValues command";
042: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/GetValuesDebuggee;";
043:
044: protected String getDebuggeeClassName() {
045: return "org.apache.harmony.jpda.tests.jdwp.ObjectReference.GetValuesDebuggee";
046: }
047:
048: /**
049: * This test exercises ObjectReference.GetValues command.
050: * <BR>The test starts GetValuesDebuggee class, gets objectID
051: * as value of static field of this class which (field) represents checked object.
052: * Then for this objectID test executes ObjectReference::GetValues command for special
053: * set of fieldIDs and checks that command returns expected jdwpTags for all checked
054: * fields and expected values for primitive fields.
055: */
056: public void testGetValues001() {
057: String this TestName = "testGetValues001";
058: logWriter.println("==> " + this TestName + " for "
059: + this CommandName + ": START...");
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 checkedFieldNames[] = { "getValuesDebuggeeObject",
071:
072: "intField", "longField", "objectField", "stringArrayField",
073: "objectArrayField", "threadField", "threadGroupField",
074: "classField", "classLoaderField", "stringField", };
075: long checkedFieldIDs[] = checkFields(refTypeID,
076: checkedFieldNames);
077: int checkedFieldsNumber = checkedFieldNames.length;
078:
079: logWriter
080: .println("=> Send ReferenceType::GetValues command and and get ObjectID to check...");
081:
082: CommandPacket getValuesCommand = new CommandPacket(
083: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
084: JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
085: getValuesCommand.setNextValueAsReferenceTypeID(refTypeID);
086: getValuesCommand.setNextValueAsInt(1);
087: getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[0]);
088:
089: ReplyPacket getValuesReply = debuggeeWrapper.vmMirror
090: .performCommand(getValuesCommand);
091: getValuesCommand = null;
092: checkReplyPacket(getValuesReply,
093: "ReferenceType::GetValues command");
094:
095: int returnedValuesNumber = getValuesReply.getNextValueAsInt();
096: logWriter.println("=> Returned values number = "
097: + returnedValuesNumber);
098: assertEquals("Invalid number of values,", 1,
099: returnedValuesNumber);
100:
101: Value checkedObjectFieldValue = getValuesReply
102: .getNextValueAsValue();
103: byte checkedObjectFieldTag = checkedObjectFieldValue.getTag();
104: logWriter
105: .println("=> Returned field value tag for checked object= "
106: + checkedObjectFieldTag
107: + "("
108: + JDWPConstants.Tag
109: .getName(checkedObjectFieldTag) + ")");
110: assertEquals(
111: "Invalid value tag for checked object,",
112: JDWPConstants.Tag.OBJECT_TAG,
113: checkedObjectFieldTag,
114: JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
115: JDWPConstants.Tag.getName(checkedObjectFieldTag));
116:
117: long checkedObjectID = checkedObjectFieldValue.getLongValue();
118: logWriter.println("=> Returned checked ObjectID = "
119: + checkedObjectID);
120: logWriter.println("=> CHECK: send " + this CommandName
121: + " for this ObjectID and check reply...");
122:
123: CommandPacket checkedCommand = new CommandPacket(
124: JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
125: JDWPCommands.ObjectReferenceCommandSet.GetValuesCommand);
126: checkedCommand.setNextValueAsObjectID(checkedObjectID);
127: checkedCommand.setNextValueAsInt(checkedFieldsNumber - 1);
128: int fieldIndex = 1; // !!!
129: for (; fieldIndex < checkedFieldsNumber; fieldIndex++) {
130: checkedCommand
131: .setNextValueAsFieldID(checkedFieldIDs[fieldIndex]);
132: }
133:
134: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
135: .performCommand(checkedCommand);
136: checkedCommand = null;
137: checkReplyPacket(checkedReply, this CommandName);
138:
139: returnedValuesNumber = checkedReply.getNextValueAsInt();
140: logWriter.println("=> Returned values number = "
141: + returnedValuesNumber);
142: assertEquals("Invalid number of values,",
143: checkedFieldsNumber - 1, returnedValuesNumber);
144:
145: byte expectedFieldTags[] = {
146: 0, // dummy
147: JDWPConstants.Tag.INT_TAG, JDWPConstants.Tag.LONG_TAG,
148: JDWPConstants.Tag.OBJECT_TAG,
149: JDWPConstants.Tag.ARRAY_TAG,
150: JDWPConstants.Tag.ARRAY_TAG,
151: JDWPConstants.Tag.THREAD_TAG,
152: JDWPConstants.Tag.THREAD_GROUP_TAG,
153: JDWPConstants.Tag.CLASS_OBJECT_TAG,
154: JDWPConstants.Tag.CLASS_LOADER_TAG,
155: JDWPConstants.Tag.STRING_TAG, };
156:
157: logWriter.println("=> CHECK for returned values...");
158: fieldIndex = 1; // !!!
159: for (; fieldIndex < checkedFieldsNumber; fieldIndex++) {
160: Value fieldValue = checkedReply.getNextValueAsValue();
161: byte fieldTag = fieldValue.getTag();
162: logWriter
163: .println("\n=> Check for returned value for field: "
164: + checkedFieldNames[fieldIndex] + " ...");
165: logWriter.println("=> Returned value tag = " + fieldTag
166: + "(" + JDWPConstants.Tag.getName(fieldTag) + ")");
167:
168: assertEquals("Invalid value tag is returned,",
169: expectedFieldTags[fieldIndex], fieldTag,
170: JDWPConstants.Tag
171: .getName(expectedFieldTags[fieldIndex]),
172: JDWPConstants.Tag.getName(fieldTag));
173:
174: switch (fieldTag) {
175: case JDWPConstants.Tag.INT_TAG:
176: int intValue = fieldValue.getIntValue();
177: logWriter.println("=> Returned value = " + intValue);
178: // here expected value = 9999 (staticIntField)
179: int expectedIntValue = 9999;
180: assertEquals("Invalid int value,", expectedIntValue,
181: intValue);
182: break;
183: case JDWPConstants.Tag.LONG_TAG:
184: long longValue = fieldValue.getLongValue();
185: logWriter.println("=> Returned value = " + longValue);
186: // here expected value = 999999 (staticLongField)
187: long expectedLongValue = 999999;
188: assertEquals("Invalid long value,", expectedLongValue,
189: longValue);
190: break;
191: case JDWPConstants.Tag.STRING_TAG:
192: case JDWPConstants.Tag.OBJECT_TAG:
193: case JDWPConstants.Tag.ARRAY_TAG:
194: case JDWPConstants.Tag.THREAD_TAG:
195: case JDWPConstants.Tag.THREAD_GROUP_TAG:
196: case JDWPConstants.Tag.CLASS_OBJECT_TAG:
197: case JDWPConstants.Tag.CLASS_LOADER_TAG:
198: long objectIDValue = fieldValue.getLongValue();
199: logWriter.println("=> ObjectId value = "
200: + objectIDValue);
201: break;
202: }
203: }
204:
205: assertAllDataRead(checkedReply);
206:
207: logWriter
208: .println("=> CHECK PASSED: All expected field values are got and have expected attributes");
209:
210: synchronizer
211: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
212: logWriter.println("==> " + this TestName + " for "
213: + this CommandName + ": FINISH");
214: }
215:
216: public static void main(String[] args) {
217: junit.textui.TestRunner.run(GetValuesTest.class);
218: }
219: }
|