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 09.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.ClassesBySignature command.
38  */
39 public class ClassesBySignatureTest extends JDWPSyncTestCase {
40 
41     static final String SIGNATURE001 = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld;";
42 
getDebuggeeClassName()43     protected String getDebuggeeClassName() {
44         return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
45     }
46 
47     /**
48      * This testcase exercises VirtualMachine.ClassesBySignature command.
49      * <BR>At first the test starts HelloWorld debuggee.
50      * <BR> Then the test performs VirtualMachine.ClassesBySignature command
51      * for signature of HelloWorld class and checks that:
52      * <BR>&nbsp;&nbsp; - number of returned reference types is equal to 1;
53      * <BR>&nbsp;&nbsp; - the JDWP command ReferenceType.Signature for
54      * returned referenceTypeID returns the expected string signature;
55      * <BR>&nbsp;&nbsp; - there are no extra data in the reply packet;
56      */
testClassesBySignature001()57     public void testClassesBySignature001() {
58         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
59 
60         CommandPacket packet = new CommandPacket(
61                 JDWPCommands.VirtualMachineCommandSet.CommandSetID,
62                 JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand);
63         packet.setNextValueAsString(SIGNATURE001);
64 
65         ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
66         checkReplyPacket(reply, "VirtualMachine::ClassesBySignature command");
67 
68         byte refTypeTag;
69         long typeID;
70         String signature;
71         int status;
72         ReplyPacket replySignature;
73 
74         int classes = reply.getNextValueAsInt();
75         logWriter.println("Number of reference types = " + classes);
76         if (classes != 1) {
77             logWriter.printError("Wrong Number of reference types");
78             //assertEquals(1, classes);
79             fail("Wrong Number of reference types");
80         }
81 
82         for (int i = 0; i < classes; i++) {
83 
84             refTypeTag = reply.getNextValueAsByte();
85             typeID = reply.getNextValueAsReferenceTypeID();
86             status = reply.getNextValueAsInt();
87 
88             logWriter.println("\trefTypeTag = "
89                     + JDWPConstants.TypeTag.getName(refTypeTag)
90                     + "(" + refTypeTag + ")");
91             if (JDWPConstants.TypeTag.CLASS != refTypeTag) {
92                 printErrorAndFail("refTypeTag must be "
93                         + JDWPConstants.TypeTag.getName(JDWPConstants.TypeTag.CLASS)
94                         + "(" + JDWPConstants.TypeTag.CLASS + ")");
95             }
96 
97             packet = new CommandPacket(
98                     JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
99                     JDWPCommands.ReferenceTypeCommandSet.SignatureCommand);
100             packet.setNextValueAsReferenceTypeID(typeID);
101 
102             replySignature = debuggeeWrapper.vmMirror.performCommand(packet);
103             signature = replySignature.getNextValueAsString();
104 
105             logWriter.println("\ttypeID = " + typeID + "(" + signature + ")");
106             if (!SIGNATURE001.equals(signature)) {
107                 printErrorAndFail("Signature must be " + SIGNATURE001);
108             }
109 
110             logWriter.println("\tstatus = "
111                     + JDWPConstants.ClassStatus.getName(status)
112                     + "(" + status + ")");
113         }
114         assertAllDataRead(reply);
115         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
116     }
117 }
118