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 Anton V. Karnachuk
21  */
22 
23 /**
24  * Created on 11.02.2005
25  */
26 package org.apache.harmony.jpda.tests.jdwp.ClassType;
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 
34 
35 /**
36  * Super class of some JDWP unit tests for JDWP ClassType command set.
37  */
38 public class JDWPClassTypeTestCase extends JDWPSyncTestCase {
39 
40     /**
41      * Returns full name of debuggee class which is used by
42      * testcases in this test.
43      * @return full name of debuggee class.
44      */
getDebuggeeClassName()45     protected String getDebuggeeClassName() {
46         return "org.apache.harmony.jpda.tests.jdwp.ClassType.ClassTypeDebuggee";
47     }
48 
49     /**
50      * Returns signature of debuggee class which is used by
51      * testcases in this test.
52      * @return signature of debuggee class.
53      */
getDebuggeeSignature()54     protected String getDebuggeeSignature() {
55       return "Lorg/apache/harmony/jpda/tests/jdwp/ClassType/ClassTypeDebuggee;";
56     }
57 
58     class FieldInfo {
59         private long fieldID;
60         private String name;
61         private String signature;
62         private int modBits;
63 
64         /**
65          * @return Returns the fieldID.
66          */
getFieldID()67         public long getFieldID() {
68             return fieldID;
69         }
70 
71         /**
72          * @return Returns the modBits.
73          */
getModBits()74         public int getModBits() {
75             return modBits;
76         }
77 
78         /**
79          * @return Returns the name.
80          */
getName()81         public String getName() {
82             return name;
83         }
84 
85         /**
86          * @return Returns the signature.
87          */
getSignature()88         public String getSignature() {
89             return signature;
90         }
91 
FieldInfo(long fieldID, String name, String signature, int modBits)92         public FieldInfo(long fieldID, String name, String signature,
93                 int modBits) {
94             super();
95             this.fieldID = fieldID;
96             this.name = name;
97             this.signature = signature;
98             this.modBits = modBits;
99         }
100 
toString()101         public String toString() {
102             return "fieldID=" + fieldID + "; name='" + name + "'; signature='" + signature
103             + "'; modbits=" + modBits;
104         }
105 
106     }
107 
108     /**
109      * Returns for specified class array with information about fields of this class.
110      * <BR>Each element of array contains:
111      * <BR>Field ID, Field name, Field signature, Field modifier bit flags;
112      * @param refType - ReferenceTypeID, defining class.
113      * @return array with information about fields.
114      */
jdwpGetFields(long refType)115     protected FieldInfo[] jdwpGetFields(long refType) {
116         CommandPacket packet = new CommandPacket(
117                 JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
118                 JDWPCommands.ReferenceTypeCommandSet.FieldsCommand);
119         packet.setNextValueAsReferenceTypeID(refType);
120 
121         ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
122         assertTrue(reply.getErrorCode() == JDWPConstants.Error.NONE);
123 
124         int declared = reply.getNextValueAsInt();
125         FieldInfo[] fields = new FieldInfo[declared];
126         for (int i = 0; i < declared; i++) {
127             fields[i] =
128                 new FieldInfo(reply.getNextValueAsFieldID(),
129                               reply.getNextValueAsString(),
130                               reply.getNextValueAsString(),
131                               reply.getNextValueAsInt());
132         }
133         return fields;
134     }
135 
136 }