|
1 /* |
|
2 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 // TEMPLATE: global replace "Template" with your test name |
|
25 // TEMPLATE: change bug number and fill out <SUMMARY> and <AUTHOR> |
|
26 // TEMPLATE: delete TEMPLATE lines |
|
27 /** |
|
28 * @test |
|
29 * @bug 0000000 |
|
30 * @summary <SUMMARY> |
|
31 * |
|
32 * @author <AUTHOR> |
|
33 * |
|
34 * @run build TestScaffold VMConnection TargetListener TargetAdapter |
|
35 * @run compile -g TemplateTest.java |
|
36 * @run main TemplateTest |
|
37 */ |
|
38 import com.sun.jdi.*; |
|
39 import com.sun.jdi.event.*; |
|
40 import com.sun.jdi.request.*; |
|
41 |
|
42 import java.util.*; |
|
43 |
|
44 /********** target program **********/ |
|
45 |
|
46 class TemplateTarg { |
|
47 public static void main(String[] args){ |
|
48 System.out.println("Howdy!"); |
|
49 System.out.println("Goodbye from TemplateTarg!"); |
|
50 } |
|
51 } |
|
52 |
|
53 /********** test program **********/ |
|
54 |
|
55 public class TemplateTest extends TestScaffold { |
|
56 ReferenceType targetClass; |
|
57 ThreadReference mainThread; |
|
58 |
|
59 TemplateTest (String args[]) { |
|
60 super(args); |
|
61 } |
|
62 |
|
63 public static void main(String[] args) throws Exception { |
|
64 new TemplateTest(args).startTests(); |
|
65 } |
|
66 |
|
67 /********** event handlers **********/ |
|
68 |
|
69 // TEMPLATE: delete the handlers you don't need |
|
70 // TEMPLATE: defaults are in TargetAdapter |
|
71 |
|
72 public void eventSetReceived(EventSet set) { |
|
73 println("Got event set"); |
|
74 } |
|
75 |
|
76 public void eventReceived(Event event) { |
|
77 println("Got event"); |
|
78 } |
|
79 |
|
80 public void breakpointReached(BreakpointEvent event) { |
|
81 println("Got BreakpointEvent"); |
|
82 } |
|
83 |
|
84 public void exceptionThrown(ExceptionEvent event) { |
|
85 println("Got ExceptionEvent"); |
|
86 } |
|
87 |
|
88 public void stepCompleted(StepEvent event) { |
|
89 println("Got StepEvent"); |
|
90 } |
|
91 |
|
92 public void classPrepared(ClassPrepareEvent event) { |
|
93 println("Got ClassPrepareEvent"); |
|
94 } |
|
95 |
|
96 public void classUnloaded(ClassUnloadEvent event) { |
|
97 println("Got ClassUnloadEvent"); |
|
98 } |
|
99 |
|
100 public void methodEntered(MethodEntryEvent event) { |
|
101 println("Got MethodEntryEvent"); |
|
102 } |
|
103 |
|
104 public void methodExited(MethodExitEvent event) { |
|
105 println("Got MethodExitEvent"); |
|
106 } |
|
107 |
|
108 public void fieldAccessed(AccessWatchpointEvent event) { |
|
109 println("Got AccessWatchpointEvent"); |
|
110 } |
|
111 |
|
112 public void fieldModified(ModificationWatchpointEvent event) { |
|
113 println("Got ModificationWatchpointEvent"); |
|
114 } |
|
115 |
|
116 public void threadStarted(ThreadStartEvent event) { |
|
117 println("Got ThreadStartEvent"); |
|
118 } |
|
119 |
|
120 public void threadDied(ThreadDeathEvent event) { |
|
121 println("Got ThreadDeathEvent"); |
|
122 } |
|
123 |
|
124 public void vmStarted(VMStartEvent event) { |
|
125 println("Got VMStartEvent"); |
|
126 } |
|
127 |
|
128 public void vmDied(VMDeathEvent event) { |
|
129 println("Got VMDeathEvent"); |
|
130 } |
|
131 |
|
132 public void vmDisconnected(VMDisconnectEvent event) { |
|
133 println("Got VMDisconnectEvent"); |
|
134 } |
|
135 |
|
136 /********** test core **********/ |
|
137 |
|
138 protected void runTests() throws Exception { |
|
139 /* |
|
140 * Get to the top of main() |
|
141 * to determine targetClass and mainThread |
|
142 */ |
|
143 BreakpointEvent bpe = startToMain("TemplateTarg"); |
|
144 targetClass = bpe.location().declaringType(); |
|
145 mainThread = bpe.thread(); |
|
146 EventRequestManager erm = vm().eventRequestManager(); |
|
147 |
|
148 // TEMPLATE: set things up |
|
149 |
|
150 // TEMPLATE: for example |
|
151 /* |
|
152 * Set event requests |
|
153 */ |
|
154 StepRequest request = erm.createStepRequest(mainThread, |
|
155 StepRequest.STEP_LINE, |
|
156 StepRequest.STEP_OVER); |
|
157 request.enable(); |
|
158 |
|
159 /* |
|
160 * resume the target listening for events |
|
161 */ |
|
162 listenUntilVMDisconnect(); |
|
163 |
|
164 /* |
|
165 * deal with results of test |
|
166 * if anything has called failure("foo") testFailed will be true |
|
167 */ |
|
168 if (!testFailed) { |
|
169 println("TemplateTest: passed"); |
|
170 } else { |
|
171 throw new Exception("TemplateTest: failed"); |
|
172 } |
|
173 } |
|
174 } |