This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 93842
Collapse All | Expand All

(-)/dev/null (+224 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.api.debugger.jpda;
21
22
import java.util.List;
23
import org.netbeans.api.debugger.ActionsManager;
24
import org.netbeans.api.debugger.DebuggerManager;
25
import org.netbeans.junit.NbTestCase;
26
import org.netbeans.spi.debugger.jpda.EditorContext.Operation;
27
28
29
/**
30
 * Tests JPDA expression stepping action.
31
 *
32
 * @author Martin Entlicher, Jan Jancura
33
 */
34
public class ExpressionStepTest extends NbTestCase {
35
36
    private DebuggerManager dm = DebuggerManager.getDebuggerManager ();
37
    private String          sourceRoot = System.getProperty ("test.dir.src");
38
    private JPDASupport     support;
39
40
    public ExpressionStepTest (String s) {
41
        super (s);
42
    }
43
44
    public void testExpressionStep() throws Exception {
45
        try {
46
            JPDASupport.removeAllBreakpoints ();
47
            LineBreakpoint lb = LineBreakpoint.create (
48
                Utils.getURL(sourceRoot + 
49
                    "org/netbeans/api/debugger/jpda/testapps/ExpressionStepApp.java"),
50
                30
51
            );
52
            dm.addBreakpoint (lb);
53
            support = JPDASupport.attach
54
                ("org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp");
55
            support.waitState (JPDADebugger.STATE_STOPPED);
56
            dm.removeBreakpoint (lb);
57
            assertEquals (
58
                "Execution stopped in wrong class", 
59
                support.getDebugger ().getCurrentCallStackFrame ().
60
                    getClassName (), 
61
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp"
62
            );
63
            assertEquals (
64
                "Execution stopped at wrong line", 
65
                30, 
66
                support.getDebugger ().getCurrentCallStackFrame ().
67
                    getLineNumber (null)
68
            );
69
            stepCheck (
70
                ActionsManager.ACTION_STEP_OPERATION, 
71
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
72
                30, 14,
73
                "factorial"
74
            );
75
            stepCheck (
76
                ActionsManager.ACTION_STEP_OPERATION, 
77
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
78
                31, 14,
79
                "factorial",
80
                new Object[] {"3628800"}
81
            );
82
            stepCheck (
83
                ActionsManager.ACTION_STEP_OPERATION, 
84
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
85
                31, 30,
86
                "factorial",
87
                new Object[] {"2432902008176640000"}
88
            );
89
            stepCheck (
90
                ActionsManager.ACTION_STEP_OPERATION, 
91
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
92
                32, 14,
93
                "factorial",
94
                new Object[] {"2432902008176640000", "-8764578968847253504"}
95
            );
96
            stepCheck (
97
                ActionsManager.ACTION_STEP_OPERATION, 
98
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
99
                32, 34,
100
                "factorial",
101
                new Object[] {"-70609262346240000"}
102
            );
103
            stepCheck (
104
                ActionsManager.ACTION_STEP_OPERATION, 
105
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
106
                33, 37,
107
                "<init>", // "ExpressionStepApp",
108
                new Object[] {"-70609262346240000", "-3258495067890909184"}
109
            );
110
            stepCheck (
111
                ActionsManager.ACTION_STEP_OPERATION, 
112
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
113
                34, 20,
114
                "m2"
115
            );
116
            stepCheck (
117
                ActionsManager.ACTION_STEP_OPERATION, 
118
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
119
                34, 13,
120
                "m1",
121
                new Object[] {"-899453552"}
122
            );
123
            
124
            stepCheck (
125
                ActionsManager.ACTION_STEP_OPERATION, 
126
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
127
                35, 27,
128
                "m2",
129
                new Object[] {"-899453552", "-404600928"}
130
            );
131
            stepCheck (
132
                ActionsManager.ACTION_STEP_OPERATION, 
133
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
134
                35, 20,
135
                "m1",
136
                new Object[] {"497916032"}
137
            );
138
            stepCheck (
139
                ActionsManager.ACTION_STEP_OPERATION, 
140
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
141
                35, 27,
142
                "m1",
143
                new Object[] {"497916032", "684193024"}
144
            );
145
            stepCheck (
146
                ActionsManager.ACTION_STEP_OPERATION, 
147
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
148
                35, 13,
149
                "m3",
150
                new Object[] {"497916032", "684193024", "248958016"}
151
            );
152
            stepCheck (
153
                ActionsManager.ACTION_STEP_OPERATION, 
154
                "org.netbeans.api.debugger.jpda.testapps.ExpressionStepApp", 
155
                35, 13,
156
                "intValue",
157
                new Object[] {"497916032", "684193024", "248958016", "933151070"}
158
            );
159
            
160
            support.doContinue ();
161
            support.waitState (JPDADebugger.STATE_DISCONNECTED);
162
        } finally {
163
            support.doFinish ();
164
        }
165
    }
166
167
    private void stepCheck (
168
        Object stepType, 
169
        String clsExpected, 
170
        int lineExpected,
171
        int column,
172
        String methodName
173
    ) {
174
        try {
175
            // We need to wait for all listeners to be notified and appropriate
176
            // actions to be enabled/disabled
177
            Thread.currentThread().sleep(10);
178
        } catch (InterruptedException ex) {
179
            ex.printStackTrace();
180
        }
181
        support.step (stepType);
182
        assertEquals(
183
            "Execution stopped in wrong class", 
184
            clsExpected, 
185
            support.getDebugger ().getCurrentCallStackFrame ().getClassName ()
186
        );
187
        assertEquals (
188
            "Execution stopped at wrong line", 
189
            lineExpected, 
190
            support.getDebugger ().getCurrentCallStackFrame ().
191
                getLineNumber (null)
192
        );
193
        if (column > 0) {
194
            Operation op = support.getDebugger ().getCurrentCallStackFrame ().getCurrentOperation(null);
195
            assertNotNull(op);
196
            assertEquals("Execution stopped at a wrong column", column, op.getMethodStartPosition().getColumn());
197
        }
198
        if (methodName != null) {
199
            Operation op = support.getDebugger ().getCurrentCallStackFrame ().getCurrentOperation(null);
200
            assertNotNull(op);
201
            assertEquals("Execution stopped at a wrong method call", methodName, op.getMethodName());
202
        }
203
    }
204
    
205
    private void stepCheck (
206
        Object stepType, 
207
        String clsExpected, 
208
        int lineExpected,
209
        int column,
210
        String methodName,
211
        Object[] returnValues
212
    ) {
213
        stepCheck(stepType, clsExpected, lineExpected, column, methodName);
214
        List<Operation> ops = support.getDebugger ().getCurrentThread().getLastOperations();
215
        assertEquals("Different count of last operations and expected return values.", returnValues.length, ops.size());
216
        for (int i = 0; i < returnValues.length; i++) {
217
            Variable rv = ops.get(i).getReturnValue();
218
            if (rv != null) {
219
                assertEquals("Bad return value", returnValues[i], rv.getValue());
220
            }
221
        }
222
    }
223
    
224
}
(-)debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/test/TestContextProvider.java:1.12 (+134 lines)
Lines 123-128 Link Here
123
        return url;
123
        return url;
124
    }
