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