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 11.03.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 for static fields.
038: */
039: public class GetValues002Test extends JDWPSyncTestCase {
040:
041: static final String this CommandName = "ObjectReference::GetValues command";
042: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/GetValues002Debuggee;";
043:
044: protected String getDebuggeeClassName() {
045: return "org.apache.harmony.jpda.tests.jdwp.ObjectReference.GetValues002Debuggee";
046: }
047:
048: /**
049: * This test exercises ObjectReference.GetValues command for static fields.
050: * <BR>The test starts GetValues002Debuggee 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 testGetValues002() {
057: String this TestName = "testGetValues002";
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[] = { "getValues002DebuggeeField",
071:
072: "staticLongField", "staticIntField", "staticStringField",
073: "staticObjectField", "staticBooleanField",
074: "staticByteField", "staticCharField",
075: "staticShortField", "staticFloatField",
076: "staticDoubleField", "staticArrayField", };
077: long checkedFieldIDs[] = checkFields(refTypeID,
078: checkedFieldNames);
079: int checkedFieldsNumber = checkedFieldNames.length;
080:
081: logWriter
082: .println("=> Send ReferenceType::GetValues command and and get ObjectID to check...");
083:
084: CommandPacket getValuesCommand = new CommandPacket(
085: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
086: JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
087: getValuesCommand.setNextValueAsReferenceTypeID(refTypeID);
088: getValuesCommand.setNextValueAsInt(1);
089: getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[0]);
090:
091: ReplyPacket getValuesReply = debuggeeWrapper.vmMirror
092: .performCommand(getValuesCommand);
093: getValuesCommand = null;
094: checkReplyPacket(getValuesReply,
095: "ReferenceType::GetValues command");
096:
097: int returnedValuesNumber = getValuesReply.getNextValueAsInt();
098: logWriter.println("=> Returned values number = "
099: + returnedValuesNumber);
100: assertEquals("Invalid number of values,", 1,
101: returnedValuesNumber);
102:
103: Value checkedObjectFieldValue = getValuesReply
104: .getNextValueAsValue();
105: byte checkedObjectFieldTag = checkedObjectFieldValue.getTag();
106: logWriter
107: .println("=> Returned field value tag for checked object= "
108: + checkedObjectFieldTag
109: + "("
110: + JDWPConstants.Tag
111: .getName(checkedObjectFieldTag) + ")");
112: assertEquals(
113: "Invalid value tag for checked object,",
114: JDWPConstants.Tag.OBJECT_TAG,
115: checkedObjectFieldTag,
116: JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
117: JDWPConstants.Tag.getName(checkedObjectFieldTag));
118:
119: long checkedObjectID = checkedObjectFieldValue.getLongValue();
120: logWriter.println("=> Returned checked ObjectID = "
121: + checkedObjectID);
122: logWriter.println("=> CHECK: send " + this CommandName
123: + " for this ObjectID and check reply...");
124:
125: CommandPacket checkedCommand = new CommandPacket(
126: JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
127: JDWPCommands.ObjectReferenceCommandSet.GetValuesCommand);
128: checkedCommand.setNextValueAsObjectID(checkedObjectID);
129: checkedCommand.setNextValueAsInt(checkedFieldsNumber - 1);
130: int fieldIndex = 1; // !!!
131: for (; fieldIndex < checkedFieldsNumber; fieldIndex++) {
132: checkedCommand
133: .setNextValueAsFieldID(checkedFieldIDs[fieldIndex]);
134: }
135:
136: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
137: .performCommand(checkedCommand);
138: checkedCommand = null;
139: checkReplyPacket(checkedReply, this CommandName);
140:
141: returnedValuesNumber = checkedReply.getNextValueAsInt();
142: logWriter.println("=> Returned values number = "
143: + returnedValuesNumber);
144: assertEquals("Invalid number of values,",
145: checkedFieldsNumber - 1, returnedValuesNumber);
146:
147: byte expectedFieldTags[] = {
148: 0, // dummy
149: JDWPConstants.Tag.LONG_TAG, JDWPConstants.Tag.INT_TAG,
150: JDWPConstants.Tag.STRING_TAG,
151: JDWPConstants.Tag.OBJECT_TAG,
152: JDWPConstants.Tag.BOOLEAN_TAG,
153: JDWPConstants.Tag.BYTE_TAG, JDWPConstants.Tag.CHAR_TAG,
154: JDWPConstants.Tag.SHORT_TAG,
155: JDWPConstants.Tag.FLOAT_TAG,
156: JDWPConstants.Tag.DOUBLE_TAG,
157: JDWPConstants.Tag.ARRAY_TAG, };
158:
159: logWriter.println("=> CHECK for returned values...");
160: fieldIndex = 1; // !!!
161: for (; fieldIndex < checkedFieldsNumber; fieldIndex++) {
162: Value fieldValue = checkedReply.getNextValueAsValue();
163: byte fieldTag = fieldValue.getTag();
164: logWriter
165: .println("\n=> Check for returned value for field: "
166: + checkedFieldNames[fieldIndex] + " ...");
167: logWriter.println("=> Returned value tag = " + fieldTag
168: + "(" + JDWPConstants.Tag.getName(fieldTag) + ")");
169:
170: assertEquals("Invalid value tag is returned,",
171: expectedFieldTags[fieldIndex], fieldTag,
172: JDWPConstants.Tag
173: .getName(expectedFieldTags[fieldIndex]),
174: JDWPConstants.Tag.getName(fieldTag));
175:
176: switch (fieldTag) {
177: case JDWPConstants.Tag.INT_TAG:
178: int intValue = fieldValue.getIntValue();
179: logWriter.println("=> Int value = " + intValue);
180: int expectedIntValue = 99;
181: assertEquals("Invalid int value,", expectedIntValue,
182: intValue);
183: break;
184: case JDWPConstants.Tag.LONG_TAG:
185: long longValue = fieldValue.getLongValue();
186: logWriter.println("=> Long value = " + longValue);
187: long expectedLongValue = 2147483647;
188: assertEquals("Invalid long value,", expectedLongValue,
189: longValue);
190: break;
191: case JDWPConstants.Tag.STRING_TAG:
192: long stringIDValue = fieldValue.getLongValue();
193: logWriter.println("=> StringID value = "
194: + stringIDValue);
195: break;
196: case JDWPConstants.Tag.OBJECT_TAG:
197: long objectIDValue = fieldValue.getLongValue();
198: logWriter.println("=> ObjectID value = "
199: + objectIDValue);
200: break;
201: case JDWPConstants.Tag.BOOLEAN_TAG:
202: boolean booleanValue = fieldValue.getBooleanValue();
203: logWriter.println("=> Boolean value = " + booleanValue);
204: boolean expectedBooleanValue = true;
205: assertEquals("Invalid boolean value,",
206: expectedBooleanValue, booleanValue);
207: break;
208: case JDWPConstants.Tag.BYTE_TAG:
209: byte byteValue = fieldValue.getByteValue();
210: logWriter.println("=> Byte value = " + byteValue);
211: byte expectedByteValue = 1;
212: assertEquals("Invalid byte value,", expectedByteValue,
213: byteValue);
214: break;
215: case JDWPConstants.Tag.CHAR_TAG:
216: char charValue = fieldValue.getCharValue();
217: logWriter.println("=> Char value = " + (int) charValue);
218: char expectedCharValue = 97;
219: assertEquals("Invalid char value,", expectedCharValue,
220: charValue);
221: break;
222: case JDWPConstants.Tag.SHORT_TAG:
223: short shortValue = fieldValue.getShortValue();
224: logWriter.println("=> Short value = " + shortValue);
225: short expectedShortValue = 2;
226: assertEquals("Invalid short value,",
227: expectedShortValue, shortValue);
228: break;
229: case JDWPConstants.Tag.FLOAT_TAG:
230: float floatValue = fieldValue.getFloatValue();
231: logWriter.println("=> Float value = " + floatValue);
232: float expectedFloatValue = 2;
233: assertEquals("Invalid float value,",
234: expectedFloatValue, floatValue, 0);
235: break;
236: case JDWPConstants.Tag.DOUBLE_TAG:
237: double doubleValue = fieldValue.getDoubleValue();
238: logWriter.println("=> Double value = " + doubleValue);
239: double expectedDoubleValue = 3.1;
240: assertEquals("Invalid double value,",
241: expectedDoubleValue, doubleValue, 0);
242: break;
243: case JDWPConstants.Tag.ARRAY_TAG:
244: long arrayIDValue = fieldValue.getLongValue();
245: logWriter.println("=> ArrayID value = " + arrayIDValue);
246: break;
247: }
248: }
249:
250: assertAllDataRead(checkedReply);
251:
252: logWriter
253: .println("=> CHECK PASSED: All expected field values are got and have expected attributes");
254:
255: synchronizer
256: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
257: logWriter.println("==> " + this TestName + " for "
258: + this CommandName + ": FINISH");
259: }
260:
261: public static void main(String[] args) {
262: junit.textui.TestRunner.run(GetValues002Test.class);
263: }
264: }
|