diff options
author | Dejan Gloszic | 2006-01-30 23:14:39 +0000 |
---|---|---|
committer | Dejan Gloszic | 2006-01-30 23:14:39 +0000 |
commit | 8a8a8fcc9d036d0e69d179cdb1849549ba9d7457 (patch) | |
tree | 9860fe78a5fc2a04aa621365a47997e4cd8b68fc /org.eclipse.ua.tests/intro/org | |
parent | 75567553c1ad70fdb0420cf1bbbae3341d825ccf (diff) | |
download | eclipse.platform.ua-8a8a8fcc9d036d0e69d179cdb1849549ba9d7457.tar.gz eclipse.platform.ua-8a8a8fcc9d036d0e69d179cdb1849549ba9d7457.tar.xz eclipse.platform.ua-8a8a8fcc9d036d0e69d179cdb1849549ba9d7457.zip |
*** empty log message ***v20060130
Diffstat (limited to 'org.eclipse.ua.tests/intro/org')
3 files changed, 210 insertions, 24 deletions
diff --git a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/ValidTest.java b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/ValidTest.java index 1c353565d..d13a73bf5 100644 --- a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/ValidTest.java +++ b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/ValidTest.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.ua.tests.intro.parser; +import java.util.Iterator; +import java.util.Map; import java.util.StringTokenizer; import junit.framework.Assert; @@ -19,12 +21,14 @@ import junit.framework.TestSuite; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; +import org.eclipse.help.ui.internal.HelpUIPlugin; import org.eclipse.ua.tests.intro.util.IntroModelSerializer; import org.eclipse.ua.tests.intro.util.IntroModelSerializerTest; import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin; import org.eclipse.ua.tests.util.FileUtil; import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot; import org.eclipse.ui.internal.intro.impl.model.loader.ExtensionPointManager; +import org.osgi.framework.Bundle; /* * Tests the intro parser on valid intro content. @@ -39,7 +43,17 @@ public class ValidTest extends TestCase { } /* - * Test valid intro content. + * 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(); + } + + /* + * Test valid intro content. This goes through all the test intro content (xml files and + * xhtml files) and serializes them using the IntroModelSerializer, then compares the result + * of the serialization with the expected content (the _serialized.txt files). */ public void testParserValid() { IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.intro.config"); @@ -48,35 +62,81 @@ public class ValidTest extends TestCase { * Only use the ones from this test plugin. */ if (elements[i].getDeclaringExtension().getNamespace().equals(UserAssistanceTestPlugin.getDefault().getBundle().getSymbolicName())) { - String pluginRoot = UserAssistanceTestPlugin.getDefault().getBundle().getLocation().substring("update@".length()); String content = elements[i].getAttribute("content"); String id = elements[i].getAttribute("id"); - String resultFile = IntroModelSerializerTest.getResultFile(pluginRoot + content); - + Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle(); + IntroModelRoot model = ExtensionPointManager.getInst().getModel(id); IntroModelSerializer serializer = new IntroModelSerializer(model); - + + /* + * Try [filename]_serialized_os_ws_arch.txt. If it's not there, try + * [filename]_serialized.txt. + * + * We use different files for os/ws/arch combinations in order to test dynamic content, + * specifically filtering. Some of the files have filters by os, ws, and arch so the + * result is different on each combination. + */ + String contents = null; try { - String expected = FileUtil.getContents(resultFile); - String actual = serializer.toString(); - - StringTokenizer tok1 = new StringTokenizer(expected, "\n"); - StringTokenizer tok2 = new StringTokenizer(actual, "\n"); + contents = FileUtil.getContents(bundle, IntroModelSerializerTest.getResultFile(content, true)); + } + catch(Exception e) { + // didn't find the _serialized_os_ws_arch.txt file, try just _serialized.txt + } + if (contents == null) { + try { + contents = FileUtil.getContents(bundle, IntroModelSerializerTest.getResultFile(content)); + } + catch(Exception e) { + Assert.fail("An error occured while loading expected result file for intro XML for: " + content); + } + } + /* + * Do a fuzzy match. Ignore all whitespace then compare. This is to avoid platform + * specific newlines, etc. + */ + String expected = contents.replaceAll("[ \t\n\r]", ""); + String actual = serializer.toString().replaceAll("[ \t\n\r]", "");; + Assert.assertEquals("The serialization generated for intro did not match the expected result for: " + id, expected, actual); + + Map map = IntroModelSerializerTest.getXHTMLFiles(model); + Iterator iter = map.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = (Map.Entry)iter.next(); + String relativePath = (String)entry.getKey(); /* - * Report the line number and line text where it didn't match, - * as well as the extension id and expected results file. + * Try [filename]_serialized_os_ws_arch.txt. If it's not there, try + * [filename]_serialized.txt. + * + * We use different files for os/ws/arch combinations in order to test dynamic content, + * specifically filtering. Some of the files have filters by os, ws, and arch so the + * result is different on each combination. */ - int lineNumber = 0; - while (tok1.hasMoreTokens() && tok2.hasMoreTokens()) { - String a = tok1.nextToken(); - String b = tok2.nextToken(); - Assert.assertEquals("Serialized intro content model text for \"" + id + "\" did not match expected result (" + IntroModelSerializerTest.getResultFile(content) + "). First difference occured on line " + lineNumber + ".", a, b); - ++lineNumber; + contents = null; + try { + contents = FileUtil.getContents(bundle, IntroModelSerializerTest.getResultFile(relativePath, true)); } - } - catch(Exception e) { - Assert.fail("An error occured while loading expected result file for intro at: " + resultFile); + catch(Exception e) { + // didn't find the _serialized_os_ws_arch.txt file, try just _serialized.txt + } + if (contents == null) { + try { + contents = FileUtil.getContents(bundle, IntroModelSerializerTest.getResultFile(relativePath)); + } + catch(Exception e) { + Assert.fail("An error occured while loading expected result file for intro XHTML for: " + relativePath); + } + } + + /* + * Do a fuzzy match. Ignore all whitespace then compare.. the XML transformers + * seem to add whitespace to the resulting XML string differently. + */ + expected = contents.replaceAll("[ \t\n\r]", ""); + actual = ((String)entry.getValue()).replaceAll("[ \t\n\r]", "");; + Assert.assertEquals("The XHTML generated for intro did not match the expected result for: " + relativePath, expected, actual); } } } diff --git a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializer.java b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializer.java index 5c7e26a81..00868543e 100644 --- a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializer.java +++ b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializer.java @@ -345,6 +345,7 @@ public class IntroModelSerializer { .getChildrenOfType(AbstractIntroElement.GROUP | AbstractIntroElement.LINK); text.append("\n\t\t\tGroups and Links: " + linksAndGroups.length); //$NON-NLS-1$ + text.append("\n"); //$NON-NLS-1$ } /** diff --git a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializerTest.java b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializerTest.java index bd5e3f771..5ea62e131 100644 --- a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializerTest.java +++ b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializerTest.java @@ -12,7 +12,14 @@ package org.eclipse.ua.tests.intro.util; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; import junit.framework.Test; import junit.framework.TestCase; @@ -20,10 +27,17 @@ import junit.framework.TestSuite; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; +import org.eclipse.help.ui.internal.HelpUIPlugin; import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin; import org.eclipse.ua.tests.util.ResourceFinder; +import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage; +import org.eclipse.ui.internal.intro.impl.model.IntroHomePage; import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot; +import org.eclipse.ui.internal.intro.impl.model.IntroPage; import org.eclipse.ui.internal.intro.impl.model.loader.ExtensionPointManager; +import org.eclipse.ui.internal.intro.impl.presentations.BrowserIntroPartImplementation; +import org.eclipse.ui.intro.config.IIntroContentProvider; +import org.eclipse.ui.intro.config.IIntroContentProviderSite; /* * A utility for regenerating the _serialized.txt files that contain the expected @@ -41,6 +55,13 @@ import org.eclipse.ui.internal.intro.impl.model.loader.ExtensionPointManager; * 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 IntroModelSerializerTest extends TestCase { @@ -51,6 +72,14 @@ public class IntroModelSerializerTest extends TestCase { return new TestSuite(IntroModelSerializerTest.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() { /* * Serialize the SDK's intro. @@ -77,7 +106,7 @@ public class IntroModelSerializerTest extends TestCase { } /* - * Serialize the test intro. + * Serialize the test intros. */ elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.intro.config"); for (int i=0;i<elements.length;++i) { @@ -89,17 +118,40 @@ public class IntroModelSerializerTest extends TestCase { String content = elements[i].getAttribute("content"); String id = elements[i].getAttribute("id"); + /* + * First do the intro XML files. + */ IntroModelRoot model = ExtensionPointManager.getInst().getModel(id); IntroModelSerializer serializer = new IntroModelSerializer(model); try { - PrintWriter out = new PrintWriter(new FileOutputStream(getResultFile(pluginRoot + content))); + String file = getResultFile(pluginRoot + content); + PrintWriter out = new PrintWriter(new FileOutputStream(file)); out.print(serializer.toString()); out.close(); } catch(FileNotFoundException e) { e.printStackTrace(); } + + /* + * Now do the intro XHTML files. Find all the XHTML files referenced + * from the model. + */ + Map map = getXHTMLFiles(model); + Iterator iter = map.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = (Map.Entry)iter.next(); + try { + String file = getResultFile(pluginRoot + entry.getKey()); + PrintWriter out = new PrintWriter(new FileOutputStream(file)); + out.print((String)entry.getValue()); + out.close(); + } + catch(IOException e) { + e.printStackTrace(); + } + } } } } @@ -109,6 +161,79 @@ public class IntroModelSerializerTest extends TestCase { * for the intro xml referred to by the string. */ public static String getResultFile(String in) { - return in.substring(0, in.lastIndexOf('.')) + "_serialized.txt"; + return getResultFile(in, false); + } + + /* + * Same as above, but gives the option of appending os, ws, and arch. For example, + * myfile_serialized_macosx_carbon_ppc.txt. + */ + public static String getResultFile(String in, boolean env) { + StringBuffer buf = new StringBuffer(); + buf.append(in.substring(0, in.lastIndexOf('.')) + "_serialized"); + if (env) { + buf.append('_'); + buf.append(Platform.getOS()); + buf.append('_'); + buf.append(Platform.getWS()); + buf.append('_'); + buf.append(Platform.getOSArch()); + } + buf.append(".txt"); + return buf.toString(); + } + + /* + * Search through the given model and find all XHTML files referred to by the model. + * Also loads the contents of the XHTML files. The result is a mapping of filenames relative + * to the test plugin to Strings, the contents of the XHTML files. + */ + public static Map getXHTMLFiles(IntroModelRoot model) { + Map map = new HashMap(); + Collection pages = new ArrayList(); + IntroHomePage home = model.getHomePage(); + if (home.isXHTMLPage()) { + pages.add(home); + } + IntroPage[] otherPages = model.getPages(); + for (int i=0;i<otherPages.length;++i) { + if (otherPages[i].isXHTMLPage()) { + pages.add(otherPages[i]); + } + } + Iterator iter = pages.iterator(); + while (iter.hasNext()) { + AbstractIntroPage page = (AbstractIntroPage)iter.next(); + BrowserIntroPartImplementation impl = new BrowserIntroPartImplementation(); + String xhtml = impl.generateXHTMLPage(page, new IIntroContentProviderSite() { + public void reflow(IIntroContentProvider provider, boolean incremental) { + // dummy site + } + }); + xhtml = removeEnvironmentSpecificContent(xhtml); + map.put(page.getInitialBase() + page.getRawContent(), xhtml); + } + return map; + } + + /* + * Some of the XHTML content is environment-specific. This means it changes depending on + * the test machine, location on filesystem, etc. This content is not important for this + * test so just strip it out before comparing the serializations. + */ + private static String removeEnvironmentSpecificContent(String xhtml) { + /* + * The base tag is added before showing in browser. It contains an absolute path + * in filesystem. + */ + xhtml = xhtml.replaceAll("<base href=\".*\" />", ""); + + /* + * The order of the params for the meta tag comes out differently on different platforms. + * I'm not sure why, and why just this tag. We don't care about this one for our tests anyway, + * so just strip it. + */ + xhtml = xhtml.replaceAll("<meta .*/>", ""); + return xhtml; } } |