Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2978/src/org/htmlparser/tests
Modified Files:
ParserTest.java
Log Message:
Fix bug #1005409 Input file not free by parser.
Files larger than 16K on Windows can now be explicitly closed with Page.close(),
or will be closed when the page is finalized.
Index: ParserTest.java
===================================================================
RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/ParserTest.java,v
retrieving revision 1.61
retrieving revision 1.62
diff -C2 -d -r1.61 -r1.62
*** ParserTest.java 31 Jul 2004 16:42:33 -0000 1.61
--- ParserTest.java 25 Aug 2004 03:36:01 -0000 1.62
***************
*** 46,49 ****
--- 46,50 ----
import org.htmlparser.filters.NodeClassFilter;
import org.htmlparser.filters.TagNameFilter;
+ import org.htmlparser.lexer.InputStreamSource;
import org.htmlparser.lexer.Lexer;
import org.htmlparser.lexer.Page;
***************
*** 375,378 ****
--- 376,436 ----
/**
+ * Tests deleting a file held open by the parser.
+ * See bug #1005409 Input file not free by parser
+ */
+ public void testFileDelete ()
+ {
+ String path;
+ File file;
+ PrintWriter out;
+ Parser parser;
+ NodeIterator enumeration;
+
+ path = System.getProperty ("user.dir");
+ if (!path.endsWith (File.separator))
+ path += File.separator;
+ file = new File (path + "delete_me.html");
+ try
+ {
+ out = new PrintWriter (new FileWriter (file));
+ out.println ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
+ out.println ("<html>");
+ out.println ("<head>");
+ out.println ("<title>test</title>");
+ out.println ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
+ out.println ("</head>");
+ out.println ("<body>");
+ out.println ("This is a test page ");
+ out.println ("</body>");
+ out.println ("</html>");
+ // fill our 16K buffer on read
+ for (int i = 0; i < InputStreamSource.BUFFER_SIZE; i++)
+ out.println ();
+ out.close ();
+ parser = new Parser (file.getAbsolutePath (), new DefaultParserFeedback(DefaultParserFeedback.QUIET));
+ parser.setNodeFactory (new PrototypicalNodeFactory (true));
+ enumeration = parser.elements ();
+ enumeration.nextNode ();
+ if (-1 != System.getProperty ("os.name").indexOf("Windows"))
+ // linux/unix lets you delete a file even when it's open
+ assertTrue ("file deleted with more available", !file.delete ());
+ // parser.getLexer ().getPage ().close ();
+ parser = null;
+ enumeration = null;
+ System.gc ();
+ System.runFinalization ();
+ assertTrue ("file not deleted after destroy", file.delete ());
+ }
+ catch (Exception e)
+ {
+ fail (e.toString ());
+ }
+ finally
+ {
+ file.delete ();
+ }
+ }
+
+ /**
* Test with a HTTP header with a valid charset parameter.
* Here, ibm.co.jp is an example of a HTTP server that correctly sets the
|