diff options
author | Curtis D'Entremont | 2006-03-28 00:04:08 +0000 |
---|---|---|
committer | Curtis D'Entremont | 2006-03-28 00:04:08 +0000 |
commit | 00f34df469506f27923247657278c2d14f4e83cf (patch) | |
tree | ea63653bd38a724a8cbefdc9a75dc574c457cb34 /org.eclipse.ua.tests/intro/org | |
parent | 2d87dded5e13b9da3bbadcac10ecefa02ee59a94 (diff) | |
download | eclipse.platform.ua-00f34df469506f27923247657278c2d14f4e83cf.tar.gz eclipse.platform.ua-00f34df469506f27923247657278c2d14f4e83cf.tar.xz eclipse.platform.ua-00f34df469506f27923247657278c2d14f4e83cf.zip |
132251 New: NOT function on filters
Diffstat (limited to 'org.eclipse.ua.tests/intro/org')
5 files changed, 43 insertions, 336 deletions
diff --git a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/AllParserTests.java b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/AllParserTests.java index fc727b468..c6b380f90 100644 --- a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/AllParserTests.java +++ b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/AllParserTests.java @@ -29,8 +29,6 @@ public class AllParserTests extends TestSuite { * Constructs a new test suite. */ public AllParserTests() { - // re-enable once universal welcome stabilizes - //addTest(PlatformTest.suite()); addTest(ValidTest.suite()); } } diff --git a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/PlatformTest.java b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/PlatformTest.java deleted file mode 100644 index 7c4ed8668..000000000 --- a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/PlatformTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.intro.parser; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.StringTokenizer; - -import junit.framework.Assert; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -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.ua.tests.util.ResourceFinder; -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. - */ -public class PlatformTest extends TestCase { - - private static final String SERIALIZED_PATH = "data/intro/platform/serialized.txt"; - - /* - * Returns an instance of this Test. - */ - public static Test suite() { - return new TestSuite(PlatformTest.class); - } - - /* - * Test the platform's parsed intro content. - */ - public void testModel() { - final String INTRO_CONFIG_ID = "org.eclipse.ui.intro.universalConfig"; - IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.intro.config"); - IConfigurationElement element = null; - for (int i=0;i<elements.length;++i) { - if (elements[i] != null) { - if (INTRO_CONFIG_ID.equals(elements[i].getAttribute("id"))) { - element = elements[i]; - } - } - } - Assert.assertNotNull("Could not find the \"org.eclipse.ui.intro.config\" extension with the id \"" + INTRO_CONFIG_ID + "\".", element); - - String pluginRoot = ResourceFinder.findFile(UserAssistanceTestPlugin.getDefault(), "/").toString().substring("file:".length()); - String content = element.getAttribute("content"); - String id = element.getAttribute("id"); - String resultFile = pluginRoot + SERIALIZED_PATH; - - IntroModelRoot model = ExtensionPointManager.getInst().getModel(id); - IntroModelSerializer serializer = new IntroModelSerializer(model); - - try { - String expected = FileUtil.getContents(resultFile); - String actual = serializer.toString(); - StringTokenizer tok1 = new StringTokenizer(expected, "\n"); - StringTokenizer tok2 = new StringTokenizer(actual, "\n"); - - /* - * Report the line number and line text where it didn't match, - * as well as the extension id and expected results file. - */ - int tokenNumber = 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 token " + tokenNumber + ".", a, b); - ++tokenNumber; - } - } - catch(Exception e) { - Assert.fail("An error occured while loading expected result file for intro at: " + resultFile); - } - } - - /* - * Some extensions run samples that involve executing code. Check to make sure - * that the classes exist and can be instantiated. - */ - public void testClasses() { - String pluginRoot = ResourceFinder.findFile(UserAssistanceTestPlugin.getDefault(), "/").toString().substring("file:".length()); - String resultFile = pluginRoot + SERIALIZED_PATH; - - try { - String contents = FileUtil.getContents(resultFile); - StringTokenizer tok = new StringTokenizer(contents); - while (tok.hasMoreTokens()) { - String next = tok.nextToken(); - if (next.startsWith("http://org.eclipse.ui.intro/runAction?")) { - Map map = createMap(next.substring("http://org.eclipse.ui.intro/runAction?".length())); - Assert.assertTrue("The runAction was missing the class attribute: " + next, map.containsKey("class")); - Assert.assertTrue("The runAction was missing the pluginId attribute: " + next, map.containsKey("pluginId")); - - String clazz = (String)map.get("class"); - String pluginId = (String)map.get("pluginId"); - - Bundle bundle = Platform.getBundle(pluginId); - Assert.assertNotNull("The plugin referenced in one of the platform's intro runAction URLs (" + next + ") was not found: " + pluginId, bundle); - - try { - Class c = bundle.loadClass(clazz); - c.newInstance(); - } - catch (ClassNotFoundException e) { - Assert.fail("One of the classes in the platform's intro runActions URLs was not found: " + clazz + " in plugin: " + pluginId); - } - catch (InstantiationException e) { - Assert.fail("One of the classes in the platform's intro runActions URLs could not be instantiated: " + clazz + " in plugin: " + pluginId); - } - catch (IllegalAccessException e) { - Assert.fail("One of the classes in the platform's intro runActions URLs could not be accessed (is it public?): " + clazz + " in plugin: " + pluginId); - } - } - } - } - catch (IOException e) { - Assert.fail("An IOException occured while reading platform's serialized.txt file"); - } - } - - /* - * Generates a map from the given string of the form: - * "key1=value1&key2=value2&..." (i.e. URL parameters) - */ - private static Map createMap(String args) { - Map map = new HashMap(); - StringTokenizer tok2 = new StringTokenizer(args, "&"); - while (tok2.hasMoreTokens()) { - String arg = tok2.nextToken(); - int separator = arg.indexOf('='); - map.put(arg.substring(0, separator), arg.substring(separator + 1)); - } - return map; - } -} 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 a453772bf..d33d7fd7e 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2005, 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 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.ua.tests.intro.parser; +import java.io.IOException; import java.util.Iterator; import java.util.Map; @@ -50,11 +51,12 @@ public class ValidTest extends TestCase { } /* - * 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). + * 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 result (the _expected.txt files). */ - public void testParserValid() { + public void testParserValid() throws IOException { IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.intro.config"); for (int i=0;i<elements.length;++i) { /* @@ -68,36 +70,9 @@ public class ValidTest extends TestCase { 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 { - 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); + String expected = FileUtil.getContents(bundle, FileUtil.getResultFile(content)); + String actual = serializer.toString(); + Assert.assertEquals("The model parsed for intro did not match the expected result for: " + id, expected, actual); Map map = IntroModelSerializerTest.getXHTMLFiles(model); Iterator iter = map.entrySet().iterator(); @@ -105,36 +80,8 @@ public class ValidTest extends TestCase { Map.Entry entry = (Map.Entry)iter.next(); String relativePath = (String)entry.getKey(); - /* - * 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. - */ - contents = null; - try { - contents = FileUtil.getContents(bundle, IntroModelSerializerTest.getResultFile(relativePath, 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(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]", "");; + expected = FileUtil.getContents(bundle, FileUtil.getResultFile(relativePath)); + actual = (String)entry.getValue(); 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 5f451708f..43b0cb1b7 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 @@ -65,7 +65,7 @@ public class IntroModelSerializer { } private void printModelRootInfo(IntroModelRoot model, StringBuffer text) { - text.append("\nIntro Model Content:"); //$NON-NLS-1$ + text.append("Intro Model Content:"); //$NON-NLS-1$ text.append("\n======================"); //$NON-NLS-1$ text.append("\n\nModel has valid config = " + model.hasValidConfig()); //$NON-NLS-1$ text.append("\nPresentation type = " //$NON-NLS-1$ @@ -344,7 +344,6 @@ 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 00a955d98..a8264c6a0 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2004 IBM Corporation and others. + * Copyright (c) 2005, 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 @@ -12,7 +12,6 @@ package org.eclipse.ua.tests.intro.util; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; @@ -28,7 +27,8 @@ 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.ua.tests.util.FileUtil; +import org.eclipse.ua.tests.util.XHTMLUtil; 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; @@ -39,11 +39,11 @@ 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 - * output for the intro content when serialized. This reads all the intro content from + * A utility for regenerating the _expected.txt files that contain the expected + * output for the intro model when serialized. This reads all the intro content from * the plugin manifest (for this test plugin only), constructs the intro 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. + * intro xml file, as <original_name>_expected.txt. * * These files are used by the JUnit tests to compare the result with the expected * result. @@ -54,13 +54,6 @@ import org.eclipse.ui.intro.config.IIntroContentProviderSite; * 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 { @@ -72,42 +65,19 @@ public class IntroModelSerializerTest extends TestCase { } /* - * Ensure that org.eclipse.help.ui is started. It contributes extra content - * filtering that is used by this test. See UIContentFilterProcessor. + * 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. - */ - IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.intro.config"); - for (int i=0;i<elements.length;++i) { - String id = elements[i].getAttribute("id"); - if ("org.eclipse.ui.intro.universalConfig".equals(id)) { - String pluginRoot = ResourceFinder.findFile(UserAssistanceTestPlugin.getDefault(), "/").toString().substring("file:".length()); - - IntroModelRoot model = ExtensionPointManager.getInst().getModel(id); - IntroModelSerializer serializer = new IntroModelSerializer(model); - - try { - PrintWriter out = new PrintWriter(new FileOutputStream(pluginRoot + "data/intro/platform/serialized.txt")); - out.print(serializer.toString()); - out.close(); - } - catch (FileNotFoundException e) { - e.printStackTrace(); - } - break; - } - } - + public void testRunSerializer() throws FileNotFoundException { /* * Serialize the test intros. */ - elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.intro.config"); + IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.intro.config"); for (int i=0;i<elements.length;++i) { /* * Only use the ones from this test plugin. @@ -123,69 +93,33 @@ public class IntroModelSerializerTest extends TestCase { IntroModelRoot model = ExtensionPointManager.getInst().getModel(id); IntroModelSerializer serializer = new IntroModelSerializer(model); - try { - String file = getResultFile(pluginRoot + content); - PrintWriter out = new PrintWriter(new FileOutputStream(file)); - out.print(serializer.toString()); - out.close(); - } - catch(FileNotFoundException e) { - e.printStackTrace(); - } + String file = FileUtil.getResultFile(pluginRoot + content); + PrintWriter out = new PrintWriter(new FileOutputStream(file)); + out.print(serializer.toString()); + out.close(); /* - * Now do the intro XHTML files. Find all the XHTML files referenced - * from the model. + * 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(); - } + file = FileUtil.getResultFile(pluginRoot + entry.getKey()); + out = new PrintWriter(new FileOutputStream(file)); + out.print((String)entry.getValue()); + out.close(); } } } } - - /* - * Generates a filename with path to the result file that will be generated - * for the intro xml referred to by the string. - */ - public static String getResultFile(String in) { - 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. + * 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(); @@ -209,30 +143,13 @@ public class IntroModelSerializerTest extends TestCase { // dummy site } }); - xhtml = removeEnvironmentSpecificContent(xhtml); + xhtml = XHTMLUtil.removeEnvironmentSpecificContent(xhtml); + // filter windows-specific newline + xhtml = xhtml.replaceAll("\r", ""); + // ignore all beginning and ending whitespace + xhtml = xhtml.trim(); 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; - } } |