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