Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2004-09-09 18:20:28 +0000
committerKai Maetzel2004-09-09 18:20:28 +0000
commite8a912aaba385a1fb8a1b5588c928e7fb497eae4 (patch)
tree19610de6328c5ed46346fe4dd5a5b6d0c8213310 /org.eclipse.core.filebuffers.tests
parent807662d54c73613ef193cc2105c4217d5cfc8147 (diff)
downloadeclipse.platform.text-e8a912aaba385a1fb8a1b5588c928e7fb497eae4.tar.gz
eclipse.platform.text-e8a912aaba385a1fb8a1b5588c928e7fb497eae4.tar.xz
eclipse.platform.text-e8a912aaba385a1fb8a1b5588c928e7fb497eae4.zip
Updated FileBuffers test suite
Diffstat (limited to 'org.eclipse.core.filebuffers.tests')
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferFunctions.java75
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForExternalFiles.java15
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForLinkedFiles.java17
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingExternalFiles.java15
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingWorkspaceFiles.java15
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForWorkspaceFiles.java17
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java18
7 files changed, 164 insertions, 8 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 e9ae95529..82e517b73 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
@@ -36,6 +36,10 @@ public abstract class FileBufferFunctions extends TestCase {
protected abstract IPath createPath(IProject project) throws Exception;
+ protected abstract void markReadOnly() throws Exception;
+
+ protected abstract boolean isStateValidationSupported();
+
protected void setUp() throws Exception {
fManager= FileBuffers.getTextFileBufferManager();
@@ -213,4 +217,75 @@ public abstract class FileBufferFunctions extends TestCase {
fManager.disconnect(fPath, null);
}
}
+
+ /*
+ * Test validateState.
+ */
+ public void test8_1() throws Exception {
+ fManager.connect(fPath, null);
+ try {
+
+ ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath);
+ fileBuffer.validateState(null, null);
+ assertTrue(fileBuffer.isStateValidated());
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+
+ /*
+ * Test validateState.
+ */
+ public void test8_2() throws Exception {
+ fManager.connect(fPath, null);
+ try {
+
+ markReadOnly();
+ ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath);
+ fileBuffer.validateState(null, null);
+ assertTrue(fileBuffer.isStateValidated());
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+
+ /*
+ * Test resetStateValidation.
+ */
+ public void test9_1() throws Exception {
+ fManager.connect(fPath, null);
+ try {
+
+ ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath);
+ fileBuffer.validateState(null, null);
+ fileBuffer.resetStateValidation();
+ if (isStateValidationSupported())
+ assertFalse(fileBuffer.isStateValidated());
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+
+ /*
+ * Test resetStateValidation.
+ */
+ public void test9_2() throws Exception {
+ fManager.connect(fPath, null);
+ try {
+
+ markReadOnly();
+ ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath);
+ fileBuffer.validateState(null, null);
+ fileBuffer.resetStateValidation();
+ if (isStateValidationSupported())
+ assertFalse(fileBuffer.isStateValidated());
+
+ } 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
index 28fff12b1..bd826d9e6 100644
--- 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
@@ -41,4 +41,19 @@ public class FileBuffersForExternalFiles extends FileBufferFunctions {
FileTool.copy(sourceFile, externalFile);
return new Path(externalFile.getAbsolutePath());
}
+
+ /*
+ * @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;
+ }
}
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
index d469d40a7..32f07b168 100644
--- 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
@@ -17,6 +17,8 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.filebuffers.FileBuffers;
+
/**
* FileBuffersForLinkedFiles
*/
@@ -43,4 +45,19 @@ public class FileBuffersForLinkedFiles extends FileBufferFunctions {
IFile file= ResourceHelper.createLinkedFile(project, new Path("LinkedFile"), fExternalFile);
return file.getFullPath();
}
+
+ /*
+ * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly()
+ */
+ protected void markReadOnly() throws Exception {
+ IFile file= FileBuffers.getWorkspaceFileAtLocation(getPath());
+ file.setReadOnly(true);
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#isStateValidationSupported()
+ */
+ protected boolean isStateValidationSupported() {
+ return true;
+ }
}
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
index 695aad3f0..9b61d90dd 100644
--- 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
@@ -37,4 +37,19 @@ public class FileBuffersForNonExistingExternalFiles extends FileBufferFunctions
path= path.append("NonExistingExternalFile");
return new Path(path.toFile().getAbsolutePath());
}
+
+ /*
+ * @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;
+ }
}
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
index 6f278f1e9..6e2a9e715 100644
--- 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
@@ -41,4 +41,19 @@ public class FileBuffersForNonExistingWorkspaceFiles extends FileBufferFunctions
IPath path= folder.getFullPath().append("NonExistingWorkspaceFile");
return new Path(path.toFile().getAbsolutePath());
}
+
+ /*
+ * @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;
+ }
}
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
index 94af7bd41..eeb8cf767 100644
--- 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
@@ -15,6 +15,8 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.filebuffers.FileBuffers;
+
/**
* FileBuffersForWorkspaceFiles
*/
@@ -25,4 +27,19 @@ public class FileBuffersForWorkspaceFiles extends FileBufferFunctions {
IFile file= ResourceHelper.createFile(folder, "WorkspaceFile", "content");
return file.getFullPath();
}
+
+ /*
+ * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly()
+ */
+ protected void markReadOnly() throws Exception {
+ IFile file= FileBuffers.getWorkspaceFileAtLocation(getPath());
+ file.setReadOnly(true);
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#isStateValidationSupported()
+ */
+ protected boolean isStateValidationSupported() {
+ return true;
+ }
}
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
index 85fc6ff62..cad283faf 100644
--- 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
@@ -233,14 +233,16 @@ public class FileTool {
}
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) {
- }
+ if (file.exists()) {
+ 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) {
+ }
+ }
}
}
}

Back to the top