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