summaryrefslogtreecommitdiff
path: root/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MethodExitWithReturnValueDebuggee.java
blob: e8dbb298a2c1f66ffa9d94c448ba6a586591b70c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.harmony.jpda.tests.jdwp.Events;

import java.io.IOException;

import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
import org.apache.harmony.jpda.tests.share.SyncDebuggee;

public class MethodExitWithReturnValueDebuggee extends SyncDebuggee {
    
    public static final String BOOLEAN_TYPE = "BOOLEAN";
    
    public static final String SHORT_TYPE = "SHORT";
    
    public static final String CHAR_TYPE = "CHAR";
    
    public static final String INT_TYPE = "INT";
    
    public static final String LONG_TYPE = "LONG";
    
    public static final String DOUBLE_TYPE = "DOUBLE";
    
    public static final String EXCEPTION_TYPE = "EXCEPTION";
    
    public static final boolean EXPECTED_BOOLEAN = true;
    
    public static final short EXPECTED_SHORT = 2;
    
    public static final char EXPECTED_CHAR = 'B';
    
    public static final int EXPECTED_INT = 230;
    
    public static final long EXPECTED_LONG = 0523l;
    
    public static final double EXPECTED_DOUBLE = 5.23d;
    
    public static final Object EXPECTED_OBJECT = new MethodExitWithReturnValueDebuggee();

    public static final String VOID_TYPE = "VOID";

    public static void main(String[] args) {
        runDebuggee(MethodExitWithReturnValueDebuggee.class);
    }
    
    /*
     * tested methods with different return values 
     */
    
    public boolean booleanMethod() {
        logWriter.println("--> calling booleanMethod()");
        return EXPECTED_BOOLEAN;
    }
    
    public short shortMethod() {
        logWriter.println("--> calling shortMethod()");
        return EXPECTED_SHORT;
    }
    
    public char charMethod() {
        logWriter.println("--> calling charMethod()");
        return EXPECTED_CHAR;
    }
    
    public int intMethod() {
        logWriter.println("--> calling intMethod()");
        return EXPECTED_INT;
    }

    public long longMethod() {
        logWriter.println("--> calling longMethod()");
        return EXPECTED_LONG;
    }
    
    public double doubleMethod() {
        logWriter.println("--> calling doubleMethod()");
        return EXPECTED_DOUBLE;
    }

    public void voidMethod() {
        logWriter.println("--> calling voidMethod()");
    }
    
    public void run() {
        logWriter.println("--> MethodExitWithReturnValueDebuggee started");
        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);

        // Receive required method type
        String type = synchronizer.receiveMessage();
        logWriter.println("--> invoke method's return type is:" + type);
        
        // Invoke desired method
        if(type.equals(BOOLEAN_TYPE)){
            boolean b = booleanMethod();
            logWriter.println("--> booleanMethod() is invoked, return value:" + b);
        }else if(type.equals(SHORT_TYPE)){
            short s = shortMethod();
            logWriter.println("--> shortMethod() is invoked, return value:" + s);
        }else if(type.equals(CHAR_TYPE)){
            char c = charMethod();
            logWriter.println("--> charMethod() is invoked, return value:" + c);
        }else if(type.equals(INT_TYPE)){
            int i = intMethod();
            logWriter.println("--> intMethod() is invoked, return value:" + i);
        }else if(type.equals(LONG_TYPE)){
            long l = longMethod();
            logWriter.println("--> longMethod() is invoked, return value:" + l);
        }else if(type.equals(DOUBLE_TYPE)){
            double d = doubleMethod();
            logWriter.println("--> doubleMethod() is invoked, return value:" + d);
        } else if (type.equals(VOID_TYPE)) {
            voidMethod();
            logWriter.println("--> voidMethod() is invoked");
        }else if(type.equals(EXCEPTION_TYPE)){
            try {
                MockExceptionMethodClass.exceptionMethod();
            } catch (IOException e) {
                // expected
            }
            logWriter.println("--> exceptionMethod() is invoked.");
        }
        
        logWriter.println("--> MethodExitWithReturnValueDebuggee finished");
    }

}

class MockExceptionMethodClass{
    
    static public int exceptionMethod() throws IOException {
        throw new IOException();
    }
}