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 Vitaly A. Provodin 21 */ 22 23 /** 24 * Created on 10.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.VirtualMachine; 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.JDWPConstants; 31 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 32 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 33 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 34 35 36 /** 37 * JDWP Unit test for VirtualMachine.AllClassesWithGeneric command. 38 */ 39 public class AllClassesWithGenericTest extends JDWPSyncTestCase { 40 getDebuggeeClassName()41 protected String getDebuggeeClassName() { 42 return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld"; 43 } 44 45 /** 46 * This testcase exercises VirtualMachine.AllClassesWithGeneric command. 47 * <BR>At first the test starts HelloWorld debuggee. 48 * <BR> Then the test performs VirtualMachine.AllClassesWithGeneric 49 * command and checks that: 50 * <BR> - number of reference types returned by command has 51 * non-zero value; 52 * <BR> - there are no classes with the 'ARRAY' or 53 * 'PRIMITIVE' bits in the status flag; 54 */ testAllClassesWithGeneric002()55 public void testAllClassesWithGeneric002() { 56 logWriter.println("==> testAllClassesWithGeneric002: START..."); 57 58 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 59 60 logWriter.println("==> Send VirtualMachine::AllClassesWithGeneric command..."); 61 CommandPacket packet = new CommandPacket( 62 JDWPCommands.VirtualMachineCommandSet.CommandSetID, 63 JDWPCommands.VirtualMachineCommandSet.AllClassesWithGenericCommand); 64 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 65 checkReplyPacket(reply, "VirtualMachine::AllClassesWithGeneric command"); 66 67 long typeID; 68 String signature, genericSignature; 69 int status; 70 71 int classes = reply.getNextValueAsInt(); 72 assertTrue(classes > 0); 73 74 int count = 0; 75 for (int i = 0; i < classes; i++) { 76 77 reply.getNextValueAsByte(); 78 typeID = reply.getNextValueAsReferenceTypeID(); 79 signature = reply.getNextValueAsString(); 80 genericSignature = reply.getNextValueAsString(); 81 status = reply.getNextValueAsInt(); 82 83 if ( (status & JDWPConstants.ClassStatus.ARRAY) != 0 ){ 84 logWriter.println("## FAILURE: Unexpected status is returned:"); 85 logWriter.println("## ReferenceTypeId = " + typeID); 86 logWriter.println("## Class signature: " + signature); 87 logWriter.println("## Class generic signature: " + genericSignature); 88 logWriter.println("## Class status = 0x" + Integer.toHexString(status) 89 + "(" + JDWPConstants.ClassStatus.getName(status)+ ")"); 90 logWriter.println("## Status \"0x" 91 + Integer.toHexString(JDWPConstants.ClassStatus.ARRAY) 92 + "(" 93 + JDWPConstants.ClassStatus.getName(JDWPConstants.ClassStatus.ARRAY) 94 + ")\" must NOT be returned!"); 95 count++; 96 } 97 if ( (status & JDWPConstants.ClassStatus.PRIMITIVE) != 0 ){ 98 logWriter.println("## FAILURE: Unexpected status is returned:"); 99 logWriter.println("## ReferenceTypeId = " + typeID); 100 logWriter.println("## Class signature: " + signature); 101 logWriter.println("## Class generic signature: " + genericSignature); 102 logWriter.println("## Class status = 0x" + Integer.toHexString(status) 103 + "(" + JDWPConstants.ClassStatus.getName(status)+ ")"); 104 logWriter.println("## Status \"0x" 105 + Integer.toHexString(JDWPConstants.ClassStatus.PRIMITIVE) 106 + "(" 107 + JDWPConstants.ClassStatus.getName(JDWPConstants.ClassStatus.PRIMITIVE) 108 + ")\" must NOT be returned!"); 109 count++; 110 } 111 } 112 assertEquals("count must be 0", 0, count); 113 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 114 logWriter.println("==> testAllClassesWithGeneric002: OK."); 115 } 116 117 /** 118 * This testcase exercises VirtualMachine.AllClassesWithGeneric command. 119 * <BR>At first the test starts HelloWorld debuggee. 120 * <BR> Then the test performs VirtualMachine.AllClassesWithGeneric 121 * command and checks that: 122 * <BR> - number of reference types returned by command has 123 * non-zero value; 124 * <BR> - refTypeTag takes one of the TypeTag constants: 125 * 'CLASS', 'INTERFACE', 'ARRAY'; 126 * <BR> - length of the signature string is not zero and starts with 'L' or 127 * '[' symbols; 128 * <BR> - signature of at least one class contains the "HelloWorld" string; 129 * <BR> - All data were read from reply packet; 130 */ testAllClassesWithGeneric001()131 public void testAllClassesWithGeneric001() { 132 133 logWriter.println("==> testAllClassesWithGeneric001: START..."); 134 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 135 136 logWriter.println("==> Send VirtualMachine::AllClassesWithGeneric command..."); 137 CommandPacket packet = new CommandPacket( 138 JDWPCommands.VirtualMachineCommandSet.CommandSetID, 139 JDWPCommands.VirtualMachineCommandSet.AllClassesWithGenericCommand); 140 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 141 checkReplyPacket(reply, "VirtualMachine::AllClassesWithGeneric command"); 142 143 byte refTypeTag; 144 String refTypeTagName; 145 long typeID; 146 String signature, genericSignature; 147 int status; 148 String msgLine; 149 boolean flagForHelloWorld = false; 150 151 int classes = reply.getNextValueAsInt(); 152 logWriter.println("==> Number of reference types = " + classes); 153 assertTrue("VirtualMachine::AllClassesWithGeneric command returned invalid number of classes: " + classes, 154 classes > 0); 155 156 int printBound_1 = classes; 157 int printBound_2 = 0; 158 if ( classes > 50 ) { 159 printBound_1 = 5; 160 printBound_2 = classes - 5; 161 } 162 for (int i = 0; i < classes; i++) { 163 164 boolean infoIsPrinted = false; 165 refTypeTag = reply.getNextValueAsByte(); 166 try { 167 refTypeTagName = JDWPConstants.TypeTag.getName(refTypeTag); 168 } catch ( Throwable thrown ) { 169 refTypeTagName = "UnknownTagName"; 170 } 171 msgLine = "\n" + i + ". " + refTypeTagName; 172 typeID = reply.getNextValueAsReferenceTypeID(); 173 signature = reply.getNextValueAsString(); 174 msgLine = msgLine + ": " + signature; 175 genericSignature = reply.getNextValueAsString(); 176 status = reply.getNextValueAsInt(); 177 msgLine = msgLine + " " + JDWPConstants.ClassStatus.getName(status); 178 if ( (i < printBound_1) || (i >= printBound_2) ) { 179 logWriter.println(msgLine); 180 logWriter.println("\treferenceTypeID = " + typeID); 181 logWriter.println("\trefTypeTag = " + refTypeTagName 182 + "(" + refTypeTag + ")"); 183 logWriter.println("\tsignature = " + signature); 184 logWriter.println("\tgenericSignature = " + genericSignature); 185 if ( i == (printBound_1-1) ) { 186 logWriter.println("...\n...\n..."); 187 } 188 infoIsPrinted = true; 189 } 190 191 try { 192 assertTrue(refTypeTag == JDWPConstants.TypeTag.ARRAY 193 || refTypeTag == JDWPConstants.TypeTag.CLASS 194 || refTypeTag == JDWPConstants.TypeTag.INTERFACE); 195 196 assertTrue(signature.length() > 0); 197 assertTrue(signature.toCharArray()[0] == 'L' 198 || signature.toCharArray()[0] == '['); 199 } catch ( Throwable thrown) { 200 // some assert is caught 201 if ( !infoIsPrinted ) { 202 logWriter.println(msgLine); 203 logWriter.println("\treferenceTypeID = " + typeID); 204 logWriter.println("\trefTypeTag = " + refTypeTagName 205 + "(" + refTypeTag + ")"); 206 logWriter.println("\tsignature = " + signature ); 207 logWriter.println("\tgenericSignature = " + genericSignature); 208 } 209 logWriter.println("## FAILURE is found out for this referenceType!\n"); 210 assertTrue("Unexpected refTypeTag", 211 refTypeTag == JDWPConstants.TypeTag.ARRAY 212 || refTypeTag == JDWPConstants.TypeTag.CLASS 213 || refTypeTag == JDWPConstants.TypeTag.INTERFACE); 214 215 assertTrue("Invalid signature", 216 signature.length() > 0); 217 assertTrue("Invalid signature", 218 signature.toCharArray()[0] == 'L' 219 || signature.toCharArray()[0] == '['); 220 } 221 if (signature.indexOf("HelloWorld") != -1) 222 flagForHelloWorld = true; 223 } 224 225 assertAllDataRead(reply); 226 assertTrue("HelloWorld has not been found in signatures of returned reference types", flagForHelloWorld); 227 228 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 229 logWriter.println("==> testAllClassesWithGeneric001: OK."); 230 } 231 } 232