forked from eclipse-lsp4e/lsp4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBreakpointMappingTest.java
More file actions
163 lines (139 loc) · 5.39 KB
/
BreakpointMappingTest.java
File metadata and controls
163 lines (139 loc) · 5.39 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*******************************************************************************
* Copyright (c) 2025 Vegard IT GmbH and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Sebastian Thomschke (Vegard IT GmbH) - initial implementation.
*******************************************************************************/
package org.eclipse.lsp4e.test.debug;
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.lsp4e.debug.breakpoints.DSPLineBreakpoint;
import org.eclipse.lsp4e.debug.debugmodel.DSPBreakpointManager;
import org.eclipse.lsp4e.test.utils.AbstractTestWithProject;
import org.eclipse.lsp4e.test.utils.TestUtils;
import org.eclipse.lsp4j.debug.Breakpoint;
import org.eclipse.lsp4j.debug.SetBreakpointsArguments;
import org.eclipse.lsp4j.debug.SetBreakpointsResponse;
import org.eclipse.lsp4j.debug.SourceBreakpoint;
import org.eclipse.lsp4j.debug.services.IDebugProtocolServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Verifies that DSPBreakpointManager maps marker attributes to DAP
* SourceBreakpoint (condition, column, hitCondition).
*/
class BreakpointMappingTest extends AbstractTestWithProject {
private static class CapturingServer implements IDebugProtocolServer {
List<SetBreakpointsArguments> calls = new ArrayList<>();
@Override
public CompletableFuture<SetBreakpointsResponse> setBreakpoints(SetBreakpointsArguments arguments) {
synchronized (calls) {
calls.add(arguments);
}
var resp = new SetBreakpointsResponse();
resp.setBreakpoints(new Breakpoint[0]);
return CompletableFuture.completedFuture(resp);
}
}
private List<IBreakpoint> created = new ArrayList<>();
@BeforeEach
void clearBreakpoints() throws CoreException {
// Ensure a clean slate for the test case
for (IBreakpoint bp : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
bp.delete();
}
}
@AfterEach
void cleanupCreated() throws CoreException {
for (IBreakpoint bp : created) {
bp.delete();
}
}
@Test
void breakpoint_conditions_are_sent_to_server() throws Exception {
IFile file = TestUtils.createUniqueTestFile(project, "txt", "first line\nsecond line\n");
var bp = new DSPLineBreakpoint(file, 2);
bp.setCondition("x > 0");
bp.setColumn(7);
bp.setHitCondition(">= 3");
created.add(bp);
DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(bp);
var server = new CapturingServer();
var manager = new DSPBreakpointManager(DebugPlugin.getDefault().getBreakpointManager(), server, null);
try {
manager.initialize().join();
SetBreakpointsArguments matching = null;
synchronized (server.calls) {
assertTrue(!server.calls.isEmpty(), "No setBreakpoints() calls captured");
String path = file.getLocation().toOSString();
for (SetBreakpointsArguments a : server.calls) {
if (a.getSource() != null && path.equals(a.getSource().getPath())) {
matching = a;
break;
}
}
}
assertNotNull(matching, "No setBreakpoints() call for our file was captured");
SourceBreakpoint[] sent = matching.getBreakpoints();
assertNotNull(sent);
assertEquals(1, sent.length, "Expected exactly one SourceBreakpoint");
SourceBreakpoint sb = sent[0];
assertEquals("x > 0", sb.getCondition());
assertEquals(7, sb.getColumn());
assertEquals(">= 3", sb.getHitCondition());
} finally {
manager.shutdown();
}
}
@Test
void changing_breakpoint_condition_replaces_existing_entry() throws Exception {
IFile file = TestUtils.createUniqueTestFile(project, "txt", "first line\nsecond line\n");
var bp = new DSPLineBreakpoint(file, 2);
bp.setCondition("x > 0");
created.add(bp);
var server = new CapturingServer();
var manager = new DSPBreakpointManager(DebugPlugin.getDefault().getBreakpointManager(), server, null);
try {
// Simulate initial registration of the breakpoint with the manager
manager.initialize().join();
manager.breakpointAdded(bp);
// Change the condition and simulate the platform reporting the change
server.calls.clear();
bp.setCondition("x > 1");
manager.breakpointChanged(bp, null);
SetBreakpointsArguments matching = null;
synchronized (server.calls) {
assertTrue(!server.calls.isEmpty(),
"No setBreakpoints() calls captured after breakpoint condition change");
String path = file.getLocation().toOSString();
for (SetBreakpointsArguments a : server.calls) {
if (a.getSource() != null && path.equals(a.getSource().getPath())) {
matching = a;
break;
}
}
}
assertNotNull(matching,
"No setBreakpoints() call for our file was captured after breakpoint condition change");
SourceBreakpoint[] sent = matching.getBreakpoints();
assertNotNull(sent);
assertEquals(1, sent.length, "Expected exactly one SourceBreakpoint after condition change");
SourceBreakpoint sb = sent[0];
assertEquals("x > 1", sb.getCondition());
} finally {
manager.shutdown();
}
}
}