Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDejan Gloszic2006-02-09 23:19:41 +0000
committerDejan Gloszic2006-02-09 23:19:41 +0000
commit045f60cde766d1b467d923ea03db0ecf31c18723 (patch)
treee9298b22706b6cad4cf893ef3263618a42d15cbb /org.eclipse.ua.tests
parent58eb0b1860f4e1a18a276ffbe39120026e02cb27 (diff)
downloadeclipse.platform.ua-045f60cde766d1b467d923ea03db0ecf31c18723.tar.gz
eclipse.platform.ua-045f60cde766d1b467d923ea03db0ecf31c18723.tar.xz
eclipse.platform.ua-045f60cde766d1b467d923ea03db0ecf31c18723.zip
127104[Help] Ability to filter out context help topics
Diffstat (limited to 'org.eclipse.ua.tests')
-rw-r--r--org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java7
-rw-r--r--org.eclipse.ua.tests/data/help/context/contexts.xml70
-rw-r--r--org.eclipse.ua.tests/data/help/context/contexts_serialized_linux_gtk_x86.txt42
-rw-r--r--org.eclipse.ua.tests/data/help/context/contexts_serialized_macosx_carbon_ppc.txt42
-rw-r--r--org.eclipse.ua.tests/data/help/context/contexts_serialized_win32_win32_x86.txt42
-rw-r--r--org.eclipse.ua.tests/data/help/context/simple_page.html14
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java2
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/AllContextTests.java34
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/ParserTest.java69
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializer.java75
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializerTest.java116
-rw-r--r--org.eclipse.ua.tests/plugin.xml11
12 files changed, 523 insertions, 1 deletions
diff --git a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java
index 23dfc7433..00d67c292 100644
--- a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java
+++ b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java
@@ -14,6 +14,7 @@ import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;
@@ -28,7 +29,11 @@ public class FileUtil {
* as a String (file must be encoded as UTF-8).
*/
public static String getContents(Bundle bundle, String relativePath) throws IOException {
- return readString(bundle.getEntry(relativePath).openStream());
+ URL url = bundle.getEntry(relativePath);
+ if (url != null) {
+ return readString(url.openStream());
+ }
+ return null;
}
/**
diff --git a/org.eclipse.ua.tests/data/help/context/contexts.xml b/org.eclipse.ua.tests/data/help/context/contexts.xml
new file mode 100644
index 000000000..ed1c0fe00
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/context/contexts.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?NLS TYPE="org.eclipse.help.contexts"?>
+
+<contexts>
+ <context id="test.id" >
+ <description>This is a test context.</description>
+ <topic label="This topic should always appear" href="data/help/context/simple_page.html"/>
+ <topic filter="os=win32" label="Your OS is win32" href="data/help/context/simple_page.html"/>
+ <topic filter="os=linux" label="Your OS is linux" href="data/help/context/simple_page.html"/>
+ <topic filter="os=macosx" label="Your OS is macosx" href="data/help/context/simple_page.html"/>
+
+ <!-- should never appear -->
+ <topic filter="os=invalid" label="Your OS is invalid" href="data/help/context/simple_page.html"/>
+
+ <topic filter="ws=win32" label="Your WS is win32" href="data/help/context/simple_page.html"/>
+ <topic filter="ws=gtk" label="Your WS is gtk" href="data/help/context/simple_page.html"/>
+ <topic filter="ws=carbon" label="Your WS is carbon" href="data/help/context/simple_page.html"/>
+
+ <!-- should never appear -->
+ <topic filter="ws=invalid" label="Your WS is invalid" href="data/help/context/simple_page.html"/>
+
+ <topic filter="arch=x86" label="Your ARCH is x86" href="data/help/context/simple_page.html"/>
+ <topic filter="arch=ppc" label="Your ARCH is ppc" href="data/help/context/simple_page.html"/>
+
+ <!-- should never appear -->
+ <topic filter="arch=invalid" label="Your ARCH is invalid" href="data/help/context/simple_page.html"/>
+
+ <topic label="Your OS is win32 AND your WS is win32" href="data/help/context/simple_page.html">
+ <filter name="os" value="win32"/>
+ <filter name="ws" value="win32"/>
+ </topic>
+
+ <topic label="Your OS is linux AND your WS is gtk" href="data/help/context/simple_page.html">
+ <filter name="os" value="linux"/>
+ <filter name="ws" value="gtk"/>
+ </topic>
+
+ <topic label="Your OS is macosx AND your WS is carbon" href="data/help/context/simple_page.html">
+ <filter name="os" value="macosx"/>
+ <filter name="ws" value="carbon"/>
+ </topic>
+
+ <!-- should never appear -->
+ <topic label="Your OS is win32 AND your WS is invalid" href="data/help/context/simple_page.html">
+ <filter name="os" value="win32"/>
+ <filter name="ws" value="invalid"/>
+ </topic>
+
+ <topic filter="plugin=org.eclipse.help" label="The plugin org.eclipse.help is installed" href="data/help/context/simple_page.html"/>
+
+ <!-- should never appear -->
+ <topic filter="plugin=invalid" label="The plugin invalid is installed" href="data/help/context/simple_page.html"/>
+
+ <topic filter="product=org.eclipse.sdk.ide" label="The product org.eclipse.sdk.ide is running" href="data/help/context/simple_page.html"/>
+
+ <!-- should never appear -->
+ <topic filter="product=invalid" label="The product invalid is running" href="data/help/context/simple_page.html"/>
+
+ <topic filter="category=org.eclipse.categories.developmentCategory" label="The category org.eclipse.categories.developmentCategory is enabled" href="data/help/context/simple_page.html"/>
+
+ <!-- should never appear -->
+ <topic filter="category=invalid" label="The category invalid is enabled" href="data/help/context/simple_page.html"/>
+
+ <topic filter="activity=org.eclipse.javaDevelopment" label="The activity org.eclipse.javaDevelopment is enabled" href="data/help/context/simple_page.html"/>
+
+ <!-- should never appear -->
+ <topic filter="activity=invalid" label="The activity invalid is enabled" href="data/help/context/simple_page.html"/>
+
+ </context>
+</contexts>
diff --git a/org.eclipse.ua.tests/data/help/context/contexts_serialized_linux_gtk_x86.txt b/org.eclipse.ua.tests/data/help/context/contexts_serialized_linux_gtk_x86.txt
new file mode 100644
index 000000000..1d86c68e4
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/context/contexts_serialized_linux_gtk_x86.txt
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<contexts>
+ <context id="test.id">
+ <description>This is a test context.<description>
+ <topic
+ label="This topic should always appear"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your OS is linux"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your WS is gtk"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your ARCH is x86"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your OS is linux AND your WS is gtk"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The plugin org.eclipse.help is installed"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The product org.eclipse.sdk.ide is running"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The category org.eclipse.categories.developmentCategory is enabled"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The activity org.eclipse.javaDevelopment is enabled"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ </context>
+</contexts>
diff --git a/org.eclipse.ua.tests/data/help/context/contexts_serialized_macosx_carbon_ppc.txt b/org.eclipse.ua.tests/data/help/context/contexts_serialized_macosx_carbon_ppc.txt
new file mode 100644
index 000000000..76f03d888
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/context/contexts_serialized_macosx_carbon_ppc.txt
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<contexts>
+ <context id="test.id">
+ <description>This is a test context.<description>
+ <topic
+ label="This topic should always appear"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your OS is macosx"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your WS is carbon"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your ARCH is ppc"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your OS is macosx AND your WS is carbon"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The plugin org.eclipse.help is installed"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The product org.eclipse.sdk.ide is running"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The category org.eclipse.categories.developmentCategory is enabled"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The activity org.eclipse.javaDevelopment is enabled"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ </context>
+</contexts>
diff --git a/org.eclipse.ua.tests/data/help/context/contexts_serialized_win32_win32_x86.txt b/org.eclipse.ua.tests/data/help/context/contexts_serialized_win32_win32_x86.txt
new file mode 100644
index 000000000..c61019fe6
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/context/contexts_serialized_win32_win32_x86.txt
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<contexts>
+ <context id="test.id">
+ <description>This is a test context.<description>
+ <topic
+ label="This topic should always appear"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your OS is win32"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your WS is win32"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your ARCH is x86"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="Your OS is win32 AND your WS is win32"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The plugin org.eclipse.help is installed"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The product org.eclipse.sdk.ide is running"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The category org.eclipse.categories.developmentCategory is enabled"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ <topic
+ label="The activity org.eclipse.javaDevelopment is enabled"
+ href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
+ </topic>
+ </context>
+</contexts>
diff --git a/org.eclipse.ua.tests/data/help/context/simple_page.html b/org.eclipse.ua.tests/data/help/context/simple_page.html
new file mode 100644
index 000000000..5918e900f
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/context/simple_page.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML>
+<HEAD>
+<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
+<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
+<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
+<TITLE>Test</TITLE>
+</HEAD>
+
+<p>
+Test
+</p>
+
+</BODY>
+</HTML>
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java
index 41880fdd2..8a044eae6 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java
@@ -13,6 +13,7 @@ package org.eclipse.ua.tests.help;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.ua.tests.help.context.AllContextTests;
import org.eclipse.ua.tests.help.toc.AllTocTests;
/*
@@ -31,6 +32,7 @@ public class AllHelpTests extends TestSuite {
* Constructs a new test suite.
*/
public AllHelpTests() {
+ addTest(AllContextTests.suite());
addTest(AllTocTests.suite());
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/AllContextTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/AllContextTests.java
new file mode 100644
index 000000000..4b27aeaa3
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/AllContextTests.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ua.tests.help.context;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/*
+ * Tests help functionality (automated).
+ */
+public class AllContextTests extends TestSuite {
+
+ /*
+ * Returns the entire test suite.
+ */
+ public static Test suite() {
+ return new AllContextTests();
+ }
+
+ /*
+ * Constructs a new test suite.
+ */
+ public AllContextTests() {
+ addTest(ParserTest.suite());
+ }
+}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/ParserTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/ParserTest.java
new file mode 100644
index 000000000..f6c769f38
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/ParserTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ua.tests.help.context;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.help.internal.context.ContextsBuilder;
+import org.eclipse.help.internal.context.ContextsFile;
+import org.eclipse.help.internal.context.PluginContexts;
+import org.eclipse.help.ui.internal.HelpUIPlugin;
+import org.eclipse.ua.tests.help.util.ContextModelSerializer;
+import org.eclipse.ua.tests.help.util.ContextModelSerializerTest;
+import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
+import org.eclipse.ua.tests.util.FileUtil;
+import org.osgi.framework.Bundle;
+
+public class ParserTest extends TestCase {
+
+ /*
+ * Returns an instance of this Test.
+ */
+ public static Test suite() {
+ return new TestSuite(ParserTest.class);
+ }
+
+ /*
+ * Ensure that org.eclipse.help.ui is started. It contributes extra content
+ * filtering that is used by this test. See UIContentFilterProcessor.
+ */
+ protected void setUp() throws Exception {
+ HelpUIPlugin.getDefault();
+ }
+
+ public void testParser() {
+ Iterator iter = ContextModelSerializerTest.getContextFiles().iterator();
+ while (iter.hasNext()) {
+ ContextsFile file = (ContextsFile)iter.next();
+ PluginContexts contexts = new PluginContexts();
+ ContextsBuilder builder = new ContextsBuilder(contexts);
+ builder.build(file);
+
+ Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle();
+ String relativePath = file.getHref();
+
+ try {
+ String expected = FileUtil.getResultFileContents(bundle, relativePath);
+ String actual = ContextModelSerializer.serialize(contexts);
+ Assert.assertEquals("Serialized context help model for " + relativePath + " did not match the expected result", expected, actual);
+ }
+ catch(IOException e) {
+ Assert.fail("An error occured while loading expected result file for context help at: " + relativePath + ": " + e);
+ }
+ }
+ }
+}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializer.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializer.java
new file mode 100644
index 000000000..4832afe55
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializer.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ua.tests.help.util;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.help.IContext;
+import org.eclipse.help.IHelpResource;
+import org.eclipse.help.UAContentFilter;
+import org.eclipse.help.internal.context.PluginContexts;
+
+public class ContextModelSerializer {
+
+ private static final String EMPTY_STRING = "";
+
+ public static String serialize(PluginContexts contexts) {
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
+ buf.append(serializeAux(contexts, ""));
+ return buf.toString();
+ }
+
+ private static String serializeAux(PluginContexts contexts, String indent) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(indent + "<contexts>\n");
+
+ Iterator iter = contexts.getMap().entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry entry = (Map.Entry)iter.next();
+ buf.append(serializeAux(entry, indent + " "));
+ }
+
+ buf.append(indent + "</contexts>\n");
+ return buf.toString();
+ }
+
+ private static String serializeAux(Map.Entry entry, String indent) {
+ String id = (String)entry.getKey();
+ IContext context = (IContext)entry.getValue();
+ StringBuffer buf = new StringBuffer();
+ buf.append(indent + "<context id=\"" + id + "\">\n");
+ buf.append(indent + " <description>");
+ buf.append(context.getText());
+ buf.append("<description>\n");
+
+ IHelpResource[] topics = context.getRelatedTopics();
+ for (int i=0;i<topics.length;++i) {
+ buf.append(serializeAux(topics[i], indent + " "));
+ }
+
+ buf.append(indent + "</context>\n");
+ return buf.toString();
+ }
+
+ private static String serializeAux(IHelpResource topic, String indent) {
+ if (!UAContentFilter.isFiltered(topic)) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(indent + "<topic\n");
+ buf.append(indent + " label=\"" + topic.getLabel() + "\"\n");
+ buf.append(indent + " href=\"" + topic.getHref() + "\">\n");
+ buf.append(indent + "</topic>\n");
+ return buf.toString();
+ }
+ return EMPTY_STRING;
+ }
+}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializerTest.java
new file mode 100644
index 000000000..429af6c4f
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializerTest.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ua.tests.help.util;
+
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.help.internal.context.ContextsBuilder;
+import org.eclipse.help.internal.context.ContextsFile;
+import org.eclipse.help.internal.context.PluginContexts;
+import org.eclipse.help.ui.internal.HelpUIPlugin;
+import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
+import org.eclipse.ua.tests.util.FileUtil;
+
+/*
+ * A utility for regenerating the _serialized.txt files that contain the expected
+ * output for the context content when serialized. This reads all the context content
+ * from the plugin manifest (for this test plugin only), constructs the model, then
+ * serializes the model to a text file, which is stored in the same directory as the
+ * intro xml file, as <original_name>_serialized.txt.
+ *
+ * These files are used by the JUnit tests to compare the result with the expected
+ * result.
+ *
+ * Usage:
+ *
+ * 1. Run this test as a JUnit plug-in test.
+ * 2. Right-click in "Package Explorer -> Refresh".
+ *
+ * The new files should appear.
+ *
+ * Note: Some of the files have os, ws, and arch appended, for example
+ * <original_name>_serialized_linux_gtk_x86.txt. These are filtering tests that have
+ * filters by os/ws/arch so the result is different on each combination. This test will
+ * only generate the _serialized file and will be the one for the current platform. You
+ * need to make one copy for each combination and edit the files manually to have the
+ * correct content (or generate on each platform).
+ */
+public class ContextModelSerializerTest extends TestCase {
+
+ /*
+ * Returns an instance of this Test.
+ */
+ public static Test suite() {
+ return new TestSuite(ContextModelSerializerTest.class);
+ }
+
+ /*
+ * Ensure that org.eclipse.help.ui is started. It contributes extra content
+ * filtering that is used by this test. See UIContentFilterProcessor.
+ */
+ protected void setUp() throws Exception {
+ HelpUIPlugin.getDefault();
+ }
+
+ public void testRunSerializer() {
+ Iterator iter = getContextFiles().iterator();
+ while (iter.hasNext()) {
+ ContextsFile file = (ContextsFile)iter.next();
+ PluginContexts contexts = new PluginContexts();
+ ContextsBuilder builder = new ContextsBuilder(contexts);
+ builder.build(file);
+
+ String pluginRoot = UserAssistanceTestPlugin.getDefault().getBundle().getLocation().substring("update@".length());
+ String relativePath = file.getHref();
+ String absolutePath = pluginRoot + relativePath;
+ String resultFile = FileUtil.getResultFile(absolutePath);
+
+ try {
+ PrintWriter out = new PrintWriter(new FileOutputStream(resultFile));
+ out.print(ContextModelSerializer.serialize(contexts));
+ out.close();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Gets all context files from the extension with id "tests.context". We only want
+ * to consider these for our tests.
+ *
+ * @return all ContextsFile objects contributed for tests
+ */
+ public static Collection getContextFiles() {
+ Collection contextFiles = new ArrayList();
+ IExtension extension = Platform.getExtensionRegistry().getExtension(UserAssistanceTestPlugin.getPluginId() + ".contextTest");
+ IConfigurationElement[] configElements = extension.getConfigurationElements();
+ for (int j=0;j<configElements.length;j++) {
+ if (configElements[j].getName().equals("contexts")) {
+ String href = configElements[j].getAttribute("file"); //$NON-NLS-1$
+ contextFiles.add(new ContextsFile(UserAssistanceTestPlugin.getPluginId(), href, null));
+ }
+ }
+ return contextFiles;
+ }
+}
diff --git a/org.eclipse.ua.tests/plugin.xml b/org.eclipse.ua.tests/plugin.xml
index 68d8d046f..9a04e75d7 100644
--- a/org.eclipse.ua.tests/plugin.xml
+++ b/org.eclipse.ua.tests/plugin.xml
@@ -216,6 +216,17 @@
configId="org.eclipse.ua.tests.intro.config.dynamicXML">
</configExtension>
</extension>
+
+ <!--
+ Context help test content
+ -->
+ <extension
+ point="org.eclipse.help.contexts"
+ id="contextTest">
+ <contexts
+ file="data/help/context/contexts.xml">
+ </contexts>
+ </extension>
<!--
TOC test content

Back to the top