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 Viacheslav G. Rybalov 21 */ 22 23/** 24 * Created on 05.03.2005 25 */ 26package org.apache.harmony.jpda.tests.jdwp.ClassLoaderReference; 27 28import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 29import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 30import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 31import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 32import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 33import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 34 35 36/** 37 * JDWP unit test for ClassLoaderReference.VisibleClasses command. 38 */ 39public class VisibleClassesTest extends JDWPSyncTestCase { 40 41 /** 42 * Returns full name of debuggee class which is used by this test. 43 * @return full name of debuggee class. 44 */ 45 @Override 46 protected String getDebuggeeClassName() { 47 return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld"; 48 } 49 50 /** 51 * This testcase exercises ClassLoaderReference.VisibleClasses command. 52 * <BR>Starts <A HREF="../share/debuggee/HelloWorld.html">HelloWorld</A> debuggee. 53 * <BR>Then the following statements are checked: 54 * <BR>It is expected: 55 * <BR> - number of reference types has non-zero value; 56 * <BR> - refTypeTag takes one of the TypeTag constants: CLASS, INTERFACE, ARRAY; 57 * <BR> - All data were read; 58 */ 59 public void testVisibleClasses001() { 60 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 61 62 CommandPacket packet = new CommandPacket( 63 JDWPCommands.ClassLoaderReferenceCommandSet.CommandSetID, 64 JDWPCommands.ClassLoaderReferenceCommandSet.VisibleClassesCommand); 65 packet.setNextValueAsClassLoaderID(0); 66 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 67 checkReplyPacket(reply, "ClassLoaderReference::VisibleClasses command"); 68 69 byte refTypeTag; 70 String refTypeTagName; 71 long typeID; 72 String msgLine; 73 74 int classes = reply.getNextValueAsInt(); 75 logWriter.println("Number of reference types = " + classes); 76 assertTrue("Invalid returned number of reference types = " + classes, classes > 0); 77 78 int printBound_1 = classes; 79 int printBound_2 = 0; 80 if (classes > 50) { 81 printBound_1 = 5; 82 printBound_2 = classes - 5; 83 } 84 for (int i = 0; i < classes; i++) { 85 refTypeTag = reply.getNextValueAsByte(); 86 refTypeTagName = JDWPConstants.TypeTag.getName(refTypeTag); 87 msgLine = "" + i + ". refTypeTag = " + refTypeTagName + "(" + refTypeTag + ")"; 88 typeID = reply.getNextValueAsReferenceTypeID(); 89 msgLine = msgLine + "; referenceTypeID = " + typeID; 90 if ( (i < printBound_1) || (i >= printBound_2) ) { 91 logWriter.println(msgLine); 92 if ( i == (printBound_1 - 1) ) { 93 logWriter.println("...\n...\n..."); 94 } 95 } 96 assertTrue("Unexpected reference TagType:<" + refTypeTag + "(" + refTypeTagName + ")>", 97 refTypeTag == JDWPConstants.TypeTag.ARRAY 98 || refTypeTag == JDWPConstants.TypeTag.CLASS 99 || refTypeTag == JDWPConstants.TypeTag.INTERFACE); 100 } 101 102 assertAllDataRead(reply); 103 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 104 } 105} 106