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 package org.apache.harmony.jpda.tests.jdwp.Events;
20 
21 import java.io.IOException;
22 
23 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
24 import org.apache.harmony.jpda.tests.share.SyncDebuggee;
25 
26 public class MethodExitWithReturnValueDebuggee extends SyncDebuggee {
27 
28     public static final String BOOLEAN_TYPE = "BOOLEAN";
29 
30     public static final String SHORT_TYPE = "SHORT";
31 
32     public static final String CHAR_TYPE = "CHAR";
33 
34     public static final String INT_TYPE = "INT";
35 
36     public static final String LONG_TYPE = "LONG";
37 
38     public static final String DOUBLE_TYPE = "DOUBLE";
39 
40     public static final String EXCEPTION_TYPE = "EXCEPTION";
41 
42     public static final boolean EXPECTED_BOOLEAN = true;
43 
44     public static final short EXPECTED_SHORT = 2;
45 
46     public static final char EXPECTED_CHAR = 'B';
47 
48     public static final int EXPECTED_INT = 230;
49 
50     public static final long EXPECTED_LONG = 0523l;
51 
52     public static final double EXPECTED_DOUBLE = 5.23d;
53 
54     public static final Object EXPECTED_OBJECT = new MethodExitWithReturnValueDebuggee();
55 
56     public static final String VOID_TYPE = "VOID";
57 
main(String[] args)58     public static void main(String[] args) {
59         runDebuggee(MethodExitWithReturnValueDebuggee.class);
60     }
61 
62     /*
63      * tested methods with different return values
64      */
65 
booleanMethod()66     public boolean booleanMethod() {
67         logWriter.println("--> calling booleanMethod()");
68         return EXPECTED_BOOLEAN;
69     }
70 
shortMethod()71     public short shortMethod() {
72         logWriter.println("--> calling shortMethod()");
73         return EXPECTED_SHORT;
74     }
75 
charMethod()76     public char charMethod() {
77         logWriter.println("--> calling charMethod()");
78         return EXPECTED_CHAR;
79     }
80 
intMethod()81     public int intMethod() {
82         logWriter.println("--> calling intMethod()");
83         return EXPECTED_INT;
84     }
85 
longMethod()86     public long longMethod() {
87         logWriter.println("--> calling longMethod()");
88         return EXPECTED_LONG;
89     }
90 
doubleMethod()91     public double doubleMethod() {
92         logWriter.println("--> calling doubleMethod()");
93         return EXPECTED_DOUBLE;
94     }
95 
voidMethod()96     public void voidMethod() {
97         logWriter.println("--> calling voidMethod()");
98     }
99 
run()100     public void run() {
101         logWriter.println("--> MethodExitWithReturnValueDebuggee started");
102         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
103 
104         // Receive required method type
105         String type = synchronizer.receiveMessage();
106         logWriter.println("--> invoke method's return type is:" + type);
107 
108         // Invoke desired method
109         if(type.equals(BOOLEAN_TYPE)){
110             boolean b = booleanMethod();
111             logWriter.println("--> booleanMethod() is invoked, return value:" + b);
112         }else if(type.equals(SHORT_TYPE)){
113             short s = shortMethod();
114             logWriter.println("--> shortMethod() is invoked, return value:" + s);
115         }else if(type.equals(CHAR_TYPE)){
116             char c = charMethod();
117             logWriter.println("--> charMethod() is invoked, return value:" + c);
118         }else if(type.equals(INT_TYPE)){
119             int i = intMethod();
120             logWriter.println("--> intMethod() is invoked, return value:" + i);
121         }else if(type.equals(LONG_TYPE)){
122             long l = longMethod();
123             logWriter.println("--> longMethod() is invoked, return value:" + l);
124         }else if(type.equals(DOUBLE_TYPE)){
125             double d = doubleMethod();
126             logWriter.println("--> doubleMethod() is invoked, return value:" + d);
127         } else if (type.equals(VOID_TYPE)) {
128             voidMethod();
129             logWriter.println("--> voidMethod() is invoked");
130         }else if(type.equals(EXCEPTION_TYPE)){
131             try {
132                 MockExceptionMethodClass.exceptionMethod();
133             } catch (IOException e) {
134                 // expected
135             }
136             logWriter.println("--> exceptionMethod() is invoked.");
137         }
138 
139         logWriter.println("--> MethodExitWithReturnValueDebuggee finished");
140     }
141 
142 }
143 
144 class MockExceptionMethodClass{
145 
exceptionMethod()146     static public int exceptionMethod() throws IOException {
147         throw new IOException();
148     }
149 }
150