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 Vitaly A. Provodin
21  */
22 
23 /**
24  * Created on 10.03.2005
25  */
26 package org.apache.harmony.jpda.tests.jdwp.share.debuggee;
27 
28 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
29 import org.apache.harmony.jpda.tests.share.SyncDebuggee;
30 
31 /**
32  * This class provides common debuggee class for InvokeMethod tests.
33  *
34  */
35 public class InvokeMethodDebuggee extends SyncDebuggee {
36 
37     public class testClass1 {
testClass1()38         public testClass1() {
39             logWriter.println("constructor testClass1 invoked");
40         }
41     }
42 
testMethod1(boolean needThrow)43     public int testMethod1(boolean needThrow) throws Throwable {
44         logWriter.println("method testClass1 invoked");
45         if (needThrow) {
46             throw new Throwable("test exception");
47         }
48         return 123;
49     }
50 
testMethod2(boolean needThrow)51     public static int testMethod2(boolean needThrow) throws Throwable {
52         if (needThrow) {
53             throw new Throwable("test exception");
54         }
55         return 234;
56     }
57 
58     static int checkInt = 1;
59     static int[] checkIntArray = {1, 2};
60     static int[][] checkIntArray2 = {{123}, {23, 34}, {2, 4, 6, 8}};
61     static String checkString = "text 1";
62     static String[] checkStringArray = {"text 2"};
63     static String[][] checkStringArray2 = {{"text 3"}, {"text 4"}};
64     static testClass checkClass = new testClass();
65     static testClass[] checkClassArray = {new testClass()};
66     static testClass[][] checkClassArray2 = {{new testClass()}, {new testClass()}};
67 
testMethod3(int i, int[] ai, int[][] aai, String s, String[] as, String[][] aas, testClass tc, testClass[] atc, testClass[][] aatc)68     public static String testMethod3(int i, int[] ai, int[][] aai,
69             String s, String[] as, String[][] aas,
70             testClass tc, testClass[] atc, testClass[][] aatc) {
71         return "qwerty";
72     }
73 
execMethod()74     void execMethod() {
75         logWriter.println("InvokeMethodDebuggee.execMethod()");
76     }
77 
run()78     public void run() {
79         Class c = null;
80         try {
81             c = Class.forName("org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee$testClass1");
82             c = Class.forName("org.apache.harmony.jpda.tests.jdwp.share.debuggee.testClass2");
83             c = Class.forName("org.apache.harmony.jpda.tests.jdwp.share.debuggee.testClass3");
84         } catch (ClassNotFoundException e) {
85             e.printStackTrace();
86         }
87         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
88         logWriter.println("InvokeMethodDebuggee");
89 //        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
90         synchronizer.receiveMessageWithoutException("org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee(#1)");
91         execMethod();
92 //        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
93         synchronizer.receiveMessageWithoutException("org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee(#2)");
94         logWriter.println("DUMP{" + c + "}");
95     }
96 
main(String[] args)97     public static void main(String[] args) {
98         runDebuggee(InvokeMethodDebuggee.class);
99     }
100 }
101 
102 class testClass {
103 }
104 
105 class testClass2 {
testClass2(boolean needThrow)106     public testClass2(boolean needThrow) throws Throwable {
107         if (needThrow) {
108             throw new Throwable("test exception");
109         }
110     }
111 
testMethod3(boolean needThrow)112     public int testMethod3(boolean needThrow) throws Throwable {
113         if (needThrow) {
114             throw new Throwable("test exception");
115         }
116         return 345;
117     }
118 }
119 
120 class testClass3 extends testClass2 {
testClass3()121     public testClass3() throws Throwable {
122         super(false);
123     }
124 
testMethod3(boolean needThrow)125     public int testMethod3(boolean needThrow) throws Throwable {
126         if (needThrow) {
127             throw new Throwable("test exception");
128         }
129         return 456;
130     }
131 }
132 
133