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 04.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.DisableCollection command.
038: */
039: public class DisableCollectionTest extends JDWPSyncTestCase {
040:
041: static final String this CommandName = "ObjectReference::DisableCollection command";
042:
043: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/DisableCollectionDebuggee;";
044:
045: protected String getDebuggeeClassName() {
046: return "org.apache.harmony.jpda.tests.jdwp.ObjectReference.DisableCollectionDebuggee";
047: }
048:
049: /**
050: * This testcase exercises ObjectReference.DisableCollection command.
051: * <BR>The test starts DisableCollectionDebuggee class, gets
052: * objectID as value of static field of this class which (field) represents
053: * checked object. Then for this objectID test executes
054: * ObjectReference.DisableCollection command for checked object. After that
055: * Debuggee tries to unload checked object and checks if checked object is
056: * unloaded. <BR>If so the test fails, otherwise it passes.
057: */
058: public void testDisableCollection001() {
059: String this TestName = "testDisableCollection001";
060: logWriter.println("==> " + this TestName + " for "
061: + this CommandName + ": START...");
062: synchronizer
063: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
064: finalSyncMessage = "TO_FINISH";
065:
066: long refTypeID = getClassIDBySignature(debuggeeSignature);
067:
068: logWriter.println("=> Debuggee class = "
069: + getDebuggeeClassName());
070: logWriter.println("=> referenceTypeID for Debuggee class = "
071: + refTypeID);
072:
073: long checkedFieldID = checkField(refTypeID, "checkedObject");
074:
075: logWriter
076: .println("=> Send ReferenceType::GetValues command for received fieldID and get ObjectID to check...");
077:
078: CommandPacket getValuesCommand = new CommandPacket(
079: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
080: JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
081: getValuesCommand.setNextValueAsReferenceTypeID(refTypeID);
082: getValuesCommand.setNextValueAsInt(1);
083: getValuesCommand.setNextValueAsFieldID(checkedFieldID);
084:
085: ReplyPacket getValuesReply = debuggeeWrapper.vmMirror
086: .performCommand(getValuesCommand);
087: getValuesCommand = null;
088: checkReplyPacket(getValuesReply,
089: "ReferenceType::GetValues command");
090:
091: int returnedValuesNumber = getValuesReply.getNextValueAsInt();
092: logWriter.println("=> Returned values number = "
093: + returnedValuesNumber);
094: assertEquals(
095: "Invalid number of values returned from ReferenceType::GetValues command,",
096: 1, returnedValuesNumber);
097:
098: Value checkedObjectFieldValue = getValuesReply
099: .getNextValueAsValue();
100: byte checkedObjectFieldTag = checkedObjectFieldValue.getTag();
101: logWriter
102: .println("=> Returned field value tag for checked object= "
103: + checkedObjectFieldTag
104: + "("
105: + JDWPConstants.Tag
106: .getName(checkedObjectFieldTag) + ")");
107: assertEquals(
108: "Invalid value tag for checked object,",
109: JDWPConstants.Tag.OBJECT_TAG,
110: checkedObjectFieldTag,
111: JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
112: JDWPConstants.Tag
113: .getName((byte) (checkedObjectFieldTag)));
114:
115: long checkedObjectID = checkedObjectFieldValue.getLongValue();
116: logWriter.println("=> Returned checked ObjectID = "
117: + checkedObjectID);
118:
119: logWriter.println("\n=> CHECK: send " + this CommandName
120: + " for checked ObjectID...");
121:
122: CommandPacket checkedCommand = new CommandPacket(
123: JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
124: JDWPCommands.ObjectReferenceCommandSet.DisableCollectionCommand);
125: checkedCommand.setNextValueAsObjectID(checkedObjectID);
126:
127: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
128: .performCommand(checkedCommand);
129: checkedCommand = null;
130: checkReplyPacket(checkedReply, this CommandName);
131:
132: logWriter
133: .println("=> CHECK: Reply is received without any error");
134: logWriter
135: .println("=> Send to Debuggee signal to continue and try to unload checked ObjectID...");
136: finalSyncMessage = null;
137: synchronizer
138: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
139: String messageFromDebuggee = synchronizer
140: .receiveMessageWithoutException("DisableCollectionDebuggee(#2)");
141: logWriter.println("==> debuggeeMsg = |" + messageFromDebuggee
142: + "|");
143: if (messageFromDebuggee.equals("Checked Object is UNLOADed!")) {
144: logWriter
145: .println("\n## FAILURE: Checked Object is UNLOADed after "
146: + this CommandName);
147: fail("Checked Object is UNLOADed after " + this CommandName);
148: } else {
149: logWriter
150: .println("\n=> PASSED: Checked Object is NOT UNLOADed after "
151: + this CommandName);
152: }
153:
154: logWriter.println("=> Send to Debuggee signal to funish ...");
155: synchronizer
156: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
157: logWriter.println("==> " + this TestName + " for "
158: + this CommandName + ": FINISH");
159:
160: assertAllDataRead(checkedReply);
161: }
162:
163: public static void main(String[] args) {
164: junit.textui.TestRunner.run(DisableCollectionTest.class);
165: }
166: }
|