diff options
author | Chris Goldthorpe | 2007-10-02 20:59:35 +0000 |
---|---|---|
committer | Chris Goldthorpe | 2007-10-02 20:59:35 +0000 |
commit | 1f2f1ff868e69774444c04efd0f59d90a0d272a8 (patch) | |
tree | 366c7b3e224848f46025eebe9cc0994d7495777e | |
parent | 5794061424acc6086db0fc3c76bdb33744798024 (diff) | |
download | eclipse.platform.ua-1f2f1ff868e69774444c04efd0f59d90a0d272a8.tar.gz eclipse.platform.ua-1f2f1ff868e69774444c04efd0f59d90a0d272a8.tar.xz eclipse.platform.ua-1f2f1ff868e69774444c04efd0f59d90a0d272a8.zip |
Bug 176985 [Webapp] NLS33:navigation link at the top of notices.html does not display NLS chars properly
-rw-r--r-- | org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java | 1 | ||||
-rw-r--r-- | org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java | 180 |
2 files changed, 181 insertions, 0 deletions
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java index 6fa18ad7b..ea1946106 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/AllWebappTests.java @@ -26,6 +26,7 @@ public class AllWebappTests extends TestSuite { "org.eclipse.ua.tests.help.AllWebappTests"); //$JUnit-BEGIN$ suite.addTestSuite(BrowserIdentificationTest.class); + suite.addTestSuite(FilterTest.class); //$JUnit-END$ return suite; } diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java new file mode 100644 index 000000000..6be1d288e --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java @@ -0,0 +1,180 @@ +/******************************************************************************* + * Copyright (c) 2007 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.webapp; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringBufferInputStream; + +import org.eclipse.help.internal.search.HTMLDocParser; +import org.eclipse.help.internal.webapp.servlet.FilterHTMLHeadAndBodyOutputStream; +import org.eclipse.help.internal.webapp.servlet.FilterHTMLHeadOutputStream; + +import junit.framework.TestCase; + +/** + * Test for functions which decode a topic string + */ + +public class FilterTest extends TestCase { + private final String HTML40 = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"; + private final String HEAD1 = "<HEAD>"; + private final String HEAD2 = "</HEAD>"; + private final String HEADLC1 = "<head>"; + private final String HEADLC2 = "</head>"; + private final String CONTENT_TYPE_ISO_8859_1 = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"; + private final String CONTENT_TYPE_ISO_8859_1_UC = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />"; + private final String CONTENT_TYPE_UTF8 = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"; + private final String CONTENT_TYPE_UTF8UC = "<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"; + private final String BODY1 = "<BODY>"; + private final String BODY2 = "</BODY></html>"; + private final String BODYLC1 = "<body>"; + private final String BODYLC2 = "</body></html>"; + private final String CSS1 = "<LINK REL=\"STYLESHEET\" HREF=\"book1.css\" TYPE=\"text/css\">"; + private final String CSS2 = "<LINK REL=\"STYLESHEET\" HREF=\"book1.css\" TYPE=\"text/css\">"; + private final String CONTENT1 = "<p>Content1</p>"; + private final String CONTENT2 = "<p>Content2</p>"; + private String CHINESE_CONTENT = "<p>" + (char)24320 + (char)21457 + (char)29932 + "</p>"; + private String CHINESE_ENTITY_CONTENT = "<p>开发瓬</p>"; + + public void testHeadOutputFilter() { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + OutputStream filteredOutput = new FilterHTMLHeadOutputStream(output, CSS2.getBytes()); + try { + filteredOutput.write(HTML40.getBytes()); + filteredOutput.write(HEAD1.getBytes()); + filteredOutput.write(CSS1.getBytes()); + filteredOutput.write(HEAD2.getBytes()); + filteredOutput.write(BODY1.getBytes()); + filteredOutput.write(CONTENT1.getBytes()); + filteredOutput.write(BODY2.getBytes()); + } catch (IOException e) { + fail("IO Exception"); + } + final String expected = HTML40 + HEAD1 + CSS1 + CSS2 + '\n' + HEAD2 + BODY1 + CONTENT1 + BODY2; + assertEquals(expected, output.toString()); + } + + public void testHeadAndBodyOutputFilter() { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, CSS2.getBytes(), CONTENT2); + try { + filteredOutput.write(HTML40.getBytes()); + filteredOutput.write(HEAD1.getBytes()); + filteredOutput.write(CONTENT_TYPE_ISO_8859_1.getBytes()); + filteredOutput.write(CSS1.getBytes()); + filteredOutput.write(HEAD2.getBytes()); + filteredOutput.write(BODY1.getBytes()); + filteredOutput.write(CONTENT1.getBytes()); + filteredOutput.write(BODY2.getBytes()); + } catch (IOException e) { + fail("IO Exception"); + } + final String expected = HTML40 + HEAD1 + CONTENT_TYPE_ISO_8859_1 + CSS1 + CSS2 + '\n' + HEAD2 + BODY1 + '\n' + CONTENT2 + '\n' + CONTENT1 + BODY2; + assertEquals(expected, output.toString()); + } + + public void testLowerCaseTags() { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + OutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, CSS1.getBytes(), CONTENT2); + try { + filteredOutput.write(HTML40.getBytes()); + filteredOutput.write(HEADLC1.getBytes()); + filteredOutput.write(HEADLC2.getBytes()); + filteredOutput.write(BODYLC1.getBytes()); + filteredOutput.write(CONTENT1.getBytes()); + filteredOutput.write(BODYLC2.getBytes()); + } catch (IOException e) { + fail("IO Exception"); + } + final String expected = HTML40 + HEADLC1 + CSS1 + '\n' + HEADLC2 + BODYLC1 + '\n' + CONTENT2 + '\n' + CONTENT1 + BODYLC2; + assertEquals(expected, output.toString()); + } + + public void testFilterHeadlessDocument() { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + OutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, CSS1.getBytes(), CONTENT2); + try { + filteredOutput.write(HTML40.getBytes()); + filteredOutput.write(BODY1.getBytes()); + filteredOutput.write(CONTENT1.getBytes()); + filteredOutput.write(BODY2.getBytes()); + } catch (IOException e) { + fail("IO Exception"); + } + final String expected = HTML40 + BODY1 + '\n' + CONTENT2 + '\n' + CONTENT1 + BODY2; + assertEquals(expected, output.toString()); + } + + public void testInsertChineseUtf8() { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null, CHINESE_CONTENT); + try { + filteredOutput.write(HTML40.getBytes()); + filteredOutput.write(HEAD1.getBytes()); + filteredOutput.write(CONTENT_TYPE_UTF8.getBytes()); + filteredOutput.write(HEAD2.getBytes()); + filteredOutput.write(BODY1.getBytes()); + filteredOutput.write(BODY2.getBytes()); + final String expected = HTML40 + HEAD1 + CONTENT_TYPE_UTF8 + HEAD2 + BODY1 + '\n' + CHINESE_CONTENT + '\n' + BODY2; + assertEquals(expected, output.toString("UTF-8")); + } catch (IOException e) { + fail("IO Exception"); + } + } + + public void testInsertChineseISO8859() { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null, CHINESE_CONTENT); + try { + filteredOutput.write(HTML40.getBytes()); + filteredOutput.write(HEAD1.getBytes()); + filteredOutput.write(CONTENT_TYPE_ISO_8859_1.getBytes()); + filteredOutput.write(HEAD2.getBytes()); + filteredOutput.write(BODY1.getBytes()); + filteredOutput.write(BODY2.getBytes()); + final String expected = HTML40 + HEAD1 + CONTENT_TYPE_ISO_8859_1 + HEAD2 + BODY1 + '\n' + CHINESE_ENTITY_CONTENT + '\n' + BODY2; + assertEquals(expected, output.toString()); + } catch (IOException e) { + fail("IO Exception"); + } + } + + public void testInsertChineseNoCharsetSpecified() { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null, CHINESE_CONTENT); + try { + filteredOutput.write(HTML40.getBytes()); + filteredOutput.write(HEAD1.getBytes()); + filteredOutput.write(HEAD2.getBytes()); + filteredOutput.write(BODY1.getBytes()); + filteredOutput.write(BODY2.getBytes()); + final String expected = HTML40 + HEAD1 + HEAD2 + BODY1 + '\n' + CHINESE_ENTITY_CONTENT + '\n' + BODY2; + assertEquals(expected, output.toString()); + } catch (IOException e) { + fail("IO Exception"); + } + } + + public void testCharsetUtf8Upper() { + InputStream is = new StringBufferInputStream(CONTENT_TYPE_UTF8UC); + assertEquals("UTF-8", HTMLDocParser.getCharsetFromHTML(is)); + } + + public void testCharsetISO_8859_UCUpper() { + InputStream is = new StringBufferInputStream(CONTENT_TYPE_ISO_8859_1_UC); + assertEquals("ISO-8859-1", HTMLDocParser.getCharsetFromHTML(is)); + } + +} |