From: Nick Burch Date: Sat, 9 Aug 2008 19:56:37 +0000 (+0000) Subject: Get most of the hwpf tests passing again X-Git-Tag: REL_3_2_FINAL~178 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7411759977a036551993743a89ab0a78d64bc302;p=poi.git Get most of the hwpf tests passing again git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@684322 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java b/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java index 85009459d7..d73aa337c0 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java @@ -128,7 +128,7 @@ public class WordExtractor extends POIOLE2TextExtractor { TextPiece piece = (TextPiece) textPieces.next(); String encoding = "Cp1252"; - if (piece.usesUnicode()) { + if (piece.isUnicode()) { encoding = "UTF-16LE"; } try { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java index 2512463276..7b9c23325f 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java @@ -104,7 +104,6 @@ public class SectionTable } int FC = TP.getPieceDescriptor().getFilePosition(); int offset = CP - TP.getCP(); - if(TP.usesUnicode()) offset*=2; FC = FC+offset-((TextPiece)_text.get(0)).getPieceDescriptor().getFilePosition(); return FC; } @@ -120,12 +119,12 @@ public class SectionTable if (fc <= piece.getEnd()) { - cp += ((fc - piece.getStart())/ (piece.usesUnicode() ? 2 : 1)); + cp += (fc - piece.getStart()); break; } else { - cp += ((piece.getEnd() - piece.getStart())/ (piece.usesUnicode() ? 2 : 1)); + cp += (piece.getEnd() - piece.getStart()); } } return cp; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java index f326e59b88..351c06ae74 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java @@ -73,9 +73,9 @@ public class TextPiece extends PropertyNode implements Comparable } /** - * @return If this text piece uses unicode + * @return If this text piece is unicode */ - public boolean usesUnicode() + public boolean isUnicode() { return _usesUnicode; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java index 9838f9ef21..c37e9be98a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java @@ -239,7 +239,7 @@ public class Range for (int i = _textStart; i < _textEnd; i++) { TextPiece piece = (TextPiece)_text.get(i); - if (piece.usesUnicode()) + if (piece.isUnicode()) return true; } @@ -332,8 +332,6 @@ public class Range // Since this is the first item in our list, it is safe to assume that // _start >= tp.getStart() int insertIndex = _start - tp.getStart(); - if (tp.usesUnicode()) - insertIndex /= 2; sb.insert(insertIndex, text); int adjustedLength = _doc.getTextTable().adjustForInsert(_textStart, text.length()); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java index ae8c8d6b26..786fc807db 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java @@ -87,7 +87,7 @@ public class TestDifferentRoutes extends TestCase { TextPiece piece = (TextPiece) textPieces.next(); String encoding = "Cp1252"; - if (piece.usesUnicode()) { + if (piece.isUnicode()) { encoding = "UTF-16LE"; } String text = new String(piece.getRawBytes(), encoding); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java index eef4f0d5eb..4595c4ce0e 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java @@ -118,9 +118,9 @@ public class TestTextPieceTable extends TestCase { TextPiece tpB = (TextPiece)tbl.getTextPieces().get(1); TextPiece tpC = (TextPiece)tbl.getTextPieces().get(2); - assertTrue(tpA.usesUnicode()); - assertTrue(tpB.usesUnicode()); - assertTrue(tpC.usesUnicode()); + assertTrue(tpA.isUnicode()); + assertTrue(tpB.isUnicode()); + assertTrue(tpC.isUnicode()); assertEquals(256, tpA.characterLength()); assertEquals(256, tpB.characterLength()); @@ -147,9 +147,9 @@ public class TestTextPieceTable extends TestCase { tpB = (TextPiece)tbl.getTextPieces().get(1); tpC = (TextPiece)tbl.getTextPieces().get(2); - assertTrue(tpA.usesUnicode()); - assertTrue(tpB.usesUnicode()); - assertTrue(tpC.usesUnicode()); + assertTrue(tpA.isUnicode()); + assertTrue(tpB.isUnicode()); + assertTrue(tpC.isUnicode()); assertEquals(256, tpA.characterLength()); assertEquals(256, tpB.characterLength()); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java new file mode 100644 index 0000000000..6c841e87a3 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java @@ -0,0 +1,82 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.hwpf.usermodel; + +import java.io.File; +import java.io.FileInputStream; + +import org.apache.poi.hwpf.HWPFDocFixture; +import org.apache.poi.hwpf.HWPFDocument; + +import junit.framework.TestCase; + +/** + * Tests to ensure that our ranges end up with + * the right text in them, and the right font/styling + * properties applied to them. + */ +public class TestRangeProperties extends TestCase { + private static final char page_break = (char)12; + + private static final String u_page_1 = + "This is a fairly simple word document, over two pages, with headers and footers.\r" + + "The trick with this one is that it contains some Unicode based strings in it.\r" + + "Firstly, some currency symbols:\r" + + "\tGBP - \u00a3\r" + + "\tEUR - \u20ac\r" + + "Now, we\u2019ll have some French text, in bold and big:\r" + + "\tMoli\u00e8re\r" + + "And some normal French text:\r" + + "\tL'Avare ou l'\u00c9cole du mensonge\r" + + "That\u2019s it for page one\r" + ; + private static final String u_page_2 = + "This is page two. Les Pr\u00e9cieuses ridicules. The end.\r" + ; + + private HWPFDocument u; + // TODO - a non unicode document too + + private String dirname; + + protected void setUp() throws Exception { + dirname = System.getProperty("HWPF.testdata.path"); + u = new HWPFDocument( + new FileInputStream(new File(dirname, "HeaderFooterUnicode.doc")) + ); + } + + public void testUnicodeTextParagraphs() throws Exception { + Range r = u.getRange(); + assertEquals( + u_page_1 + + page_break + "\r" + + u_page_2, + r.text() + ); + + assertEquals( + 5, + r.numParagraphs() + ); + + System.out.println(r.getParagraph(2).text()); + } + public void testUnicodeStyling() throws Exception { + + } +}