15f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes/* 25f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * Licensed to the Apache Software Foundation (ASF) under one or more 35f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * contributor license agreements. See the NOTICE file distributed with 45f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * this work for additional information regarding copyright ownership. 55f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0 65f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * (the "License"); you may not use this file except in compliance with 75f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * the License. You may obtain a copy of the License at 85f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * 95f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 105f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * 115f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * Unless required by applicable law or agreed to in writing, software 125f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 135f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 145f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * 155f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * See the License for the specific language governing permissions and 165f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * limitations under the License. 175f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes */ 185f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 195f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes/** 205f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * @author Anatoly F. Bondarenko 215f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes */ 225f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 235f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes/** 245f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * Created on 04.03.2005 255f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes */ 265f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughespackage org.apache.harmony.jpda.tests.jdwp.ObjectReference; 275f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 285f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughesimport org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 295f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughesimport org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 305f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughesimport org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 315f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughesimport org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 325f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughesimport org.apache.harmony.jpda.tests.framework.jdwp.Value; 335f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughesimport org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 34c688942db58f6e3bed189c1e5416a010f20f8bb8Sebastien Hertzimport org.apache.harmony.jpda.tests.jdwp.share.JDWPTestConstants; 355f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughesimport org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 365f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 375f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 385f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes/** 395f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * JDWP Unit test for ObjectReference.EnableCollection command. 405f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes */ 415f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughespublic class EnableCollectionTest extends JDWPSyncTestCase { 425f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 435f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes static final int testStatusPassed = 0; 445f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes static final int testStatusFailed = -1; 455f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes static final String thisCommandName = "ObjectReference::EnableCollection command"; 465f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/EnableCollectionDebuggee;"; 475f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 485f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes protected String getDebuggeeClassName() { 495f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes return "org.apache.harmony.jpda.tests.jdwp.ObjectReference.EnableCollectionDebuggee"; 505f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes } 515f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 525f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes /** 535f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * This testcase exercises ObjectReference.EnableCollection command. 545f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * <BR>The test starts EnableCollectionDebuggee class, gets objectID 555f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * as value of static field of this class which (field) represents checked object. 565f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * Then for this objectID test executes ObjectReference::DisableCollection command 575f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * and ObjectReference.EnableCollection command. After that Debuggee tries to 585f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * unload checked object and checks if checked object is unloaded. 595f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes * <BR>If so the test passes. Otherwise it fails in case when pattern object is unloaded. 605f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes */ 615f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes public void testEnableCollection001() { 625f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes String thisTestName = "testEnableCollection001"; 635f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 645f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 655f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes finalSyncMessage = "TO_FINISH"; 665f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 675f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes long refTypeID = getClassIDBySignature(debuggeeSignature); 685f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 695f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); 705f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); 715f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 725f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println 735f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes ("=> Send ReferenceType::Fields command and get fieldID for field representing checked object..."); 745f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 755f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes long checkedFieldID = checkFields(refTypeID, new String[] { "checkedObject" })[0]; 765f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 775f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println 785f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes ("=> Send ReferenceType::GetValues command for received fieldID and get ObjectID to check..."); 795f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 805f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes CommandPacket getValuesCommand = new CommandPacket( 815f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 825f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); 835f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes getValuesCommand.setNextValueAsReferenceTypeID(refTypeID); 845f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes getValuesCommand.setNextValueAsInt(1); 855f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes getValuesCommand.setNextValueAsFieldID(checkedFieldID); 865f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 875f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand); 885f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes getValuesCommand = null; 895f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes checkReplyPacket(getValuesReply, "ReferenceType::GetValues command"); 905f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 915f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes int returnedValuesNumber = getValuesReply.getNextValueAsInt(); 925f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println("=> Returned values number = " + returnedValuesNumber); 935f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes assertEquals("Invalid number of values,", 1, returnedValuesNumber); 945f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 955f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes Value checkedObjectFieldValue = getValuesReply.getNextValueAsValue(); 965f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes byte checkedObjectFieldTag = checkedObjectFieldValue.getTag(); 975f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println("=> Returned field value tag for checked object= " + checkedObjectFieldTag 985f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes + "(" + JDWPConstants.Tag.getName(checkedObjectFieldTag) + ")"); 995f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes assertEquals("invalid value tag for checked object,", JDWPConstants.Tag.OBJECT_TAG, checkedObjectFieldTag 1005f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes , JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG) 1015f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes , JDWPConstants.Tag.getName(checkedObjectFieldTag)); 1025f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 1035f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes long checkedObjectID = checkedObjectFieldValue.getLongValue(); 1045f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println("=> Returned checked ObjectID = " + checkedObjectID); 1055f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 1065f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println 1075f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes ("\n=> Send ObjectReference::DisableCollection command for checked ObjectID..."); 1085f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 1095f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes CommandPacket disableCollectionCommand = new CommandPacket( 1105f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes JDWPCommands.ObjectReferenceCommandSet.CommandSetID, 1115f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes JDWPCommands.ObjectReferenceCommandSet.DisableCollectionCommand); 1125f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes disableCollectionCommand.setNextValueAsObjectID(checkedObjectID); 1135f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 1145f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes ReplyPacket disableCollectionReply = debuggeeWrapper.vmMirror.performCommand(disableCollectionCommand); 1155f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes disableCollectionCommand = null; 1165f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes checkReplyPacket(disableCollectionReply, "ObjectReference::DisableCollection command"); 1175f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 1185f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println 1195f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes ("\n=> CHECK: Send " + thisCommandName + " for checked ObjectID..."); 1205f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 1215f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes CommandPacket checkedCommand = new CommandPacket( 1225f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes JDWPCommands.ObjectReferenceCommandSet.CommandSetID, 1235f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes JDWPCommands.ObjectReferenceCommandSet.EnableCollectionCommand); 1245f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes checkedCommand.setNextValueAsObjectID(checkedObjectID); 1255f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 1265f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand); 1275f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes checkedCommand = null; 1285f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes checkReplyPacket(checkedReply, thisCommandName); 1295f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 1305f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println("=> CHECK: Reply is received without any error"); 1315f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 1325f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println("=> Send to Debuggee signal to continue and try to unload checked ObjectID..."); 1335f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes finalSyncMessage = null; 1345f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 1355f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes String messageFromDebuggee = synchronizer.receiveMessage(); 1365f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println 1375f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes ("\n=> Received message from Debuggee = \"" + messageFromDebuggee + "\"" ); 1385f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes if ( messageFromDebuggee.equals 1395f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes ("Checked Object is NOT UNLOADed; Pattern Object is UNLOADed;") ) { 1405f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println 1415f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes ("## FAILURE: Checked Object is NOT UNLOADed after " + thisCommandName ); 1425f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes fail("Checked Object is NOT UNLOADed after " + thisCommandName); 1435f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes } else { 1445f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println("=> PASSED: It is expected result" ); 1455f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes } 1465f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 1475f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes assertAllDataRead(checkedReply); 1485f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes 1495f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println("=> Send to Debuggee signal to funish ..."); 1505f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 1515f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH"); 1525f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes } 15337b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz 15437b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz /** 15537b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz * This testcase exercises ObjectReference.EnableCollection command. 15637b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz * <BR>The test starts EnableCollectionDebuggee class. Then attempts to 15737b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz * enable collection for an invalid objectID and checks no error is 15837b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz * returned. 15937b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz */ 160c688942db58f6e3bed189c1e5416a010f20f8bb8Sebastien Hertz public void testEnableCollection_invalid() { 16137b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 16237b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz 163c688942db58f6e3bed189c1e5416a010f20f8bb8Sebastien Hertz enableCollection(JDWPTestConstants.INVALID_OBJECT_ID, 164c688942db58f6e3bed189c1e5416a010f20f8bb8Sebastien Hertz JDWPConstants.Error.INVALID_OBJECT); 16537b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz 16637b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 16737b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz } 16837b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz 16937b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz /** 17037b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz * This testcase exercises ObjectReference.EnableCollection command. 17137b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz * <BR>The test starts EnableCollectionDebuggee class. Then attempts to 17237b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz * enable collection for for "null" object (id=0) and checks no error is 17337b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz * returned. 17437b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz */ 175c688942db58f6e3bed189c1e5416a010f20f8bb8Sebastien Hertz public void testEnableCollection_null() { 17637b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 17737b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz 178c688942db58f6e3bed189c1e5416a010f20f8bb8Sebastien Hertz enableCollection(JDWPTestConstants.NULL_OBJECT_ID, 179c688942db58f6e3bed189c1e5416a010f20f8bb8Sebastien Hertz JDWPConstants.Error.INVALID_OBJECT); 18037b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz 18137b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 18237b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz } 18337b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz 18437b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz private void enableCollection(long objectID, int expectedErrorCode) { 18537b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz CommandPacket command = new CommandPacket( 18637b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz JDWPCommands.ObjectReferenceCommandSet.CommandSetID, 18737b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz JDWPCommands.ObjectReferenceCommandSet.EnableCollectionCommand); 18837b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz command.setNextValueAsObjectID(objectID); 18937b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz 19037b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(command); 19137b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz checkReplyPacket(reply, thisCommandName, expectedErrorCode); 19237b95e332fe4d776e33e64f0fa1980fb4f7a83e0Sebastien Hertz } 1935f0a23683aa603d8c50b6dd071a565821b76067bElliott Hughes} 194