diff options
Diffstat (limited to 'org.eclipse.search.tests/src/org/eclipse/search/tests')
13 files changed, 162 insertions, 162 deletions
diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/FileTool.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/FileTool.java index 20550b15829..26568301af5 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/FileTool.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/FileTool.java @@ -32,26 +32,26 @@ import org.eclipse.core.runtime.Plugin; public class FileTool { - + private final static int MAX_RETRY= 5; - + /** * A buffer. */ private static byte[] buffer = new byte[8192]; - + /** * Unzips the given zip file to the given destination directory * extracting only those entries the pass through the given * filter. - * + * * @param zipFile the zip file to unzip * @param dstDir the destination directory * @throws IOException in case of problem */ public static void unzip(ZipFile zipFile, File dstDir) throws IOException { Enumeration<? extends ZipEntry> entries = zipFile.entries(); - + try { while(entries.hasMoreElements()){ ZipEntry entry = entries.nextElement(); @@ -76,12 +76,12 @@ public class FileTool { } } } - + /** * Returns the given file path with its separator * character changed from the given old separator to the * given new separator. - * + * * @param path a file path * @param oldSeparator a path separator character * @param newSeparator a path separator character @@ -92,11 +92,11 @@ public class FileTool { public static String changeSeparator(String path, char oldSeparator, char newSeparator){ return path.replace(oldSeparator, newSeparator); } - + /** * Copies all bytes in the given source file to * the given destination file. - * + * * @param source the given source file * @param destination the given destination file * @throws IOException in case of error @@ -107,16 +107,16 @@ public class FileTool { InputStream is = new FileInputStream(source); OutputStream os = new FileOutputStream(destination); ) { - + transferData(is, os); } } - + /** * Copies all bytes in the given source stream to * the given destination stream. Neither streams * are closed. - * + * * @param source the given source stream * @param destination the given destination stream * @throws IOException in case of error @@ -133,7 +133,7 @@ public class FileTool { /** * Copies the given source file to the given destination file. - * + * * @param src the given source file * @param dst the given destination file * @throws IOException in case of error @@ -159,13 +159,13 @@ public class FileTool { return null; } } - + public static File createTempFileInPlugin(Plugin plugin, IPath path) { IPath stateLocation= plugin.getStateLocation(); stateLocation= stateLocation.append(path); return stateLocation.toFile(); } - + public static StringBuffer read(String fileName) throws IOException { return read(new FileReader(fileName)); } @@ -193,7 +193,7 @@ public class FileTool { writer.write(content.toString()); } } - + public static void delete(File file) { if (file.exists()) { for (int i= 0; i < MAX_RETRY; i++) { diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/ResourceHelper.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/ResourceHelper.java index b9a030b7fdd..597d4ee7e2c 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/ResourceHelper.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/ResourceHelper.java @@ -40,32 +40,32 @@ import org.eclipse.core.resources.ResourcesPlugin; * @since 3.0 */ public class ResourceHelper { - + private final static IProgressMonitor NULL_MONITOR= new NullProgressMonitor(); private static final int MAX_RETRY= 10; - + public static IProject createProject(String projectName) throws CoreException { - + IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); IProject project= root.getProject(projectName); if (!project.exists()) project.create(NULL_MONITOR); else project.refreshLocal(IResource.DEPTH_INFINITE, null); - + if (!project.isOpen()) project.open(NULL_MONITOR); - + return project; } - + public static void deleteProject(String projectName) throws CoreException { IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); IProject project= root.getProject(projectName); if (project.exists()) delete(project); } - + public static void delete(final IResource resource) throws CoreException { IWorkspaceRunnable runnable= new IWorkspaceRunnable() { @Override @@ -89,12 +89,12 @@ public class ResourceHelper { } }; ResourcesPlugin.getWorkspace().run(runnable, null); - + } /** * Creates a folder and all parent folders if not existing. Project must exist. - * + * * @param folder The folder to create * @return Returns the input folder * @throws CoreException if creation fails @@ -109,7 +109,7 @@ public class ResourceHelper { } return folder; } - + public static IFile createFile(IFolder folder, String name, String contents, String encoding) throws CoreException, IOException { IFile file= folder.getFile(name); if (contents == null) @@ -121,55 +121,55 @@ public class ResourceHelper { return file; } - + public static IFile createFile(IFolder folder, String name, String contents) throws CoreException, IOException { return createFile(folder, name, contents, "ISO-8859-1"); } - + public static IFile createLinkedFile(IContainer container, IPath linkPath, File linkedFileTarget) throws CoreException { IFile iFile= container.getFile(linkPath); iFile.createLink(new Path(linkedFileTarget.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR); return iFile; } - + public static IFile createLinkedFile(IContainer container, IPath linkPath, Plugin plugin, IPath linkedFileTargetPath) throws CoreException { File file= FileTool.getFileInPlugin(plugin, linkedFileTargetPath); IFile iFile= container.getFile(linkPath); iFile.createLink(new Path(file.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR); return iFile; } - + public static IFolder createLinkedFolder(IContainer container, IPath linkPath, File linkedFolderTarget) throws CoreException { IFolder folder= container.getFolder(linkPath); folder.createLink(new Path(linkedFolderTarget.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR); return folder; } - + public static IFolder createLinkedFolder(IContainer container, IPath linkPath, Plugin plugin, IPath linkedFolderTargetPath) throws CoreException { File file= FileTool.getFileInPlugin(plugin, linkedFolderTargetPath); IFolder iFolder= container.getFolder(linkPath); iFolder.createLink(new Path(file.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR); return iFolder; } - + public static IProject createLinkedProject(String projectName, Plugin plugin, IPath linkPath) throws CoreException { IWorkspace workspace= ResourcesPlugin.getWorkspace(); IProject project= workspace.getRoot().getProject(projectName); - + IProjectDescription desc= workspace.newProjectDescription(projectName); File file= FileTool.getFileInPlugin(plugin, linkPath); IPath projectLocation= new Path(file.getAbsolutePath()); if (Platform.getLocation().equals(projectLocation)) projectLocation= null; desc.setLocation(projectLocation); - + project.create(desc, NULL_MONITOR); if (!project.isOpen()) project.open(NULL_MONITOR); - + return project; } - + public static IProject createJUnitSourceProject(String projectName) throws CoreException, ZipException, IOException { IProject project= ResourceHelper.createProject(projectName); ZipFile zip= new ZipFile(FileTool.getFileInPlugin(SearchTestPlugin.getDefault(), new Path("testresources/junit37-noUI-src.zip"))); //$NON-NLS-1$ diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/SearchTestPlugin.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/SearchTestPlugin.java index fcdde820efe..142af04745a 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/SearchTestPlugin.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/SearchTestPlugin.java @@ -35,7 +35,7 @@ import org.eclipse.search2.internal.ui.SearchView; public class SearchTestPlugin extends AbstractUIPlugin { //The shared instance. private static SearchTestPlugin fgPlugin; - + public SearchTestPlugin() { fgPlugin = this; } @@ -43,7 +43,7 @@ public class SearchTestPlugin extends AbstractUIPlugin { public static SearchTestPlugin getDefault() { return fgPlugin; } - + public SearchView getSearchView() { return (SearchView) NewSearchUI.activateSearchResultView(); } diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java index 80881a32665..c6d922b9401 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java @@ -65,13 +65,13 @@ public class AnnotationManagerTest { fQuery1= new FileSearchQuery("Test", false, true, scope); //$NON-NLS-1$//$NON-NLS-2$ fQuery2= new FileSearchQuery("Test", false, true, scope); //$NON-NLS-1$//$NON-NLS-2$ } - + @After public void tearDown() { InternalSearchUI.getInstance().removeAllQueries(); fQuery1= null; fQuery2= null; - + EditorAnnotationManager.debugSetHighlighterType(EditorAnnotationManager.HIGHLLIGHTER_ANY); } @@ -94,20 +94,20 @@ public class AnnotationManagerTest { positions.add(annotationModel.getPosition(annotation)); } } - + Match[] matches= result.getMatches(file); for (int j= 0; j < matches.length; j++) { Position position= new Position(matches[j].getOffset(), matches[j].getLength()); assertTrue("position not found at: "+j, positions.remove(position)); //$NON-NLS-1$ } assertEquals(0, positions.size()); - + } } finally { SearchPlugin.getActivePage().closeAllEditors(false); } } - + @Test public void testBogusAnnotation() throws Exception { NewSearchUI.runQueryInForeground(null, fQuery1); @@ -116,14 +116,14 @@ public class AnnotationManagerTest { SearchTestPlugin.openTextEditor(SearchTestPlugin.getDefault().getWorkbench().getWorkbenchWindows()[0].getPages()[0], file); result.addMatch(new FileMatch(file)); } - + @Test public void testRemoveQuery() throws Exception { NewSearchUI.runQueryInForeground(null, fQuery1); AbstractTextSearchResult result= (AbstractTextSearchResult) fQuery1.getSearchResult(); Object[] files= result.getElements(); InternalSearchUI.getInstance().removeQuery(fQuery1); - + try { for (int i= 0; i < files.length; i++) { IFile file= (IFile)files[i]; @@ -170,7 +170,7 @@ public class AnnotationManagerTest { SearchPlugin.getActivePage().closeAllEditors(false); } } - + @Test public void testSwitchQuery() throws Exception { NewSearchUI.runQueryInForeground(null, fQuery1); diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java index f0ac8c9e917..f9df723bf44 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java @@ -31,19 +31,19 @@ import org.eclipse.search.tests.ResourceHelper; public class FileCharSequenceTests { private final String TEST_CONTENT= "ABCDEFGHIJKLMNOPQRSTUVWXYZÜöäüèéùabcdefghijklmnopqrstuvwxyz1234567890@\'\"\n$¢"; //€ - + private IProject fProject; - + @Before public void setUp() throws Exception { fProject= ResourceHelper.createProject("my-project"); //$NON-NLS-1$ } - + @After public void tearDown() throws Exception { ResourceHelper.deleteProject("my-project"); //$NON-NLS-1$ } - + @Test public void testFileCharSequence() throws Exception { StringBuilder buf= new StringBuilder(); @@ -77,26 +77,26 @@ public class FileCharSequenceTests { private void testForEncoding(CharSequence buf, String encoding) throws CoreException, IOException { IFolder folder= ResourceHelper.createFolder(fProject.getFolder("folder1")); IFile file1= ResourceHelper.createFile(folder, "file1", buf.toString(), encoding); - + FileCharSequenceProvider provider= new FileCharSequenceProvider(); CharSequence cs= null; try { cs= provider.newCharSequence(file1); - + assertEquals(encoding, cs, buf); - + assertSubSequence(encoding, cs, buf, 0, buf.length() / 6); assertSubSequence(encoding, cs, buf, buf.length() / 6, FileCharSequenceProvider.BUFFER_SIZE); - + int pos= 8 * buf.length() / 9; assertSubSequence(encoding, cs, buf, pos, buf.length() - pos); - + CharSequence seq1a= cs.subSequence(100, 100 + FileCharSequenceProvider.BUFFER_SIZE); CharSequence seq1e= buf.subSequence(100, 100 + FileCharSequenceProvider.BUFFER_SIZE); assertSubSequence(encoding, seq1a, seq1e, 500, 500); - + assertSubSequence(encoding, seq1a, seq1e, FileCharSequenceProvider.BUFFER_SIZE, 0); - + } finally { if (cs != null) { provider.releaseCharSequence(cs); @@ -104,13 +104,13 @@ public class FileCharSequenceTests { file1.delete(true, null); } } - + private void assertSubSequence(String message, CharSequence actual, CharSequence expected, int start, int length) { CharSequence actualSub= actual.subSequence(start, start + length); CharSequence expectedSub= expected.subSequence(start, start + length); assertEquals(message + " - subsequence(" + start + ", " + length + ")", actualSub, expectedSub); } - + private void assertEquals(String desc, CharSequence actual, CharSequence expected) { for (int i= 0; i < expected.length(); i++) { Assert.assertEquals(desc + " - forward " + i, expected.charAt(i), actual.charAt(i)); @@ -125,14 +125,14 @@ public class FileCharSequenceTests { for (int i= 0; i < expected.length(); i+= FileCharSequenceProvider.BUFFER_SIZE) { Assert.assertEquals(desc + " - forward - buffersize" + i, expected.charAt(i), actual.charAt(i)); } - + assertOutOfBound(desc + "access at length", actual, expected.length()); assertOutOfBound(desc + "access at -1", actual, -1); Assert.assertEquals(desc + " - length", actual.toString(), expected.toString()); } - - + + private void assertOutOfBound(String message, CharSequence cs, int i) { try { cs.charAt(i); @@ -143,5 +143,5 @@ public class FileCharSequenceTests { } - + } diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java index d0ceb1def42..4496d61fb60 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java @@ -43,7 +43,7 @@ import org.eclipse.search.tests.SearchTestPlugin; import org.eclipse.search.ui.text.FileTextSearchScope; public class FileSearchTests { - + private static class TestResult { public IResource resource; public int offset; @@ -114,12 +114,12 @@ public class FileSearchTests { public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup(); private IProject fProject; - + @Before public void setUp() throws Exception{ fProject= ResourceHelper.createProject("my-project"); //$NON-NLS-1$ } - + @After public void tearDown() throws Exception { ResourceHelper.deleteProject("my-project"); //$NON-NLS-1$ @@ -129,7 +129,7 @@ public class FileSearchTests { public void testSimpleFilesSerial() throws Exception { testSimpleFiles(new SerialTestResultCollector()); } - + @Test public void testSimpleFilesParallel() throws Exception { testSimpleFiles(new ParallelTestResultCollector()); @@ -156,12 +156,12 @@ public class FileSearchTests { assertMatches(results, 2, file1, buf.toString(), "hello"); assertMatches(results, 2, file2, buf.toString(), "hello"); } - + @Test public void testWildCards1Serial() throws Exception { testWildCards1(new SerialTestResultCollector()); } - + @Test public void testWildCards1Parallel() throws Exception { testWildCards1(new ParallelTestResultCollector()); @@ -179,19 +179,19 @@ public class FileSearchTests { ResourceHelper.createFile(folder, "file2", buf.toString()); Pattern searchPattern= PatternConstructor.createPattern("mor*", false, false); - + FileTextSearchScope scope= FileTextSearchScope.newSearchScope(new IResource[] {fProject}, (String[]) null, false); TextSearchEngine.create().search(scope, collector, searchPattern, null); - + TestResult[] results= collector.getResults(); assertEquals("Number of total results", 6, results.length); } - + @Test public void testWildCards2Serial() throws Exception { testWildCards2(new SerialTestResultCollector()); } - + @Test public void testWildCards2Parallel() throws Exception { testWildCards2(new ParallelTestResultCollector()); @@ -209,39 +209,39 @@ public class FileSearchTests { ResourceHelper.createFile(folder, "file2", buf.toString()); Pattern searchPattern= PatternConstructor.createPattern("mo?e", false, false); - + FileTextSearchScope scope= FileTextSearchScope.newSearchScope(new IResource[] {fProject}, (String[]) null, false); TextSearchEngine.create().search(scope, collector, searchPattern, null); - + TestResult[] results= collector.getResults(); assertEquals("Number of total results", 4, results.length); } - + @Test public void testWildCards3Serial() throws Exception { testWildCards3(new SerialTestResultCollector()); } - + @Test public void testWildCards3Parallel() throws Exception { testWildCards3(new ParallelTestResultCollector()); } private void testWildCards3(TestResultCollector collector) throws Exception { - + IProject project= fgJUnitSource.getStandardProject(); IFile openFile1= (IFile) project.findMember("junit/framework/TestCase.java"); IFile openFile2= (IFile) project.findMember("junit/extensions/ExceptionTestCase.java"); IFile openFile3= (IFile) project.findMember("junit/framework/Assert.java"); IFile openFile4= (IFile) project.findMember("junit/samples/money/MoneyTest.java"); - + IWorkbenchPage activePage= SearchPlugin.getActivePage(); try { SearchTestPlugin.openTextEditor(activePage, openFile1); SearchTestPlugin.openTextEditor(activePage, openFile2); SearchTestPlugin.openTextEditor(activePage, openFile3); SearchTestPlugin.openTextEditor(activePage, openFile4); - + long start= System.currentTimeMillis(); Pattern searchPattern= PatternConstructor.createPattern("\\w*\\(\\)", false, true); @@ -260,12 +260,12 @@ public class FileSearchTests { } } - + @Test public void testWholeWordSerial() throws Exception { testWholeWord(new SerialTestResultCollector()); } - + @Test public void testWholeWordParallel() throws Exception { testWholeWord(new ParallelTestResultCollector()); @@ -316,12 +316,12 @@ public class FileSearchTests { assertEquals("Number of partial-word results", 22, collector.getNumberOfResults()); } } - + @Test public void testFileOpenInEditorSerial() throws Exception { testFileOpenInEditor(new SerialTestResultCollector()); } - + @Test public void testFileOpenInEditorParallel() throws Exception { testFileOpenInEditor(new ParallelTestResultCollector()); @@ -339,7 +339,7 @@ public class FileSearchTests { try { SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file2); - + Pattern searchPattern= PatternConstructor.createPattern("hello", false, true); FileTextSearchScope scope= FileTextSearchScope.newSearchScope(new IResource[] {fProject}, (String[]) null, false); @@ -354,12 +354,12 @@ public class FileSearchTests { SearchPlugin.getActivePage().closeAllEditors(false); } } - + @Test public void testDerivedFilesSerial() throws Exception { testDerivedFiles(new SerialTestResultCollector()); } - + @Test public void testDerivedFilesParallel() throws Exception { testDerivedFiles(new ParallelTestResultCollector()); @@ -372,17 +372,17 @@ public class FileSearchTests { ResourceHelper.createFile(folder1, "file1", buf.toString()); IFile file2= ResourceHelper.createFile(folder1, "file2", buf.toString()); file2.setDerived(true, null); - + IFolder folder2= ResourceHelper.createFolder(folder1.getFolder("folder2")); folder2.setDerived(true, null); ResourceHelper.createFile(folder2, "file3", buf.toString()); IFolder folder3= ResourceHelper.createFolder(folder2.getFolder("folder3")); ResourceHelper.createFile(folder3, "file4", buf.toString()); - + IFolder folder4= ResourceHelper.createFolder(folder1.getFolder("folder4")); ResourceHelper.createFile(folder4, "file5", buf.toString()); - + /** * folder1 * file1 @@ -394,8 +394,8 @@ public class FileSearchTests { * folder4 * file5 */ - - + + Pattern searchPattern= PatternConstructor.createPattern("hello", false, true); Pattern fileNamePattern= PatternConstructor.createPattern("*", false, false); TextSearchEngine engine= TextSearchEngine.create(); @@ -442,12 +442,12 @@ public class FileSearchTests { assertEquals(0, collector.getNumberOfResults()); } } - + @Test public void testFileNamePatternsSerial() throws Exception { testFileNamePatterns(new SerialTestResultCollector()); } - + @Test public void testFileNamePatternsParallel() throws Exception { testFileNamePatterns(new ParallelTestResultCollector()); @@ -463,52 +463,52 @@ public class FileSearchTests { Pattern searchPattern= PatternConstructor.createPattern("Test", false, false); String[] fileNamePatterns= { "*" }; - + TestResult[] results= performSearch(collector, fileNamePatterns, searchPattern); assertEquals("Number of total results", 4, results.length); - + fileNamePatterns= new String[] { "*.x" }; results= performSearch(collector, fileNamePatterns, searchPattern); assertEquals("Number of total results", 2, results.length); - + fileNamePatterns= new String[] { "*.x", "*.y*" }; results= performSearch(collector, fileNamePatterns, searchPattern); assertEquals("Number of total results", 3, results.length); - + fileNamePatterns= new String[] { "!*.x" }; results= performSearch(collector, fileNamePatterns, searchPattern); assertEquals("Number of total results", 2, results.length); - + fileNamePatterns= new String[] { "!*.x", "!*.y" }; results= performSearch(collector, fileNamePatterns, searchPattern); assertEquals("Number of total results", 1, results.length); - + fileNamePatterns= new String[] { "*", "!*.y" }; results= performSearch(collector, fileNamePatterns, searchPattern); assertEquals("Number of total results", 3, results.length); - + fileNamePatterns= new String[] { "*", "!*.*" }; results= performSearch(collector, fileNamePatterns, searchPattern); assertEquals("Number of total results", 0, results.length); - + fileNamePatterns= new String[] { "*.x", "*.y*", "!*.y" }; results= performSearch(collector, fileNamePatterns, searchPattern); assertEquals("Number of total results", 2, results.length); - + fileNamePatterns= new String[] { "file*", "!*.x*", "!*.y" }; results= performSearch(collector, fileNamePatterns, searchPattern); assertEquals("Number of total results", 1, results.length); } - + private TestResult[] performSearch(TestResultCollector collector, String[] fileNamePatterns, Pattern searchPattern) { collector.reset(); FileTextSearchScope scope= FileTextSearchScope.newSearchScope(new IResource[] {fProject}, fileNamePatterns, false); TextSearchEngine.create().search(scope, collector, searchPattern, null); - + return collector.getResults(); } - + private void assertMatches(TestResult[] results, int expectedCount, IFile file, String fileContent, String string) { @@ -522,6 +522,6 @@ public class FileSearchTests { } assertEquals("Number of results in file", expectedCount, k); } - - + + } diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/JUnitSourceSetup.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/JUnitSourceSetup.java index 50849a88961..bd560a54d41 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/JUnitSourceSetup.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/JUnitSourceSetup.java @@ -20,12 +20,12 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.search.tests.ResourceHelper; public class JUnitSourceSetup extends ExternalResource { - + public static final String STANDARD_PROJECT_NAME= "JUnitSource"; - + private IProject fProject= null; private final String fProjectName; - + public IProject getStandardProject() { return ResourcesPlugin.getWorkspace().getRoot().getProject(STANDARD_PROJECT_NAME); } @@ -33,11 +33,11 @@ public class JUnitSourceSetup extends ExternalResource { public JUnitSourceSetup() { this(STANDARD_PROJECT_NAME); } - + public JUnitSourceSetup(String projectName) { fProjectName= projectName; } - + @Override public void before() throws Exception { IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(fProjectName); @@ -45,7 +45,7 @@ public class JUnitSourceSetup extends ExternalResource { fProject= ResourceHelper.createJUnitSourceProject(fProjectName); } } - + @Override public void after() /*throws Exception (but JUnit4 API is stupid...)*/ { if (fProject != null) { // delete only by the setup who created the project diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java index eb18d53f23b..5c673e1cdca 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java @@ -57,22 +57,22 @@ public class LineAnnotationManagerTest { @Before public void setUp() throws Exception { EditorAnnotationManager.debugSetHighlighterType(EditorAnnotationManager.HIGHLIGHTER_ANNOTATION); - + String[] fileNamePatterns= { "*.java" }; FileTextSearchScope scope= FileTextSearchScope.newWorkspaceScope(fileNamePatterns, false); - + fLineQuery= new LineBasedFileSearch(scope, false, true, "Test"); } - + @After public void tearDown() throws Exception { InternalSearchUI.getInstance().removeAllQueries(); fLineQuery= null; - + EditorAnnotationManager.debugSetHighlighterType(EditorAnnotationManager.HIGHLLIGHTER_ANY); } - - @Test + + @Test public void testLineBasedQuery() throws Exception { NewSearchUI.runQueryInForeground(null, fLineQuery); AbstractTextSearchResult result= (AbstractTextSearchResult) fLineQuery.getSearchResult(); diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineBasedFileSearch.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineBasedFileSearch.java index a8d969940d5..66076c4bd34 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineBasedFileSearch.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineBasedFileSearch.java @@ -39,13 +39,13 @@ import org.eclipse.search.ui.text.FileTextSearchScope; /** */ public class LineBasedFileSearch extends FileSearchQuery { - - + + private static class LineBasedTextSearchResultCollector extends TextSearchRequestor { - + private final AbstractTextSearchResult fResult; private IFile fLastFile; - private IDocument fLastDocument; + private IDocument fLastDocument; private Object fLock= new Object(); private LineBasedTextSearchResultCollector(AbstractTextSearchResult result) { @@ -87,12 +87,12 @@ public class LineBasedFileSearch extends FileSearchQuery { FileBuffers.getTextFileBufferManager().disconnect(fLastFile.getFullPath(), LocationKind.IFILE, null); } fLastFile= file; - + FileBuffers.getTextFileBufferManager().connect(file.getFullPath(), LocationKind.IFILE, null); fLastDocument= FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE).getDocument(); return fLastDocument; } - + @Override public void endReporting() { if (fLastFile != null) { @@ -103,10 +103,10 @@ public class LineBasedFileSearch extends FileSearchQuery { } } } - + private final FileTextSearchScope fScope; - - + + public LineBasedFileSearch(FileTextSearchScope scope, boolean isRegEx, boolean isCaseSensitive, String searchString) { super(searchString, isRegEx, isCaseSensitive, scope); fScope= scope; @@ -117,12 +117,12 @@ public class LineBasedFileSearch extends FileSearchQuery { public IStatus run(IProgressMonitor monitor) { AbstractTextSearchResult textResult= (AbstractTextSearchResult) getSearchResult(); textResult.removeAll(); - + LineBasedTextSearchResultCollector collector= new LineBasedTextSearchResultCollector(textResult); - + Pattern searchPattern= getSearchPattern(); return TextSearchEngine.create().search(fScope, collector, searchPattern, monitor); } - + } diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/PositionTrackerTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/PositionTrackerTest.java index ec5659a0016..504c63aa5bd 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/PositionTrackerTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/PositionTrackerTest.java @@ -50,11 +50,11 @@ public class PositionTrackerTest { public void setUp() throws Exception { String[] fileNamePatterns= { "*.java" }; FileTextSearchScope scope= FileTextSearchScope.newWorkspaceScope(fileNamePatterns, false); - + fQuery1= new FileSearchQuery("Test", false, true, scope); } - - + + @Test public void testInsertAt0() throws Exception { NewSearchUI.runQueryInForeground(null, fQuery1); @@ -68,7 +68,7 @@ public class PositionTrackerTest { SearchPlugin.getActivePage().closeAllEditors(false); } } - + @Test public void testInsertInsideMatch() throws Exception { NewSearchUI.runQueryInForeground(null, fQuery1); @@ -133,5 +133,5 @@ public class PositionTrackerTest { SearchPlugin.getActivePage().closeAllEditors(false); } } - + } diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/ResultUpdaterTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/ResultUpdaterTest.java index aba4fcc0586..72a224a5437 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/ResultUpdaterTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/ResultUpdaterTest.java @@ -30,27 +30,27 @@ import org.eclipse.search.tests.ResourceHelper; public class ResultUpdaterTest { private FileSearchQuery fQuery1; - + private IProject fProject; - + private static final String PROJECT_TO_MODIFY= "ModifiableProject"; @Before public void setUp() throws Exception { // create a own project to make modifications fProject= ResourceHelper.createJUnitSourceProject(PROJECT_TO_MODIFY); - + String[] fileNamePatterns= { "*.java" }; FileTextSearchScope scope= FileTextSearchScope.newSearchScope(new IResource[] { fProject }, fileNamePatterns, false); - + fQuery1= new FileSearchQuery("Test", false, true, scope); } - + @After public void tearDown() throws Exception { ResourceHelper.deleteProject(PROJECT_TO_MODIFY); } - + @Test public void testRemoveFile() throws Exception { NewSearchUI.runQueryInForeground(null, fQuery1); @@ -62,7 +62,7 @@ public class ResultUpdaterTest { assertEquals(totalCount-fileCount, result.getMatchCount()); assertEquals(0, result.getMatchCount(elements[0])); } - + @Test public void testRemoveProject() throws Exception { NewSearchUI.runQueryInForeground(null, fQuery1); diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SearchResultPageTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SearchResultPageTest.java index 7d401f10ded..1dc55ae50a0 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SearchResultPageTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SearchResultPageTest.java @@ -52,7 +52,7 @@ public class SearchResultPageTest { SearchTestPlugin.ensureWelcomePageClosed(); String[] fileNamePatterns= { "*.java" }; FileTextSearchScope scope= FileTextSearchScope.newWorkspaceScope(fileNamePatterns, false); - + fQuery1= new FileSearchQuery("Test", false, true, scope); } @@ -67,7 +67,7 @@ public class SearchResultPageTest { page.setLayout(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT); checkViewerDisplay(page); } - + private void checkViewerDisplay(FileSearchPage page) { StructuredViewer viewer= page.getViewer(); AbstractTextSearchResult result= (AbstractTextSearchResult) fQuery1.getSearchResult(); @@ -81,7 +81,7 @@ public class SearchResultPageTest { } } - + @Test @Ignore // checkElementDisplay(..) misses cases where one line contains multiple matches public void testRemoveTreeMatches() throws Exception { @@ -113,7 +113,7 @@ public class SearchResultPageTest { Display.getDefault().readAndDispatch(); } } - + private void consumeEvents() { while (Display.getDefault().readAndDispatch()) { } @@ -128,7 +128,7 @@ public class SearchResultPageTest { if (itemCount > 1) assertTrue(item.getText().indexOf(String.valueOf(itemCount)) >= 0); } - + @Test public void testTableNavigation() { NewSearchUI.runQueryInForeground(null, fQuery1); @@ -136,25 +136,25 @@ public class SearchResultPageTest { FileSearchPage page= (FileSearchPage) view.getActivePage(); page.setLayout(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT); Table table= ((TableViewer) page.getViewer()).getTable(); - + consumeEvents(); - + // select the first element. table.setSelection(0); table.showSelection(); - + consumeEvents(); // back from first match, goto last page.gotoPreviousMatch(); - + consumeEvents(); - + assertEquals(1, table.getSelectionCount()); assertEquals(table.getItemCount()-1, table.getSelectionIndex()); // and forward again, to the first match. page.gotoNextMatch(); - + consumeEvents(); assertEquals(1, table.getSelectionCount()); assertEquals(0, table.getSelectionIndex()); diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java index 2571535db8a..b370c8692b9 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java @@ -36,10 +36,10 @@ public class SortingTest { public void setUp() throws Exception { String[] fileNamePatterns= { "*.java" }; FileTextSearchScope scope= FileTextSearchScope.newWorkspaceScope(fileNamePatterns, false); - + fQuery1= new FileSearchQuery("Test", false, true, scope); } - + @Test public void testSorted() throws Exception { NewSearchUI.activateSearchResultView(); @@ -47,7 +47,7 @@ public class SortingTest { AbstractTextSearchResult result= (AbstractTextSearchResult) fQuery1.getSearchResult(); int originalMatchCount= result.getMatchCount(); List<Match> allMatches= new ArrayList<>(originalMatchCount); - + // first, collect all matches Object[] elements= result.getElements(); for (int i= 0; i < elements.length; i++) { @@ -59,13 +59,13 @@ public class SortingTest { // now remove them and readd them in reverse order result.removeAll(); assertTrue("removed all matches", result.getMatchCount() == 0); - + for (int i= allMatches.size()-1; i >= 0; i--) { result.addMatch(allMatches.get(i)); } - + assertEquals("Test that all matches have been added again", result.getMatchCount(), originalMatchCount); - + // now check that they're ordered by position. for (int i= 0; i < elements.length; i++) { Match[] matches= result.getMatches(elements[i]); @@ -90,5 +90,5 @@ public class SortingTest { return false; } } - + } |