Env tests: added test for django conditional breakpoint.
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Wed, 22 Jun 2011 12:34:27 +0000 (16:34 +0400)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Wed, 22 Jun 2011 16:09:03 +0000 (20:09 +0400)
platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java

index bba37ad71587c89c63ea8586d532fc74d8d5ba2b..4773798a5a5b43ae6a4ea44eadea3f75ca096e46 100644 (file)
@@ -21,15 +21,14 @@ import com.intellij.openapi.application.Result;
 import com.intellij.openapi.application.WriteAction;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Pair;
+import com.intellij.openapi.util.Ref;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.testFramework.UsefulTestCase;
 import com.intellij.util.ui.UIUtil;
-import com.intellij.xdebugger.breakpoints.XBreakpoint;
-import com.intellij.xdebugger.breakpoints.XBreakpointManager;
-import com.intellij.xdebugger.breakpoints.XBreakpointType;
-import com.intellij.xdebugger.breakpoints.XLineBreakpointType;
+import com.intellij.xdebugger.breakpoints.*;
 import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
 import com.intellij.xdebugger.frame.*;
+import com.intellij.xdebugger.impl.breakpoints.XBreakpointUtil;
 import com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl;
 import com.intellij.xdebugger.ui.DebuggerIcons;
 import junit.framework.Assert;
@@ -212,6 +211,45 @@ public class XDebuggerTestUtil {
     return consoleView.getEditor().getDocument().getText();
   }
 
+  public static <T extends XBreakpointType> XBreakpoint addBreakpoint(@NotNull final Project project,
+                                                               @NotNull final Class<T> exceptionType,
+                                                               @NotNull final XBreakpointProperties properties) {
+    final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
+    XBreakpointType[] types = XBreakpointUtil.getBreakpointTypes();
+    final Ref<XBreakpoint> breakpoint = Ref.create(null);
+    for (XBreakpointType type : types) {
+      if (exceptionType.isInstance(type)) {
+        final T breakpointType = exceptionType.cast(type);
+        new WriteAction() {
+          @Override
+          protected void run(Result result) throws Throwable {
+            breakpoint.set(breakpointManager.addBreakpoint(breakpointType, properties));
+          }
+        }.execute();
+        break;
+      }
+    }
+    return breakpoint.get();
+  }
+
+  public static void setBreakpointCondition(Project project, int line, final String condition) {
+    XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
+    for (XBreakpoint breakpoint : breakpointManager.getAllBreakpoints()) {
+      if (breakpoint instanceof XLineBreakpoint) {
+        final XLineBreakpoint lineBreakpoint = (XLineBreakpoint)breakpoint;
+
+        if (lineBreakpoint.getLine() == line) {
+          new WriteAction() {
+            @Override
+            protected void run(Result result) throws Throwable {
+              lineBreakpoint.setCondition(condition);
+            }
+          }.execute();
+        }
+      }
+    }
+  }
+
   public static class XTestStackFrameContainer extends XTestContainer<XStackFrame> implements XExecutionStack.XStackFrameContainer {
     public void addStackFrames(@NotNull List<? extends XStackFrame> stackFrames, boolean last) {
       addChildren(stackFrames, last);