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 Viacheslav G. Rybalov
021: * @version $Revision: 1.4 $
022: */
023:
024: /**
025: * Created on 05.03.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ClassLoaderReference;
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 ClassLoaderReference.VisibleClasses command.
037: */
038: public class VisibleClassesTest extends JDWPSyncTestCase {
039:
040: /**
041: * Returns full name of debuggee class which is used by this test.
042: * @return full name of debuggee class.
043: */
044: protected String getDebuggeeClassName() {
045: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
046: }
047:
048: /**
049: * This testcase exercises ClassLoaderReference.VisibleClasses command.
050: * <BR>Starts <A HREF="../share/debuggee/HelloWorld.html">HelloWorld</A> debuggee.
051: * <BR>Then the following statements are checked:
052: * <BR>It is expected:
053: * <BR> - number of reference types has non-zero value;
054: * <BR> - refTypeTag takes one of the TypeTag constants: CLASS, INTERFACE, ARRAY;
055: * <BR> - All data were read;
056: */
057: public void testVisibleClasses001() {
058: synchronizer
059: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
060:
061: CommandPacket packet = new CommandPacket(
062: JDWPCommands.ClassLoaderReferenceCommandSet.CommandSetID,
063: JDWPCommands.ClassLoaderReferenceCommandSet.VisibleClassesCommand);
064: packet.setNextValueAsClassLoaderID(0);
065: ReplyPacket reply = debuggeeWrapper.vmMirror
066: .performCommand(packet);
067: checkReplyPacket(reply,
068: "ClassLoaderReference::VisibleClasses command");
069:
070: byte refTypeTag;
071: String refTypeTagName;
072: long typeID;
073: String msgLine;
074:
075: int classes = reply.getNextValueAsInt();
076: logWriter.println("Number of reference types = " + classes);
077: assertTrue("Invalid returned number of reference types = "
078: + classes, classes > 0);
079:
080: int printBound_1 = classes;
081: int printBound_2 = 0;
082: if (classes > 50) {
083: printBound_1 = 5;
084: printBound_2 = classes - 5;
085: }
086: for (int i = 0; i < classes; i++) {
087: refTypeTag = reply.getNextValueAsByte();
088: refTypeTagName = JDWPConstants.TypeTag.getName(refTypeTag);
089: msgLine = "" + i + ". refTypeTag = " + refTypeTagName
090: + "(" + refTypeTag + ")";
091: typeID = reply.getNextValueAsReferenceTypeID();
092: msgLine = msgLine + "; referenceTypeID = " + typeID;
093: if ((i < printBound_1) || (i >= printBound_2)) {
094: logWriter.println(msgLine);
095: if (i == (printBound_1 - 1)) {
096: logWriter.println("...\n...\n...");
097: }
098: }
099: assertTrue(
100: "Unexpected reference TagType:<" + refTypeTag + "("
101: + refTypeTagName + ")>",
102: refTypeTag == JDWPConstants.TypeTag.ARRAY
103: || refTypeTag == JDWPConstants.TypeTag.CLASS
104: || refTypeTag == JDWPConstants.TypeTag.INTERFACE);
105: }
106:
107: assertAllDataRead(reply);
108: synchronizer
109: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
110: }
111:
112: /**
113: * Starts this test by junit.textui.TestRunner.run() method.
114: */
115: public static void main(String[] args) {
116: junit.textui.TestRunner.run(VisibleClassesTest.class);
117: }
118: }
|