124
    }
125
125
126
    public Operation[] getOperations(String url, final int lineNumber,
127
                                     final BytecodeProvider bytecodeProvider) {
128
        //EditorContextImpl impl = new EditorContextImpl();
129
        //return impl.getOperations(url, lineNumber, bytecodeProvider);
130
        // Hard-coded operations, because of problematic access to jpda/projects module
131
        if (url.endsWith("ExpressionStepApp.java")) {
132
            Operation[] ops = createExpressionSteppAppOperations(lineNumber);
133
            if (ops == null) {
134
                throw new IllegalStateException(url+":"+lineNumber);
135
            }
136
            return ops;
137
        }
138
        throw new IllegalStateException(url);
139
    }
140
    
141
    private Operation[] createExpressionSteppAppOperations(int lineNumber) {
142
        if (lineNumber == 30) {
143
            return new Operation[] {
144
                createMethodOperation(createPosition(1124, 30, 14),
145
                                      createPosition(1137, 30, 27),
146
                                      createPosition(1124, 30, 14),
147
                                      createPosition(1133, 30, 23),
148
                                      "factorial",
149
                                      "debuggertest1.ExpressionStepApp",
150
                                      5)
151
            };
152
        }
153
        if (lineNumber == 31) {
154
            return new Operation[] {
155
                createMethodOperation(createPosition(1152, 31, 14),
156
                                      createPosition(1165, 31, 27),
157
                                      createPosition(1152, 31, 14),
158
                                      createPosition(1161, 31, 23),
159
                                      "factorial",
160
                                      "debuggertest1.ExpressionStepApp",
161
                                      17),
162
                createMethodOperation(createPosition(1168, 31, 30),
163
                                      createPosition(1181, 31, 43),
164
                                      createPosition(1168, 31, 30),
165
                                      createPosition(1177, 31, 39),
166
                                      "factorial",
167
                                      "debuggertest1.ExpressionStepApp",
168
                                      22)
169
            };
170
        }
171
        if (lineNumber == 32) {
172
            return new Operation[] {
173
                createMethodOperation(createPosition(1196, 32, 14),
174
                                      createPosition(1209, 32, 27),
175
                                      createPosition(1196, 32, 14),
176
                                      createPosition(1205, 32, 23),
177
                                      "factorial",
178
                                      "debuggertest1.ExpressionStepApp",
179
                                      35),
180
                createMethodOperation(createPosition(1216, 32, 34),
181
                                      createPosition(1229, 32, 47),
182
                                      createPosition(1216, 32, 34),
183
                                      createPosition(1225, 32, 43),
184
                                      "factorial",
185
                                      "debuggertest1.ExpressionStepApp",
186
                                      47)
187
            };
188
        }
189
        if (lineNumber == 33) {
190
            return new Operation[] {
191
                createMethodOperation(createPosition(1263, 33, 33),
192
                                      createPosition(1286, 33, 56),
193
                                      createPosition(1267, 33, 37),
194
                                      createPosition(1284, 33, 54),
195
                                      "<init>",
196
                                      "debuggertest1.ExpressionStepApp",
197
                                      58)
198
            };
199
        }
200
        if (lineNumber == 34) {
201
            return new Operation[] {
202
                createMethodOperation(createPosition(1307, 34, 20),
203
                                      createPosition(1322, 34, 35),
204
                                      createPosition(1307, 34, 20),
205
                                      createPosition(1313, 34, 26),
206
                                      "m2",
207
                                      "debuggertest1.ExpressionStepApp",
208
                                      68),
209
                createMethodOperation(createPosition(1300, 34, 13),
210
                                      createPosition(1323, 34, 36),
211
                                      createPosition(1300, 34, 13),
212
                                      createPosition(1306, 34, 19),
213
                                      "m1",
214
                                      "debuggertest1.ExpressionStepApp",
215
                                      71)
216
            };
217
        }
218
        if (lineNumber == 35) {
219
            return new Operation[] {
220
                createMethodOperation(createPosition(1351, 35, 27),
221
                                      createPosition(1366, 35, 42),
222
                                      createPosition(1351, 35, 27),
223
                                      createPosition(1357, 35, 33),
224
                                      "m2",
225
                                      "debuggertest1.ExpressionStepApp",
226
                                      85),
227
                createMethodOperation(createPosition(1344, 35, 20),
228
                                      createPosition(1367, 35, 43),
229
                                      createPosition(1344, 35, 20),
230
                                      createPosition(1350, 35, 26),
231
                                      "m1",
232
                                      "debuggertest1.ExpressionStepApp",
233
                                      88),
234
                createMethodOperation(createPosition(1395, 36, 27),
235
                                      createPosition(1410, 36, 42),
236
                                      createPosition(1395, 36, 27),
237
                                      createPosition(1401, 36, 33),
238
                                      "m1",
239
                                      "debuggertest1.ExpressionStepApp",
240
                                      96),
241
                createMethodOperation(createPosition(1337, 35, 13),
242
                                      createPosition(1411, 35, 43),
243
                                      createPosition(1337, 35, 13),
244
                                      createPosition(1343, 35, 19),
245
                                      "m3",
246
                                      "debuggertest1.ExpressionStepApp",
247
                                      99),
248
                createMethodOperation(createPosition(1337, 35, 13),
249
                                      createPosition(1422, 36, 54),
250
                                      createPosition(1337, 35, 13),
251
                                      createPosition(1420, 36, 52),
252
                                      "intValue",
253
                                      "debuggertest1.ExpressionStepApp",
254
                                      102)
255
            };
256
        }
257
        return null;
258
    }
