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 05.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.IsCollected command.
038: */
039: public class IsCollectedTest extends JDWPSyncTestCase {
040:
041: static final String this CommandName = "ObjectReference.IsCollected command";
042:
043: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/IsCollectedDebuggee;";
044:
045: protected String getDebuggeeClassName() {
046: return "org.apache.harmony.jpda.tests.jdwp.ObjectReference.IsCollectedDebuggee";
047: }
048:
049: /**
050: * This test exercises ObjectReference.IsCollected command.
051: * <BR>The test starts IsCollectedDebuggee class, gets two
052: * objectIDs as value of static fields of this class which (fields)
053: * represent two checked objects. Then for the first objectID test executes
054: * ObjectReference.DisableCollection command. After that Debuggee tries to
055: * unload checked objects. Then the test executes
056: * ObjectReference.IsCollected commands for both checked objects and checks
057: * replies.
058: */
059: public void testIsCollected001() {
060: String this TestName = "testIsCollected001";
061: logWriter.println("==> " + this TestName + " for "
062: + this CommandName + ": START...");
063: String failMessage = "";
064: synchronizer
065: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
066: finalSyncMessage = "TO_FINISH";
067:
068: long refTypeID = getClassIDBySignature(debuggeeSignature);
069:
070: logWriter.println("=> Debuggee class = "
071: + getDebuggeeClassName());
072: logWriter.println("=> referenceTypeID for Debuggee class = "
073: + refTypeID);
074:
075: String checkedFieldNames[] = { "checkedObject_01",
076: "checkedObject_02", };
077: long checkedFieldIDs[] = checkFields(refTypeID,
078: checkedFieldNames);
079: long checkedField_01ID = checkedFieldIDs[0];
080: long checkedField_02ID = checkedFieldIDs[1];
081:
082: logWriter
083: .println("=> Send ReferenceType::GetValues command for received fieldIDs and get ObjectIDs to check...");
084:
085: CommandPacket getValuesCommand = new CommandPacket(
086: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
087: JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
088: getValuesCommand.setNextValueAsReferenceTypeID(refTypeID);
089: getValuesCommand.setNextValueAsInt(2);
090: getValuesCommand.setNextValueAsFieldID(checkedField_01ID);
091: getValuesCommand.setNextValueAsFieldID(checkedField_02ID);
092:
093: ReplyPacket getValuesReply = debuggeeWrapper.vmMirror
094: .performCommand(getValuesCommand);
095: getValuesCommand = null;
096: checkReplyPacket(getValuesReply,
097: "ReferenceType::GetValues command");
098:
099: int returnedValuesNumber = getValuesReply.getNextValueAsInt();
100: logWriter.println("=> Returned values number = "
101: + returnedValuesNumber);
102: assertEquals("Invalid number of values,", 2,
103: returnedValuesNumber);
104:
105: Value checkedObjectFieldValue = getValuesReply
106: .getNextValueAsValue();
107: byte checkedObjectFieldTag = checkedObjectFieldValue.getTag();
108: logWriter
109: .println("=> Returned field value tag for checkedObject_01 = "
110: + checkedObjectFieldTag
111: + "("
112: + JDWPConstants.Tag
113: .getName(checkedObjectFieldTag) + ")");
114: assertEquals(
115: "Invalid value tag for checkedObject_01",
116: JDWPConstants.Tag.OBJECT_TAG,
117: checkedObjectFieldTag,
118: JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
119: JDWPConstants.Tag.getName(checkedObjectFieldTag));
120:
121: long checkedObject_01ID = checkedObjectFieldValue
122: .getLongValue();
123: logWriter
124: .println("=> Returned ObjectID for checkedObject_01 = "
125: + checkedObject_01ID);
126:
127: checkedObjectFieldValue = getValuesReply.getNextValueAsValue();
128: checkedObjectFieldTag = checkedObjectFieldValue.getTag();
129: logWriter
130: .println("=> Returned field value tag for checkedObject_02 = "
131: + checkedObjectFieldTag
132: + "("
133: + JDWPConstants.Tag
134: .getName(checkedObjectFieldTag) + ")");
135: assertEquals(
136: "Invalid value tag for checkedObject_02",
137: JDWPConstants.Tag.OBJECT_TAG,
138: checkedObjectFieldTag,
139: JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
140: JDWPConstants.Tag.getName(checkedObjectFieldTag));
141:
142: long checkedObject_02ID = checkedObjectFieldValue
143: .getLongValue();
144: logWriter
145: .println("=> Returned ObjectID for checkedObject_02 = "
146: + checkedObject_02ID);
147:
148: logWriter
149: .println("\n=> Send ObjectReference::DisableCollection command for checkedObject_01...");
150:
151: CommandPacket disableCollectionCommand = new CommandPacket(
152: JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
153: JDWPCommands.ObjectReferenceCommandSet.DisableCollectionCommand);
154: disableCollectionCommand
155: .setNextValueAsObjectID(checkedObject_01ID);
156:
157: ReplyPacket disableCollectionReply = debuggeeWrapper.vmMirror
158: .performCommand(disableCollectionCommand);
159: disableCollectionCommand = null;
160: checkReplyPacket(disableCollectionReply,
161: "ObjectReference::DisableCollection command");
162:
163: logWriter
164: .println("=> Send to Debuggee signal to continue and try to unload checked objects...");
165: finalSyncMessage = null;
166: synchronizer
167: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
168: String messageFromDebuggee = synchronizer.receiveMessage();
169: logWriter.println("\n=> Received message from Debuggee = \""
170: + messageFromDebuggee + "\"");
171:
172: logWriter.println("\n=> Send " + this CommandName
173: + " for checkedObject_01 and check reply...");
174:
175: CommandPacket checkedCommand = new CommandPacket(
176: JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
177: JDWPCommands.ObjectReferenceCommandSet.IsCollectedCommand);
178: checkedCommand.setNextValueAsObjectID(checkedObject_01ID);
179:
180: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
181: .performCommand(checkedCommand);
182: checkedCommand = null;
183: checkReplyPacket(checkedReply, this CommandName);
184:
185: boolean checkedObject_01_IsCollected = checkedReply
186: .getNextValueAsBoolean();
187: logWriter.println("=> IsCollected for checkedObject_01 = "
188: + checkedObject_01_IsCollected);
189:
190: if (messageFromDebuggee
191: .indexOf("checkedObject_01 is UNLOADed;") != -1) {
192: if (!checkedObject_01_IsCollected) {
193: logWriter
194: .println("## FAILURE: Unexpected result for checkedObject_01 of "
195: + this CommandName + ":");
196: logWriter
197: .println("## checkedObject_01 is UNLOADed so IsCollected must be 'true'");
198: failMessage = failMessage
199: + "Unexpected result for checkedObject_01 of "
200: + this CommandName + "\n";
201: }
202: } else {
203: if (checkedObject_01_IsCollected) {
204: logWriter
205: .println("## FAILURE: Unexpected result for checkedObject_01 of "
206: + this CommandName + ":");
207: logWriter
208: .println("## checkedObject_01 is NOT UNLOADed so IsCollected must be 'false'");
209: failMessage = failMessage
210: + "Unexpected result for checkedObject_01 of "
211: + this CommandName + "\n";
212: }
213: }
214:
215: logWriter.println("=> PASSED for checkedObject_01");
216:
217: logWriter.println("\n=> Send " + this CommandName
218: + " for checkedObject_02 and check reply...");
219:
220: checkedCommand = new CommandPacket(
221: JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
222: JDWPCommands.ObjectReferenceCommandSet.IsCollectedCommand);
223: checkedCommand.setNextValueAsObjectID(checkedObject_02ID);
224:
225: checkedReply = debuggeeWrapper.vmMirror
226: .performCommand(checkedCommand);
227: checkedCommand = null;
228: checkReplyPacket(checkedReply, this CommandName);
229:
230: boolean checkedObject_02_IsCollected = checkedReply
231: .getNextValueAsBoolean();
232: logWriter.println("=> IsCollected for checkedObject_02 = "
233: + checkedObject_02_IsCollected);
234:
235: if (messageFromDebuggee
236: .indexOf("checkedObject_02 is UNLOADed;") != -1) {
237: if (!checkedObject_02_IsCollected) {
238: logWriter
239: .println("## FAILURE: Unexpected result for checkedObject_02 of "
240: + this CommandName + ":");
241: logWriter
242: .println("## checkedObject_02 is UNLOADed so IsCollected must be 'true'");
243: failMessage = failMessage
244: + "Unexpected result for checkedObject_02 of "
245: + this CommandName + "\n";
246: }
247: } else {
248: if (checkedObject_02_IsCollected) {
249: logWriter
250: .println("## FAILURE: Unexpected result for checkedObject_02 of "
251: + this CommandName + ":");
252: logWriter
253: .println("## checkedObject_02 is NOT UNLOADed so IsCollected must be 'false'");
254: failMessage = failMessage
255: + "Unexpected result for checkedObject_02 of "
256: + this CommandName + "\n";
257: }
258: }
259:
260: logWriter.println("=> PASSED for checkedObject_02");
261: logWriter.println("=> Send to Debuggee signal to funish ...");
262: synchronizer
263: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
264: logWriter.println("==> " + this TestName + " for "
265: + this CommandName + ": FINISH");
266:
267: if (failMessage.length() > 0) {
268: fail(failMessage);
269: }
270:
271: assertAllDataRead(checkedReply);
272: }
273:
274: public static void main(String[] args) {
275: junit.textui.TestRunner.run(IsCollectedTest.class);
276: }
277: }
|