View | Details | Raw Unified | Return to bug 86862 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/tests/runtime/content/IContentTypeManagerTest.java (-3 / +70 lines)
Lines 12-22 Link Here
12
12
13
import java.io.*;
13
import java.io.*;
14
import java.util.*;
14
import java.util.*;
15
import junit.framework.*;
15
import junit.framework.AssertionFailedError;
16
import junit.framework.Test;
16
import org.eclipse.core.internal.content.*;
17
import org.eclipse.core.internal.content.*;
17
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.content.*;
19
import org.eclipse.core.runtime.content.*;
19
import org.eclipse.core.runtime.content.IContentTypeManager.ContentTypeChangeEvent;
20
import org.eclipse.core.runtime.content.IContentTypeManager.ContentTypeChangeEvent;
21
import org.eclipse.core.runtime.content.IContentTypeMatcher.IRelatedRegistry;
20
import org.eclipse.core.runtime.preferences.InstanceScope;
22
import org.eclipse.core.runtime.preferences.InstanceScope;
21
import org.eclipse.core.tests.harness.BundleTestingHelper;
23
import org.eclipse.core.tests.harness.BundleTestingHelper;
22
import org.eclipse.core.tests.harness.TestRegistryChangeListener;
24
import org.eclipse.core.tests.harness.TestRegistryChangeListener;
Lines 71-78 Link Here
71
	private final static String XML_UTF_8 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><org.eclipse.core.runtime.tests.root/>";
73
	private final static String XML_UTF_8 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><org.eclipse.core.runtime.tests.root/>";
72
74
73
	public static Test suite() {
75
	public static Test suite() {
74
		//return new IContentTypeManagerTest("testListParsing");
76
		return new IContentTypeManagerTest("testRelatedRegistry");
75
		return new TestSuite(IContentTypeManagerTest.class);
77
		//return new TestSuite(IContentTypeManagerTest.class);
76
	}
78
	}
77
79
78
	public IContentTypeManagerTest(String name) {
80
	public IContentTypeManagerTest(String name) {
Lines 1099-1104 Link Here
1099
		assertNotNull("9.2", subFooBar);
1101
		assertNotNull("9.2", subFooBar);
1100
		assertTrue("9.3", contains(fooBarTypes, fooBar));
1102
		assertTrue("9.3", contains(fooBarTypes, fooBar));
1101
		assertTrue("9.4", contains(fooBarTypes, subFooBar));
1103
		assertTrue("9.4", contains(fooBarTypes, subFooBar));
1104
	}
1105
1106
	public void testRelatedRegistry() {
1107
		IContentTypeManager manager = Platform.getContentTypeManager();
1108
		IContentType text = manager.getContentType(Platform.PI_RUNTIME + ".text");
1109
		IContentType xml = manager.getContentType(Platform.PI_RUNTIME + ".xml");
1110
		String textEditor = "Text editor";
1111
		String xmlEditor = "XML editor";
1112
		String legacyTextEditor = "Legacy Text editor";
1113
		String legacyXmlEditor = "Legacy XML editor";
1114
		final Object[][] contentTypeAssociations = { {text, textEditor}, {xml, xmlEditor}};
1115
		final Object[][] legacyAssociations = { {"legacy.txt", legacyTextEditor}, {"legacy.xml", legacyXmlEditor}};
1116
1117
		IContentTypeMatcher matcher = manager.getMatcher(new LocalSelectionPolicy());
1118
1119
		IRelatedRegistry registry = new IRelatedRegistry() {
1120
			public Object[] getRelatedObjects(IContentType type) {
1121
				List result = new ArrayList();
1122
				for (int i = 0; i < contentTypeAssociations.length; i++)
1123
					if (contentTypeAssociations[i][0].equals(type))
1124
						result.add(contentTypeAssociations[i][1]);
1125
				return result.toArray();
1126
			}
1127
1128
			public Object[] getRelatedObjects(String fileName) {
1129
				List result = new ArrayList();
1130
				for (int i = 0; i < contentTypeAssociations.length; i++)
1131
					if (legacyAssociations[i][0].equals(fileName))
1132
						result.add(legacyAssociations[i][1]);
1133
				return result.toArray();
1134
			}
1135
		};
1136
1137
		Object[] editors;
1138
		editors = matcher.findRelatedObjects(xml, null, registry);
1139
		assertEquals("1.0", 2, editors.length);
1140
		assertEquals("1.1", editors[0], xmlEditor);
1141
		assertEquals("1.1", editors[1], textEditor);
1142
1143
		editors = matcher.findRelatedObjects(text, null, registry);
1144
		assertEquals("2.0", 1, editors.length);
1145
		assertEquals("2.1", editors[0], textEditor);
1146
1147
		editors = matcher.findRelatedObjects(xml, "legacy.txt", registry);
1148
		assertEquals("3.0", 3, editors.length);
1149
		assertEquals("3.1", editors[0], xmlEditor);
1150
		assertEquals("3.2", editors[1], legacyTextEditor);
1151
		assertEquals("3.3", editors[2], textEditor);
1152
1153
		editors = matcher.findRelatedObjects(text, "legacy.xml", registry);
1154
		assertEquals("4.0", 2, editors.length);
1155
		assertEquals("4.1", editors[0], textEditor);
1156
		assertEquals("4.2", editors[1], legacyXmlEditor);
1157
1158
		editors = matcher.findRelatedObjects(xml, "legacy.xml", registry);
1159
		assertEquals("5.0", 3, editors.length);
1160
		assertEquals("5.1", editors[0], xmlEditor);
1161
		assertEquals("5.2", editors[1], legacyXmlEditor);
1162
		assertEquals("5.3", editors[2], textEditor);
1163
1164
		editors = matcher.findRelatedObjects(text, "legacy.txt", registry);
1165
		assertEquals("6.0", 2, editors.length);
1166
		assertEquals("6.1", editors[0], textEditor);
1167
		assertEquals("6.2", editors[1], legacyTextEditor);
1168
1102
	}
1169
	}
1103
1170
1104
	public void testRootElementAndDTDDescriber() throws IOException {
1171
	public void testRootElementAndDTDDescriber() throws IOException {

Return to bug 86862