KickJava   Java API By Example, From Geeks To Geeks.

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


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Dhaval Udani
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/InputTagTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/05/22 03:57:31 $
10
// $Revision: 1.40 $
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.tags.FormTag;
30 import org.htmlparser.tags.InputTag;
31 import org.htmlparser.tags.TableColumn;
32 import org.htmlparser.tags.TableRow;
33 import org.htmlparser.tags.TableTag;
34 import org.htmlparser.tests.ParserTestCase;
35 import org.htmlparser.util.ParserException;
36
37 public class InputTagTest extends ParserTestCase {
38
39     static
40     {
41         System.setProperty ("org.htmlparser.tests.tagTests.InputTagTest", "InputTagTest");
42     }
43
44     public InputTagTest(String JavaDoc name)
45     {
46         super(name);
47     }
48
49     public void testToHTML() throws ParserException
50     {
51         String JavaDoc testHTML = "<INPUT type=\"text\" name=\"Google\">";
52         createParser(testHTML);
53         parseAndAssertNodeCount(1);
54         assertTrue("Node 1 should be INPUT Tag",node[0] instanceof InputTag);
55         InputTag InputTag;
56         InputTag = (InputTag) node[0];
57         assertStringEquals ("HTML String",testHTML,InputTag.toHtml());
58     }
59
60     /**
61      * Reproduction of bug report 663038
62      * @throws ParserException
63      */

64     public void testToHTML2() throws ParserException
65     {
66         String JavaDoc testHTML ="<INPUT type=\"checkbox\" "
67             +"name=\"cbCheck\" checked>";
68         createParser(testHTML);
69         parseAndAssertNodeCount(1);
70         assertTrue("Node 1 should be INPUT Tag",
71             node[0] instanceof InputTag);
72         InputTag InputTag;
73         InputTag = (InputTag) node[0];
74         assertStringEquals("HTML String", testHTML, InputTag.toHtml());
75     }
76
77     public void testScan() throws ParserException
78     {
79         createParser("<INPUT type=\"text\" name=\"Google\">","http://www.google.com/test/index.html");
80         parseAndAssertNodeCount(1);
81         assertTrue(node[0] instanceof InputTag);
82
83         // check the input node
84
InputTag inputTag = (InputTag) node[0];
85         assertEquals("Type","text",inputTag.getAttribute("TYPE"));
86         assertEquals("Name","Google",inputTag.getAttribute("NAME"));
87     }
88
89     /**
90      * Bug #923146 tag nesting rule too strict for forms
91      */

92     public void testTable () throws ParserException
93     {
94         String JavaDoc html =
95             "<table>" +
96             "<tr>" +
97             "<td>" +
98             "<form>" +
99             "<input name=input1>" +
100             "</td>" +
101             // <tr> missing
102
"<tr>" +
103             "<td>" +
104             "<input name=input2>" +
105             "</td>" +
106             "</tr>" +
107             "</form>" +
108             "</table>";
109         createParser (html);
110         parseAndAssertNodeCount (1);
111         assertTrue ("not a table", node[0] instanceof TableTag);
112         TableTag table = (TableTag)node[0];
113         assertTrue ("not two rows", 2 == table.getRowCount ());
114 // assertTrue ("not one row", 1 == table.getRowCount ());
115
TableRow row = table.getRow (0);
116         assertTrue ("not one column", 1 == row.getColumnCount ());
117         TableColumn column = row.getColumns ()[0];
118         assertTrue ("not one child", 1 == column.getChildCount ());
119         assertTrue ("column doesn't have a form", column.getChild (0) instanceof FormTag);
120         FormTag form = (FormTag)column.getChild (0);
121         assertTrue ("form only has one input field", 2 == form.getFormInputs ().size ());
122     }
123
124 }
Popular Tags