001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017: package org.apache.poi.hdgf.extractor;
018:
019: import java.io.ByteArrayOutputStream;
020: import java.io.FileInputStream;
021: import java.io.PrintStream;
022:
023: import junit.framework.TestCase;
024:
025: import org.apache.poi.hdgf.HDGFDiagram;
026: import org.apache.poi.hdgf.chunks.Chunk;
027: import org.apache.poi.hdgf.chunks.ChunkFactory;
028: import org.apache.poi.hdgf.pointers.Pointer;
029: import org.apache.poi.hdgf.pointers.PointerFactory;
030: import org.apache.poi.hssf.record.formula.eval.StringOperationEval;
031: import org.apache.poi.poifs.filesystem.DocumentEntry;
032: import org.apache.poi.poifs.filesystem.POIFSFileSystem;
033:
034: public class TestVisioExtractor extends TestCase {
035: private String filename;
036:
037: protected void setUp() throws Exception {
038: String dirname = System.getProperty("HDGF.testdata.path");
039: filename = dirname + "/Test_Visio-Some_Random_Text.vsd";
040: }
041:
042: /**
043: * Test the 3 different ways of creating one
044: */
045: public void testCreation() throws Exception {
046: VisioTextExtractor extractor;
047:
048: extractor = new VisioTextExtractor(
049: new FileInputStream(filename));
050: assertNotNull(extractor);
051: assertNotNull(extractor.getAllText());
052: assertEquals(3, extractor.getAllText().length);
053:
054: extractor = new VisioTextExtractor(new POIFSFileSystem(
055: new FileInputStream(filename)));
056: assertNotNull(extractor);
057: assertNotNull(extractor.getAllText());
058: assertEquals(3, extractor.getAllText().length);
059:
060: extractor = new VisioTextExtractor(new HDGFDiagram(
061: new POIFSFileSystem(new FileInputStream(filename))));
062: assertNotNull(extractor);
063: assertNotNull(extractor.getAllText());
064: assertEquals(3, extractor.getAllText().length);
065: }
066:
067: public void testExtraction() throws Exception {
068: VisioTextExtractor extractor = new VisioTextExtractor(
069: new FileInputStream(filename));
070:
071: // Check the array fetch
072: String[] text = extractor.getAllText();
073: assertNotNull(text);
074: assertEquals(3, text.length);
075:
076: assertEquals("Test View\n", text[0]);
077: assertEquals("I am a test view\n", text[1]);
078: assertEquals("Some random text, on a page\n", text[2]);
079:
080: // And the all-in fetch
081: String textS = extractor.getText();
082: assertEquals(
083: "Test View\nI am a test view\nSome random text, on a page\n",
084: textS);
085: }
086:
087: public void testMain() throws Exception {
088: PrintStream oldOut = System.out;
089: ByteArrayOutputStream baos = new ByteArrayOutputStream();
090: PrintStream capture = new PrintStream(baos);
091: System.setOut(capture);
092:
093: VisioTextExtractor.main(new String[] { filename });
094:
095: // Put things back
096: System.setOut(oldOut);
097:
098: // Check
099: capture.flush();
100: String text = baos.toString();
101: assertEquals(
102: "Test View\nI am a test view\nSome random text, on a page\n",
103: text);
104: }
105: }
|