diff options
author | Rainer Klute <klute@apache.org> | 2004-12-28 20:13:25 +0000 |
---|---|---|
committer | Rainer Klute <klute@apache.org> | 2004-12-28 20:13:25 +0000 |
commit | 1b12cfa66bed5d3e0807a2f135ff3ab63cbd5a02 (patch) | |
tree | 4584b6513900e8221378b08f99978d602310c5bd /src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java | |
parent | 8237d0930f093c6a2911d5765ab17019ed76b1ec (diff) | |
download | poi-1b12cfa66bed5d3e0807a2f135ff3ab63cbd5a02.tar.gz poi-1b12cfa66bed5d3e0807a2f135ff3ab63cbd5a02.zip |
- Test case for empty documents added.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353611 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java')
-rw-r--r-- | src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java new file mode 100644 index 0000000000..8579e42175 --- /dev/null +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java @@ -0,0 +1,130 @@ +package org.apache.poi.poifs.filesystem; + +import java.io.IOException; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import junit.framework.TestCase; + +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSWriterEvent; +import org.apache.poi.poifs.filesystem.POIFSWriterListener; +import org.apache.poi.poifs.filesystem.DirectoryEntry; + +public class TestEmptyDocument extends TestCase { + + public static void main(String[] args) { + TestEmptyDocument driver = new TestEmptyDocument(); + + System.out.println(); + System.out.println("As only file..."); + System.out.println(); + + System.out.print("Trying using createDocument(String,InputStream): "); + try { + driver.testSingleEmptyDocument(); + System.out.println("Worked!"); + } catch (IOException exception) { + System.out.println("failed! "); + System.out.println(exception.toString()); + } + System.out.println(); + + System.out.print + ("Trying using createDocument(String,int,POIFSWriterListener): "); + try { + driver.testSingleEmptyDocumentEvent(); + System.out.println("Worked!"); + } catch (IOException exception) { + System.out.println("failed!"); + System.out.println(exception.toString()); + } + System.out.println(); + + System.out.println(); + System.out.println("After another file..."); + System.out.println(); + + System.out.print("Trying using createDocument(String,InputStream): "); + try { + driver.testEmptyDocumentWithFriend(); + System.out.println("Worked!"); + } catch (IOException exception) { + System.out.println("failed! "); + System.out.println(exception.toString()); + } + System.out.println(); + + System.out.print + ("Trying using createDocument(String,int,POIFSWriterListener): "); + try { + driver.testEmptyDocumentWithFriend(); + System.out.println("Worked!"); + } catch (IOException exception) { + System.out.println("failed!"); + System.out.println(exception.toString()); + } + System.out.println(); + } + + public void testSingleEmptyDocument() throws IOException { + POIFSFileSystem fs = new POIFSFileSystem(); + DirectoryEntry dir = fs.getRoot(); + dir = fs.getRoot(); + dir.createDocument("Foo", new ByteArrayInputStream(new byte[] { })); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + fs.writeFilesystem(out); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + } + + public void testSingleEmptyDocumentEvent() throws IOException { + POIFSFileSystem fs = new POIFSFileSystem(); + DirectoryEntry dir = fs.getRoot(); + dir = fs.getRoot(); + dir.createDocument("Foo", 0, new POIFSWriterListener() { + public void processPOIFSWriterEvent(POIFSWriterEvent event) { + System.out.println("written"); + } + }); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + fs.writeFilesystem(out); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + } + + public void testEmptyDocumentWithFriend() throws IOException { + POIFSFileSystem fs = new POIFSFileSystem(); + DirectoryEntry dir = fs.getRoot(); + dir = fs.getRoot(); + dir.createDocument("Bar", new ByteArrayInputStream(new byte[] { 0 })); + dir.createDocument("Foo", new ByteArrayInputStream(new byte[] { })); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + fs.writeFilesystem(out); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + } + + public void testEmptyDocumentEventWithFriend() throws IOException { + POIFSFileSystem fs = new POIFSFileSystem(); + DirectoryEntry dir = fs.getRoot(); + dir = fs.getRoot(); + dir.createDocument("Bar", 1, new POIFSWriterListener() { + public void processPOIFSWriterEvent(POIFSWriterEvent event) { + try { + event.getStream().write(0); + } catch (IOException exception) { + throw new RuntimeException("exception on write: " + exception); + } + } + }); + dir.createDocument("Foo", 0, new POIFSWriterListener() { + public void processPOIFSWriterEvent(POIFSWriterEvent event) { + } + }); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + fs.writeFilesystem(out); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + } +}
\ No newline at end of file |