mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
XDebuggerTestUtil overloads which take custom waiter function as parameter
This commit is contained in:
committed by
Dmitry Jemerov
parent
9522f9962d
commit
f27e8d2aaf
@@ -38,6 +38,7 @@ import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -122,9 +123,13 @@ public class XDebuggerTestUtil {
|
||||
}
|
||||
|
||||
public static Pair<List<XExecutionStack>, String> collectThreadsWithErrors(@NotNull XDebugSession session) {
|
||||
return collectThreadsWithErrors(session, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
|
||||
public static Pair<List<XExecutionStack>, String> collectThreadsWithErrors(@NotNull XDebugSession session, @NotNull BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
XTestExecutionStackContainer container = new XTestExecutionStackContainer();
|
||||
session.getSuspendContext().computeExecutionStacks(container);
|
||||
return container.waitFor(TIMEOUT_MS);
|
||||
return container.waitFor(TIMEOUT_MS, waitFunction);
|
||||
}
|
||||
|
||||
public static List<XStackFrame> collectFrames(@NotNull XDebugSession session) {
|
||||
@@ -146,13 +151,21 @@ public class XDebuggerTestUtil {
|
||||
}
|
||||
|
||||
public static List<XStackFrame> collectFrames(XExecutionStack thread, long timeout) {
|
||||
return collectFramesWithError(thread, timeout).first;
|
||||
return collectFrames(thread, timeout, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
|
||||
public static List<XStackFrame> collectFrames(XExecutionStack thread, long timeout, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
return collectFramesWithError(thread, timeout, waitFunction).first;
|
||||
}
|
||||
|
||||
public static Pair<List<XStackFrame>, String> collectFramesWithError(XExecutionStack thread, long timeout) {
|
||||
return collectFramesWithError(thread, timeout, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
|
||||
public static Pair<List<XStackFrame>, String> collectFramesWithError(XExecutionStack thread, long timeout, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
XTestStackFrameContainer container = new XTestStackFrameContainer();
|
||||
thread.computeStackFrames(0, container);
|
||||
return container.waitFor(timeout);
|
||||
return container.waitFor(timeout, waitFunction);
|
||||
}
|
||||
|
||||
public static Pair<List<XStackFrame>, XStackFrame> collectFramesWithSelected(@NotNull XDebugSession session, long timeout) {
|
||||
@@ -160,9 +173,13 @@ public class XDebuggerTestUtil {
|
||||
}
|
||||
|
||||
public static Pair<List<XStackFrame>, XStackFrame> collectFramesWithSelected(XExecutionStack thread, long timeout) {
|
||||
return collectFramesWithSelected(thread, timeout, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
|
||||
public static Pair<List<XStackFrame>, XStackFrame> collectFramesWithSelected(XExecutionStack thread, long timeout, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
XTestStackFrameContainer container = new XTestStackFrameContainer();
|
||||
thread.computeStackFrames(0, container);
|
||||
List<XStackFrame> all = container.waitFor(timeout).first;
|
||||
List<XStackFrame> all = container.waitFor(timeout, waitFunction).first;
|
||||
return Pair.create(all, container.frameToSelect);
|
||||
}
|
||||
|
||||
@@ -175,31 +192,50 @@ public class XDebuggerTestUtil {
|
||||
}
|
||||
|
||||
public static List<XValue> collectChildren(XValueContainer value) {
|
||||
return collectChildren(value, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
|
||||
public static List<XValue> collectChildren(XValueContainer value, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
XTestCompositeNode container = new XTestCompositeNode();
|
||||
value.computeChildren(container);
|
||||
return container.waitFor(TIMEOUT_MS).first;
|
||||
|
||||
return container.waitFor(TIMEOUT_MS, waitFunction).first;
|
||||
}
|
||||
|
||||
public static Pair<XValue, String> evaluate(XDebugSession session, XExpression expression) {
|
||||
return evaluate(session, expression, TIMEOUT_MS);
|
||||
}
|
||||
|
||||
public static Pair<XValue, String> evaluate(XDebugSession session, XExpression expression, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
return evaluate(session, expression, TIMEOUT_MS, waitFunction);
|
||||
}
|
||||
|
||||
public static Pair<XValue, String> evaluate(XDebugSession session, String expression) {
|
||||
return evaluate(session, XExpressionImpl.fromText(expression), TIMEOUT_MS);
|
||||
return evaluate(session, expression, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
public static Pair<XValue, String> evaluate(XDebugSession session, String expression, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
return evaluate(session, XExpressionImpl.fromText(expression), TIMEOUT_MS, waitFunction);
|
||||
}
|
||||
|
||||
public static Pair<XValue, String> evaluate(XDebugSession session, String expression, long timeout) {
|
||||
return evaluate(session, XExpressionImpl.fromText(expression), timeout);
|
||||
return evaluate(session, expression, timeout, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
public static Pair<XValue, String> evaluate(XDebugSession session, String expression, long timeout, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
return evaluate(session, XExpressionImpl.fromText(expression), timeout, waitFunction);
|
||||
}
|
||||
|
||||
private static Pair<XValue, String> evaluate(XDebugSession session, XExpression expression, long timeout) {
|
||||
return evaluate(session, expression, timeout, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
|
||||
private static Pair<XValue, String> evaluate(XDebugSession session, XExpression expression, long timeout, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
XStackFrame frame = session.getCurrentStackFrame();
|
||||
assertNotNull(frame);
|
||||
XDebuggerEvaluator evaluator = frame.getEvaluator();
|
||||
assertNotNull(evaluator);
|
||||
XTestEvaluationCallback callback = new XTestEvaluationCallback();
|
||||
evaluator.evaluate(expression, callback, session.getCurrentPosition());
|
||||
return callback.waitFor(timeout);
|
||||
return callback.waitFor(timeout, waitFunction);
|
||||
}
|
||||
|
||||
public static void waitForSwing() throws InterruptedException {
|
||||
@@ -226,16 +262,22 @@ public class XDebuggerTestUtil {
|
||||
}
|
||||
|
||||
public static XTestValueNode computePresentation(@NotNull XValue value) {
|
||||
return computePresentation(value, TIMEOUT_MS);
|
||||
return computePresentation(value, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
public static XTestValueNode computePresentation(@NotNull XValue value, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
return computePresentation(value, TIMEOUT_MS, waitFunction);
|
||||
}
|
||||
|
||||
public static XTestValueNode computePresentation(XValue value, long timeout) {
|
||||
return computePresentation(value, timeout, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
public static XTestValueNode computePresentation(XValue value, long timeout, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
XTestValueNode node = new XTestValueNode();
|
||||
if (value instanceof XNamedValue) {
|
||||
node.myName = ((XNamedValue)value).getName();
|
||||
}
|
||||
value.computePresentation(node, XValuePlace.TREE);
|
||||
node.waitFor(timeout);
|
||||
node.waitFor(timeout, waitFunction);
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -244,7 +286,16 @@ public class XDebuggerTestUtil {
|
||||
@Nullable String type,
|
||||
@Nullable String value,
|
||||
@Nullable Boolean hasChildren) {
|
||||
XTestValueNode node = computePresentation(var);
|
||||
assertVariable(var, name, type, value, hasChildren, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
|
||||
public static void assertVariable(XValue var,
|
||||
@Nullable String name,
|
||||
@Nullable String type,
|
||||
@Nullable String value,
|
||||
@Nullable Boolean hasChildren,
|
||||
BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
XTestValueNode node = computePresentation(var, waitFunction);
|
||||
|
||||
if (name != null) assertEquals(name, node.myName);
|
||||
if (type != null) assertEquals(type, node.myType);
|
||||
@@ -299,7 +350,16 @@ public class XDebuggerTestUtil {
|
||||
@Nullable String type,
|
||||
@Nullable @Language("RegExp") String valuePattern,
|
||||
@Nullable Boolean hasChildren) {
|
||||
XTestValueNode node = computePresentation(var);
|
||||
assertVariableValueMatches(var, name, type, valuePattern, hasChildren, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
|
||||
public static void assertVariableValueMatches(@NotNull XValue var,
|
||||
@Nullable String name,
|
||||
@Nullable String type,
|
||||
@Nullable @Language("RegExp") String valuePattern,
|
||||
@Nullable Boolean hasChildren,
|
||||
BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
XTestValueNode node = computePresentation(var, waitFunction);
|
||||
if (name != null) assertEquals(name, node.myName);
|
||||
if (type != null) assertEquals(type, node.myType);
|
||||
if (valuePattern != null) {
|
||||
@@ -317,7 +377,14 @@ public class XDebuggerTestUtil {
|
||||
public static void assertVariableTypeMatches(@NotNull XValue var,
|
||||
@Nullable String name,
|
||||
@Nullable @Language("RegExp") String typePattern) {
|
||||
XTestValueNode node = computePresentation(var);
|
||||
assertVariableTypeMatches(var, name, typePattern, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
|
||||
public static void assertVariableTypeMatches(@NotNull XValue var,
|
||||
@Nullable String name,
|
||||
@Nullable @Language("RegExp") String typePattern,
|
||||
@NotNull BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
XTestValueNode node = computePresentation(var, waitFunction);
|
||||
if (name != null) {
|
||||
assertEquals(name, node.myName);
|
||||
}
|
||||
@@ -328,7 +395,13 @@ public class XDebuggerTestUtil {
|
||||
|
||||
public static void assertVariableFullValue(@NotNull XValue var,
|
||||
@Nullable String value) throws Exception {
|
||||
XTestValueNode node = computePresentation(var);
|
||||
assertVariableFullValue(var, value, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
|
||||
public static void assertVariableFullValue(@NotNull XValue var,
|
||||
@Nullable String value,
|
||||
@NotNull BiFunction<Semaphore, Long, Boolean> waitFunction) throws Exception {
|
||||
XTestValueNode node = computePresentation(var, waitFunction);
|
||||
|
||||
if (value == null) {
|
||||
assertNull("full value evaluator should be null", node.myFullValueEvaluator);
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class XTestContainer<T> {
|
||||
private final List<T> myChildren = new SmartList<>();
|
||||
@@ -41,7 +42,11 @@ public class XTestContainer<T> {
|
||||
}
|
||||
|
||||
public Pair<List<T>, String> waitFor(long timeoutMs) {
|
||||
if (!XDebuggerTestUtil.waitFor(myFinished, timeoutMs)) {
|
||||
return waitFor(timeoutMs, (semaphore, timeout) -> XDebuggerTestUtil.waitFor(myFinished, timeout));
|
||||
}
|
||||
|
||||
public Pair<List<T>, String> waitFor(long timeoutMs, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
if (!waitFunction.apply(myFinished, timeoutMs)) {
|
||||
throw new AssertionError("Waiting timed out");
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.xdebugger.impl.ui.tree.nodes.XEvaluationCallbackBase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -42,7 +43,11 @@ public class XTestEvaluationCallback extends XEvaluationCallbackBase {
|
||||
}
|
||||
|
||||
public Pair<XValue, String> waitFor(long timeoutInMilliseconds) {
|
||||
assertTrue("timed out", XDebuggerTestUtil.waitFor(myFinished, timeoutInMilliseconds));
|
||||
return waitFor(timeoutInMilliseconds, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
|
||||
public Pair<XValue, String> waitFor(long timeoutInMilliseconds, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
assertTrue("timed out", waitFunction.apply(myFinished, timeoutInMilliseconds));
|
||||
return Pair.create(myResult, myErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class XTestValueNode extends XValueNodePresentationConfigurator.ConfigurableXValueNodeImpl {
|
||||
public Icon myIcon;
|
||||
@@ -42,7 +43,10 @@ public class XTestValueNode extends XValueNodePresentationConfigurator.Configura
|
||||
}
|
||||
|
||||
public void waitFor(long timeoutInMillis) {
|
||||
if (!XDebuggerTestUtil.waitFor(myFinished, timeoutInMillis)) {
|
||||
waitFor(timeoutInMillis, XDebuggerTestUtil::waitFor);
|
||||
}
|
||||
public void waitFor(long timeoutInMillis, BiFunction<Semaphore, Long, Boolean> waitFunction) {
|
||||
if (!waitFunction.apply(myFinished, timeoutInMillis)) {
|
||||
throw new AssertionError("Waiting timed out");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user