diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/data/test2.doc b/src/scratchpad/testcases/org/apache/poi/hwpf/data/test2.doc new file mode 100755 index 000000000..06921df39 Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hwpf/data/test2.doc differ diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java new file mode 100644 index 000000000..23ff64f1a --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java @@ -0,0 +1,87 @@ +package org.apache.poi.hwpf.extractor; + +import java.io.FileInputStream; +import java.util.Iterator; + +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.model.TextPiece; +import org.apache.poi.hwpf.usermodel.Paragraph; +import org.apache.poi.hwpf.usermodel.Range; + +import junit.framework.TestCase; + +/** + * Test the different routes to extracting text + * + * @author Nick Burch (nick at torchbox dot com) + */ +public class TestDifferentRoutes extends TestCase { + private String[] p_text = new String[] { + "This is a simple word document\r", + "\r", + "It has a number of paragraphs in it\r", + "\r", + "Some of them even feature bold, italic and underlined text\r", + "\r", + "\r", + "This bit is in a different font and size\r", + "\r", + "\r", + "This bit features some red text.\r", + "\r", + "\r", + "It is otherwise very very boring.\r" + }; + + private HWPFDocument doc; + + protected void setUp() throws Exception { + String dirname = System.getProperty("HWPF.testdata.path"); + + String filename = dirname + "/test2.doc"; + doc = new HWPFDocument(new FileInputStream(filename)); + } + + /** + * Test model based extraction + */ + public void testExtractFromModel() { + Range r = doc.getRange(); + + String[] text = new String[r.numParagraphs()]; + for(int i=0; i < r.numParagraphs(); i++) { + Paragraph p = r.getParagraph(i); + text[i] = p.text(); + } + + assertEquals(p_text.length, text.length); + for(int i=0; i flat extraction + */ + public void testGetText() { + assertEquals(p_text1_block, extractor.getText()); + + // On second one, should fall back to text piece + assertEquals(extractor2.getTextFromPieces(), extractor2.getText()); + } + + /** + * Test textPieces based extraction + */ + public void testExtractFromTextPieces() throws Exception { + String text = extractor.getTextFromPieces(); + assertEquals(p_text1_block, text); + } +}