Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2004-09-09 17:18:32 +0000
committerKai Maetzel2004-09-09 17:18:32 +0000
commit807662d54c73613ef193cc2105c4217d5cfc8147 (patch)
tree601e765e7ec3c785ed9982f3c894c3c90aba69a0 /org.eclipse.core.filebuffers.tests
parentc85f19e21da05a0e193e6c36a3f3644ec6455663 (diff)
downloadeclipse.platform.text-807662d54c73613ef193cc2105c4217d5cfc8147.tar.gz
eclipse.platform.text-807662d54c73613ef193cc2105c4217d5cfc8147.tar.xz
eclipse.platform.text-807662d54c73613ef193cc2105c4217d5cfc8147.zip
Updated FileBuffers test suite
Diffstat (limited to 'org.eclipse.core.filebuffers.tests')
-rw-r--r--org.eclipse.core.filebuffers.tests/plugin.xml6
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java (renamed from org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferTest1.java)93
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferFunctions.java216
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForExternalFiles.java44
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForLinkedFiles.java46
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingExternalFiles.java40
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingWorkspaceFiles.java44
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForWorkspaceFiles.java28
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestPlugin.java30
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestSuite.java (renamed from org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FilebuffersTestSuite.java)9
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java247
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FilebuffersTestPlugin.java64
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceHelper.java (renamed from org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TestHelper.java)29
-rw-r--r--org.eclipse.core.filebuffers.tests/test.xml2
-rw-r--r--org.eclipse.core.filebuffers.tests/testResources/LinkTarget (renamed from org.eclipse.core.filebuffers.tests/testResources/LinkTarget1)0
15 files changed, 779 insertions, 119 deletions
diff --git a/org.eclipse.core.filebuffers.tests/plugin.xml b/org.eclipse.core.filebuffers.tests/plugin.xml
index 518049b9c..26b831d11 100644
--- a/org.eclipse.core.filebuffers.tests/plugin.xml
+++ b/org.eclipse.core.filebuffers.tests/plugin.xml
@@ -5,7 +5,7 @@
name="%Plugin.name"
version="3.1.0"
provider-name="%Plugin.providerName"
- class="org.eclipse.core.filebuffers.tests.FilebuffersTestPlugin">
+ class="org.eclipse.core.filebuffers.tests.FileBuffersTestPlugin">
<runtime>
<library name="filebufferstests.jar">
@@ -13,10 +13,10 @@
</library>
</runtime>
<requires>
- <import plugin="org.eclipse.core.runtime.compatibility"/>
+ <import plugin="org.eclipse.core.runtime"/>
+ <import plugin="org.eclipse.core.filebuffers"/>
<import plugin="org.eclipse.core.resources"/>
<import plugin="org.junit"/>
- <import plugin="org.eclipse.core.filebuffers"/>
<import plugin="org.eclipse.text"/>
</requires>
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferTest1.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java
index 41610550c..298e1e0fb 100644
--- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferTest1.java
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java
@@ -13,9 +13,7 @@ package org.eclipse.core.filebuffers.tests;
import java.io.File;
import junit.framework.Assert;
-import junit.framework.Test;
import junit.framework.TestCase;
-import junit.framework.TestSuite;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -34,7 +32,7 @@ import org.eclipse.jface.text.IDocument;
-public class FileBufferTest1 extends TestCase {
+public class FileBufferCreation extends TestCase {
private final static String CONTENT1= "This is the content of the workspace file.";
private final static String CONTENT2= "This is the content of the link target.";
@@ -43,33 +41,30 @@ public class FileBufferTest1 extends TestCase {
private IProject fProject;
-
- public static Test suite() {
- TestSuite suite= new TestSuite();
- suite.addTest(new FileBufferTest1("test1"));
- suite.addTest(new FileBufferTest1("test2"));
- suite.addTest(new FileBufferTest1("test3"));
- suite.addTest(new FileBufferTest1("test4"));
- suite.addTest(new FileBufferTest1("test5"));
- suite.addTest(new FileBufferTest1("test6"));
- return suite;
- }
-
- public FileBufferTest1(String name) {
+
+ public FileBufferCreation(String name) {
super(name);
}
protected void setUp() throws Exception {
- fProject= TestHelper.createProject("project");
+ fProject= ResourceHelper.createProject("project");
}
protected void tearDown() throws Exception {
- TestHelper.deleteProject("project");
- }
+ ResourceHelper.deleteProject("project");
+ }
+
+ private IPath createLinkedFile(String fileName, String linkTarget) throws CoreException {
+ IFile file= ResourceHelper.createLinkedFile(fProject, new Path(fileName), FileBuffersTestPlugin.getDefault(), new Path(linkTarget));
+ return file != null ? file.getFullPath() : null;
+ }
+ /*
+ * Tests the creation of file buffer for an existing file.
+ */
public void test1() throws Exception {
- IFolder folder= TestHelper.createFolder("project/folderA/folderB/");
- IFile file= TestHelper.createFile(folder, "file", CONTENT1);
+ IFolder folder= ResourceHelper.createFolder("project/folderA/folderB/");
+ IFile file= ResourceHelper.createFile(folder, "file", CONTENT1);
IPath path= file.getFullPath();
assertNotNull(path);
@@ -86,10 +81,14 @@ public class FileBufferTest1 extends TestCase {
assertNull(manager.getTextFileBuffer(path));
}
+ /*
+ * Tests that two different paths pointing to the same physical resource
+ * result in the same shared file buffer.
+ */
public void test2() throws Exception {
- IFolder folder= TestHelper.createFolder("project/folderA/folderB/");
- IFile file= TestHelper.createFile(folder, "file", CONTENT1);
+ IFolder folder= ResourceHelper.createFolder("project/folderA/folderB/");
+ IFile file= ResourceHelper.createFile(folder, "file", CONTENT1);
IPath path1= file.getFullPath();
assertNotNull(path1);
@@ -133,8 +132,11 @@ public class FileBufferTest1 extends TestCase {
assertNull(manager.getTextFileBuffer(path2));
}
+ /*
+ * Tests the creation of a file buffer for a linked file.
+ */
public void test3() throws Exception {
- IPath path= createLinkedFile("file", "testResources/LinkTarget1");
+ IPath path= createLinkedFile("file", "testResources/LinkTarget");
assertNotNull(path);
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
@@ -150,11 +152,15 @@ public class FileBufferTest1 extends TestCase {
assertNull(manager.getTextFileBuffer(path));
}
+ /*
+ * Tests that two different files linked to the same target file result
+ * in two different, independent file buffers.
+ */
public void test4() throws Exception {
- IPath path1= createLinkedFile("file1", "testResources/LinkTarget1");
+ IPath path1= createLinkedFile("file1", "testResources/LinkTarget");
assertNotNull(path1);
- IPath path2= createLinkedFile("file2", "testResources/LinkTarget1");
+ IPath path2= createLinkedFile("file2", "testResources/LinkTarget");
assertNotNull(path2);
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
@@ -183,12 +189,16 @@ public class FileBufferTest1 extends TestCase {
manager.disconnect(path1, null);
assertNull(manager.getTextFileBuffer(path1));
+ assertNotNull(manager.getTextFileBuffer(path2));
manager.disconnect(path2, null);
assertNull(manager.getTextFileBuffer(path2));
}
+ /*
+ * Tests the creation of a file buffer for an external file.
+ */
public void test5() throws Exception {
- File externalFile= TestHelper.getFileInPlugin(FilebuffersTestPlugin.getDefault(), new Path("testResources/ExternalFile"));
+ File externalFile= FileTool.getFileInPlugin(FileBuffersTestPlugin.getDefault(), new Path("testResources/ExternalFile"));
assertNotNull(externalFile);
IPath path= new Path(externalFile.getAbsolutePath());
@@ -205,12 +215,16 @@ public class FileBufferTest1 extends TestCase {
assertNull(manager.getTextFileBuffer(path));
}
+ /*
+ * Tests that a workspace file linked to an external file and the external file result
+ * in two different, independent file buffers.
+ */
public void test6() throws Exception {
IPath path1= createLinkedFile("file1", "testResources/ExternalFile");
assertNotNull(path1);
- File externalFile= TestHelper.getFileInPlugin(FilebuffersTestPlugin.getDefault(), new Path("testResources/ExternalFile"));
+ File externalFile= FileTool.getFileInPlugin(FileBuffersTestPlugin.getDefault(), new Path("testResources/ExternalFile"));
assertNotNull(externalFile);
IPath path2= new Path(externalFile.getAbsolutePath());
@@ -243,9 +257,24 @@ public class FileBufferTest1 extends TestCase {
manager.disconnect(path2, null);
assertNull(manager.getTextFileBuffer(path2));
}
-
- private IPath createLinkedFile(String fileName, String linkTarget) throws CoreException {
- IFile file= TestHelper.createLinkedFile(fProject, new Path(fileName), FilebuffersTestPlugin.getDefault(), new Path(linkTarget));
- return file != null ? file.getFullPath() : null;
+
+ /*
+ * Tests the creation of a file buffer for a non-existing file.
+ */
+ public void test7() throws Exception {
+ IPath path= FileBuffersTestPlugin.getDefault().getStateLocation();
+ path= path.append("NonExistingFile");
+
+ ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
+ manager.connect(path, null);
+ ITextFileBuffer buffer= manager.getTextFileBuffer(path);
+ Assert.assertNotNull(buffer);
+
+ IDocument document= buffer.getDocument();
+ Assert.assertNotNull(document);
+ Assert.assertTrue("".equals(document.get()));
+
+ manager.disconnect(path, null);
+ assertNull(manager.getTextFileBuffer(path));
}
}
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
new file mode 100644
index 000000000..e9ae95529
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferFunctions.java
@@ -0,0 +1,216 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+
+import org.eclipse.jface.text.IDocument;
+
+/**
+ * FileBufferFunctions
+ */
+public abstract class FileBufferFunctions extends TestCase {
+
+ private IProject fProject;
+ private ITextFileBufferManager fManager;
+ private IPath fPath;
+
+
+ protected abstract IPath createPath(IProject project) throws Exception;
+
+
+ protected void setUp() throws Exception {
+ fManager= FileBuffers.getTextFileBufferManager();
+ fProject= ResourceHelper.createProject("project");
+ fPath= createPath(fProject);
+ }
+
+ protected void tearDown() throws Exception {
+ ResourceHelper.deleteProject("project");
+ }
+
+ protected IPath getPath() {
+ return fPath;
+ }
+
+ /*
+ * Tests getLocation.
+ */
+ public void test1() throws Exception {
+ fManager.connect(fPath, null);
+ try {
+ ITextFileBuffer buffer= fManager.getTextFileBuffer(fPath);
+ assertEquals(fPath, buffer.getLocation());
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+
+ /*
+ * Tests isSynchronized.
+ */
+ public void test2() throws Exception {
+ fManager.connect(fPath, null);
+ try {
+ ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath);
+ assertTrue(fileBuffer.isSynchronized());
+ File file= FileBuffers.getSystemFileAtLocation(fPath);
+ boolean modified= file.setLastModified(1000);
+ assertEquals(modified, !fileBuffer.isSynchronized());
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+
+ /*
+ * Tests isDirty.
+ */
+ public void test3() throws Exception {
+ fManager.connect(fPath, null);
+ try {
+ ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath);
+ assertFalse(fileBuffer.isDirty());
+ IDocument document= fileBuffer.getDocument();
+ document.replace(document.getLength(), 0, "appendix");
+ assertTrue(fileBuffer.isDirty());
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+
+ /*
+ * Tests isShared.
+ */
+ public void test4() throws Exception {
+ fManager.connect(fPath, null);
+ try {
+ ITextFileBuffer fileBuffer1= fManager.getTextFileBuffer(fPath);
+ assertFalse(fileBuffer1.isShared());
+
+ fManager.connect(fPath, null);
+ try {
+ ITextFileBuffer fileBuffer2= fManager.getTextFileBuffer(fPath);
+ assertTrue(fileBuffer1.isShared());
+ assertTrue(fileBuffer2.isShared());
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+
+ assertFalse(fileBuffer1.isShared());
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+
+ /*
+ * Tests getModificationStamp.
+ */
+ public void test5() throws Exception {
+ fManager.connect(fPath, null);
+ try {
+ ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath);
+ File file= FileBuffers.getSystemFileAtLocation(fPath);
+
+ long modificationStamp= fileBuffer.getModificationStamp();
+ assertEquals(modificationStamp != IResource.NULL_STAMP, file.exists());
+ boolean modified= file.setLastModified(1000);
+ assertEquals(modified, modificationStamp != fileBuffer.getModificationStamp());
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+
+ /*
+ * Test revert.
+ */
+ public void test6() throws Exception {
+ fManager.connect(fPath, null);
+ try {
+
+ ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath);
+ // set dirty bit
+ IDocument document= fileBuffer.getDocument();
+ String originalContent= document.get();
+ document.replace(document.getLength(), 0, "appendix");
+ // invalidate synchronization state
+ File file= FileBuffers.getSystemFileAtLocation(fPath);
+ file.setLastModified(1000);
+ //revert
+ fileBuffer.revert(null);
+ // check assertions
+ assertEquals(originalContent, document.get());
+ assertFalse(fileBuffer.isDirty());
+ assertTrue(fileBuffer.isSynchronized());
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+
+ /*
+ * Test commit.
+ */
+ public void test7() throws Exception {
+ fManager.connect(fPath, null);
+ try {
+
+ ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath);
+ // set dirty bit
+ IDocument document= fileBuffer.getDocument();
+ document.replace(document.getLength(), 0, "appendix");
+ String originalContent= document.get();
+ // commit
+ fileBuffer.commit(null, true);
+ // check assertions
+ assertEquals(originalContent, document.get());
+ assertFalse(fileBuffer.isDirty());
+ assertTrue(fileBuffer.isSynchronized());
+ // revert to see effect is persistent
+ fileBuffer.revert(null);
+ // check assertions
+ assertEquals(originalContent, document.get());
+ assertFalse(fileBuffer.isDirty());
+ assertTrue(fileBuffer.isSynchronized());
+ // disconnect
+ fManager.disconnect(fPath, null);
+ // reconnect
+ fManager.connect(fPath, null);
+ try {
+ fileBuffer= fManager.getTextFileBuffer(fPath);
+ document= fileBuffer.getDocument();
+ // check assertions
+ assertEquals(originalContent, document.get());
+ assertFalse(fileBuffer.isDirty());
+ assertTrue(fileBuffer.isSynchronized());
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForExternalFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForExternalFiles.java
new file mode 100644
index 000000000..28fff12b1
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForExternalFiles.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+
+/**
+ * FileBuffersForExternalFiles
+ */
+public class FileBuffersForExternalFiles extends FileBufferFunctions {
+
+ /*
+ * @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#createPath(org.eclipse.core.resources.IProject)
+ */
+ protected IPath createPath(IProject project) throws Exception {
+ File sourceFile= FileTool.getFileInPlugin(FileBuffersTestPlugin.getDefault(), new Path("testResources/ExternalFile"));
+ File externalFile= FileTool.createTempFileInPlugin(FileBuffersTestPlugin.getDefault(), new Path("externalResources/ExternalFile"));
+ FileTool.copy(sourceFile, externalFile);
+ return new Path(externalFile.getAbsolutePath());
+ }
+}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForLinkedFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForLinkedFiles.java
new file mode 100644
index 000000000..d469d40a7
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForLinkedFiles.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * FileBuffersForLinkedFiles
+ */
+public class FileBuffersForLinkedFiles extends FileBufferFunctions {
+
+ private File fExternalFile;
+
+ /*
+ * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ FileTool.delete(fExternalFile);
+ FileTool.delete(fExternalFile.getParentFile());
+ super.tearDown();
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#createPath(org.eclipse.core.resources.IProject)
+ */
+ protected IPath createPath(IProject project) throws Exception {
+ File sourceFile= FileTool.getFileInPlugin(FileBuffersTestPlugin.getDefault(), new Path("testResources/LinkTarget"));
+ fExternalFile= FileTool.createTempFileInPlugin(FileBuffersTestPlugin.getDefault(), new Path("externalResources/LinkTarget"));
+ FileTool.copy(sourceFile, fExternalFile);
+ IFile file= ResourceHelper.createLinkedFile(project, new Path("LinkedFile"), fExternalFile);
+ return file.getFullPath();
+ }
+}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingExternalFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingExternalFiles.java
new file mode 100644
index 000000000..695aad3f0
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingExternalFiles.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+
+/**
+ * FileBuffersForNonExistingExternalFiles
+ */
+public class FileBuffersForNonExistingExternalFiles extends FileBufferFunctions {
+
+ /*
+ * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ File file= FileBuffers.getSystemFileAtLocation(getPath());
+ FileTool.delete(file);
+ super.tearDown();
+ }
+
+ protected IPath createPath(IProject project) throws Exception {
+ IPath path= FileBuffersTestPlugin.getDefault().getStateLocation();
+ path= path.append("NonExistingExternalFile");
+ return new Path(path.toFile().getAbsolutePath());
+ }
+}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingWorkspaceFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingWorkspaceFiles.java
new file mode 100644
index 000000000..6f278f1e9
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingWorkspaceFiles.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+
+/**
+ * FileBuffersForNonExistingWorkspaceFiles
+ */
+public class FileBuffersForNonExistingWorkspaceFiles extends FileBufferFunctions {
+
+ /*
+ * @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#createPath(org.eclipse.core.resources.IProject)
+ */
+ protected IPath createPath(IProject project) throws Exception {
+ IFolder folder= ResourceHelper.createFolder("project/folderA/folderB/");
+ IPath path= folder.getFullPath().append("NonExistingWorkspaceFile");
+ return new Path(path.toFile().getAbsolutePath());
+ }
+}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForWorkspaceFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForWorkspaceFiles.java
new file mode 100644
index 000000000..94af7bd41
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForWorkspaceFiles.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * FileBuffersForWorkspaceFiles
+ */
+public class FileBuffersForWorkspaceFiles extends FileBufferFunctions {
+
+ protected IPath createPath(IProject project) throws Exception {
+ IFolder folder= ResourceHelper.createFolder("project/folderA/folderB/");
+ IFile file= ResourceHelper.createFile(folder, "WorkspaceFile", "content");
+ return file.getFullPath();
+ }
+}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestPlugin.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestPlugin.java
new file mode 100644
index 000000000..baa08cd6c
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestPlugin.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import org.eclipse.core.runtime.Plugin;
+
+/**
+ * The main plug-in class to be used in the desktop.
+ *
+ * @since 3.0
+ */
+public class FileBuffersTestPlugin extends Plugin {
+ private static FileBuffersTestPlugin fgPlugin;
+
+ public FileBuffersTestPlugin() {
+ fgPlugin = this;
+ }
+
+ public static FileBuffersTestPlugin getDefault() {
+ return fgPlugin;
+ }
+}
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 13bbfa26b..37f8a3d6f 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
@@ -20,12 +20,17 @@ import junit.framework.TestSuite;
*
* @since 3.0
*/
-public class FilebuffersTestSuite {
+public class FileBuffersTestSuite {
public static Test suite() {
TestSuite suite = new TestSuite("Test Suite for org.eclipse.core.filebuffers"); //$NON-NLS-1$
//$JUnit-BEGIN$
- suite.addTest(FileBufferTest1.suite());
+ suite.addTestSuite(FileBufferCreation.class);
+ suite.addTestSuite(FileBuffersForWorkspaceFiles.class);
+ suite.addTestSuite(FileBuffersForExternalFiles.class);
+ suite.addTestSuite(FileBuffersForLinkedFiles.class);
+ suite.addTestSuite(FileBuffersForNonExistingExternalFiles.class);
+ suite.addTestSuite(FileBuffersForNonExistingWorkspaceFiles.class);
//$JUnit-END$
return suite;
}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java
new file mode 100644
index 000000000..85fc6ff62
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java
@@ -0,0 +1,247 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.core.filebuffers.tests;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+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 {
+ unzip(zipFile, dstDir, dstDir, 0);
+ }
+
+ private static void unzip(ZipFile zipFile, File rootDstDir, File dstDir, int depth) throws IOException {
+
+ Enumeration entries = zipFile.entries();
+
+ try {
+ while(entries.hasMoreElements()){
+ ZipEntry entry = (ZipEntry)entries.nextElement();
+ if(entry.isDirectory()){
+ continue;
+ }
+ String entryName = entry.getName();
+ File file = new File(dstDir, changeSeparator(entryName, '/', File.separatorChar));
+ file.getParentFile().mkdirs();
+ InputStream src = null;
+ OutputStream dst = null;
+ try {
+ src = zipFile.getInputStream(entry);
+ dst = new FileOutputStream(file);
+ transferData(src, dst);
+ } finally {
+ if(dst != null){
+ try {
+ dst.close();
+ } catch(IOException e){
+ }
+ }
+ if(src != null){
+ try {
+ src.close();
+ } catch(IOException e){
+ }
+ }
+ }
+ }
+ } finally {
+ try {
+ zipFile.close();
+ } catch(IOException e){
+ }
+ }
+ }
+
+ /**
+ * 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
+ * @return the file path with its separator character
+ * changed from the given old separator to the given new
+ * separator
+ */
+ 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
+ */
+ public static void transferData(File source, File destination) throws IOException {
+ destination.getParentFile().mkdirs();
+ InputStream is = null;
+ OutputStream os = null;
+ try {
+ is = new FileInputStream(source);
+ os = new FileOutputStream(destination);
+ transferData(is, os);
+ } finally {
+ if(os != null){
+ try {
+ os.close();
+ } catch(IOException e){
+ }
+ }
+ if(is != null){
+ try {
+ is.close();
+ } catch(IOException e){
+ }
+ }
+ }
+ }
+
+ /**
+ * 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
+ */
+ public static void transferData(InputStream source, OutputStream destination) throws IOException {
+ int bytesRead = 0;
+ while(bytesRead != -1){
+ bytesRead = source.read(buffer, 0, buffer.length);
+ if(bytesRead != -1){
+ destination.write(buffer, 0, bytesRead);
+ }
+ }
+ }
+
+ /**
+ * 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
+ */
+ public static void copy(File src, File dst) throws IOException {
+ if(src.isDirectory()){
+ String[] srcChildren = src.list();
+ for(int i = 0; i < srcChildren.length; ++i){
+ File srcChild= new File(src, srcChildren[i]);
+ File dstChild= new File(dst, srcChildren[i]);
+ copy(srcChild, dstChild);
+ }
+ } else
+ transferData(src, dst);
+ }
+
+ public static File getFileInPlugin(Plugin plugin, IPath path) {
+ try {
+ URL installURL= plugin.getBundle().getEntry(path.toString());
+ URL localURL= Platform.asLocalURL(installURL);
+ return new File(localURL.getFile());
+ } catch (IOException e) {
+ 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));
+ }
+
+ public static StringBuffer read(Reader reader) throws IOException {
+ StringBuffer s= new StringBuffer();
+ try {
+ char[] charBuffer= new char[8196];
+ int chars= reader.read(charBuffer);
+ while (chars != -1) {
+ s.append(charBuffer, 0, chars);
+ chars= reader.read(charBuffer);
+ }
+ } finally {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ }
+ }
+ return s;
+ }
+
+ public static void write(String fileName, StringBuffer content) throws IOException {
+ Writer writer= new FileWriter(fileName);
+ try {
+ writer.write(content.toString());
+ } finally {
+ try {
+ writer.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ public static void delete(File file) throws CoreException {
+ for (int i= 0; i < MAX_RETRY; i++) {
+ if (file.delete())
+ i= MAX_RETRY;
+ else {
+ try {
+ Thread.sleep(1000); // sleep a second
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FilebuffersTestPlugin.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FilebuffersTestPlugin.java
deleted file mode 100644
index 922b4db14..000000000
--- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FilebuffersTestPlugin.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * 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 Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.filebuffers.tests;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IPluginDescriptor;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Plugin;
-
-/**
- * The main plug-in class to be used in the desktop.
- *
- * @since 3.0
- */
-public class FilebuffersTestPlugin extends Plugin {
- //The shared instance.
- private static FilebuffersTestPlugin fPlugin;
-
- /**
- * The constructor.
- */
- public FilebuffersTestPlugin(IPluginDescriptor descriptor) {
- super(descriptor);
- fPlugin = this;
- }
-
- /**
- * Returns the shared instance.
- */
- public static FilebuffersTestPlugin getDefault() {
- return fPlugin;
- }
-
- /**
- * Returns the workspace instance.
- */
- public static IWorkspace getWorkspace() {
- return ResourcesPlugin.getWorkspace();
- }
-
- public static File getFileInPlugin(Plugin plugin, IPath path) {
- try {
- URL installURL= new URL(plugin.getDescriptor().getInstallURL(), path.toString());
- URL localURL= Platform.asLocalURL(installURL);
- return new File(localURL.getFile());
- } catch (IOException e) {
- return null;
- }
- }
-}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TestHelper.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceHelper.java
index 482f060cf..725029d63 100644
--- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TestHelper.java
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceHelper.java
@@ -11,10 +11,8 @@
package org.eclipse.core.filebuffers.tests;
import java.io.File;
-import java.io.IOException;
import java.io.InputStream;
import java.io.StringBufferInputStream;
-import java.net.URL;
import org.eclipse.core.internal.filebuffers.ContainerGenerator;
import org.eclipse.core.resources.IContainer;
@@ -37,21 +35,11 @@ import org.eclipse.core.runtime.Plugin;
/**
* @since 3.0
*/
-public class TestHelper {
+public class ResourceHelper {
private final static IProgressMonitor NULL_MONITOR= new NullProgressMonitor();
private static final int MAX_RETRY= 5;
- public static File getFileInPlugin(Plugin plugin, IPath path) {
- try {
- URL installURL= new URL(plugin.getDescriptor().getInstallURL(), path.toString());
- URL localURL= Platform.asLocalURL(installURL);
- return new File(localURL.getFile());
- } catch (IOException e) {
- return null;
- }
- }
-
public static IProject createProject(String projectName) throws CoreException {
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
@@ -85,7 +73,7 @@ public class TestHelper {
i= MAX_RETRY;
} catch (CoreException x) {
if (i == MAX_RETRY - 1) {
- FilebuffersTestPlugin.getDefault().getLog().log(x.getStatus());
+ FileBuffersTestPlugin.getDefault().getLog().log(x.getStatus());
throw x;
}
try {
@@ -113,16 +101,23 @@ public class TestHelper {
return file;
}
+ public static IFile createLinkedFile(IContainer container, IPath linkedFilePath, File linkTarget) throws CoreException {
+ IFile iFile= container.getFile(linkedFilePath);
+ iFile.createLink(new Path(linkTarget.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
+ return iFile;
+
+ }
+
public static IFile createLinkedFile(IContainer container, IPath filePath, Plugin plugin, IPath linkPath) throws CoreException {
IFile iFile= container.getFile(filePath);
- File file= getFileInPlugin(plugin, linkPath);
+ File file= FileTool.getFileInPlugin(plugin, linkPath);
iFile.createLink(new Path(file.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
return iFile;
}
public static IFolder createLinkedFolder(IContainer container, IPath folderPath, Plugin plugin, IPath linkPath) throws CoreException {
IFolder iFolder= container.getFolder(folderPath);
- File file= getFileInPlugin(plugin, linkPath);
+ File file= FileTool.getFileInPlugin(plugin, linkPath);
iFolder.createLink(new Path(file.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
return iFolder;
}
@@ -132,7 +127,7 @@ public class TestHelper {
IProject project= workspace.getRoot().getProject(projectName);
IProjectDescription desc= workspace.newProjectDescription(projectName);
- File file= getFileInPlugin(plugin, linkPath);
+ File file= FileTool.getFileInPlugin(plugin, linkPath);
IPath projectLocation= new Path(file.getAbsolutePath());
if (Platform.getLocation().equals(projectLocation))
projectLocation= null;
diff --git a/org.eclipse.core.filebuffers.tests/test.xml b/org.eclipse.core.filebuffers.tests/test.xml
index 415b80d48..d6b8b99f7 100644
--- a/org.eclipse.core.filebuffers.tests/test.xml
+++ b/org.eclipse.core.filebuffers.tests/test.xml
@@ -29,7 +29,7 @@
<property name="data-dir" value="${core-filebuffers-folder}"/>
<property name="plugin-name" value="${plugin-name}"/>
<property name="classname"
- value="org.eclipse.core.filebuffers.tests.FilebuffersTestSuite"/>
+ value="org.eclipse.core.filebuffers.tests.FileBuffersTestSuite"/>
</ant>
</target>
diff --git a/org.eclipse.core.filebuffers.tests/testResources/LinkTarget1 b/org.eclipse.core.filebuffers.tests/testResources/LinkTarget
index d80dbfd20..d80dbfd20 100644
--- a/org.eclipse.core.filebuffers.tests/testResources/LinkTarget1
+++ b/org.eclipse.core.filebuffers.tests/testResources/LinkTarget

Back to the top