Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2004-09-10 16:12:32 +0000
committerKai Maetzel2004-09-10 16:12:32 +0000
commit58cf8aa0b1fb814180e1c11c05765322aa428ce8 (patch)
treef43d65878ef03cfc19e698137185c3c4f4ca5346 /org.eclipse.core.filebuffers.tests/src
parent9be58989193507861ae8ee30d3a683915584098d (diff)
downloadeclipse.platform.text-58cf8aa0b1fb814180e1c11c05765322aa428ce8.tar.gz
eclipse.platform.text-58cf8aa0b1fb814180e1c11c05765322aa428ce8.tar.xz
eclipse.platform.text-58cf8aa0b1fb814180e1c11c05765322aa428ce8.zip
Updated FileBuffers test suite
Diffstat (limited to 'org.eclipse.core.filebuffers.tests/src')
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferFunctions.java130
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferListener.java82
2 files changed, 212 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 82e517b73..e4d5da688 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
@@ -19,6 +19,7 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.IFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBufferManager;
@@ -288,4 +289,133 @@ public abstract class FileBufferFunctions extends TestCase {
}
}
+ /*
+ * Test IFileBufferListener#bufferCreated and IFileBufferListener#bufferDisposed
+ */
+ public void test10() throws Exception {
+ class Listener extends FileBufferListener {
+
+ public IFileBuffer buffer;
+ public int count;
+
+ public void bufferCreated(IFileBuffer buffer) {
+ ++count;
+ this.buffer= buffer;
+ }
+
+ public void bufferDisposed(IFileBuffer buffer) {
+ --count;
+ this.buffer= buffer;
+ }
+ }
+
+ Listener listener= new Listener();
+ fManager.addFileBufferListener(listener);
+
+ fManager.connect(fPath, null);
+ try {
+
+ assertTrue(listener.count == 1);
+ assertNotNull(listener.buffer);
+ IFileBuffer fileBuffer= fManager.getFileBuffer(fPath);
+ assertTrue(listener.buffer == fileBuffer);
+
+ fManager.disconnect(fPath, null);
+ assertTrue(listener.count == 0);
+ assertTrue(listener.buffer == fileBuffer);
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+
+ /*
+ * Test IFileBufferListener#dirtyStateChanged
+ */
+ public void test11_1() throws Exception {
+ class Listener extends FileBufferListener {
+
+ public IFileBuffer buffer;
+ public int count;
+ public boolean isDirty;
+
+ public void dirtyStateChanged(IFileBuffer buffer, boolean isDirty) {
+ ++count;
+ this.buffer= buffer;
+ this.isDirty= isDirty;
+ }
+ }
+
+ Listener listener= new Listener();
+ fManager.addFileBufferListener(listener);
+
+ ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath);
+ assertTrue(listener.count == 0 && listener.buffer == null);
+
+ fManager.connect(fPath, null);
+ try {
+
+ fileBuffer= fManager.getTextFileBuffer(fPath);
+ IDocument document= fileBuffer.getDocument();
+ document.replace(0, 0, "prefix");
+
+ assertTrue(listener.count == 1);
+ assertTrue(listener.buffer == fileBuffer);
+ assertTrue(listener.isDirty);
+
+ fileBuffer.commit(null, true);
+
+ assertTrue(listener.count == 2);
+ assertTrue(listener.buffer == fileBuffer);
+ assertFalse(listener.isDirty);
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
+
+ /*
+ * Test IFileBufferListener#dirtyStateChanged
+ */
+ public void test11_2() throws Exception {
+ class Listener extends FileBufferListener {
+
+ public IFileBuffer buffer;
+ public int count;
+ public boolean isDirty;
+
+ public void dirtyStateChanged(IFileBuffer buffer, boolean isDirty) {
+ ++count;
+ this.buffer= buffer;
+ this.isDirty= isDirty;
+ }
+ }
+
+ Listener listener= new Listener();
+ fManager.addFileBufferListener(listener);
+
+ ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath);
+ assertTrue(listener.count == 0 && listener.buffer == null);
+
+ fManager.connect(fPath, null);
+ try {
+
+ fileBuffer= fManager.getTextFileBuffer(fPath);
+ IDocument document= fileBuffer.getDocument();
+ document.replace(0, 0, "prefix");
+
+ assertTrue(listener.count == 1);
+ assertTrue(listener.buffer == fileBuffer);
+ assertTrue(listener.isDirty);
+
+ fileBuffer.revert(null);
+
+ assertTrue(listener.count == 2);
+ assertTrue(listener.buffer == fileBuffer);
+ assertFalse(listener.isDirty);
+
+ } finally {
+ fManager.disconnect(fPath, null);
+ }
+ }
}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferListener.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferListener.java
new file mode 100644
index 000000000..68f333839
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferListener.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 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.IPath;
+
+import org.eclipse.core.filebuffers.IFileBuffer;
+import org.eclipse.core.filebuffers.IFileBufferListener;
+
+/**
+ * FileBufferListener
+ */
+public class FileBufferListener implements IFileBufferListener {
+
+ /*
+ * @see org.eclipse.core.filebuffers.IFileBufferListener#bufferCreated(org.eclipse.core.filebuffers.IFileBuffer)
+ */
+ public void bufferCreated(IFileBuffer buffer) {
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.IFileBufferListener#bufferDisposed(org.eclipse.core.filebuffers.IFileBuffer)
+ */
+ public void bufferDisposed(IFileBuffer buffer) {
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.IFileBufferListener#bufferContentAboutToBeReplaced(org.eclipse.core.filebuffers.IFileBuffer)
+ */
+ public void bufferContentAboutToBeReplaced(IFileBuffer buffer) {
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.IFileBufferListener#bufferContentReplaced(org.eclipse.core.filebuffers.IFileBuffer)
+ */
+ public void bufferContentReplaced(IFileBuffer buffer) {
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.IFileBufferListener#stateChanging(org.eclipse.core.filebuffers.IFileBuffer)
+ */
+ public void stateChanging(IFileBuffer buffer) {
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.IFileBufferListener#dirtyStateChanged(org.eclipse.core.filebuffers.IFileBuffer, boolean)
+ */
+ public void dirtyStateChanged(IFileBuffer buffer, boolean isDirty) {
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.IFileBufferListener#stateValidationChanged(org.eclipse.core.filebuffers.IFileBuffer, boolean)
+ */
+ public void stateValidationChanged(IFileBuffer buffer, boolean isStateValidated) {
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.IFileBufferListener#underlyingFileMoved(org.eclipse.core.filebuffers.IFileBuffer, org.eclipse.core.runtime.IPath)
+ */
+ public void underlyingFileMoved(IFileBuffer buffer, IPath path) {
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.IFileBufferListener#underlyingFileDeleted(org.eclipse.core.filebuffers.IFileBuffer)
+ */
+ public void underlyingFileDeleted(IFileBuffer buffer) {
+ }
+
+ /*
+ * @see org.eclipse.core.filebuffers.IFileBufferListener#stateChangeFailed(org.eclipse.core.filebuffers.IFileBuffer)
+ */
+ public void stateChangeFailed(IFileBuffer buffer) {
+ }
+}

Back to the top