[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/tagTests ImageTagTest.java,1.27,1.28
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-09-01 21:41:32
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests In directory sc8-pr-cvs1:/tmp/cvs-serv8038 Modified Files: ImageTagTest.java Log Message: Add test case text from bug bug #778781 SRC-attribute suppression in IMG-tags. Index: ImageTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/ImageTagTest.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** ImageTagTest.java 24 Aug 2003 21:59:44 -0000 1.27 --- ImageTagTest.java 1 Sep 2003 21:41:28 -0000 1.28 *************** *** 41,158 **** public class ImageTagTest extends ParserTestCase { ! public ImageTagTest(String name) { ! super(name); ! } ! /** ! * The bug being reproduced is this : <BR> ! * <BODY aLink=#ff0000 bgColor=#ffffff link=#0000cc onload=setfocus() text=#000000 <BR> ! * vLink=#551a8b> ! * The above line is incorrectly parsed in that, the BODY tag is not identified. ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testImageTag() throws ParserException ! { ! createParser("<IMG alt=Google height=115 src=\"goo/title_homepage4.gif\" width=305>","http://www.google.com/test/index.html"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! // The node should be an HTMLImageTag ! assertTrue("Node should be a HTMLImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertEquals("The image locn","http://www.google.com/test/goo/title_homepage4.gif",imageTag.getImageURL()); ! } ! /** ! * The bug being reproduced is this : <BR> ! * <BODY aLink=#ff0000 bgColor=#ffffff link=#0000cc onload=setfocus() text=#000000 <BR> ! * vLink=#551a8b> ! * The above line is incorrectly parsed in that, the BODY tag is not identified. ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testImageTagBug() throws ParserException ! { ! createParser("<IMG alt=Google height=115 src=\"../goo/title_homepage4.gif\" width=305>","http://www.google.com/test/"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! // The node should be an HTMLImageTag ! assertTrue("Node should be a HTMLImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertEquals("The image locn","http://www.google.com/goo/title_homepage4.gif",imageTag.getImageURL()); ! } ! /** ! * The bug being reproduced is this : <BR> ! * <BODY aLink=#ff0000 bgColor=#ffffff link=#0000cc onload=setfocus() text=#000000 <BR> ! * vLink=#551a8b> ! * The above line is incorrectly parsed in that, the BODY tag is not identified. ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testImageTageBug2() throws ParserException ! { ! createParser("<IMG alt=Google height=115 src=\"../../goo/title_homepage4.gif\" width=305>","http://www.google.com/test/test/index.html"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! // The node should be an HTMLImageTag ! assertTrue("Node should be a HTMLImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertEquals("The image locn","http://www.google.com/goo/title_homepage4.gif",imageTag.getImageURL()); ! } ! /** ! * This bug occurs when there is a null pointer exception thrown while scanning a tag using LinkScanner. ! * Creation date: (7/1/2001 2:42:13 PM) ! */ ! public void testImageTagSingleQuoteBug() throws ParserException ! { ! createParser("<IMG SRC='abcd.jpg'>","http://www.cj.com/"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! assertTrue("Node should be a HTMLImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertEquals("Image incorrect","http://www.cj.com/abcd.jpg",imageTag.getImageURL()); ! } ! /** ! * The bug being reproduced is this : <BR> ! * <A HREF=>Something<A><BR> ! * vLink=#551a8b> ! * The above line is incorrectly parsed in that, the BODY tag is not identified. ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testNullImageBug() throws ParserException ! { ! createParser("<IMG SRC=>","http://www.google.com/test/index.html"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! // The node should be an HTMLLinkTag ! assertTrue("Node should be a HTMLImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertStringEquals("The image location","",imageTag.getImageURL()); ! } ! public void testToHTML() throws ParserException { ! createParser("<IMG alt=Google height=115 src=\"../../goo/title_homepage4.gif\" width=305>","http://www.google.com/test/test/index.html"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! // The node should be an ImageTag ! assertTrue("Node should be a ImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertStringEquals("The image locn","<IMG WIDTH=\"305\" ALT=\"Google\" SRC=\"../../goo/title_homepage4.gif\" HEIGHT=\"115\">",imageTag.toHtml()); ! assertEquals("Alt","Google",imageTag.getAttribute("alt")); ! assertEquals("Height","115",imageTag.getAttribute("height")); ! assertEquals("Width","305",imageTag.getAttribute("width")); ! } /** --- 41,158 ---- public class ImageTagTest extends ParserTestCase { ! public ImageTagTest(String name) { ! super(name); ! } ! /** ! * The bug being reproduced is this : <BR> ! * <BODY aLink=#ff0000 bgColor=#ffffff link=#0000cc onload=setfocus() text=#000000 <BR> ! * vLink=#551a8b> ! * The above line is incorrectly parsed in that, the BODY tag is not identified. ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testImageTag() throws ParserException ! { ! createParser("<IMG alt=Google height=115 src=\"goo/title_homepage4.gif\" width=305>","http://www.google.com/test/index.html"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! // The node should be an HTMLImageTag ! assertTrue("Node should be a HTMLImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertEquals("The image locn","http://www.google.com/test/goo/title_homepage4.gif",imageTag.getImageURL()); ! } ! /** ! * The bug being reproduced is this : <BR> ! * <BODY aLink=#ff0000 bgColor=#ffffff link=#0000cc onload=setfocus() text=#000000 <BR> ! * vLink=#551a8b> ! * The above line is incorrectly parsed in that, the BODY tag is not identified. ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testImageTagBug() throws ParserException ! { ! createParser("<IMG alt=Google height=115 src=\"../goo/title_homepage4.gif\" width=305>","http://www.google.com/test/"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! // The node should be an HTMLImageTag ! assertTrue("Node should be a HTMLImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertEquals("The image locn","http://www.google.com/goo/title_homepage4.gif",imageTag.getImageURL()); ! } ! /** ! * The bug being reproduced is this : <BR> ! * <BODY aLink=#ff0000 bgColor=#ffffff link=#0000cc onload=setfocus() text=#000000 <BR> ! * vLink=#551a8b> ! * The above line is incorrectly parsed in that, the BODY tag is not identified. ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testImageTageBug2() throws ParserException ! { ! createParser("<IMG alt=Google height=115 src=\"../../goo/title_homepage4.gif\" width=305>","http://www.google.com/test/test/index.html"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! // The node should be an HTMLImageTag ! assertTrue("Node should be a HTMLImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertEquals("The image locn","http://www.google.com/goo/title_homepage4.gif",imageTag.getImageURL()); ! } ! /** ! * This bug occurs when there is a null pointer exception thrown while scanning a tag using LinkScanner. ! * Creation date: (7/1/2001 2:42:13 PM) ! */ ! public void testImageTagSingleQuoteBug() throws ParserException ! { ! createParser("<IMG SRC='abcd.jpg'>","http://www.cj.com/"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! assertTrue("Node should be a HTMLImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertEquals("Image incorrect","http://www.cj.com/abcd.jpg",imageTag.getImageURL()); ! } ! /** ! * The bug being reproduced is this : <BR> ! * <A HREF=>Something<A><BR> ! * vLink=#551a8b> ! * The above line is incorrectly parsed in that, the BODY tag is not identified. ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testNullImageBug() throws ParserException ! { ! createParser("<IMG SRC=>","http://www.google.com/test/index.html"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! // The node should be an HTMLLinkTag ! assertTrue("Node should be a HTMLImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertStringEquals("The image location","",imageTag.getImageURL()); ! } ! public void testToHTML() throws ParserException { ! createParser("<IMG alt=Google height=115 src=\"../../goo/title_homepage4.gif\" width=305>","http://www.google.com/test/test/index.html"); ! // Register the image scanner ! parser.addScanner(new ImageScanner("-i",new LinkProcessor())); ! ! parseAndAssertNodeCount(1); ! // The node should be an ImageTag ! assertTrue("Node should be a ImageTag",node[0] instanceof ImageTag); ! ImageTag imageTag = (ImageTag)node[0]; ! assertStringEquals("The image locn","<IMG WIDTH=\"305\" ALT=\"Google\" SRC=\"../../goo/title_homepage4.gif\" HEIGHT=\"115\">",imageTag.toHtml()); ! assertEquals("Alt","Google",imageTag.getAttribute("alt")); ! assertEquals("Height","115",imageTag.getAttribute("height")); ! assertEquals("Width","305",imageTag.getAttribute("width")); ! } /** *************** *** 191,199 **** + "</map>" + "</a>"; ! createParser (html); ! parser.registerScanners (); ! ! parseAndAssertNodeCount (1); ! assertTrue ("Node should be a LinkTag", node[0] instanceof LinkTag); LinkTag link = (LinkTag)node[0]; ImageTag img = extractLinkImage (link); --- 191,199 ---- + "</map>" + "</a>"; ! createParser (html); ! parser.registerScanners (); ! ! parseAndAssertNodeCount (1); ! assertTrue ("Node should be a LinkTag", node[0] instanceof LinkTag); LinkTag link = (LinkTag)node[0]; ImageTag img = extractLinkImage (link); *************** *** 211,220 **** createParser (html); ! parser.registerScanners (); parseAndAssertNodeCount (1); ! assertTrue ("Node should be an ImageTag", node[0] instanceof ImageTag); ImageTag img = (ImageTag)node[0]; assertTrue ("bad source", "http://i.cnn.net/cnn/images/1.gif".equals (img.getImageURL ())); ! } } --- 211,234 ---- createParser (html); ! parser.registerScanners (); parseAndAssertNodeCount (1); ! assertTrue ("Node should be an ImageTag", node[0] instanceof ImageTag); ImageTag img = (ImageTag)node[0]; assertTrue ("bad source", "http://i.cnn.net/cnn/images/1.gif".equals (img.getImageURL ())); ! } ! ! // see bug #778781 SRC-attribute suppression in IMG-tags ! // HTML before parse: ! // <img src="images/first" alt="first"> ! // <img src="images/second" alt=""> ! // <img alt="third" src="images/third"> ! // <img alt="" src="images/fourth"> ! // ! // HTML after parse: ! // <IMG ALT="first" SRC="images/first"> ! // <IMG ALT="" SRC="images/second"> ! // <IMG ALT="third" SRC="images/third"> ! // <IMG ALT=""> ! } |