diff options
author | Dani Megert | 2008-09-11 12:01:34 +0000 |
---|---|---|
committer | Dani Megert | 2008-09-11 12:01:34 +0000 |
commit | 632fd1ce2f0a9ab9359727ceae521e223ae22973 (patch) | |
tree | b584161996bfb35f9dd2e5dd5ebf1ca5b15493d3 /org.eclipse.core.filebuffers.tests | |
parent | ecd77176ea6b00c6d7f9f6d751105808d9309158 (diff) | |
download | eclipse.platform.text-632fd1ce2f0a9ab9359727ceae521e223ae22973.tar.gz eclipse.platform.text-632fd1ce2f0a9ab9359727ceae521e223ae22973.tar.xz eclipse.platform.text-632fd1ce2f0a9ab9359727ceae521e223ae22973.zip |
Removed trailing whitespace and organized the importsv20080909-ascu
Diffstat (limited to 'org.eclipse.core.filebuffers.tests')
23 files changed, 501 insertions, 499 deletions
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/AbstractFileBufferDocCreationTests.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/AbstractFileBufferDocCreationTests.java index 4bed6a6efbd..51d86213dde 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/AbstractFileBufferDocCreationTests.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/AbstractFileBufferDocCreationTests.java @@ -16,6 +16,8 @@ import java.util.Set; import junit.framework.TestCase; +import org.eclipse.core.runtime.Path; + import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension; import org.eclipse.core.filebuffers.ITextFileBufferManager; import org.eclipse.core.filebuffers.LocationKind; @@ -25,7 +27,7 @@ import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP3 import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP4; import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP5; import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP6; -import org.eclipse.core.runtime.Path; + import org.eclipse.jface.text.IDocument; @@ -34,93 +36,93 @@ import org.eclipse.jface.text.IDocument; */ public abstract class AbstractFileBufferDocCreationTests extends TestCase { protected ITextFileBufferManager fManager; - - + + public void testCreateDocumentPartipants_FileExt() { assertParticipantsInvoked("anything.111foo", new Class[] {TestDSP1.class, TestDSP3.class}); } - + public void testCreateDocumentPartipants_Name() { assertParticipantsInvoked("111fooname", new Class[] {TestDSP2.class, TestDSP3.class}); } - + public void testCreateDocumentPartipants_FileExt_Name() { assertParticipantsInvoked("111fooname.111foo", new Class[] {TestDSP1.class, TestDSP2.class, TestDSP3.class}); } - + public void testCreateDocumentPartipants_FileExt_Extension() { assertParticipantsInvoked("anything.222foo", new Class[] {TestDSP4.class, TestDSP6.class}); } - + public void testCreateDocumentPartipants_Name_Extension() { assertParticipantsInvoked("222fooname", new Class[] {TestDSP5.class, TestDSP6.class}); } - + public void testCreateDocumentPartipants_FileExt_Name_Extension() { assertParticipantsInvoked("222fooname.222foo", new Class[] {TestDSP4.class, TestDSP5.class, TestDSP6.class}); } - + public void testDocumentSetupParticipantExtension_1() { assertDocumentContent("emanoof333/p/", "/p/333fooname", LocationKind.IFILE); assertDocumentContent("oof333.emanoof333/p/", "/p/333fooname.333foo", LocationKind.IFILE); assertDocumentContent("oof333.gnihtyna/p/", "/p/anything.333foo", LocationKind.IFILE); - + assertDocumentContent("", "333fooname", LocationKind.LOCATION); assertDocumentContent("", "333fooname.333foo", LocationKind.LOCATION); assertDocumentContent("", "anything.333foo", LocationKind.LOCATION); - + assertDocumentContent("", "333fooname", LocationKind.NORMALIZE); assertDocumentContent("", "333fooname.333foo", LocationKind.NORMALIZE); assertDocumentContent("", "anything.333foo", LocationKind.NORMALIZE); } - + public void testDocumentSetupParticipantExtension_2() { assertDocumentContent("", "/p/444fooname", LocationKind.IFILE); assertDocumentContent("", "/p/444fooname.444foo", LocationKind.IFILE); assertDocumentContent("", "/p/anything.444foo", LocationKind.IFILE); - + assertDocumentContent("emanoof444", "444fooname", LocationKind.LOCATION); assertDocumentContent("oof444.emanoof444", "444fooname.444foo", LocationKind.LOCATION); assertDocumentContent("oof444.gnihtyna", "anything.444foo", LocationKind.LOCATION); - + assertDocumentContent("", "444fooname", LocationKind.NORMALIZE); assertDocumentContent("", "444fooname.444foo", LocationKind.NORMALIZE); assertDocumentContent("", "anything.444foo", LocationKind.NORMALIZE); } - + public void testDocumentSetupParticipantExtension_3() { assertDocumentContent("", "/p/555fooname", LocationKind.IFILE); assertDocumentContent("", "/p/555fooname.555foo", LocationKind.IFILE); assertDocumentContent("", "/p/anything.555foo", LocationKind.IFILE); - + assertDocumentContent("", "555fooname", LocationKind.LOCATION); assertDocumentContent("", "555fooname.555foo", LocationKind.LOCATION); assertDocumentContent("", "anything.555foo", LocationKind.LOCATION); - + assertDocumentContent("emanoof555", "555fooname", LocationKind.NORMALIZE); assertDocumentContent("oof555.emanoof555", "555fooname.555foo", LocationKind.NORMALIZE); assertDocumentContent("oof555.gnihtyna", "anything.555foo", LocationKind.NORMALIZE); } - + /* Utilities */ - + private void assertParticipantsInvoked(String path, Class[] expectedDSPsArray) { LocationKind[] lks= getSupportLocationKinds(); for(int i=0; i<lks.length; i++) { - IDocument document= fManager.createEmptyDocument(new Path(path), lks[i]); + IDocument document= fManager.createEmptyDocument(new Path(path), lks[i]); String content= document.get(); Set expectedDSPs= new HashSet(Arrays.asList(toString(expectedDSPsArray))); Set actualDSPs= new HashSet(Arrays.asList(content.split("\n"))); assertEquals(expectedDSPs, actualDSPs); } } - + abstract protected LocationKind[] getSupportLocationKinds(); - + protected void assertDocumentContent(String expectedContent, String path, LocationKind locKind) { assertEquals(expectedContent, fManager.createEmptyDocument(new Path(path), locKind).get()); } - + private static String[] toString(Class[] clss) { String[] result= new String[clss.length]; for(int i=0; i<result.length; i++) { diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java index cf77cae4aab..11b162d0af8 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java @@ -93,7 +93,7 @@ public class FileBufferCreation extends TestCase { manager.disconnect(path, LocationKind.NORMALIZE, null); assertNull(manager.getTextFileBuffer(path, LocationKind.NORMALIZE)); } - + /* * Tests the creation of file buffer for an existing file. */ @@ -103,18 +103,18 @@ public class FileBufferCreation extends TestCase { IPath path= file.getFullPath(); assertNotNull(path); IFileStore fileStore= EFS.getLocalFileSystem().getStore(file.getLocation()); - + ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); manager.connectFileStore(fileStore, null); ITextFileBuffer buffer= manager.getFileStoreTextFileBuffer(fileStore); assertNotNull(buffer); - + IDocument document= buffer.getDocument(); assertNotNull(document); assertEquals(CONTENT1, document.get()); - + assertSame(buffer, manager.getTextFileBuffer(document)); - + manager.disconnectFileStore(fileStore, null); assertNull(manager.getFileStoreTextFileBuffer(fileStore)); } @@ -132,7 +132,7 @@ public class FileBufferCreation extends TestCase { IPath path2= ResourcesPlugin.getWorkspace().getRoot().getLocation(); path2= path2.append(path1.makeAbsolute()); - + ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); manager.connect(path1, LocationKind.NORMALIZE, null); ITextFileBuffer buffer1= manager.getTextFileBuffer(path1, LocationKind.NORMALIZE); @@ -329,7 +329,7 @@ public class FileBufferCreation extends TestCase { } /* - * Tests the creation of a file buffer for a non-existing file. + * Tests the creation of a file buffer for a non-existing file. */ public void test7() throws Exception { IPath path= FileBuffersTestPlugin.getDefault().getStateLocation(); @@ -537,7 +537,7 @@ public class FileBufferCreation extends TestCase { } /* - * Tests the creation of a file buffer for a non-existing file. + * Tests the creation of a file buffer for a non-existing file. */ public void test7_location() throws Exception { IPath path= FileBuffersTestPlugin.getDefault().getStateLocation(); @@ -556,25 +556,25 @@ public class FileBufferCreation extends TestCase { manager.disconnect(path, LocationKind.LOCATION, null); assertNull(manager.getTextFileBuffer(path, LocationKind.LOCATION)); } - + /* - * Tests the creation of a file buffer for a non-existing file. + * Tests the creation of a file buffer for a non-existing file. */ public void test7_IFileStore() throws Exception { IPath path= FileBuffersTestPlugin.getDefault().getStateLocation(); path= path.append("NonExistingFile"); IFileStore fileStore= EFS.getLocalFileSystem().getStore(path); - + ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); manager.connectFileStore(fileStore, null); ITextFileBuffer buffer= manager.getFileStoreTextFileBuffer(fileStore); Assert.assertNotNull(buffer); - + IDocument document= buffer.getDocument(); Assert.assertNotNull(document); Assert.assertTrue("".equals(document.get())); assertSame(buffer, manager.getTextFileBuffer(document)); - + manager.disconnectFileStore(fileStore, null); assertNull(manager.getFileStoreTextFileBuffer(fileStore)); } 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 2bb1ff09e0e..56f6c915942 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 @@ -38,26 +38,26 @@ import org.eclipse.jface.text.source.IAnnotationModel; * FileBufferFunctions */ public abstract class FileBufferFunctions extends TestCase { - + private IProject fProject; protected ITextFileBufferManager fManager; private IPath fPath; - - + + protected abstract IPath createPath(IProject project) throws Exception; - + protected abstract void setReadOnly(boolean state) throws Exception; - + protected abstract boolean modifyUnderlyingFile() throws Exception; - + protected abstract boolean deleteUnderlyingFile() throws Exception; - + protected abstract IPath moveUnderlyingFile() throws Exception; - + protected abstract boolean isStateValidationSupported(); - + protected abstract Class getAnnotationModelClass() throws Exception; - + protected void setUp() throws Exception { fManager= FileBuffers.getTextFileBufferManager(); @@ -66,21 +66,21 @@ public abstract class FileBufferFunctions extends TestCase { ITextFileBuffer buffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); assertTrue(buffer == null); } - + protected IProject getProject() { return fProject; } - + protected void tearDown() throws Exception { ITextFileBuffer buffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); assertTrue(buffer == null); ResourceHelper.deleteProject("project"); } - + protected IPath getPath() { return fPath; } - + /* * Tests getLocation. */ @@ -89,12 +89,12 @@ public abstract class FileBufferFunctions extends TestCase { try { ITextFileBuffer buffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); assertEquals(fPath, buffer.getLocation()); - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * Tests isSynchronized. */ @@ -110,12 +110,12 @@ public abstract class FileBufferFunctions extends TestCase { fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null); long lastModified= fileStore.fetchInfo().getLastModified(); assertTrue(lastModified == EFS.NONE || !fileBuffer.isSynchronized()); - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * Tests isDirty. */ @@ -127,12 +127,12 @@ public abstract class FileBufferFunctions extends TestCase { IDocument document= fileBuffer.getDocument(); document.replace(document.getLength(), 0, "appendix"); assertTrue(fileBuffer.isDirty()); - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * Tests isShared. */ @@ -141,7 +141,7 @@ public abstract class FileBufferFunctions extends TestCase { try { ITextFileBuffer fileBuffer1= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); assertFalse(fileBuffer1.isShared()); - + fManager.connect(fPath, LocationKind.NORMALIZE, null); try { ITextFileBuffer fileBuffer2= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); @@ -150,14 +150,14 @@ public abstract class FileBufferFunctions extends TestCase { } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + assertFalse(fileBuffer1.isShared()); - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * Tests getModificationStamp. */ @@ -185,7 +185,7 @@ public abstract class FileBufferFunctions extends TestCase { public void test6() throws Exception { fManager.connect(fPath, LocationKind.NORMALIZE, null); try { - + ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); // set dirty bit IDocument document= fileBuffer.getDocument(); @@ -208,14 +208,14 @@ public abstract class FileBufferFunctions extends TestCase { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * Test commit. */ public void test7() throws Exception { fManager.connect(fPath, LocationKind.NORMALIZE, null); try { - + ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); // set dirty bit IDocument document= fileBuffer.getDocument(); @@ -247,119 +247,119 @@ public abstract class FileBufferFunctions extends TestCase { } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * Test validateState. */ public void test8_1() throws Exception { fManager.connect(fPath, LocationKind.NORMALIZE, null); try { - + ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); fileBuffer.validateState(null, null); assertTrue(fileBuffer.isStateValidated()); - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * Test validateState. */ public void test8_2() throws Exception { fManager.connect(fPath, LocationKind.NORMALIZE, null); try { - + setReadOnly(true); ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); fileBuffer.validateState(null, null); assertTrue(fileBuffer.isStateValidated()); - + } finally { setReadOnly(false); fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * Test resetStateValidation. */ public void test9_1() throws Exception { fManager.connect(fPath, LocationKind.NORMALIZE, null); try { - + ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); fileBuffer.validateState(null, null); fileBuffer.resetStateValidation(); if (isStateValidationSupported()) assertFalse(fileBuffer.isStateValidated()); - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * Test resetStateValidation. */ public void test9_2() throws Exception { fManager.connect(fPath, LocationKind.NORMALIZE, null); try { - + setReadOnly(true); ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); fileBuffer.validateState(null, null); fileBuffer.resetStateValidation(); if (isStateValidationSupported()) assertFalse(fileBuffer.isStateValidated()); - + } finally { setReadOnly(false); fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * 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 buf) { ++count; this.buffer= buf; } - + public void bufferDisposed(IFileBuffer buf) { --count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { - + fManager.connect(fPath, LocationKind.NORMALIZE, null); - + assertTrue(listener.count == 1); assertNotNull(listener.buffer); IFileBuffer fileBuffer= fManager.getFileBuffer(fPath, LocationKind.NORMALIZE); assertTrue(listener.buffer == fileBuffer); - + fManager.disconnect(fPath, LocationKind.NORMALIZE, null); assertTrue(listener.count == 0); assertTrue(listener.buffer == fileBuffer); - + } finally { try { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); @@ -368,263 +368,263 @@ public abstract class FileBufferFunctions extends TestCase { } } } - + /* * 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 buf, boolean state) { ++count; this.buffer= buf; this.isDirty= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { - + ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); assertTrue(listener.count == 0 && listener.buffer == null); - + fManager.connect(fPath, LocationKind.NORMALIZE, null); try { - + fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); 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, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * 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 buf, boolean state) { ++count; this.buffer= buf; this.isDirty= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); assertTrue(listener.count == 0 && listener.buffer == null); - + fManager.connect(fPath, LocationKind.NORMALIZE, null); try { - + fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); 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, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#bufferContentAboutToBeReplaced/replaced */ public void test12_1() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer preBuffer, postBuffer; public int preCount, postCount; - + public void bufferContentAboutToBeReplaced(IFileBuffer buffer) { ++preCount; preBuffer= buffer; } - + public void bufferContentReplaced(IFileBuffer buffer) { ++postCount; postBuffer= buffer; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); assertTrue(listener.preCount == 0 && listener.postCount == 0 && listener.preBuffer == null && listener.postBuffer == null); - + fManager.connect(fPath, LocationKind.NORMALIZE, null); try { - + fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); IDocument document= fileBuffer.getDocument(); document.replace(0, 0, "prefix"); - + fileBuffer.revert(null); - + assertTrue(listener.preCount == 1); assertTrue(listener.preBuffer == fileBuffer); assertTrue(listener.postCount == 1); assertTrue(listener.postBuffer == fileBuffer); - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#bufferContentAboutToBeReplaced/replaced */ public void test12_2() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer preBuffer, postBuffer; public int preCount, postCount; - + public void bufferContentAboutToBeReplaced(IFileBuffer buffer) { ++preCount; preBuffer= buffer; } - + public void bufferContentReplaced(IFileBuffer buffer) { ++postCount; postBuffer= buffer; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); assertTrue(listener.preCount == 0 && listener.postCount == 0 && listener.preBuffer == null && listener.postBuffer == null); - + fManager.connect(fPath, LocationKind.NORMALIZE, null); try { - + fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); - + if (modifyUnderlyingFile()) { assertTrue(listener.preCount == 1); assertTrue(listener.preBuffer == fileBuffer); assertTrue(listener.postCount == 1); assertTrue(listener.postBuffer == fileBuffer); } - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateValidationChanged */ public void test13_1() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; public boolean isStateValidated; - + public void stateValidationChanged(IFileBuffer buf, boolean state) { ++count; this.buffer= buf; this.isStateValidated= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { ITextFileBuffer fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); assertTrue(listener.count == 0 && listener.buffer == null); - + fManager.connect(fPath, LocationKind.NORMALIZE, null); try { - + fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); fileBuffer.validateState(null, null); - + if (isStateValidationSupported()) { assertTrue(listener.count == 1); assertTrue(listener.buffer == fileBuffer); assertTrue(listener.isStateValidated); } - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateValidationChanged */ public void test13_2() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; public boolean isStateValidated; - + public void stateValidationChanged(IFileBuffer buf, boolean state) { ++count; this.buffer= buf; this.isStateValidated= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -648,7 +648,7 @@ public abstract class FileBufferFunctions extends TestCase { setReadOnly(false); fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } @@ -658,18 +658,18 @@ public abstract class FileBufferFunctions extends TestCase { */ public void test13_3() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; public boolean isStateValidated; - + public void stateValidationChanged(IFileBuffer buf, boolean state) { ++count; this.buffer= buf; this.isStateValidated= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -682,7 +682,7 @@ public abstract class FileBufferFunctions extends TestCase { fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); fileBuffer.validateState(null, null); fileBuffer.resetStateValidation(); - + if (isStateValidationSupported()) { assertTrue(listener.count == 2); assertTrue(listener.buffer == fileBuffer); @@ -692,29 +692,29 @@ public abstract class FileBufferFunctions extends TestCase { } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateValidationChanged */ public void test13_4() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; public boolean isStateValidated; - + public void stateValidationChanged(IFileBuffer buf, boolean state) { ++count; this.buffer= buf; this.isStateValidated= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -739,27 +739,27 @@ public abstract class FileBufferFunctions extends TestCase { setReadOnly(false); fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#underlyingFileDeleted */ public void test14() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void underlyingFileDeleted(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -778,29 +778,29 @@ public abstract class FileBufferFunctions extends TestCase { } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#underlyingFileMoved */ public void test15() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; public IPath newLocation; - + public void underlyingFileMoved(IFileBuffer buf, IPath location) { ++count; this.buffer= buf; this.newLocation= location; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -821,7 +821,7 @@ public abstract class FileBufferFunctions extends TestCase { } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } @@ -832,16 +832,16 @@ public abstract class FileBufferFunctions extends TestCase { */ public void test16_1() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -860,27 +860,27 @@ public abstract class FileBufferFunctions extends TestCase { } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateChanging for external changes */ public void test16_2() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -899,7 +899,7 @@ public abstract class FileBufferFunctions extends TestCase { } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } @@ -910,16 +910,16 @@ public abstract class FileBufferFunctions extends TestCase { */ public void test16_3() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -938,27 +938,27 @@ public abstract class FileBufferFunctions extends TestCase { } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateChanging for internal changes */ public void test17_1() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -970,7 +970,7 @@ public abstract class FileBufferFunctions extends TestCase { fileBuffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); fileBuffer.validateState(null, null); - + if (isStateValidationSupported()) { assertTrue(listener.count == 1); assertTrue(listener.buffer == fileBuffer); @@ -979,7 +979,7 @@ public abstract class FileBufferFunctions extends TestCase { } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } @@ -989,16 +989,16 @@ public abstract class FileBufferFunctions extends TestCase { */ public void test17_2() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -1012,34 +1012,34 @@ public abstract class FileBufferFunctions extends TestCase { IDocument document= fileBuffer.getDocument(); document.replace(0, 0, "prefix"); fileBuffer.revert(null); - + assertTrue(listener.count == 1); assertTrue(listener.buffer == fileBuffer); } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateChanging for internal changes */ public void test17_3() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -1053,19 +1053,19 @@ public abstract class FileBufferFunctions extends TestCase { IDocument document= fileBuffer.getDocument(); document.replace(0, 0, "prefix"); fileBuffer.commit(null, true); - + assertTrue(listener.count == 1); assertTrue(listener.buffer == fileBuffer); } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test annotation model existence. * ATTENTION: This test is only effective in a workspace that contains the "org.eclipse.ui.editors" bundle. @@ -1075,27 +1075,27 @@ public abstract class FileBufferFunctions extends TestCase { try { ITextFileBuffer buffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); assertNotNull(buffer); - + Class clazz= getAnnotationModelClass(); if (clazz != null) { IAnnotationModel model= buffer.getAnnotationModel(); assertTrue(clazz.isInstance(model)); } - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * Test notification in case of failing listener. */ public void test19() throws Exception { - + class NotifiedListener extends FileBufferListener { - + int notifyCount= 0; - + public void bufferCreated(IFileBuffer buffer) { notifyCount++; } @@ -1103,22 +1103,22 @@ public abstract class FileBufferFunctions extends TestCase { notifyCount++; } } - + class ForcedException extends RuntimeException { private static final long serialVersionUID= 1L; public void printStackTrace(PrintStream s) { s.println("!FORCED BY TEST: this entry is intentional"); } - + public void printStackTrace(PrintWriter s) { s.println("!FORCED BY TEST: this entry is intentional"); } } - + NotifiedListener notifyCounter1= new NotifiedListener(); NotifiedListener notifyCounter2= new NotifiedListener(); - + FileBufferListener failingListener= new FileBufferListener() { public void bufferCreated(IFileBuffer buffer) { throw new ForcedException(); @@ -1127,33 +1127,33 @@ public abstract class FileBufferFunctions extends TestCase { throw new ForcedException(); } }; - + fManager.addFileBufferListener(notifyCounter1); fManager.addFileBufferListener(failingListener); fManager.addFileBufferListener(notifyCounter2); - + fManager.connect(fPath, LocationKind.NORMALIZE, null); try { ITextFileBuffer buffer= fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE); assertNotNull(buffer); - + Class clazz= getAnnotationModelClass(); if (clazz != null) { IAnnotationModel model= buffer.getAnnotationModel(); assertTrue(clazz.isInstance(model)); } - + } finally { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); fManager.removeFileBufferListener(notifyCounter1); fManager.removeFileBufferListener(failingListener); fManager.removeFileBufferListener(notifyCounter2); } - + assertEquals(2, notifyCounter1.notifyCount); assertEquals(2, notifyCounter2.notifyCount); } - + public void testGetBufferForDocument() throws Exception { fManager.connect(fPath, LocationKind.NORMALIZE, null); try { @@ -1166,7 +1166,7 @@ public abstract class FileBufferFunctions extends TestCase { fManager.disconnect(fPath, LocationKind.NORMALIZE, null); } } - + /* * Tests isSynchronized. */ @@ -1186,7 +1186,7 @@ public abstract class FileBufferFunctions extends TestCase { fManager.disconnectFileStore(fileStore, null); } } - + public void testGetFileBuffers() throws Exception { fManager.connect(fPath, LocationKind.NORMALIZE, null); try { @@ -1203,5 +1203,5 @@ public abstract class FileBufferFunctions extends TestCase { fManager.disconnect(fPath, LocationKind.NORMALIZE, 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 index 8585f39d39d..01090433d60 100644 --- 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 @@ -19,7 +19,7 @@ import org.eclipse.core.filebuffers.IFileBufferListener; * FileBufferListener */ public class FileBufferListener implements IFileBufferListener { - + /* * @see org.eclipse.core.filebuffers.IFileBufferListener#bufferCreated(org.eclipse.core.filebuffers.IFileBuffer) */ 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 ba0b5e57a17..cc6824c9afa 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 @@ -26,7 +26,7 @@ import org.eclipse.core.filebuffers.FileBuffers; * FileBuffersForExternalFiles */ public class FileBuffersForExternalFiles extends FileBufferFunctions { - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() */ @@ -35,7 +35,7 @@ public class FileBuffersForExternalFiles extends FileBufferFunctions { FileTool.delete(FileBuffers.getSystemFileAtLocation(getPath()).getParentFile()); super.tearDown(); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#createPath(org.eclipse.core.resources.IProject) */ @@ -45,7 +45,7 @@ public class FileBuffersForExternalFiles extends FileBufferFunctions { FileTool.copy(sourceFile, externalFile); return new Path(externalFile.getAbsolutePath()); } - + protected void setReadOnly(boolean state) throws Exception { IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath()); assertNotNull(fileStore); @@ -79,7 +79,7 @@ public class FileBuffersForExternalFiles extends FileBufferFunctions { protected boolean modifyUnderlyingFile() throws Exception { return false; } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#getAnnotationModelClass() */ diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForFilesInLinkedFolders.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForFilesInLinkedFolders.java index c1d3f9e2db7..7162cbd5f96 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForFilesInLinkedFolders.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForFilesInLinkedFolders.java @@ -38,9 +38,9 @@ import org.eclipse.jface.text.source.IAnnotationModel; * FileBuffersForLinkedFiles */ public class FileBuffersForFilesInLinkedFolders extends FileBufferFunctions { - + private File fExternalFile; - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() */ @@ -54,7 +54,7 @@ public class FileBuffersForFilesInLinkedFolders extends FileBufferFunctions { FileTool.delete(file); // externalResources/ super.tearDown(); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#createPath(org.eclipse.core.resources.IProject) */ @@ -62,12 +62,12 @@ public class FileBuffersForFilesInLinkedFolders extends FileBufferFunctions { File sourceFile= FileTool.getFileInPlugin(FileBuffersTestPlugin.getDefault(), new Path("testResources/linkedFolderTarget/FileInLinkedFolder")); fExternalFile= FileTool.createTempFileInPlugin(FileBuffersTestPlugin.getDefault(), new Path("externalResources/linkedFolderTarget/FileInLinkedFolder")); FileTool.copy(sourceFile, fExternalFile); - + IFolder folder= ResourceHelper.createLinkedFolder(project, new Path("LinkedFolder"), fExternalFile.getParentFile()); IFile file= folder.getFile(new Path("FileInLinkedFolder")); return file.getFullPath(); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly() */ @@ -84,7 +84,7 @@ public class FileBuffersForFilesInLinkedFolders extends FileBufferFunctions { protected boolean isStateValidationSupported() { return true; } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#deleteUnderlyingFile() */ @@ -93,7 +93,7 @@ public class FileBuffersForFilesInLinkedFolders extends FileBufferFunctions { file.delete(true, false, null); return file.exists(); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#moveUnderlyingFile() */ @@ -102,11 +102,11 @@ public class FileBuffersForFilesInLinkedFolders extends FileBufferFunctions { ResourceHelper.createFolder("project/folderA"); IPath path= new Path("/project/folderA/MovedLinkedFile"); file.move(path, true, false, null); - + file= FileBuffers.getWorkspaceFileAtLocation(path); if (file != null && file.exists()) return path; - + return null; } @@ -129,7 +129,7 @@ public class FileBuffersForFilesInLinkedFolders extends FileBufferFunctions { fileInfo.setLastModified(1000); fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null); - + IFile iFile= FileBuffers.getWorkspaceFileAtLocation(getPath()); iFile.refreshLocal(IResource.DEPTH_INFINITE, null); return true; 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 55b1d284b6c..874080daaba 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 @@ -12,28 +12,28 @@ 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.resources.IResource; -import org.eclipse.core.resources.ResourceAttributes; +import org.osgi.framework.Bundle; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourceAttributes; + import org.eclipse.core.filebuffers.FileBuffers; import org.eclipse.jface.text.source.IAnnotationModel; -import org.osgi.framework.Bundle; - /** * FileBuffersForLinkedFiles */ public class FileBuffersForLinkedFiles extends FileBufferFunctions { - + private File fExternalFile; - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() */ @@ -42,7 +42,7 @@ public class FileBuffersForLinkedFiles extends FileBufferFunctions { FileTool.delete(fExternalFile.getParentFile()); super.tearDown(); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#createPath(org.eclipse.core.resources.IProject) */ @@ -53,7 +53,7 @@ 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() */ @@ -70,7 +70,7 @@ public class FileBuffersForLinkedFiles extends FileBufferFunctions { protected boolean isStateValidationSupported() { return true; } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#deleteUnderlyingFile() */ @@ -79,7 +79,7 @@ public class FileBuffersForLinkedFiles extends FileBufferFunctions { file.delete(true, false, null); return file.exists(); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#moveUnderlyingFile() */ @@ -88,11 +88,11 @@ public class FileBuffersForLinkedFiles extends FileBufferFunctions { ResourceHelper.createFolder("project/folderA"); IPath path= new Path("/project/folderA/MovedLinkedFile"); file.move(path, true, false, null); - + file= FileBuffers.getWorkspaceFileAtLocation(path); if (file != null && file.exists()) return path; - + return null; } 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 index 49272d4ed67..68b309ca638 100644 --- 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 @@ -25,19 +25,19 @@ import org.eclipse.core.filebuffers.FileBuffers; * 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() */ @@ -45,7 +45,7 @@ public class FileBuffersForNonAccessibleWorkspaceFiles extends FileBufferFunctio FileTool.delete(getPath()); super.tearDown(); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly() */ @@ -89,11 +89,11 @@ public class FileBuffersForNonAccessibleWorkspaceFiles extends FileBufferFunctio protected Class getAnnotationModelClass() throws Exception { return null; } - + public void test7() throws Exception { // disable because it might create a file outside the closed project } - + public void test11_1() throws Exception { // disable because it might create a file outside the closed project } 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 8a75059d578..5644bd3a330 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 @@ -24,7 +24,7 @@ import org.eclipse.core.filebuffers.FileBuffers; * FileBuffersForNonExistingExternalFiles */ public class FileBuffersForNonExistingExternalFiles extends FileBufferFunctions { - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() */ @@ -32,13 +32,13 @@ public class FileBuffersForNonExistingExternalFiles extends FileBufferFunctions FileTool.delete(getPath()); super.tearDown(); } - + protected IPath createPath(IProject project) throws Exception { IPath path= FileBuffersTestPlugin.getDefault().getStateLocation(); path= path.append("NonExistingExternalFile"); return new Path(path.toFile().getAbsolutePath()); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly() */ 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 2ab753d1e0a..e621183e98e 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 @@ -27,7 +27,7 @@ import org.eclipse.core.filebuffers.LocationKind; * FileBuffersForNonExistingWorkspaceFiles */ public class FileBuffersForNonExistingWorkspaceFiles extends FileBufferFunctions { - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() */ @@ -35,7 +35,7 @@ public class FileBuffersForNonExistingWorkspaceFiles extends FileBufferFunctions FileTool.delete(getPath()); super.tearDown(); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#createPath(org.eclipse.core.resources.IProject) */ @@ -44,7 +44,7 @@ public class FileBuffersForNonExistingWorkspaceFiles extends FileBufferFunctions IPath filePath= folder.getLocation().append("NonExistingWorkspaceFile"); return filePath.makeAbsolute(); } - + public void testBug118199() throws Exception { IFile file= getProject().getWorkspace().getRoot().getFile(getPath()); assertFalse(file.exists()); 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 4c36f557afa..497041b2f0b 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 @@ -37,7 +37,7 @@ import org.eclipse.jface.text.source.IAnnotationModel; * 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"); @@ -78,11 +78,11 @@ public class FileBuffersForWorkspaceFiles extends FileBufferFunctions { ResourceHelper.createFolder("project/folderA/folderB/folderC"); IPath path= new Path("/project/folderA/folderB/folderC/MovedWorkspaceFile"); file.move(path, true, false, null); - + file= FileBuffers.getWorkspaceFileAtLocation(path); if (file != null && file.exists()) return path; - + return null; } 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 index 2ca63ae4b36..5674af1b29b 100644 --- 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 @@ -14,12 +14,12 @@ 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; } 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 d39561559b8..00a0c6c9242 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 @@ -18,7 +18,7 @@ import junit.framework.TestSuite; /** * Test Suite for org.eclipse.core.filebuffers. - * + * * @since 3.0 */ public class FileBuffersTestSuite { @@ -34,12 +34,12 @@ public class FileBuffersTestSuite { suite.addTestSuite(FileBuffersForNonExistingExternalFiles.class); suite.addTestSuite(FileBuffersForNonExistingWorkspaceFiles.class); suite.addTestSuite(FileBuffersForNonAccessibleWorkspaceFiles.class); - + suite.addTestSuite(FileStoreFileBuffersForWorkspaceFiles.class); suite.addTestSuite(FileStoreFileBuffersForExternalFiles.class); suite.addTestSuite(FileStoreFileBuffersForNonExistingExternalFiles.class); suite.addTestSuite(FileStoreFileBuffersForNonExistingWorkspaceFiles.class); - + suite.addTestSuite(TextFileManagerDocCreationTests.class); suite.addTestSuite(ResourceTextFileManagerDocCreationTests.class); //$JUnit-END$ diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBufferFunctions.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBufferFunctions.java index dff5619d8b3..559c8631532 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBufferFunctions.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBufferFunctions.java @@ -37,26 +37,26 @@ import org.eclipse.jface.text.source.IAnnotationModel; * FileBufferFunctions */ public abstract class FileStoreFileBufferFunctions extends TestCase { - + private IProject fProject; protected ITextFileBufferManager fManager; private IFileStore fFileStore; - - + + protected abstract IPath createPath(IProject project) throws Exception; - + protected abstract void setReadOnly(boolean state) throws Exception; - + protected abstract boolean modifyUnderlyingFile() throws Exception; - + protected abstract boolean deleteUnderlyingFile() throws Exception; - + protected abstract IPath moveUnderlyingFile() throws Exception; - + protected abstract boolean isStateValidationSupported(); - + protected abstract Class getAnnotationModelClass() throws Exception; - + protected void setUp() throws Exception { fManager= FileBuffers.getTextFileBufferManager(); @@ -65,21 +65,21 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { ITextFileBuffer buffer= fManager.getFileStoreTextFileBuffer(fFileStore); assertTrue(buffer == null); } - + protected IProject getProject() { return fProject; } - + protected void tearDown() throws Exception { ITextFileBuffer buffer= fManager.getFileStoreTextFileBuffer(fFileStore); assertTrue(buffer == null); ResourceHelper.deleteProject("project"); } - + protected IPath getPath() { return URIUtil.toPath(fFileStore.toURI()); } - + /* * Tests getLocation. */ @@ -88,12 +88,12 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { try { ITextFileBuffer buffer= fManager.getFileStoreTextFileBuffer(fFileStore); assertEquals(fFileStore, buffer.getFileStore()); - + } finally { fManager.disconnectFileStore(fFileStore, null); } } - + /* * Tests isSynchronized. */ @@ -109,12 +109,12 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null); long lastModified= fileStore.fetchInfo().getLastModified(); assertTrue(lastModified == EFS.NONE || !fileBuffer.isSynchronized()); - + } finally { fManager.disconnectFileStore(fFileStore, null); } } - + /* * Tests isDirty. */ @@ -126,12 +126,12 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { IDocument document= fileBuffer.getDocument(); document.replace(document.getLength(), 0, "appendix"); assertTrue(fileBuffer.isDirty()); - + } finally { fManager.disconnectFileStore(fFileStore, null); } } - + /* * Tests isShared. */ @@ -140,7 +140,7 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { try { ITextFileBuffer fileBuffer1= fManager.getFileStoreTextFileBuffer(fFileStore); assertFalse(fileBuffer1.isShared()); - + fManager.connectFileStore(fFileStore, null); try { ITextFileBuffer fileBuffer2= fManager.getFileStoreTextFileBuffer(fFileStore); @@ -149,14 +149,14 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { } finally { fManager.disconnectFileStore(fFileStore, null); } - + assertFalse(fileBuffer1.isShared()); - + } finally { fManager.disconnectFileStore(fFileStore, null); } } - + /* * Tests getModificationStamp. */ @@ -183,7 +183,7 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { public void test6() throws Exception { fManager.connectFileStore(fFileStore, null); try { - + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); // set dirty bit IDocument document= fileBuffer.getDocument(); @@ -205,14 +205,14 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { fManager.disconnectFileStore(fFileStore, null); } } - + /* * Test commit. */ public void test7() throws Exception { fManager.connectFileStore(fFileStore, null); try { - + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); // set dirty bit IDocument document= fileBuffer.getDocument(); @@ -244,119 +244,119 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.disconnectFileStore(fFileStore, null); } } - + /* * Test validateState. */ public void test8_1() throws Exception { fManager.connectFileStore(fFileStore, null); try { - + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); fileBuffer.validateState(null, null); assertTrue(fileBuffer.isStateValidated()); - + } finally { fManager.disconnectFileStore(fFileStore, null); } } - + /* * Test validateState. */ public void test8_2() throws Exception { fManager.connectFileStore(fFileStore, null); try { - + setReadOnly(true); ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); fileBuffer.validateState(null, null); assertTrue(fileBuffer.isStateValidated()); - + } finally { setReadOnly(false); fManager.disconnectFileStore(fFileStore, null); } } - + /* * Test resetStateValidation. */ public void test9_1() throws Exception { fManager.connectFileStore(fFileStore, null); try { - + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); fileBuffer.validateState(null, null); fileBuffer.resetStateValidation(); if (isStateValidationSupported()) assertFalse(fileBuffer.isStateValidated()); - + } finally { fManager.disconnectFileStore(fFileStore, null); } } - + /* * Test resetStateValidation. */ public void test9_2() throws Exception { fManager.connectFileStore(fFileStore, null); try { - + setReadOnly(true); ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); fileBuffer.validateState(null, null); fileBuffer.resetStateValidation(); if (isStateValidationSupported()) assertFalse(fileBuffer.isStateValidated()); - + } finally { setReadOnly(false); fManager.disconnectFileStore(fFileStore, null); } } - + /* * 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 buf) { ++count; this.buffer= buf; } - + public void bufferDisposed(IFileBuffer buf) { --count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { - + fManager.connectFileStore(fFileStore, null); - + assertTrue(listener.count == 1); assertNotNull(listener.buffer); IFileBuffer fileBuffer= fManager.getFileStoreFileBuffer(fFileStore); assertTrue(listener.buffer == fileBuffer); - + fManager.disconnectFileStore(fFileStore, null); assertTrue(listener.count == 0); assertTrue(listener.buffer == fileBuffer); - + } finally { try { fManager.disconnectFileStore(fFileStore, null); @@ -365,263 +365,263 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { } } } - + /* * 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 buf, boolean state) { ++count; this.buffer= buf; this.isDirty= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { - + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); assertTrue(listener.count == 0 && listener.buffer == null); - + fManager.connectFileStore(fFileStore, null); try { - + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); 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.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * 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 buf, boolean state) { ++count; this.buffer= buf; this.isDirty= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); assertTrue(listener.count == 0 && listener.buffer == null); - + fManager.connectFileStore(fFileStore, null); try { - + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); 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.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#bufferContentAboutToBeReplaced/replaced */ public void test12_1() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer preBuffer, postBuffer; public int preCount, postCount; - + public void bufferContentAboutToBeReplaced(IFileBuffer buffer) { ++preCount; preBuffer= buffer; } - + public void bufferContentReplaced(IFileBuffer buffer) { ++postCount; postBuffer= buffer; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); assertTrue(listener.preCount == 0 && listener.postCount == 0 && listener.preBuffer == null && listener.postBuffer == null); - + fManager.connectFileStore(fFileStore, null); try { - + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); IDocument document= fileBuffer.getDocument(); document.replace(0, 0, "prefix"); - + fileBuffer.revert(null); - + assertTrue(listener.preCount == 1); assertTrue(listener.preBuffer == fileBuffer); assertTrue(listener.postCount == 1); assertTrue(listener.postBuffer == fileBuffer); - + } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#bufferContentAboutToBeReplaced/replaced */ public void test12_2() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer preBuffer, postBuffer; public int preCount, postCount; - + public void bufferContentAboutToBeReplaced(IFileBuffer buffer) { ++preCount; preBuffer= buffer; } - + public void bufferContentReplaced(IFileBuffer buffer) { ++postCount; postBuffer= buffer; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); assertTrue(listener.preCount == 0 && listener.postCount == 0 && listener.preBuffer == null && listener.postBuffer == null); - + fManager.connectFileStore(fFileStore, null); try { - + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); - + if (modifyUnderlyingFile()) { assertTrue(listener.preCount == 1); assertTrue(listener.preBuffer == fileBuffer); assertTrue(listener.postCount == 1); assertTrue(listener.postBuffer == fileBuffer); } - + } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateValidationChanged */ public void test13_1() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; public boolean isStateValidated; - + public void stateValidationChanged(IFileBuffer buf, boolean state) { ++count; this.buffer= buf; this.isStateValidated= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); assertTrue(listener.count == 0 && listener.buffer == null); - + fManager.connectFileStore(fFileStore, null); try { - + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); fileBuffer.validateState(null, null); - + if (isStateValidationSupported()) { assertTrue(listener.count == 1); assertTrue(listener.buffer == fileBuffer); assertTrue(listener.isStateValidated); } - + } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateValidationChanged */ public void test13_2() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; public boolean isStateValidated; - + public void stateValidationChanged(IFileBuffer buf, boolean state) { ++count; this.buffer= buf; this.isStateValidated= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -645,7 +645,7 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { setReadOnly(false); fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } @@ -655,18 +655,18 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { */ public void test13_3() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; public boolean isStateValidated; - + public void stateValidationChanged(IFileBuffer buf, boolean state) { ++count; this.buffer= buf; this.isStateValidated= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -679,7 +679,7 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); fileBuffer.validateState(null, null); fileBuffer.resetStateValidation(); - + if (isStateValidationSupported()) { assertTrue(listener.count == 2); assertTrue(listener.buffer == fileBuffer); @@ -689,29 +689,29 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateValidationChanged */ public void test13_4() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; public boolean isStateValidated; - + public void stateValidationChanged(IFileBuffer buf, boolean state) { ++count; this.buffer= buf; this.isStateValidated= state; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -736,27 +736,27 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { setReadOnly(false); fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#underlyingFileDeleted */ public void test14() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void underlyingFileDeleted(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -775,29 +775,29 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#underlyingFileMoved */ public void test15() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; public IPath newLocation; - + public void underlyingFileMoved(IFileBuffer buf, IPath location) { ++count; this.buffer= buf; this.newLocation= location; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -818,7 +818,7 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } @@ -829,16 +829,16 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { */ public void test16_1() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -857,27 +857,27 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateChanging for external changes */ public void test16_2() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -896,7 +896,7 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } @@ -907,16 +907,16 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { */ public void test16_3() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -935,27 +935,27 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateChanging for internal changes */ public void test17_1() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -967,7 +967,7 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); fileBuffer.validateState(null, null); - + if (isStateValidationSupported()) { assertTrue(listener.count == 1); assertTrue(listener.buffer == fileBuffer); @@ -976,7 +976,7 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } @@ -986,16 +986,16 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { */ public void test17_2() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -1009,34 +1009,34 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { IDocument document= fileBuffer.getDocument(); document.replace(0, 0, "prefix"); fileBuffer.revert(null); - + assertTrue(listener.count == 1); assertTrue(listener.buffer == fileBuffer); } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test IFileBufferListener#stateChanging for internal changes */ public void test17_3() throws Exception { class Listener extends FileBufferListener { - + public IFileBuffer buffer; public int count; - + public void stateChanging(IFileBuffer buf) { ++count; this.buffer= buf; } } - + Listener listener= new Listener(); fManager.addFileBufferListener(listener); try { @@ -1050,19 +1050,19 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { IDocument document= fileBuffer.getDocument(); document.replace(0, 0, "prefix"); fileBuffer.commit(null, true); - + assertTrue(listener.count == 1); assertTrue(listener.buffer == fileBuffer); } finally { fManager.disconnectFileStore(fFileStore, null); } - + } finally { fManager.removeFileBufferListener(listener); } } - + /* * Test annotation model existence. * ATTENTION: This test is only effective in a workspace that contains the "org.eclipse.ui.editors" bundle. @@ -1072,27 +1072,27 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { try { ITextFileBuffer buffer= fManager.getFileStoreTextFileBuffer(fFileStore); assertNotNull(buffer); - + Class clazz= getAnnotationModelClass(); if (clazz != null) { IAnnotationModel model= buffer.getAnnotationModel(); assertTrue(clazz.isInstance(model)); } - + } finally { fManager.disconnectFileStore(fFileStore, null); } } - + /* * Test notification in case of failing listener. */ public void test19() throws Exception { - + class NotifiedListener extends FileBufferListener { - + int notifyCount= 0; - + public void bufferCreated(IFileBuffer buffer) { notifyCount++; } @@ -1100,22 +1100,22 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { notifyCount++; } } - + class ForcedException extends RuntimeException { private static final long serialVersionUID= 1L; public void printStackTrace(PrintStream s) { s.println("!FORCED BY TEST: this entry is intentional"); } - + public void printStackTrace(PrintWriter s) { s.println("!FORCED BY TEST: this entry is intentional"); } } - + NotifiedListener notifyCounter1= new NotifiedListener(); NotifiedListener notifyCounter2= new NotifiedListener(); - + FileBufferListener failingListener= new FileBufferListener() { public void bufferCreated(IFileBuffer buffer) { throw new ForcedException(); @@ -1124,33 +1124,33 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { throw new ForcedException(); } }; - + fManager.addFileBufferListener(notifyCounter1); fManager.addFileBufferListener(failingListener); fManager.addFileBufferListener(notifyCounter2); - + fManager.connectFileStore(fFileStore, null); try { ITextFileBuffer buffer= fManager.getFileStoreTextFileBuffer(fFileStore); assertNotNull(buffer); - + Class clazz= getAnnotationModelClass(); if (clazz != null) { IAnnotationModel model= buffer.getAnnotationModel(); assertTrue(clazz.isInstance(model)); } - + } finally { fManager.disconnectFileStore(fFileStore, null); fManager.removeFileBufferListener(notifyCounter1); fManager.removeFileBufferListener(failingListener); fManager.removeFileBufferListener(notifyCounter2); } - + assertEquals(2, notifyCounter1.notifyCount); assertEquals(2, notifyCounter2.notifyCount); } - + public void testGetBufferForDocument() throws Exception { fManager.connectFileStore(fFileStore, null); try { @@ -1180,5 +1180,5 @@ public abstract class FileStoreFileBufferFunctions extends TestCase { fManager.disconnectFileStore(fFileStore, null); } } - + } diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForExternalFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForExternalFiles.java index 97a6846eedd..7514e6a03be 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForExternalFiles.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForExternalFiles.java @@ -26,7 +26,7 @@ import org.eclipse.core.filebuffers.FileBuffers; * FileBuffersForExternalFiles */ public class FileStoreFileBuffersForExternalFiles extends FileStoreFileBufferFunctions { - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() */ @@ -35,7 +35,7 @@ public class FileStoreFileBuffersForExternalFiles extends FileStoreFileBufferFun FileTool.delete(FileBuffers.getSystemFileAtLocation(getPath()).getParentFile()); super.tearDown(); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#createPath(org.eclipse.core.resources.IProject) */ @@ -45,7 +45,7 @@ public class FileStoreFileBuffersForExternalFiles extends FileStoreFileBufferFun FileTool.copy(sourceFile, externalFile); return new Path(externalFile.getAbsolutePath()); } - + protected void setReadOnly(boolean state) throws Exception { IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath()); assertNotNull(fileStore); @@ -79,7 +79,7 @@ public class FileStoreFileBuffersForExternalFiles extends FileStoreFileBufferFun protected boolean modifyUnderlyingFile() throws Exception { return false; } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#getAnnotationModelClass() */ diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingExternalFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingExternalFiles.java index 815309c0287..5b713b107eb 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingExternalFiles.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingExternalFiles.java @@ -24,7 +24,7 @@ import org.eclipse.core.filebuffers.FileBuffers; * FileBuffersForNonExistingExternalFiles */ public class FileStoreFileBuffersForNonExistingExternalFiles extends FileStoreFileBufferFunctions { - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() */ @@ -32,13 +32,13 @@ public class FileStoreFileBuffersForNonExistingExternalFiles extends FileStoreFi FileTool.delete(getPath()); super.tearDown(); } - + protected IPath createPath(IProject project) throws Exception { IPath path= FileBuffersTestPlugin.getDefault().getStateLocation(); path= path.append("NonExistingExternalFile"); return new Path(path.toFile().getAbsolutePath()); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly() */ diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java index 0650d8bc686..222a20f8df5 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java @@ -27,7 +27,7 @@ import org.eclipse.core.filebuffers.LocationKind; * FileBuffersForNonExistingWorkspaceFiles */ public class FileStoreFileBuffersForNonExistingWorkspaceFiles extends FileStoreFileBufferFunctions { - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() */ @@ -35,7 +35,7 @@ public class FileStoreFileBuffersForNonExistingWorkspaceFiles extends FileStoreF FileTool.delete(getPath()); super.tearDown(); } - + /* * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#createPath(org.eclipse.core.resources.IProject) */ @@ -44,7 +44,7 @@ public class FileStoreFileBuffersForNonExistingWorkspaceFiles extends FileStoreF IPath filePath= folder.getLocation().append("NonExistingWorkspaceFile"); return filePath.makeAbsolute(); } - + public void testBug118199() throws Exception { IFile file= getProject().getWorkspace().getRoot().getFile(getPath()); assertFalse(file.exists()); diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForWorkspaceFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForWorkspaceFiles.java index ed8557b3375..17ffdebf2b0 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForWorkspaceFiles.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForWorkspaceFiles.java @@ -37,7 +37,7 @@ import org.eclipse.jface.text.source.IAnnotationModel; * FileBuffersForWorkspaceFiles */ public class FileStoreFileBuffersForWorkspaceFiles extends FileBufferFunctions { - + protected IPath createPath(IProject project) throws Exception { IFolder folder= ResourceHelper.createFolder("project/folderA/folderB/"); IFile file= ResourceHelper.createFile(folder, "WorkspaceFile", "content"); @@ -78,11 +78,11 @@ public class FileStoreFileBuffersForWorkspaceFiles extends FileBufferFunctions { ResourceHelper.createFolder("project/folderA/folderB/folderC"); IPath path= new Path("/project/folderA/folderB/folderC/MovedWorkspaceFile"); file.move(path, true, false, null); - + file= FileBuffers.getWorkspaceFileAtLocation(path); if (file != null && file.exists()) return path; - + return null; } 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 ffc7daaa339..7d88be8dd12 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 @@ -34,27 +34,27 @@ import org.eclipse.core.filebuffers.FileBuffers; 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 entries = zipFile.entries(); - + try { while(entries.hasMoreElements()){ ZipEntry entry = (ZipEntry)entries.nextElement(); @@ -92,12 +92,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 @@ -108,11 +108,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 @@ -132,12 +132,12 @@ public class FileTool { is.close(); } } - + /** * 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 @@ -154,7 +154,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 @@ -180,13 +180,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)); } @@ -220,12 +220,12 @@ public class FileTool { } } } - + public static void delete(IPath path) { File file= FileBuffers.getSystemFileAtLocation(path); delete(file); } - + public static void delete(File file) { if (file.exists()) { for (int i= 0; i < MAX_RETRY; i++) { diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/MockDocumentSetupParticipants.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/MockDocumentSetupParticipants.java index fa3eb16cbc2..fd0ba7655ed 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/MockDocumentSetupParticipants.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/MockDocumentSetupParticipants.java @@ -40,7 +40,7 @@ public class MockDocumentSetupParticipants { append(document, getClass()+"\n"); } } - + static abstract class AbstractTestDSPExtension extends AbstractTestDSP implements IDocumentSetupParticipantExtension { /* * @see org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension#setup(org.eclipse.jface.text.IDocument, org.eclipse.core.runtime.IPath, org.eclipse.core.filebuffers.LocationKind) @@ -49,36 +49,36 @@ public class MockDocumentSetupParticipants { append(document, getClass()+"%%EXTENSION\n"); } } - + public static class TestDSP1 extends AbstractTestDSP {} public static class TestDSP2 extends AbstractTestDSP {} public static class TestDSP3 extends AbstractTestDSP {} - + public static class TestDSP4 extends AbstractTestDSPExtension {} public static class TestDSP5 extends AbstractTestDSPExtension {} public static class TestDSP6 extends AbstractTestDSPExtension {} - + public static class TestDSP7 extends AbstractTestDSPExtension { public void setup(IDocument document, IPath location, LocationKind locationKind) { if (locationKind == LocationKind.IFILE) append(document, new StringBuffer(location.toPortableString()).reverse().toString()); } } - + public static class TestDSP8 extends AbstractTestDSPExtension { public void setup(IDocument document, IPath location, LocationKind locationKind) { if (locationKind == LocationKind.LOCATION) append(document, new StringBuffer(location.toPortableString()).reverse().toString()); } } - + public static class TestDSP9 extends AbstractTestDSPExtension { public void setup(IDocument document, IPath location, LocationKind locationKind) { if (locationKind == LocationKind.NORMALIZE) append(document, new StringBuffer(location.toPortableString()).reverse().toString()); } } - + private static void append(IDocument document, String string) { try { document.replace(document.getLength(), 0, string); diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceHelper.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceHelper.java index 6abec6e5fce..2fc23f6b59e 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceHelper.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceHelper.java @@ -37,36 +37,36 @@ import org.eclipse.core.filebuffers.manipulation.ContainerCreator; * @since 3.0 */ public class ResourceHelper { - + private final static IProgressMonitor NULL_MONITOR= new NullProgressMonitor(); private static final int MAX_RETRY= 5; - + 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) { IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); IProject project= root.getProject(projectName); if (project.exists()) delete(project); } - + public static void delete(final IProject project) { delete(project, true); } - + public static void delete(final IProject project, boolean deleteContent) { for (int i= 0; i < MAX_RETRY; i++) { try { @@ -84,7 +84,7 @@ public class ResourceHelper { } } } - + public static IFolder createFolder(String portableFolderPath) throws CoreException { ContainerCreator creator= new ContainerCreator(ResourcesPlugin.getWorkspace(), new Path(portableFolderPath)); IContainer container= creator.createContainer(NULL_MONITOR); @@ -96,11 +96,11 @@ public class ResourceHelper { public static IFile createFile(IFolder folder, String name, String contents) throws CoreException { return createFile(folder.getFile(name), contents); } - + public static IFile createFile(IProject project, String name, String contents) throws CoreException { return createFile(project.getFile(name), contents); } - + private static IFile createFile(IFile file, String contents) throws CoreException { if (contents == null) contents= ""; @@ -108,48 +108,48 @@ public class ResourceHelper { file.create(inputStream, true, NULL_MONITOR); return file; } - + 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; } } diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceTextFileManagerDocCreationTests.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceTextFileManagerDocCreationTests.java index a1936b81e4e..adb3c35793e 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceTextFileManagerDocCreationTests.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceTextFileManagerDocCreationTests.java @@ -24,11 +24,11 @@ import org.eclipse.core.filebuffers.LocationKind; * @since 3.4 */ public class ResourceTextFileManagerDocCreationTests extends AbstractFileBufferDocCreationTests { - + protected void setUp() throws Exception { fManager= new ResourceTextFileBufferManager(); } - + protected void assertDocumentContent(String expectedContent, String fullPath, LocationKind locKind) { assertEquals(expectedContent, fManager.createEmptyDocument(new Path(fullPath), locKind).get()); if (locKind == LocationKind.IFILE) { @@ -36,7 +36,7 @@ public class ResourceTextFileManagerDocCreationTests extends AbstractFileBufferD assertEquals(expectedContent, ((ResourceTextFileBufferManager)fManager).createEmptyDocument(file).get()); } } - + protected LocationKind[] getSupportLocationKinds() { return new LocationKind[] {LocationKind.IFILE, LocationKind.LOCATION, LocationKind.NORMALIZE}; } diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TextFileManagerDocCreationTests.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TextFileManagerDocCreationTests.java index be35088d2db..f8d37fc06a4 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TextFileManagerDocCreationTests.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TextFileManagerDocCreationTests.java @@ -19,18 +19,18 @@ import org.eclipse.core.filebuffers.LocationKind; * @since 3.4 */ public class TextFileManagerDocCreationTests extends AbstractFileBufferDocCreationTests { - + protected void setUp() throws Exception { fManager= new TextFileBufferManager(); } - + protected void assertDocumentContent(String expectedContent, String path, LocationKind locKind) { if (locKind != LocationKind.IFILE) { /** {@link TextFileBufferManager} does not deal with {@link LocationKind#IFILE} */ super.assertDocumentContent(expectedContent, path, locKind); } } - + protected LocationKind[] getSupportLocationKinds() { return new LocationKind[] {LocationKind.LOCATION, LocationKind.NORMALIZE}; } |