Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis D'Entremont2006-07-21 21:13:51 +0000
committerCurtis D'Entremont2006-07-21 21:13:51 +0000
commit31f94b3f34c07196181428a5567707901bc8eb6d (patch)
tree20606afe550f38a8e2b2ebd8054331b3009429b8 /org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc
parent7c3f41331c64e14f826fafc0070539942e21c62b (diff)
downloadeclipse.platform.ua-31f94b3f34c07196181428a5567707901bc8eb6d.tar.gz
eclipse.platform.ua-31f94b3f34c07196181428a5567707901bc8eb6d.tar.xz
eclipse.platform.ua-31f94b3f34c07196181428a5567707901bc8eb6d.zip
122967 [Help] Remote help system (toc provider part)
Diffstat (limited to 'org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc')
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/AllTocTests.java5
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/ParserTest.java78
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java114
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocFileParserTest.java123
4 files changed, 240 insertions, 80 deletions
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/AllTocTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/AllTocTests.java
index e44c82f3e..a42ee2e54 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/AllTocTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/AllTocTests.java
@@ -14,7 +14,7 @@ import junit.framework.Test;
import junit.framework.TestSuite;
/*
- * Tests help TOC functionality (automated).
+ * Tests help table of contents functionality.
*/
public class AllTocTests extends TestSuite {
@@ -29,6 +29,7 @@ public class AllTocTests extends TestSuite {
* Constructs a new test suite.
*/
public AllTocTests() {
- addTest(ParserTest.suite());
+ addTest(TocFileParserTest.suite());
+ addTest(TocAssemblerTest.suite());
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/ParserTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/ParserTest.java
deleted file mode 100644
index d8ede3fcf..000000000
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/ParserTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * 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.toc;
-
-import java.io.IOException;
-import java.util.Collection;
-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.toc.Toc;
-import org.eclipse.help.internal.toc.TocBuilder;
-import org.eclipse.help.internal.toc.TocFile;
-import org.eclipse.help.ui.internal.HelpUIPlugin;
-import org.eclipse.ua.tests.help.util.TocModelSerializer;
-import org.eclipse.ua.tests.help.util.TocModelSerializerTest;
-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() {
- Collection tocFiles = TocModelSerializerTest.getTocFiles();
- TocBuilder builder = new TocBuilder();
- builder.build(tocFiles);
- Collection builtTocs = builder.getBuiltTocs();
-
- Iterator iter = builtTocs.iterator();
- while (iter.hasNext()) {
- Toc toc = (Toc)iter.next();
- TocFile file = toc.getTocFile();
-
- Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle();
- String relativePath = file.getHref();
-
- /*
- * Only test what's in the toc test data folder.
- */
- if (relativePath.startsWith("data/help/toc/")) {
- try {
- String expected = FileUtil.getContents(bundle, FileUtil.getResultFile(relativePath));
- String actual = TocModelSerializer.serialize(toc);
- Assert.assertEquals("Serialized toc 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 TOC at: " + relativePath + ": " + e);
- }
- }
- }
- }
-}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java
new file mode 100644
index 000000000..b453c0782
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * 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.toc;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.help.IToc;
+import org.eclipse.help.ITocContribution;
+import org.eclipse.help.ITopic;
+import org.eclipse.help.internal.toc.TocAssembler;
+import org.eclipse.help.internal.toc.TocFile;
+import org.eclipse.help.internal.toc.TocFileParser;
+import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
+
+public class TocAssemblerTest extends TestCase {
+
+ /*
+ * Returns an instance of this Test.
+ */
+ public static Test suite() {
+ return new TestSuite(TocAssemblerTest.class);
+ }
+
+ public void testAssemble() throws Exception {
+ TocFileParser parser = new TocFileParser();
+ ITocContribution b = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/b.xml", true, "en", null, null));
+ ITocContribution c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/c.xml", true, "en", null, null));
+ ITocContribution result_b_c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/result_b_c.xml", true, "en", null, null));
+
+ TocAssembler assembler = new TocAssembler();
+ List contributions = new ArrayList(Arrays.asList(new Object[] { b, c }));
+ assembler.assemble(contributions);
+ assertEquals(1, contributions.size());
+ String expected = serialize(result_b_c);
+ String actual = serialize((ITocContribution)contributions.get(0));
+ assertEquals(expected, actual);
+
+ ITocContribution a = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/a.xml", true, "en", null, null));
+ b = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/b.xml", true, "en", null, null));
+ c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/c.xml", true, "en", null, null));
+ ITocContribution result_a_b_c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/result_a_b_c.xml", true, "en", null, null));
+
+ contributions = new ArrayList(Arrays.asList(new Object[] { a, b, c }));
+ assembler.assemble(contributions);
+ assertEquals(1, contributions.size());
+ expected = serialize(result_a_b_c);
+ actual = serialize((ITocContribution)contributions.get(0));
+ assertEquals(expected, actual);
+ }
+
+ private String serialize(ITocContribution contribution) {
+ return serialize(contribution.getToc());
+ }
+
+ private String serialize(IToc toc) {
+ StringBuffer buf = new StringBuffer();
+ buf.append("<toc");
+ if (toc.getLabel() != null) {
+ buf.append(" label=\"" + toc.getLabel() + "\"");
+ }
+ if (toc.getTopic(null).getHref() != null) {
+ buf.append(" topic=\"" + toc.getTopic(null).getHref() + "\"");
+ }
+ buf.append(">\n");
+
+ ITopic[] topics = toc.getTopics();
+ String indent = " ";
+ for (int i=0;i<topics.length;++i) {
+ buf.append(serialize(topics[i], indent));
+ }
+
+ buf.append("</toc>\n");
+ return buf.toString();
+ }
+
+ private String serialize(ITopic topic, String indent) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(indent + "<topic");
+ if (topic.getLabel() != null) {
+ buf.append(" label=\"" + topic.getLabel() + "\"");
+ }
+ String href = topic.getHref();
+ if (href != null) {
+ buf.append(" href=\"" + href.substring(href.indexOf('/', 1) + 1) + "\"");
+ }
+
+ ITopic[] subtopics = topic.getSubtopics();
+ if (subtopics.length == 0) {
+ buf.append("/>\n");
+ }
+ else {
+ buf.append(">\n");
+ for (int i=0;i<subtopics.length;++i) {
+ buf.append(serialize(subtopics[i], indent + " "));
+ }
+ buf.append(indent + "</topic>\n");
+ }
+ return buf.toString();
+ }
+}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocFileParserTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocFileParserTest.java
new file mode 100644
index 000000000..ef23794c9
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocFileParserTest.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * 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.toc;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.help.IAnchor;
+import org.eclipse.help.INode;
+import org.eclipse.help.IFilter;
+import org.eclipse.help.IInclude;
+import org.eclipse.help.IToc;
+import org.eclipse.help.ITocContribution;
+import org.eclipse.help.ITopic;
+import org.eclipse.help.internal.toc.TocFile;
+import org.eclipse.help.internal.toc.TocFileParser;
+import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
+
+public class TocFileParserTest extends TestCase {
+
+ /*
+ * Returns an instance of this Test.
+ */
+ public static Test suite() {
+ return new TestSuite(TocFileParserTest.class);
+ }
+
+ public void testParse() throws Exception {
+ String pluginId = UserAssistanceTestPlugin.getPluginId();
+ String file = "data/help/toc/parser/toc.xml";
+ boolean isPrimary = false;
+ String locale = "en_CA";
+ String extraDir = "data/help/toc/parser/extraDir";
+ String category = null;
+
+ TocFile tocFile = new TocFile(pluginId, file, isPrimary, locale, extraDir, category);
+ TocFileParser parser = new TocFileParser();
+ ITocContribution contribution = parser.parse(tocFile);
+ assertNotNull(contribution);
+ assertEquals("/org.eclipse.ua.tests/data/help/toc/parser/toc.xml", contribution.getId());
+ assertEquals(isPrimary, contribution.isPrimary());
+ assertEquals(locale, contribution.getLocale());
+
+ String[] extraDocs = contribution.getExtraDocuments();
+ assertEquals(3, extraDocs.length);
+ Set set = new HashSet(Arrays.asList(extraDocs));
+ assertTrue(set.contains("/org.eclipse.ua.tests/data/help/toc/parser/extraDir/page1.html"));
+ assertTrue(set.contains("/org.eclipse.ua.tests/data/help/toc/parser/extraDir/page2.html"));
+ assertTrue(set.contains("/org.eclipse.ua.tests/data/help/toc/parser/extraDir/otherDir/page3.html"));
+
+ assertEquals(category, contribution.getCategoryId());
+ assertEquals("/org.eclipse.ua.tests/myOtherToc.xml", contribution.getLinkTo());
+
+ IToc toc = contribution.getToc();
+ assertNotNull(toc);
+
+ assertEquals("myToc", toc.getLabel());
+ assertEquals("myToc", toc.getTopic(null).getLabel());
+ assertEquals("/org.eclipse.ua.tests/myFakeTopic.html", toc.getTopic(null).getHref());
+ assertEquals(3, toc.getChildren().length);
+ assertEquals(1, toc.getTopics().length);
+ assertNotNull(toc.getTopic(null));
+ assertNull(toc.getParent());
+
+ INode node = toc.getChildren()[0];
+ assertTrue(node instanceof IAnchor);
+ IAnchor anchor = (IAnchor)node;
+ assertEquals("myAnchor", anchor.getId());
+ assertEquals(0, anchor.getChildren().length);
+ assertEquals(toc, anchor.getParent());
+
+ node = toc.getChildren()[1];
+ assertEquals(node, toc.getTopics()[0]);
+ assertTrue(node instanceof ITopic);
+ ITopic topic = (ITopic)node;
+ assertEquals("myTopic", topic.getLabel());
+ assertEquals("/org.eclipse.ua.tests/myTopic.html", topic.getHref());
+ assertEquals(1, topic.getChildren().length);
+ assertEquals(toc, topic.getParent());
+
+ node = topic.getChildren()[0];
+ assertTrue(node instanceof IFilter);
+ IFilter filter = (IFilter)node;
+ assertEquals("os=win32", filter.getExpression());
+ assertEquals(1, filter.getChildren().length);
+ assertEquals(topic, filter.getParent());
+
+ node = filter.getChildren()[0];
+ assertTrue(node instanceof ITopic);
+ topic = (ITopic)node;
+ assertEquals("mySubtopic", topic.getLabel());
+ assertEquals("/org.eclipse.ua.tests/mySubtopic.html", topic.getHref());
+ assertEquals(0, topic.getChildren().length);
+ assertEquals(filter, topic.getParent());
+
+ node = toc.getChildren()[2];
+ assertTrue(node instanceof IFilter);
+ filter = (IFilter)node;
+ assertEquals("ws!=gtk", filter.getExpression());
+ assertEquals(1, filter.getChildren().length);
+ assertEquals(toc, filter.getParent());
+
+ node = filter.getChildren()[0];
+ assertTrue(node instanceof IInclude);
+ IInclude include = (IInclude)node;
+ assertEquals("/org.eclipse.ua.tests/myOtherToc2.xml", include.getTarget());
+ assertEquals(0, include.getChildren().length);
+ assertEquals(filter, include.getParent());
+ }
+}

Back to the top