[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/temporaryFailures AttributeParserTest.java,1.10
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-09-03 23:36:25
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/temporaryFailures In directory sc8-pr-cvs1:/tmp/cvs-serv31228/tests/temporaryFailures Modified Files: AttributeParserTest.java TagParserTest.java Log Message: Change tabs to spaces in all source files. Index: AttributeParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/temporaryFailures/AttributeParserTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** AttributeParserTest.java 24 Aug 2003 21:59:44 -0000 1.10 --- AttributeParserTest.java 3 Sep 2003 23:36:22 -0000 1.11 *************** *** 44,90 **** public class AttributeParserTest extends ParserTestCase { ! private AttributeParser parser; ! private Tag tag; ! private Hashtable table; ! ! public AttributeParserTest(String name) { ! super(name); ! } ! protected void setUp() { ! parser = new AttributeParser(); ! } ! ! public void getParameterTableFor(String tagContents) { ! tag = new Tag(new TagData(0,0,tagContents,"")); ! table = parser.parseAttributes(tag.getText ()); ! ! } ! ! public void testParseParameters() { ! getParameterTableFor("a b = \"c\""); ! assertEquals("Value","c",table.get("B")); ! } ! public void testParseTokenValues() { ! getParameterTableFor("a b = \"'\""); ! assertEquals("Value","'",table.get("B")); ! } ! public void testParseEmptyValues() { ! getParameterTableFor("a b = \"\""); ! assertEquals("Value","",table.get("B")); ! } ! public void testParseMissingEqual() { ! getParameterTableFor("a b\"c\""); ! assertEquals("ValueB",null,table.get("B")); ! } public void testTwoParams(){ ! getParameterTableFor("PARAM NAME=\"Param1\" VALUE=\"Somik\">\n"); ! assertEquals("Param1","Param1",table.get("NAME")); ! assertEquals("Somik","Somik",table.get("VALUE")); } --- 44,90 ---- public class AttributeParserTest extends ParserTestCase { ! private AttributeParser parser; ! private Tag tag; ! private Hashtable table; ! ! public AttributeParserTest(String name) { ! super(name); ! } ! protected void setUp() { ! parser = new AttributeParser(); ! } ! ! public void getParameterTableFor(String tagContents) { ! tag = new Tag(new TagData(0,0,tagContents,"")); ! table = parser.parseAttributes(tag.getText ()); ! ! } ! ! public void testParseParameters() { ! getParameterTableFor("a b = \"c\""); ! assertEquals("Value","c",table.get("B")); ! } ! public void testParseTokenValues() { ! getParameterTableFor("a b = \"'\""); ! assertEquals("Value","'",table.get("B")); ! } ! public void testParseEmptyValues() { ! getParameterTableFor("a b = \"\""); ! assertEquals("Value","",table.get("B")); ! } ! public void testParseMissingEqual() { ! getParameterTableFor("a b\"c\""); ! assertEquals("ValueB",null,table.get("B")); ! } public void testTwoParams(){ ! getParameterTableFor("PARAM NAME=\"Param1\" VALUE=\"Somik\">\n"); ! assertEquals("Param1","Param1",table.get("NAME")); ! assertEquals("Somik","Somik",table.get("VALUE")); } *************** *** 111,122 **** public void testIncorrectSpaceKeyBug() { getParameterTableFor("TEXTAREA name=\"Remarks\" "); ! // There should only be two keys.. ! assertEquals("There should only be two keys",2,table.size()); ! // The first key is name ! String key1 = "NAME"; ! String value1 = (String)table.get(key1); ! assertEquals("Expected value 1", "Remarks",value1); ! String key2 = Tag.TAGNAME; ! assertEquals("Expected Value 2","TEXTAREA",table.get(key2)); } --- 111,122 ---- public void testIncorrectSpaceKeyBug() { getParameterTableFor("TEXTAREA name=\"Remarks\" "); ! // There should only be two keys.. ! assertEquals("There should only be two keys",2,table.size()); ! // The first key is name ! String key1 = "NAME"; ! String value1 = (String)table.get(key1); ! assertEquals("Expected value 1", "Remarks",value1); ! String key2 = Tag.TAGNAME; ! assertEquals("Expected Value 2","TEXTAREA",table.get(key2)); } *************** *** 128,155 **** public void testAttributeWithSpuriousEqualTo() { ! getParameterTableFor( ! "a class=rlbA href=/news/866201.asp?0sl=-32" ! ); ! assertStringEquals( ! "href", ! "/news/866201.asp?0sl=-32", ! (String)table.get("HREF") ! ); } public void testQuestionMarksInAttributes() { ! getParameterTableFor( ! "a href=\"mailto:sa...@ne...?subject=Site Comments\"" ! ); ! assertStringEquals( ! "href", ! "mailto:sa...@ne...?subject=Site Comments", ! (String)table.get("HREF") ! ); ! assertStringEquals( ! "tag name", ! "A", ! (String)table.get(Tag.TAGNAME) ! ); } --- 128,155 ---- public void testAttributeWithSpuriousEqualTo() { ! getParameterTableFor( ! "a class=rlbA href=/news/866201.asp?0sl=-32" ! ); ! assertStringEquals( ! "href", ! "/news/866201.asp?0sl=-32", ! (String)table.get("HREF") ! ); } public void testQuestionMarksInAttributes() { ! getParameterTableFor( ! "a href=\"mailto:sa...@ne...?subject=Site Comments\"" ! ); ! assertStringEquals( ! "href", ! "mailto:sa...@ne...?subject=Site Comments", ! (String)table.get("HREF") ! ); ! assertStringEquals( ! "tag name", ! "A", ! (String)table.get(Tag.TAGNAME) ! ); } *************** *** 164,169 **** **/ public void testEmptyTag () { ! getParameterTableFor(""); ! assertNotNull ("No Tag.TAGNAME",table.get(Tag.TAGNAME)); } --- 164,169 ---- **/ public void testEmptyTag () { ! getParameterTableFor(""); ! assertNotNull ("No Tag.TAGNAME",table.get(Tag.TAGNAME)); } Index: TagParserTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/temporaryFailures/TagParserTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TagParserTest.java 24 Aug 2003 21:59:44 -0000 1.8 --- TagParserTest.java 3 Sep 2003 23:36:22 -0000 1.9 *************** *** 45,143 **** public class TagParserTest extends ParserTestCase { ! private static final String TEST_HTML = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" + ! "<!-- Server: sf-web2 -->" + ! "<html lang=\"en\">" + ! " <head><link rel=\"stylesheet\" type=\"text/css\" href=\"http://sourceforge.net/cssdef.php\">" + ! " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" + ! " <TITLE>SourceForge.net: Modify: 711073 - HTMLTagParser not threadsafe as a static variable in Tag</TITLE>" + ! " <SCRIPT language=\"JavaScript\" type=\"text/javascript\">" + ! " <!--" + ! " function help_window(helpurl) {" + ! " HelpWin = window.open( 'http://sourceforge.net' + helpurl,'HelpWindow','scrollbars=yes,resizable=yes,toolbar=no,height=400,width=400');" + ! " }" + ! " // -->" + ! " </SCRIPT>" + ! " <link rel=\"SHORTCUT ICON\" href=\"/images/favicon.ico\">" + ! "<!-- This is temp javascript for the jump button. If we could actually have a jump script on the server side that would be ideal -->" + ! "<script language=\"JavaScript\" type=\"text/javascript\">" + ! "<!--" + ! " function jump(targ,selObj,restore){ //v3.0" + ! " if (selObj.options[selObj.selectedIndex].value) " + ! " eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");" + ! " if (restore) selObj.selectedIndex=0;" + ! " }" + ! " //-->" + ! "</script>" + ! "<a href=\"http://normallink.com/sometext.html\">" + ! "<style type=\"text/css\">" + ! "<!--" + ! "A:link { text-decoration:none }" + ! "A:visited { text-decoration:none }" + ! "A:active { text-decoration:none }" + ! "A:hover { text-decoration:underline; color:#0066FF; }" + ! "-->" + ! "</style>" + ! "</head>" + ! "<body bgcolor=\"#FFFFFF\" text=\"#000000\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" link=\"#003399\" vlink=\"#003399\" alink=\"#003399\">"; ! private Map results; ! private int testProgress; ! ! public TagParserTest(String name) { ! super(name); ! } ! ! public void testTagWithQuotes() throws Exception { ! String testHtml = ! "<img src=\"http://g-images.amazon.com/images/G/01/merchants/logos/marshall-fields-logo-20.gif\" width=87 height=20 border=0 alt=\"Marshall Field's\">"; ! ! createParser(testHtml); ! parseAndAssertNodeCount(1); ! assertType("should be Tag",Tag.class,node[0]); ! Tag tag = (Tag)node[0]; ! assertStringEquals("alt","Marshall Field's",tag.getAttribute("ALT")); ! assertStringEquals( ! "html", ! "<IMG BORDER=\"0\" ALT=\"Marshall Field's\" WIDTH=\"87\" SRC=\"http://g-images.amazon.com/images/G/01/merchants/logos/marshall-fields-logo-20.gif\" HEIGHT=\"20\">", ! tag.toHtml() ! ); ! } ! ! public void testEmptyTag() throws Exception { ! createParser("<custom/>"); ! parseAndAssertNodeCount(1); ! assertType("should be Tag",Tag.class,node[0]); ! Tag tag = (Tag)node[0]; ! assertStringEquals("tag name","CUSTOM",tag.getTagName()); ! assertTrue("empty tag",tag.isEmptyXmlTag()); ! assertStringEquals( ! "html", ! "<CUSTOM/>", ! tag.toHtml() ! ); ! } ! ! public void testTagWithCloseTagSymbolInAttribute() throws ParserException { ! createParser("<tag att=\"a>b\">"); ! parseAndAssertNodeCount(1); ! assertType("should be Tag",Tag.class,node[0]); ! Tag tag = (Tag)node[0]; ! assertStringEquals("attribute","a>b",tag.getAttribute("att")); ! } ! ! public void testTagWithOpenTagSymbolInAttribute() throws ParserException { ! createParser("<tag att=\"a<b\">"); ! parseAndAssertNodeCount(1); ! assertType("should be Tag",Tag.class,node[0]); ! Tag tag = (Tag)node[0]; ! assertStringEquals("attribute","a<b",tag.getAttribute("att")); ! } ! public void testTagWithSingleQuote() throws ParserException { ! createParser("<tag att=\'a<b\'>"); ! parseAndAssertNodeCount(1); ! assertType("should be Tag",Tag.class,node[0]); ! Tag tag = (Tag)node[0]; ! assertStringEquals("html","<TAG ATT=\"a<b\">",tag.toHtml()); ! assertStringEquals("attribute","a<b",tag.getAttribute("att")); } --- 45,143 ---- public class TagParserTest extends ParserTestCase { ! private static final String TEST_HTML = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" + ! "<!-- Server: sf-web2 -->" + ! "<html lang=\"en\">" + ! " <head><link rel=\"stylesheet\" type=\"text/css\" href=\"http://sourceforge.net/cssdef.php\">" + ! " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" + ! " <TITLE>SourceForge.net: Modify: 711073 - HTMLTagParser not threadsafe as a static variable in Tag</TITLE>" + ! " <SCRIPT language=\"JavaScript\" type=\"text/javascript\">" + ! " <!--" + ! " function help_window(helpurl) {" + ! " HelpWin = window.open( 'http://sourceforge.net' + helpurl,'HelpWindow','scrollbars=yes,resizable=yes,toolbar=no,height=400,width=400');" + ! " }" + ! " // -->" + ! " </SCRIPT>" + ! " <link rel=\"SHORTCUT ICON\" href=\"/images/favicon.ico\">" + ! "<!-- This is temp javascript for the jump button. If we could actually have a jump script on the server side that would be ideal -->" + ! "<script language=\"JavaScript\" type=\"text/javascript\">" + ! "<!--" + ! " function jump(targ,selObj,restore){ //v3.0" + ! " if (selObj.options[selObj.selectedIndex].value) " + ! " eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");" + ! " if (restore) selObj.selectedIndex=0;" + ! " }" + ! " //-->" + ! "</script>" + ! "<a href=\"http://normallink.com/sometext.html\">" + ! "<style type=\"text/css\">" + ! "<!--" + ! "A:link { text-decoration:none }" + ! "A:visited { text-decoration:none }" + ! "A:active { text-decoration:none }" + ! "A:hover { text-decoration:underline; color:#0066FF; }" + ! "-->" + ! "</style>" + ! "</head>" + ! "<body bgcolor=\"#FFFFFF\" text=\"#000000\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" link=\"#003399\" vlink=\"#003399\" alink=\"#003399\">"; ! private Map results; ! private int testProgress; ! ! public TagParserTest(String name) { ! super(name); ! } ! ! public void testTagWithQuotes() throws Exception { ! String testHtml = ! "<img src=\"http://g-images.amazon.com/images/G/01/merchants/logos/marshall-fields-logo-20.gif\" width=87 height=20 border=0 alt=\"Marshall Field's\">"; ! ! createParser(testHtml); ! parseAndAssertNodeCount(1); ! assertType("should be Tag",Tag.class,node[0]); ! Tag tag = (Tag)node[0]; ! assertStringEquals("alt","Marshall Field's",tag.getAttribute("ALT")); ! assertStringEquals( ! "html", ! "<IMG BORDER=\"0\" ALT=\"Marshall Field's\" WIDTH=\"87\" SRC=\"http://g-images.amazon.com/images/G/01/merchants/logos/marshall-fields-logo-20.gif\" HEIGHT=\"20\">", ! tag.toHtml() ! ); ! } ! ! public void testEmptyTag() throws Exception { ! createParser("<custom/>"); ! parseAndAssertNodeCount(1); ! assertType("should be Tag",Tag.class,node[0]); ! Tag tag = (Tag)node[0]; ! assertStringEquals("tag name","CUSTOM",tag.getTagName()); ! assertTrue("empty tag",tag.isEmptyXmlTag()); ! assertStringEquals( ! "html", ! "<CUSTOM/>", ! tag.toHtml() ! ); ! } ! ! public void testTagWithCloseTagSymbolInAttribute() throws ParserException { ! createParser("<tag att=\"a>b\">"); ! parseAndAssertNodeCount(1); ! assertType("should be Tag",Tag.class,node[0]); ! Tag tag = (Tag)node[0]; ! assertStringEquals("attribute","a>b",tag.getAttribute("att")); ! } ! ! public void testTagWithOpenTagSymbolInAttribute() throws ParserException { ! createParser("<tag att=\"a<b\">"); ! parseAndAssertNodeCount(1); ! assertType("should be Tag",Tag.class,node[0]); ! Tag tag = (Tag)node[0]; ! assertStringEquals("attribute","a<b",tag.getAttribute("att")); ! } ! public void testTagWithSingleQuote() throws ParserException { ! createParser("<tag att=\'a<b\'>"); ! parseAndAssertNodeCount(1); ! assertType("should be Tag",Tag.class,node[0]); ! Tag tag = (Tag)node[0]; ! assertStringEquals("html","<TAG ATT=\"a<b\">",tag.toHtml()); ! assertStringEquals("attribute","a<b",tag.getAttribute("att")); } *************** *** 251,255 **** } } ! /** * Test multiline split tag like attribute. --- 251,255 ---- } } ! /** * Test multiline split tag like attribute. *************** *** 285,289 **** * Only perform this test if it's version 1.4 or higher. */ ! public void testThreadSafety() throws Exception { createParser("<html></html>"); --- 285,289 ---- * Only perform this test if it's version 1.4 or higher. */ ! public void testThreadSafety() throws Exception { createParser("<html></html>"); *************** *** 307,311 **** new ParsingThread(i,testHtml2,parsingThread.length); ! Thread thread = new Thread(parsingThread[i]); thread.start(); } --- 307,311 ---- new ParsingThread(i,testHtml2,parsingThread.length); ! Thread thread = new Thread(parsingThread[i]); thread.start(); } *************** *** 319,323 **** catch (InterruptedException e) { } ! } while (testProgress!=completionValue); for (int i=0;i<parsingThread.length;i++) { --- 319,323 ---- catch (InterruptedException e) { } ! } while (testProgress!=completionValue); for (int i=0;i<parsingThread.length;i++) { *************** *** 348,413 **** parsingThread[i].getLink2().getLink() ); ! } } } ! } ! } ! private int computeCompletionValue(int numThreads) { ! return numThreads * (numThreads - 1) / 2; ! } ! ! class ParsingThread implements Runnable { ! Parser parser; ! int id; ! LinkTag link1, link2; ! boolean result; ! int max; ! ! ParsingThread(int id, String testHtml, int max) { ! this.id = id; ! this.max = max; ! this.parser = ! Parser.createParser(testHtml); ! parser.registerScanners(); ! } ! ! public void run() { ! try { ! result = false; ! Node linkTag [] = parser.extractAllNodesThatAre(LinkTag.class); ! link1 = (LinkTag)linkTag[0]; ! link2 = (LinkTag)linkTag[1]; ! if (id<max/2) { ! if (link1.getLink().equals("/cgi-bin/view_search?query_text=postdate>20020701&txt_clr=White&bg_clr=Red&url=http://localhost/Testing/Report1.html") && ! link2.getLink().equals("http://normallink.com/sometext.html")) ! result = true; ! } else { ! if (link1.getLink().equals("http://normallink.com/sometext.html") && ! link2.getLink().equals("http://normallink.com/sometext.html")) ! result = true; ! } ! } ! catch (ParserException e) { ! System.err.println("Parser Exception"); ! e.printStackTrace(); ! } ! finally { ! testProgress += id; ! } ! } ! ! public LinkTag getLink1() { ! return link1; ! } ! ! public LinkTag getLink2() { ! return link2; ! } ! ! public boolean passed() { ! return result; ! } } --- 348,413 ---- parsingThread[i].getLink2().getLink() ); ! } } } ! } ! } ! private int computeCompletionValue(int numThreads) { ! return numThreads * (numThreads - 1) / 2; ! } ! ! class ParsingThread implements Runnable { ! Parser parser; ! int id; ! LinkTag link1, link2; ! boolean result; ! int max; ! ! ParsingThread(int id, String testHtml, int max) { ! this.id = id; ! this.max = max; ! this.parser = ! Parser.createParser(testHtml); ! parser.registerScanners(); ! } ! ! public void run() { ! try { ! result = false; ! Node linkTag [] = parser.extractAllNodesThatAre(LinkTag.class); ! link1 = (LinkTag)linkTag[0]; ! link2 = (LinkTag)linkTag[1]; ! if (id<max/2) { ! if (link1.getLink().equals("/cgi-bin/view_search?query_text=postdate>20020701&txt_clr=White&bg_clr=Red&url=http://localhost/Testing/Report1.html") && ! link2.getLink().equals("http://normallink.com/sometext.html")) ! result = true; ! } else { ! if (link1.getLink().equals("http://normallink.com/sometext.html") && ! link2.getLink().equals("http://normallink.com/sometext.html")) ! result = true; ! } ! } ! catch (ParserException e) { ! System.err.println("Parser Exception"); ! e.printStackTrace(); ! } ! finally { ! testProgress += id; ! } ! } ! ! public LinkTag getLink1() { ! return link1; ! } ! ! public LinkTag getLink2() { ! return link2; ! } ! ! public boolean passed() { ! return result; ! } } |