KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > MemoryTest


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/MemoryTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/07/31 01:22:45 $
10
// $Revision: 1.3 $
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;
28
29 import org.htmlparser.Node;
30 import org.htmlparser.Parser;
31 import org.htmlparser.util.NodeIterator;
32
33 /**
34  * Test big memory requirements.
35  */

36 public class MemoryTest extends ParserTestCase
37 {
38     
39     static
40     {
41         System.setProperty ("org.htmlparser.tests.MemoryTest", "MemoryTest");
42     }
43
44     public MemoryTest (String JavaDoc name)
45     {
46         super (name);
47     }
48
49     /**
50      * Test for bug #922439 OutOfMemory on huge HTML files (4,7MB)
51      */

52     public void testBigFile () throws Exception JavaDoc
53     {
54         Parser parser;
55         NodeIterator iterator;
56         Node node;
57         int size;
58         
59         parser = new Parser ("http://htmlparser.sourceforge.net/test/A002.html");
60         size = 0;
61         try
62         {
63             iterator = parser.elements ();
64             while (iterator.hasMoreNodes ())
65             {
66                 node = iterator.nextNode ();
67                 size += node.toHtml ().length ();
68             }
69         }
70         catch (OutOfMemoryError JavaDoc ome)
71         {
72             fail ("out of memory");
73         }
74         assertEquals ("wrong size fetched", 4697386, size);
75     }
76     
77 }
78
Popular Tags