Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2008-01-25 10:38:30 +0000
committerDani Megert2008-01-25 10:38:30 +0000
commit11a77f21a68dccbe72a0a3a6cc09492fb6d5802a (patch)
tree703384ad287d22ef43cd07beacce5d1197c25750 /org.eclipse.core.filebuffers.tests
parent29e2bde1e40bd3bd5fe4b6b7b1dfbcdeabed3dec (diff)
downloadeclipse.platform.text-11a77f21a68dccbe72a0a3a6cc09492fb6d5802a.tar.gz
eclipse.platform.text-11a77f21a68dccbe72a0a3a6cc09492fb6d5802a.tar.xz
eclipse.platform.text-11a77f21a68dccbe72a0a3a6cc09492fb6d5802a.zip
Committed Andrew's patch to fix 208881: [api] enable document setup participants to customize behaviour based on resource being openedv20080128
Diffstat (limited to 'org.eclipse.core.filebuffers.tests')
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/AbstractFileBufferDocCreationTests.java138
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/MockDocumentSetupParticipants.java89
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceTextFileManagerDocCreationTests.java43
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TextFileManagerDocCreationTests.java37
4 files changed, 307 insertions, 0 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
new file mode 100644
index 00000000000..4bed6a6efbd
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/AbstractFileBufferDocCreationTests.java
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation - [api] enable document setup participants to customize behaviour based on resource being opened - https://bugs.eclipse.org/bugs/show_bug.cgi?id=208881
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.eclipse.core.filebuffers.LocationKind;
+import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP1;
+import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP2;
+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;
+
+
+/**
+ * @since 3.4
+ */
+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]);
+ 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++) {
+ String s= null;
+ if(clss[i]!=null) {
+ s= clss[i].toString();
+ if(IDocumentSetupParticipantExtension.class.isAssignableFrom(clss[i])) {
+ s+= "%%EXTENSION";
+ }
+ }
+ result[i]= s;
+ }
+ return result;
+ }
+}
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
new file mode 100644
index 00000000000..6b9a642e342
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/MockDocumentSetupParticipants.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation - [api] enable document setup participants to customize behaviour based on resource being opened - https://bugs.eclipse.org/bugs/show_bug.cgi?id=208881
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
+import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
+import org.eclipse.core.filebuffers.LocationKind;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+
+
+/**
+ * Holds {@link IDocumentSetupParticipant}'s for registering against fictional
+ * document extensions for test purposes.
+ *
+ * @since 3.4
+ */
+public class MockDocumentSetupParticipants {
+ /**
+ * An {@link IDocumentSetupParticipant} which stamps its name
+ * into the document being setup for integration test purposes.
+ */
+ static abstract class AbstractTestDSP implements IDocumentSetupParticipant {
+ /*
+ * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
+ */
+ public void setup(IDocument document) {
+ append(document, getClass()+"\n");
+ }
+ }
+
+ static abstract class AbstractTestDSPExtension extends AbstractTestDSP implements IDocumentSetupParticipant, IDocumentSetupParticipantExtension {
+ /*
+ * @see org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension#setup(org.eclipse.jface.text.IDocument, org.eclipse.core.runtime.IPath, org.eclipse.core.filebuffers.LocationKind)
+ */
+ public void setup(IDocument document, IPath location, LocationKind locationKind) {
+ 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);
+ } catch(BadLocationException ble) {
+ Assert.isTrue(false);
+ }
+ }
+}
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
new file mode 100644
index 00000000000..a1936b81e4e
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/ResourceTextFileManagerDocCreationTests.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation - [api] enable document setup participants to customize behaviour based on resource being opened - https://bugs.eclipse.org/bugs/show_bug.cgi?id=208881
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import org.eclipse.core.internal.filebuffers.ResourceTextFileBufferManager;
+
+import org.eclipse.core.runtime.Path;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+
+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) {
+ IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath));
+ 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
new file mode 100644
index 00000000000..be35088d2db
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TextFileManagerDocCreationTests.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation - [api] enable document setup participants to customize behaviour based on resource being opened - https://bugs.eclipse.org/bugs/show_bug.cgi?id=208881
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import org.eclipse.core.internal.filebuffers.TextFileBufferManager;
+
+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};
+ }
+}

Back to the top