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 20.05.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 for field of super class.
038: */
039: public class GetValues003Test extends JDWPSyncTestCase {
040:
041: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues003Debuggee;";
042: static final String chekedClassSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/RFGetValues003CheckedClass;";
043:
044: protected String getDebuggeeClassName() {
045: return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.GetValues003Debuggee";
046: }
047:
048: /**
049: * This testcase exercises ReferenceType.GetValues command for field of super class.
050: * <BR>The test starts GetValues003Debuggee and checks that
051: * ReferenceType.GetValues command runs correctly for field declaring
052: * in super class of passed to GetValues command ReferenceTypeID.
053: * <BR>Test checks that expected value of this field is returned.
054: */
055: public void testGetValues003() {
056: String this TestName = "testGetValues003";
057: logWriter.println("==> " + this TestName
058: + " for ReferenceType.GetValues command: START...");
059: synchronizer
060: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
061:
062: logWriter
063: .println("\n=> Get debuggeeRefTypeID for debuggee class = "
064: + getDebuggeeClassName() + "...");
065: long debuggeeRefTypeID = 0;
066: try {
067: debuggeeRefTypeID = debuggeeWrapper.vmMirror
068: .getClassID(debuggeeSignature);
069: } catch (Throwable thrown) {
070: logWriter
071: .println("## FAILURE: Can not get debuggeeRefTypeID:");
072: logWriter.println("## Exception: " + thrown);
073: fail("Can not get debuggeeRefTypeID, Exception: " + thrown);
074: }
075: if (debuggeeRefTypeID == -1) {
076: logWriter
077: .println("## FAILURE: Can not get debuggeeRefTypeID for given signature!");
078: logWriter.println("## Signature = |" + debuggeeSignature
079: + "|");
080: fail("Can not get debuggeeRefTypeID for given signature:<"
081: + debuggeeSignature + ">");
082: }
083: logWriter
084: .println("=> debuggeeRefTypeID = " + debuggeeRefTypeID);
085:
086: logWriter
087: .println("\n=> Get superClassCheckedFieldID for field of debuggee class...");
088: String super ClassCheckedFieldName = "superClassStaticIntVar";
089: long super ClassCheckedFieldID = 0;
090: try {
091: super ClassCheckedFieldID = debuggeeWrapper.vmMirror
092: .getFieldID(debuggeeRefTypeID,
093: super ClassCheckedFieldName);
094: } catch (Throwable thrown) {
095: logWriter
096: .println("## FAILURE: Can not get superClassCheckedFieldID:");
097: logWriter.println("## Exception: " + thrown);
098: fail("Can not get superClassCheckedFieldID, Exception: "
099: + thrown);
100: }
101: logWriter.println("=> superClassCheckedFieldID = "
102: + super ClassCheckedFieldID);
103:
104: logWriter
105: .println("\n=> Get chekedClassRefTypeID for chekedClass class = RFGetValues003CheckedClass...");
106: long chekedClassRefTypeID = 0;
107: try {
108: chekedClassRefTypeID = debuggeeWrapper.vmMirror
109: .getClassID(chekedClassSignature);
110: } catch (Throwable thrown) {
111: logWriter
112: .println("## FAILURE: Can not get chekedClassRefTypeID:");
113: logWriter.println("## Exception: " + thrown);
114: fail(" Can not get chekedClassRefTypeID, Exception: "
115: + thrown);
116: }
117: if (chekedClassRefTypeID == -1) {
118: logWriter
119: .println("## FAILURE: Can not get chekedClassRefTypeID for given signature!");
120: logWriter.println("## Signature = |" + chekedClassSignature
121: + "|");
122: fail("Can not get chekedClassRefTypeID for given signature:<"
123: + chekedClassSignature + ">");
124: }
125: logWriter.println("=> chekedClassRefTypeID = "
126: + chekedClassRefTypeID);
127:
128: logWriter
129: .println("\n=> CHECK ReferenceType::GetValues command for chekedClassRefTypeID, superClassCheckedFieldID...");
130: CommandPacket getValuesCommand = new CommandPacket(
131: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
132: JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
133: getValuesCommand
134: .setNextValueAsReferenceTypeID(chekedClassRefTypeID);
135: getValuesCommand.setNextValueAsInt(1);
136: getValuesCommand
137: .setNextValueAsFieldID(super ClassCheckedFieldID);
138: ReplyPacket getValuesReply = debuggeeWrapper.vmMirror
139: .performCommand(getValuesCommand);
140: checkReplyPacket(getValuesReply,
141: "ReferenceType::GetValues command");
142:
143: //int returnedValuesNumber =
144: getValuesReply.getNextValueAsInt();
145: Value fieldValue = getValuesReply.getNextValueAsValue();
146: byte fieldTag = fieldValue.getTag();
147: logWriter.println("=> Returned value tag = " + fieldTag + "("
148: + JDWPConstants.Tag.getName(fieldTag) + ")");
149: assertEquals("Invalid value tag is returned,",
150: JDWPConstants.Tag.INT_TAG, fieldTag, JDWPConstants.Tag
151: .getName(JDWPConstants.Tag.INT_TAG),
152: JDWPConstants.Tag.getName(fieldTag));
153:
154: int intValue = fieldValue.getIntValue();
155: logWriter.println("=> Returned value = " + intValue);
156: // here expected value = 99 (staticIntField)
157: int expectedIntValue = 99;
158: assertEquals("Invalid int value,", expectedIntValue, intValue);
159:
160: assertAllDataRead(getValuesReply);
161:
162: logWriter
163: .println("=> CHECK PASSED: Expected value is returned!");
164:
165: synchronizer
166: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
167: logWriter.println("==> " + this TestName
168: + " for ReferenceType::GetValues command: FINISH");
169: }
170:
171: public static void main(String[] args) {
172: junit.textui.TestRunner.run(GetValues003Test.class);
173: }
174: }
|