[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/nodeDecoratorTests DecodingNodeTest.java,NONE,1
Brought to you by:
derrickoswald
From: <jke...@us...> - 2003-06-25 03:56:23
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/nodeDecoratorTests In directory sc8-pr-cvs1:/tmp/cvs-serv27589/src/org/htmlparser/tests/nodeDecoratorTests Added Files: DecodingNodeTest.java EscapeCharacterRemovingNodeTest.java AllTests.java Log Message: moved node decorator code and tests to their own packages. --- NEW FILE: DecodingNodeTest.java --- // HTMLParser Library v1_4_20030622 - A java-based parser for HTML // Copyright (C) Dec 31, 2000 Somik Raha // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // For any questions or suggestions, you can write to me at : // Email :so...@in... // // Postal Address : // Somik Raha // Extreme Programmer & Coach // Industrial Logic Corporation // 2583 Cedar Street, Berkeley, // CA 94708, USA // Website : http://www.industriallogic.com // // This test class produced by Joshua Kerievsky package org.htmlparser.tests.nodeDecoratorTests; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.NodeIterator; import org.htmlparser.util.ParserException; public class DecodingNodeTest extends ParserTestCase { public DecodingNodeTest(String name) { super(name); } private String parseToObtainDecodedResult(String STRING_TO_DECODE) throws ParserException { StringBuffer decodedContent = new StringBuffer(); createParser(STRING_TO_DECODE); parser.setNodeDecoding(true); // tell parser to decode StringNodes NodeIterator nodes = parser.elements(); while (nodes.hasMoreNodes()) decodedContent.append(nodes.nextNode().toPlainTextString()); return decodedContent.toString(); } public void testAmpersand() throws Exception { String ENCODED_WORKSHOP_TITLE = "The Testing & Refactoring Workshop"; String DECODED_WORKSHOP_TITLE = "The Testing & Refactoring Workshop"; assertEquals( "ampersand in string", DECODED_WORKSHOP_TITLE, parseToObtainDecodedResult(ENCODED_WORKSHOP_TITLE)); } public void testNumericReference() throws Exception { String ENCODED_DIVISION_SIGN = "÷ is the division sign."; String DECODED_DIVISION_SIGN = "÷ is the division sign."; assertEquals( "numeric reference for division sign", DECODED_DIVISION_SIGN, parseToObtainDecodedResult(ENCODED_DIVISION_SIGN)); } public void testReferencesInString () throws Exception { String ENCODED_REFERENCE_IN_STRING = "Thus, the character entity reference ÷ is a more convenient" + " form than ÷ for obtaining the division sign (÷)"; String DECODED_REFERENCE_IN_STRING = "Thus, the character entity reference ÷ is a more convenient" + " form than ÷ for obtaining the division sign (÷)"; assertEquals ( "character references within a string", DECODED_REFERENCE_IN_STRING, parseToObtainDecodedResult(ENCODED_REFERENCE_IN_STRING)); } public void testBogusCharacterEntityReference() throws Exception { String ENCODED_BOGUS_CHARACTER_ENTITY = "The character entity reference &divode; is bogus"; String DECODED_BOGUS_CHARACTER_ENTITY = "The character entity reference &divode; is bogus"; assertEquals ( "bogus character entity reference", DECODED_BOGUS_CHARACTER_ENTITY, parseToObtainDecodedResult(ENCODED_BOGUS_CHARACTER_ENTITY)); } } --- NEW FILE: EscapeCharacterRemovingNodeTest.java --- // HTMLParser Library v1_4_20030622 - A java-based parser for HTML // Copyright (C) Dec 31, 2000 Somik Raha // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // For any questions or suggestions, you can write to me at : // Email :so...@in... // // Postal Address : // Somik Raha // Extreme Programmer & Coach // Industrial Logic Corporation // 2583 Cedar Street, Berkeley, // CA 94708, USA // Website : http://www.industriallogic.com // // This test class produced by Joshua Kerievsky package org.htmlparser.tests.nodeDecoratorTests; import org.htmlparser.tests.ParserTestCase; import org.htmlparser.util.NodeIterator; import org.htmlparser.util.ParserException; public class EscapeCharacterRemovingNodeTest extends ParserTestCase { public EscapeCharacterRemovingNodeTest(String name) { super(name); } private String parseToObtainDecodedResult(String STRING_TO_DECODE) throws ParserException { StringBuffer decodedContent = new StringBuffer(); createParser(STRING_TO_DECODE); parser.setEscapeCharacterRemoval(true); NodeIterator nodes = parser.elements(); while (nodes.hasMoreNodes()) decodedContent.append(nodes.nextNode().toPlainTextString()); return decodedContent.toString(); } public void testTab() throws Exception { String ENCODED_WORKSHOP_TITLE = "The Testing & Refactoring Workshop\tCreated by Industrial Logic, Inc."; String DECODED_WORKSHOP_TITLE = "The Testing & Refactoring WorkshopCreated by Industrial Logic, Inc."; assertEquals( "tab in string", DECODED_WORKSHOP_TITLE, parseToObtainDecodedResult(ENCODED_WORKSHOP_TITLE)); } public void testCarriageReturn() throws Exception { String ENCODED_WORKSHOP_TITLE = "The Testing & Refactoring Workshop\nCreated by Industrial Logic, Inc.\n"; String DECODED_WORKSHOP_TITLE = "The Testing & Refactoring WorkshopCreated by Industrial Logic, Inc."; assertEquals( "tab in string", DECODED_WORKSHOP_TITLE, parseToObtainDecodedResult(ENCODED_WORKSHOP_TITLE)); } public void testWithDecodingNodeDecorator() throws Exception { String ENCODED_WORKSHOP_TITLE = "The Testing & Refactoring Workshop\nCreated by Industrial Logic, Inc.\n"; String DECODED_WORKSHOP_TITLE = "The Testing & Refactoring WorkshopCreated by Industrial Logic, Inc."; StringBuffer decodedContent = new StringBuffer(); createParser(ENCODED_WORKSHOP_TITLE); parser.setEscapeCharacterRemoval(true); parser.setNodeDecoding(true); NodeIterator nodes = parser.elements(); while (nodes.hasMoreNodes()) decodedContent.append(nodes.nextNode().toPlainTextString()); assertEquals( "tab in string", DECODED_WORKSHOP_TITLE, decodedContent.toString()); } } --- NEW FILE: AllTests.java --- // HTMLParser Library v1_4_20030622 - A java-based parser for HTML // Copyright (C) Dec 31, 2000 Somik Raha // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // For any questions or suggestions, you can write to me at : // Email :so...@in... // // Postal Address : // Somik Raha // Extreme Programmer & Coach // Industrial Logic Corporation // 2583 Cedar Street, Berkeley, // CA 94708, USA // Website : http://www.industriallogic.com package org.htmlparser.tests.nodeDecoratorTests; import junit.framework.TestSuite; public class AllTests extends junit.framework.TestCase { public AllTests(String name) { super(name); } public static TestSuite suite() { TestSuite suite = new TestSuite("Node Decorator Tests"); suite.addTestSuite(DecodingNodeTest.class); suite.addTestSuite(EscapeCharacterRemovingNodeTest.class); return suite; } /** * Mainline for all suites of tests. * @param args Command line arguments. The following options * are understood: * <pre> * -text -- use junit.textui.TestRunner * -awt -- use junit.awtui.TestRunner * -swing -- use junit.swingui.TestRunner (default) * </pre> * All other options are passed on to the junit framework. */ public static void main(String[] args) { String runner; int i; String arguments[]; Class cls; runner = null; for (i = 0; (i < args.length) && (null == runner); i++) { if (args[i].equalsIgnoreCase ("-text")) runner = "junit.textui.TestRunner"; else if (args[i].equalsIgnoreCase ("-awt")) runner = "junit.awtui.TestRunner"; else if (args[i].equalsIgnoreCase ("-swing")) runner = "junit.swingui.TestRunner"; } if (null != runner) { // remove it from the arguments arguments = new String[args.length - 1]; System.arraycopy (args, 0, arguments, 0, i - 1); System.arraycopy (args, i, arguments, i - 1, args.length - i); args = arguments; } else runner = "junit.swingui.TestRunner"; // append the test class arguments = new String[args.length + 1]; System.arraycopy (args, 0, arguments, 0, args.length); arguments[args.length] = "org.htmlparser.tests.nodeDecoratorTests.AllTests"; // invoke main() of the test runner try { cls = Class.forName (runner); java.lang.reflect.Method method = cls.getDeclaredMethod ( "main", new Class[] { String[].class }); method.invoke ( null, new Object[] { arguments }); } catch (Throwable t) { System.err.println ( "cannot run unit test (" + t.getMessage () + ")"); } } } |