unfinished release guide. It would be nice to have a html version.
[poi.git] / src / scratchpad / ooxml-testcases / org / apache / poi / hwpf / extractor / TestHXFWordExtractor.java
blob62695b3a8c3d62181f93b29db14e75bebcd70c45
1 /* ====================================================================
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 ==================================================================== */
17 package org.apache.poi.hwpf.extractor;
19 import java.io.File;
21 import org.apache.poi.hwpf.HWPFXML;
22 import org.apache.poi.hwpf.usermodel.HWPFXMLDocument;
23 import org.apache.poi.hxf.HXFDocument;
25 import junit.framework.TestCase;
27 /**
28 * Tests for HXFWordExtractor
30 public class TestHXFWordExtractor extends TestCase {
31 /**
32 * A very simple file
34 private HWPFXML xmlA;
35 /**
36 * A fairly complex file
38 private HWPFXML xmlB;
40 protected void setUp() throws Exception {
41 super.setUp();
43 File fileA = new File(
44 System.getProperty("HWPF.testdata.path") +
45 File.separator + "sample.docx"
47 File fileB = new File(
48 System.getProperty("HWPF.testdata.path") +
49 File.separator + "IllustrativeCases.docx"
52 xmlA = new HWPFXML(HXFDocument.openPackage(fileA));
53 xmlB = new HWPFXML(HXFDocument.openPackage(fileB));
56 /**
57 * Get text out of the simple file
59 public void testGetSimpleText() throws Exception {
60 new HXFWordExtractor(xmlA.getPackage());
61 new HXFWordExtractor(new HWPFXMLDocument(xmlA));
63 HXFWordExtractor extractor =
64 new HXFWordExtractor(xmlA.getPackage());
65 extractor.getText();
67 String text = extractor.getText();
68 assertTrue(text.length() > 0);
70 // Check contents
71 assertTrue(text.startsWith(
72 "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nunc at risus vel erat tempus posuere. Aenean non ante. Suspendisse vehicula dolor sit amet odio."
73 ));
74 assertTrue(text.endsWith(
75 "Phasellus ultricies mi nec leo. Sed tempus. In sit amet lorem at velit faucibus vestibulum.\n"
76 ));
78 // Check number of paragraphs
79 int ps = 0;
80 char[] t = text.toCharArray();
81 for (int i = 0; i < t.length; i++) {
82 if(t[i] == '\n') { ps++; }
84 assertEquals(3, ps);
87 /**
88 * Tests getting the text out of a complex file
90 public void testGetComplexText() throws Exception {
91 HXFWordExtractor extractor =
92 new HXFWordExtractor(xmlB.getPackage());
93 extractor.getText();
95 String text = extractor.getText();
96 assertTrue(text.length() > 0);
98 char euro = '\u20ac';
99 System.err.println("'"+text.substring(text.length() - 20) + "'");
101 // Check contents
102 assertTrue(text.startsWith(
103 " \n(V) ILLUSTRATIVE CASES\n\n"
105 assertTrue(text.endsWith(
106 "As well as gaining "+euro+"90 from child benefit increases, he will also receive the early childhood supplement of "+euro+"250 per quarter for Vincent for the full four quarters of the year.\n\n\n\n \n\n\n"
109 // Check number of paragraphs
110 int ps = 0;
111 char[] t = text.toCharArray();
112 for (int i = 0; i < t.length; i++) {
113 if(t[i] == '\n') { ps++; }
115 assertEquals(79, ps);