1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /** 20 * @author Anatoly F. Bondarenko 21 */ 22 23 /** 24 * Created on 24.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.ReferenceType; 27 28 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 29 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 30 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 31 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 32 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 33 34 35 /** 36 * JDWP Unit test for ReferenceType.Interfaces command. 37 */ 38 public class InterfacesTest extends JDWPSyncTestCase { 39 40 static final int testStatusPassed = 0; 41 static final int testStatusFailed = -1; 42 static final String thisCommandName = "ReferenceType.Interfaces command"; 43 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/InterfacesDebuggee;"; 44 getDebuggeeClassName()45 protected String getDebuggeeClassName() { 46 return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.InterfacesDebuggee"; 47 } 48 49 /** 50 * This testcase exercises ReferenceType.Interfaces command. 51 * <BR>The test starts InterfacesDebuggee class, requests referenceTypeId 52 * for this class by VirtualMachine.ClassesBySignature command, then 53 * performs ReferenceType.Interfaces command and checks that returned 54 * list of interfaces corresponds to expected list. 55 */ testInterfaces001()56 public void testInterfaces001() { 57 String thisTestName = "testInterfaces001"; 58 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 59 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 60 61 String checkedClassSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/CheckedClass_Interfaces001;"; 62 long refTypeID = getClassIDBySignature(checkedClassSignature); 63 64 logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); 65 logWriter.println("=> Checked class = org.apache.harmony.jpda.tests.jdwp.ReferenceType.CheckedClass_Interfaces001"); 66 logWriter.println("=> referenceTypeID for Checked class = " + refTypeID); 67 logWriter.println("=> CHECK: send " + thisCommandName + " for Checked class and check reply..."); 68 69 CommandPacket checkedCommand = new CommandPacket( 70 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 71 JDWPCommands.ReferenceTypeCommandSet.InterfacesCommand); 72 checkedCommand.setNextValueAsReferenceTypeID(refTypeID); 73 ReplyPacket checkedReply = 74 debuggeeWrapper.vmMirror.performCommand(checkedCommand); 75 checkedCommand = null; 76 checkReplyPacket(checkedReply, thisCommandName); 77 78 int returnedInterfacesNumber = checkedReply.getNextValueAsInt(); 79 logWriter.println("=> Returned interfaces number = " + returnedInterfacesNumber); 80 81 String interfacesSignatures[] = { 82 "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/Interface_1_Interfaces001;", 83 "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/Interface_2_Interfaces001;", 84 }; 85 86 boolean interfacesFound[] = { 87 false, 88 false, 89 }; 90 91 int expectedInterfacesNumber = interfacesSignatures.length; 92 93 logWriter.println("=> CHECK for all expected interfaces..."); 94 for (int i=0; i < returnedInterfacesNumber; i++) { 95 logWriter.println("\n=> Check for returned interface[" + i + "] ..."); 96 long returnedInterfaceID = checkedReply.getNextValueAsReferenceTypeID(); 97 logWriter.println("=> RefTypeID of interface = " + returnedInterfaceID); 98 logWriter.println("=> Get signature for interface..."); 99 100 CommandPacket signatureCommand = new CommandPacket( 101 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 102 JDWPCommands.ReferenceTypeCommandSet.SignatureCommand); 103 signatureCommand.setNextValueAsReferenceTypeID(returnedInterfaceID); 104 ReplyPacket signatureReply = 105 debuggeeWrapper.vmMirror.performCommand(signatureCommand); 106 signatureCommand = null; 107 checkReplyPacket(signatureReply, "ReferenceType::Signature command"); 108 109 String returnedSignature = signatureReply.getNextValueAsString(); 110 logWriter.println("=> Signature of interface = " + returnedSignature); 111 signatureReply = null; 112 logWriter.println("=> Signature of interface = " + returnedSignature); 113 114 int k = 0; 115 for (; k < expectedInterfacesNumber; k++) { 116 if ( ! interfacesSignatures[k].equals(returnedSignature)) { 117 continue; 118 } 119 if ( interfacesFound[k] ) { 120 logWriter.println("\n## FAILURE: This interface is found repeatedly in the list"); 121 fail("This interface is found repeatedly in the list"); 122 break; 123 } 124 interfacesFound[k] = true; 125 break; 126 } 127 if ( k == expectedInterfacesNumber ) { 128 // returned interface is not found out in the list of expected interfaces 129 logWriter.println("\n## FAILURE: It is unexpected interface"); 130 fail("It is unexpected interface"); 131 } 132 } 133 for (int k=0; k < expectedInterfacesNumber; k++) { 134 if ( ! interfacesFound[k] ) { 135 logWriter.println 136 ("\n## FAILURE: Expected interface is NOT found in the returned list:"); 137 logWriter.println("=> Signature of interface = " + 138 interfacesSignatures[k]); 139 fail("Expected interface is NOT found in the returned list: " + 140 interfacesSignatures[k]); 141 } 142 } 143 144 assertAllDataRead(checkedReply); 145 146 logWriter.println 147 ("\n=> CHECK PASSED: All expected interfaces are found out"); 148 149 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 150 logWriter.println("\n==> " + thisTestName + " for " + thisCommandName + ": OK."); 151 } 152 } 153