KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > tagTests > DoctypeTagTest


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Somik Raha
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/DoctypeTagTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/01/02 16:24:57 $
10
// $Revision: 1.36 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.tests.tagTests;
28
29 import org.htmlparser.Node;
30 import org.htmlparser.tags.DoctypeTag;
31 import org.htmlparser.tests.ParserTestCase;
32 import org.htmlparser.util.NodeIterator;
33 import org.htmlparser.util.ParserException;
34
35 public class DoctypeTagTest extends ParserTestCase {
36
37     static
38     {
39         System.setProperty ("org.htmlparser.tests.tagTests.DoctypeTagTest", "DoctypeTagTest");
40     }
41
42     public DoctypeTagTest(String JavaDoc name) {
43         super(name);
44     }
45
46     public void testToHTML() throws ParserException
47     {
48         String JavaDoc testHTML = new String JavaDoc(
49         "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n"+
50         "<HTML>\n"+
51         "<HEAD>\n"+
52         "<TITLE>Cogs of Chicago</TITLE>\n"+
53         "</HEAD>\n"+
54         "<BODY>\n"+
55         "...\n"+
56         "</BODY>\n"+
57         "</HTML>\n");
58         createParser(testHTML);
59         parseAndAssertNodeCount(4);
60         // The first node should be an DoctypeTag
61
assertTrue("First node should be a DoctypeTag",node[0] instanceof DoctypeTag);
62         DoctypeTag docTypeTag = (DoctypeTag)node[0];
63         assertStringEquals("toHTML()","<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">",docTypeTag.toHtml());
64     }
65
66     /**
67      * See bug #833592 DOCTYPE element is not parsed correctly
68      * Contributed by Trevor Watson (t007).
69      */

70     public void DocTypeElementTest () throws ParserException
71     {
72         final String JavaDoc DOCTYPE = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
73         final String JavaDoc HTML = DOCTYPE + "\n<HTML>\n <HEAD>\n <TITLE>HTMLParserDocTypeBugTest</TITLE>\n </HEAD>\n <BODY>\n HTMLParser DOCTYPE node bug test.\n </BODY>\n</HTML>";
74
75         createParser(HTML);
76
77         NodeIterator e = parser.elements();
78         Node node = e.nextNode();
79
80         // First node is doctype
81
assertStringEquals("Doctype element output is incorrect.", DOCTYPE, node.toHtml());
82     }
83 }
84
Popular Tags