1// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2package com.intellij.testFramework; 3 4import com.intellij.configurationStore.StateStorageManagerKt; 5import com.intellij.execution.ExecutionException; 6import com.intellij.execution.configurations.GeneralCommandLine; 7import com.intellij.execution.process.ProcessIOExecutorService; 8import com.intellij.execution.process.ProcessOutput; 9import com.intellij.execution.util.ExecUtil; 10import com.intellij.ide.DataManager; 11import com.intellij.ide.IdeEventQueue; 12import com.intellij.ide.fileTemplates.FileTemplateManager; 13import com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl; 14import com.intellij.ide.util.treeView.AbstractTreeBuilder; 15import com.intellij.ide.util.treeView.AbstractTreeNode; 16import com.intellij.ide.util.treeView.AbstractTreeStructure; 17import com.intellij.ide.util.treeView.AbstractTreeUi; 18import com.intellij.openapi.Disposable; 19import com.intellij.openapi.actionSystem.*; 20import com.intellij.openapi.actionSystem.ex.ActionUtil; 21import com.intellij.openapi.application.Application; 22import com.intellij.openapi.application.ModalityState; 23import com.intellij.openapi.application.impl.ApplicationImpl; 24import com.intellij.openapi.application.impl.LaterInvocator; 25import com.intellij.openapi.editor.Document; 26import com.intellij.openapi.extensions.*; 27import com.intellij.openapi.fileEditor.FileDocumentManager; 28import com.intellij.openapi.fileEditor.impl.LoadTextUtil; 29import com.intellij.openapi.fileTypes.FileTypes; 30import com.intellij.openapi.paths.WebReference; 31import com.intellij.openapi.project.Project; 32import com.intellij.openapi.project.ex.ProjectManagerEx; 33import com.intellij.openapi.ui.Queryable; 34import com.intellij.openapi.util.ActionCallback; 35import com.intellij.openapi.util.Comparing; 36import com.intellij.openapi.util.Disposer; 37import com.intellij.openapi.util.SystemInfo; 38import com.intellij.openapi.util.io.FileUtil; 39import com.intellij.openapi.util.io.FileUtilRt; 40import com.intellij.openapi.util.text.StringUtil; 41import com.intellij.openapi.vfs.LocalFileSystem; 42import com.intellij.openapi.vfs.VfsUtilCore; 43import com.intellij.openapi.vfs.VirtualFile; 44import com.intellij.openapi.vfs.VirtualFileFilter; 45import com.intellij.openapi.vfs.ex.temp.TempFileSystem; 46import com.intellij.psi.PsiElement; 47import com.intellij.psi.PsiRecursiveElementWalkingVisitor; 48import com.intellij.psi.PsiReference; 49import com.intellij.rt.execution.junit.FileComparisonFailure; 50import com.intellij.testFramework.fixtures.IdeaTestExecutionPolicy; 51import com.intellij.ui.tree.AsyncTreeModel; 52import com.intellij.util.*; 53import com.intellij.util.concurrency.AppExecutorUtil; 54import com.intellij.util.concurrency.AppScheduledExecutorService; 55import com.intellij.util.io.Decompressor; 56import com.intellij.util.lang.JavaVersion; 57import com.intellij.util.ui.UIUtil; 58import com.intellij.util.ui.tree.TreeUtil; 59import gnu.trove.Equality; 60import junit.framework.AssertionFailedError; 61import org.jetbrains.annotations.Contract; 62import org.jetbrains.annotations.NonNls; 63import org.jetbrains.annotations.NotNull; 64import org.jetbrains.annotations.Nullable; 65import org.jetbrains.concurrency.AsyncPromise; 66import org.jetbrains.concurrency.Promise; 67 68import javax.swing.*; 69import javax.swing.tree.TreeModel; 70import javax.swing.tree.TreePath; 71import java.awt.*; 72import java.awt.event.InvocationEvent; 73import java.io.File; 74import java.io.IOException; 75import java.io.OutputStream; 76import java.io.PrintStream; 77import java.lang.reflect.Method; 78import java.net.MalformedURLException; 79import java.net.URL; 80import java.nio.charset.Charset; 81import java.util.List; 82import java.util.*; 83import java.util.concurrent.CopyOnWriteArrayList; 84import java.util.concurrent.TimeUnit; 85import java.util.concurrent.atomic.AtomicBoolean; 86import java.util.function.Function; 87import java.util.function.Predicate; 88import java.util.jar.JarFile; 89import java.util.stream.Collectors; 90import java.util.stream.Stream; 91 92import static com.intellij.openapi.application.ApplicationManager.getApplication; 93import static org.junit.Assert.*; 94 95/** 96 * @author yole 97 */ 98@SuppressWarnings({"UseOfSystemOutOrSystemErr", "TestOnlyProblems"}) 99public class PlatformTestUtil { 100 public static <T> void assertComparisonContractNotViolated(@NotNull List<? extends T> values, 101 @NotNull Comparator<? super T> comparator, 102 @NotNull Equality<? super T> equality) { 103 for (int i1 = 0; i1 < values.size(); i1++) { 104 for (int i2 = i1; i2 < values.size(); i2++) { 105 T value1 = values.get(i1); 106 T value2 = values.get(i2); 107 108 int result12 = comparator.compare(value1, value2); 109 int result21 = comparator.compare(value2, value1); 110 if (equality.equals(value1, value2)) { 111 assertEquals(String.format("Equal, but not 0: '%s' - '%s'", value1, value2), 0, result12); 112 assertEquals(String.format("Equal, but not 0: '%s' - '%s'", value2, value1), 0, result21); 113 } 114 else { 115 if (result12 == 0) fail(String.format("Not equal, but 0: '%s' - '%s'", value1, value2)); 116 if (result21 == 0) fail(String.format("Not equal, but 0: '%s' - '%s'", value2, value1)); 117 if (Integer.signum(result12) == Integer.signum(result21)) { 118 fail(String.format("Not symmetrical: '%s' - '%s'", value1, value2)); 119 } 120 } 121 122 for (int i3 = i2; i3 < values.size(); i3++) { 123 T value3 = values.get(i3); 124 125 int result23 = comparator.compare(value2, value3); 126 int result31 = comparator.compare(value3, value1); 127 128 if (!isTransitive(result12, result23, result31)) { 129 fail(String.format("Not transitive: '%s' - '%s' - '%s'", value1, value2, value3)); 130 } 131 } 132 } 133 } 134 } 135}