diff options
author | teicher | 2005-06-03 10:39:47 +0000 |
---|---|---|
committer | teicher | 2005-06-03 10:39:47 +0000 |
commit | a695a4cccd429e9da204580d5fe1a8c878c2038e (patch) | |
tree | 61e194c2f60745d81337a3f2179959f32666cc8b /org.eclipse.core.filebuffers.tests/src/org | |
parent | f7289834e93155ed6a7719f152e403a07ecba8d8 (diff) | |
download | eclipse.platform.text-a695a4cccd429e9da204580d5fe1a8c878c2038e.tar.gz eclipse.platform.text-a695a4cccd429e9da204580d5fe1a8c878c2038e.tar.xz eclipse.platform.text-a695a4cccd429e9da204580d5fe1a8c878c2038e.zip |
91508 [implementation] text search spends 7% in ITextFileBufferManager.getTextFileBufferManager
- check workspaceRoot.exists(path) first, which is the 93% case
- clarified constract of normalize
- added tests for non-accessible workspace files (ie. in closed projects)
Diffstat (limited to 'org.eclipse.core.filebuffers.tests/src/org')
3 files changed, 135 insertions, 0 deletions
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferFunctions.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferFunctions.java index 460a733d771..1eb12f15ecc 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferFunctions.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferFunctions.java @@ -60,6 +60,10 @@ public abstract class FileBufferFunctions extends TestCase { fPath= createPath(fProject); } + protected IProject getProject() { + return fProject; + } + protected void tearDown() throws Exception { ResourceHelper.deleteProject("project"); } diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonAccessibleWorkspaceFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonAccessibleWorkspaceFiles.java new file mode 100644 index 00000000000..9cf3ab5ef8c --- /dev/null +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonAccessibleWorkspaceFiles.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.core.filebuffers.tests; + +import java.io.File; +import java.io.FileNotFoundException; + +import org.eclipse.core.filebuffers.FileBuffers; +import org.eclipse.core.internal.filebuffers.FileBuffersPlugin; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; + +/** + * FileBuffersForWorkspaceFiles + */ +public class FileBuffersForNonAccessibleWorkspaceFiles extends FileBufferFunctions { + + protected void setUp() throws Exception { + super.setUp(); + getProject().close(null); + } + + protected IPath createPath(IProject project) throws Exception { + IFolder folder= ResourceHelper.createFolder("project/folderA/folderB/"); + IFile file= ResourceHelper.createFile(folder, "WorkspaceFile", "content"); + return file.getFullPath(); + } + + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() + */ + protected void tearDown() throws Exception { + File file= FileBuffers.getSystemFileAtLocation(getPath()); + FileTool.delete(file); + super.tearDown(); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly() + */ + protected void markReadOnly() throws Exception { + File file= FileBuffers.getSystemFileAtLocation(getPath()); + file.setReadOnly(); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#isStateValidationSupported() + */ + protected boolean isStateValidationSupported() { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#deleteUnderlyingFile() + */ + protected boolean deleteUnderlyingFile() throws Exception { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#moveUnderlyingFile() + */ + protected IPath moveUnderlyingFile() throws Exception { + return null; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#modifyUnderlyingFile() + */ + protected boolean modifyUnderlyingFile() throws Exception { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#getAnnotationModelClass() + */ + protected Class getAnnotationModelClass() throws Exception { + return null; + } + + public void test7() throws Exception { + try { + super.test7(); + fail(); + } catch (CoreException e) { + ensureFileNotFoundError(e); + } + } + + public void test11_1() throws Exception { + try { + super.test11_1(); + fail(); + } catch (CoreException e) { + ensureFileNotFoundError(e); + } + } + + public void test17_3() throws Exception { + try { + super.test17_3(); + fail(); + } catch (CoreException e) { + ensureFileNotFoundError(e); + } + } + + private void ensureFileNotFoundError(CoreException e) { + IStatus status= e.getStatus(); + assertEquals(FileBuffersPlugin.PLUGIN_ID, status.getPlugin()); + assertEquals(IStatus.ERROR, status.getSeverity()); + assertEquals(IStatus.OK, status.getCode()); + Throwable cause= status.getException(); + assertNotNull(cause); + assertTrue(cause instanceof FileNotFoundException); + } +} diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestSuite.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestSuite.java index 67adeb385da..ff9e6ebeffb 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestSuite.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestSuite.java @@ -32,6 +32,7 @@ public class FileBuffersTestSuite { suite.addTestSuite(FileBuffersForFilesInLinkedFolders.class); suite.addTestSuite(FileBuffersForNonExistingExternalFiles.class); suite.addTestSuite(FileBuffersForNonExistingWorkspaceFiles.class); + suite.addTestSuite(FileBuffersForNonAccessibleWorkspaceFiles.class); //$JUnit-END$ return suite; } |