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 Vitaly A. Provodin
021: * @version $Revision: 1.4 $
022: */
023:
024: /**
025: * Created on 28.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
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.jdwp.share.JDWPSyncTestCase;
033: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
034:
035: /**
036: * JDWP Unit test for VirtualMachine.DisposeObjects command.
037: */
038: public class DisposeObjectsTest extends JDWPSyncTestCase {
039:
040: static final String CHECKED_STRING = "Hello World!";
041:
042: protected String getDebuggeeClassName() {
043: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
044: }
045:
046: /**
047: * This testcase exercises VirtualMachine.DisposeObjects command.
048: * <BR>At first the test starts HelloWorld debuggee.
049: * <BR> Then the test performs VirtualMachine.CreateString command
050: * for some string and checks that VirtualMachine.DisposeObjects command
051: * for returned by CreateString command stringID with refCount = 0
052: * does not dispose that stringID - ObjectReference::ReferenceType
053: * command should return some referenceTypeID without any error.
054: * <BR>Then the test check that repeated VirtualMachine.DisposeObjects command
055: * with refCount = 1 disposes that stringID - ObjectReference::ReferenceType
056: * command should return INVALID_OBJECT error.
057: */
058: public void testDisposeObjects001() {
059: synchronizer
060: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
061:
062: CommandPacket packet = new CommandPacket(
063: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
064: JDWPCommands.VirtualMachineCommandSet.CreateStringCommand);
065: packet.setNextValueAsString(CHECKED_STRING);
066: logWriter.println("\tcreate string: " + CHECKED_STRING);
067: ReplyPacket reply = debuggeeWrapper.vmMirror
068: .performCommand(packet);
069:
070: long stringID = reply.getNextValueAsStringID();
071: logWriter.println("\tstring creared: stringID = " + stringID);
072:
073: logWriter
074: .println("\tsend DisposeObjects for created string with refCount = 0"
075: + " - string should not be disposed...");
076: packet = new CommandPacket(
077: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
078: JDWPCommands.VirtualMachineCommandSet.DisposeObjectsCommand);
079: packet.setNextValueAsInt(1);
080: packet.setNextValueAsObjectID(stringID);
081: packet.setNextValueAsInt(0);
082: reply = debuggeeWrapper.vmMirror.performCommand(packet);
083: checkReplyPacket(reply,
084: "VirtualMachine::DisposeObjects command");
085:
086: logWriter
087: .println("\tsend ObjectReference::ReferenceType command for created string"
088: + " to make sure that string is not disposed...");
089: packet = new CommandPacket(
090: JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
091: JDWPCommands.ObjectReferenceCommandSet.ReferenceTypeCommand);
092: packet.setNextValueAsObjectID(stringID);
093: reply = debuggeeWrapper.vmMirror.performCommand(packet);
094: checkReplyPacket(reply,
095: "ObjectReference::ReferenceType command");
096:
097: byte refTypeTag = reply.getNextValueAsByte();
098: long refTypeID = reply.getNextValueAsReferenceTypeID();
099: logWriter.println("\tReturned refTypeTag = " + refTypeTag + "("
100: + JDWPConstants.TypeTag.getName(refTypeTag) + ")");
101: logWriter.println("\tReturned ReferenceTypeID for string = "
102: + refTypeID);
103:
104: logWriter
105: .println("\tsend DisposeObjects for created string with refCount = 1"
106: + " - string should be disposed...");
107: packet = new CommandPacket(
108: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
109: JDWPCommands.VirtualMachineCommandSet.DisposeObjectsCommand);
110: packet.setNextValueAsInt(1);
111: packet.setNextValueAsObjectID(stringID);
112: packet.setNextValueAsInt(1);
113: reply = debuggeeWrapper.vmMirror.performCommand(packet);
114: checkReplyPacket(reply,
115: "VirtualMachine::DisposeObjects command");
116:
117: logWriter
118: .println("\tsend ObjectReference::ReferenceType command for disposed string"
119: + " - INVALID_OBJECT should be...");
120: packet = new CommandPacket(
121: JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
122: JDWPCommands.ObjectReferenceCommandSet.ReferenceTypeCommand);
123: packet.setNextValueAsObjectID(stringID);
124: reply = debuggeeWrapper.vmMirror.performCommand(packet);
125:
126: checkReplyPacket(reply,
127: "ObjectReference::ReferenceType command",
128: JDWPConstants.Error.INVALID_OBJECT);
129:
130: synchronizer
131: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
132: }
133:
134: public static void main(String[] args) {
135: junit.textui.TestRunner.run(DisposeObjectsTest.class);
136: }
137: }
|