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 14.02.2005
25 */
26package org.apache.harmony.jpda.tests.jdwp.Method;
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;
33
34
35public class JDWPMethodTestCase extends JDWPSyncTestCase {
36
37    protected String getDebuggeeClassName() {
38        return MethodDebuggee.class.getName();
39    }
40
41    static class MethodInfo {
42        private long methodID;
43        private String name;
44        private String signature;
45        private int modBits;
46
47        public MethodInfo(long methodID, String name, String signature,
48                int modBits) {
49            super();
50            this.methodID = methodID;
51            this.name = name;
52            this.signature = signature;
53            this.modBits = modBits;
54        }
55
56        /**
57         * @return Returns the methodID.
58         */
59        public long getMethodID() {
60            return methodID;
61        }
62        /**
63         * @return Returns the modBits.
64         */
65        public int getModBits() {
66            return modBits;
67        }
68        /**
69         * @return Returns the name.
70         */
71        public String getName() {
72            return name;
73        }
74        /**
75         * @return Returns the signature.
76         */
77        public String getSignature() {
78            return signature;
79        }
80        public String toString() {
81            return ""+methodID+" "+name+" "+signature+" "+modBits;
82        }
83
84    }
85
86    protected MethodInfo[] jdwpGetMethodsInfo(long classID) {
87
88        CommandPacket packet = new CommandPacket(
89                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
90                JDWPCommands.ReferenceTypeCommandSet.MethodsCommand);
91        packet.setNextValueAsClassID(classID);
92        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
93
94        assertTrue(reply.getErrorCode() == JDWPConstants.Error.NONE);
95        int declared = reply.getNextValueAsInt();
96
97        MethodInfo[] methodsInfo = new MethodInfo[declared];
98        for (int i = 0; i < declared; i++) {
99            methodsInfo[i] = new MethodInfo(
100                reply.getNextValueAsMethodID(),
101                reply.getNextValueAsString(),
102                reply.getNextValueAsString(),
103                reply.getNextValueAsInt()
104            );
105        }
106        return methodsInfo;
107    }
108}
109