259
    
126
    public String[] getImports(String url) {
260
    public String[] getImports(String url) {
127
        return new String[0];
261
        return new String[0];
128
    }
262
    }
(-)/dev/null (+66 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.api.debugger.jpda.testapps;
21
22
/**
23
 * Sample step application. DO NOT MODIFY - line numbers must not change in this source file.
24
 *
25
 * @author Martin Entlicher
26
 */
27
public class ExpressionStepApp {
28
29
    public static void main(String[] args) {
30
        x += factorial(10);
31
        x += factorial(20) + factorial(30);
32
        x += factorial(40); x += factorial(50);
33
        ExpressionStepApp exs = new ExpressionStepApp();
34
        x = exs.m1(exs.m2((int) x));
35
        x = exs.m3(exs.m1(exs.m2((int) x)), exs.m1((int) x)).intValue();
36
        System.out.println(x);
37
    }
38
39
    public ExpressionStepApp() {
40
    }
41
    
42
    public static long factorial(int n) {
43
        long f = 1;
44
        for (int i = 2; i <= n; i++) {
45
            f *= i;
46
        }
47
        return f;
48
    }
49
    
50
    private int m1(int x) {
51
        int im1 = 10;
52
        return im1*x;
53
    }
54
55
    private int m2(int x) {
56
        int im2 = 20;
57
        return im2*x;
58
    }
59
60
    private Integer m3(int x, int y) {
61
        int im3 = 30;
62
        return new Integer(im3 + x + y);
63
    }
64
65
    static long x = 20L;
66
}

Return to bug 93842