[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/lexerTests PageIndexTests.java,NONE,1.1 AllTest
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-08-10 23:36:21
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests In directory sc8-pr-cvs1:/tmp/cvs-serv1881 Modified Files: AllTests.java PageTests.java Added Files: PageIndexTests.java Log Message: Unit tests for second drop of new io subsystem. --- NEW FILE: PageIndexTests.java --- // HTMLParser Library v1_4_20030727 - 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.lexerTests; import junit.framework.TestCase; import org.htmlparser.lexer.PageIndex; public class PageIndexTests extends TestCase { /** * Test the end-of-line index class. */ public PageIndexTests (String name) { super (name); } public void testAppend1 () { PageIndex index; int pos; int[] list; index = new PageIndex (null); for (int i = 0; i < 10000; i++) { pos = index.row (i); assertTrue ("append not at end", pos == i); assertTrue ("wrong position", pos == index.add (i)); } list = index.get (); for (int i = 0; i < 10000; i++) assertTrue ("wrong value", list[i] == i); } public void testAppend2 () { PageIndex index; int pos; int[] list; index = new PageIndex (null); for (int i = 0; i < 10000; i++) { pos = index.row (i + 42); assertTrue ("append not at end", pos == i); assertTrue ("wrong position", pos == index.add (i + 42)); } list = index.get (); for (int i = 0; i < 10000; i++) assertTrue ("wrong value", list[i] == i + 42); } public void testAppend3 () { PageIndex index; int pos; int[] list; index = new PageIndex (null); for (int i = 0; i < 10000; i++) { pos = index.row (i * 42); assertTrue ("append not at end", pos == i); assertTrue ("wrong position", pos == index.add (i * 42)); } list = index.get (); for (int i = 0; i < 10000; i++) assertTrue ("wrong value", list[i] == i * 42); } public void testInsert () { PageIndex index; double d; int n; int pos; int[] list; index = new PageIndex (null); for (int i = 0; i < 10000; i++) { d = Math.random (); d -= 0.5; n = (int)(d * 100838); pos = index.row (n); // test for correct position if (0 <= pos - 1) assertTrue ("search error less " + pos + " " + index.elementAt (pos - 1) + " " + n, index.elementAt (pos - 1) < n); if (pos + 1 < index.size ()) assertTrue ("search error greater " + pos + " " + index.elementAt (pos + 1) + " " + n, index.elementAt (pos + 1) > n); assertTrue ("wrong position", pos == index.add (n)); } list = index.get (); n = Integer.MIN_VALUE; for (int i = 0; i < list.length; i++) { assertTrue ("wrong order", list[i] > n); n = list[i]; } } } Index: AllTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/AllTests.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AllTests.java 27 Jul 2003 19:19:20 -0000 1.2 --- AllTests.java 10 Aug 2003 23:36:18 -0000 1.3 *************** *** 45,49 **** suite.addTestSuite (SourceTests.class); suite.addTestSuite (PageTests.class); ! return suite; } --- 45,50 ---- suite.addTestSuite (SourceTests.class); suite.addTestSuite (PageTests.class); ! suite.addTestSuite (PageIndexTests.class); ! return suite; } Index: PageTests.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/lexerTests/PageTests.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PageTests.java 27 Jul 2003 19:19:20 -0000 1.2 --- PageTests.java 10 Aug 2003 23:36:18 -0000 1.3 *************** *** 37,40 **** --- 37,41 ---- import org.htmlparser.lexer.Page; + import org.htmlparser.util.ParserException; public class PageTests extends TestCase *************** *** 59,66 **** * Test initialization with a null value. */ ! public void testNull () ! throws ! IOException, ! UnsupportedEncodingException { Page page; --- 60,64 ---- * Test initialization with a null value. */ ! public void testNull () throws ParserException { Page page; *************** *** 80,87 **** * Test initialization with a real value. */ ! public void testURLConnection () ! throws ! IOException, ! UnsupportedEncodingException { String link; --- 78,82 ---- * Test initialization with a real value. */ ! public void testURLConnection () throws ParserException, IOException { String link; *************** *** 92,95 **** --- 87,111 ---- url = new URL (link); page = new Page (url.openConnection ()); + } + + /** + * Test initialization with non-existant URL. + */ + public void testBadURLConnection () throws IOException + { + String link; + URL url; + Page page; + + link = "http://www.bigbogosity.org/"; + url = new URL (link); + try + { + page = new Page (url.openConnection ()); + } + catch (ParserException pe) + { + // expected response + } } } |