From 069207f64edf6486525e2bdbb815be81924d5a46 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 28 Jan 2010 12:20:32 +0000 Subject: [PATCH] Fix generics warnings, and fix up tests to handle the extra bit of text being extracted now git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@904060 13f79535-47bb-0310-9956-ffa450edef68 --- .../hdgf/extractor/VisioTextExtractor.java | 16 ++++++--- .../hdgf/extractor/TestVisioExtractor.java | 33 ++++++++++++------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java b/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java index c83257f5a3..74488f4bed 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java @@ -61,13 +61,13 @@ public final class VisioTextExtractor extends POIOLE2TextExtractor { * contents. */ public String[] getAllText() { - ArrayList text = new ArrayList(); + ArrayList text = new ArrayList(); for(int i=0; i text) { if(stream instanceof PointerContainingStream) { PointerContainingStream ps = (PointerContainingStream)stream; for(int i=0; i 0) { + // First command Command cmd = chunk.getCommands()[0]; if(cmd != null && cmd.getValue() != null) { - text.add( cmd.getValue().toString() ); + // Capture the text, as long as it isn't + // simply an empty string + String str = cmd.getValue().toString(); + if(str.equals("") || str.equals("\n")) { + // Ignore empty strings + } else { + text.add( str ); + } } } } diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java b/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java index 30b8db4fbd..24b2a45b73 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java @@ -18,7 +18,6 @@ package org.apache.poi.hdgf.extractor; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.PrintStream; import junit.framework.TestCase; @@ -31,8 +30,10 @@ public final class TestVisioExtractor extends TestCase { private static POIDataSamples _dgTests = POIDataSamples.getDiagramInstance(); private String defFilename; + private int defTextChunks; protected void setUp() { defFilename = "Test_Visio-Some_Random_Text.vsd"; + defTextChunks = 5; } /** @@ -44,7 +45,7 @@ public final class TestVisioExtractor extends TestCase { extractor = new VisioTextExtractor(_dgTests.openResourceAsStream(defFilename)); assertNotNull(extractor); assertNotNull(extractor.getAllText()); - assertEquals(3, extractor.getAllText().length); + assertEquals(defTextChunks, extractor.getAllText().length); extractor = new VisioTextExtractor( new POIFSFileSystem( @@ -53,7 +54,7 @@ public final class TestVisioExtractor extends TestCase { ); assertNotNull(extractor); assertNotNull(extractor.getAllText()); - assertEquals(3, extractor.getAllText().length); + assertEquals(defTextChunks, extractor.getAllText().length); extractor = new VisioTextExtractor( new HDGFDiagram( @@ -64,7 +65,7 @@ public final class TestVisioExtractor extends TestCase { ); assertNotNull(extractor); assertNotNull(extractor.getAllText()); - assertEquals(3, extractor.getAllText().length); + assertEquals(defTextChunks, extractor.getAllText().length); } public void testExtraction() throws Exception { @@ -74,19 +75,25 @@ public final class TestVisioExtractor extends TestCase { // Check the array fetch String[] text = extractor.getAllText(); assertNotNull(text); - assertEquals(3, text.length); + assertEquals(defTextChunks, text.length); - assertEquals("Test View\n", text[0]); - assertEquals("I am a test view\n", text[1]); - assertEquals("Some random text, on a page\n", text[2]); + assertEquals("text\n", text[0]); + assertEquals("View\n", text[1]); + assertEquals("Test View\n", text[2]); + assertEquals("I am a test view\n", text[3]); + assertEquals("Some random text, on a page\n", text[4]); // And the all-in fetch String textS = extractor.getText(); - assertEquals("Test View\nI am a test view\nSome random text, on a page\n", textS); + assertEquals("text\nView\nTest View\nI am a test view\nSome random text, on a page\n", textS); } public void testProblemFiles() throws Exception { - String[] files = {"44594.vsd", "44594-2.vsd", "ShortChunk1.vsd", "ShortChunk2.vsd", "ShortChunk3.vsd"}; + String[] files = { + "44594.vsd", "44594-2.vsd", + "ShortChunk1.vsd", "ShortChunk2.vsd", "ShortChunk3.vsd", + "NegativeChunkLength.vsd", "NegativeChunkLength2.vsd" + }; for(String file : files){ VisioTextExtractor ex = new VisioTextExtractor(_dgTests.openResourceAsStream(file)); ex.getText(); @@ -108,6 +115,10 @@ public final class TestVisioExtractor extends TestCase { // Check capture.flush(); String text = baos.toString(); - assertEquals("Test View\nI am a test view\nSome random text, on a page\n", text); + assertEquals( + "text\nView\n" + + "Test View\nI am a test view\n" + + "Some random text, on a page\n", + text); } } -- 2.39.5