diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 6506898626..175ed9c17a 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 48065 - Problems with save output of HWPF (losing formatting) 47563 - Exception when working with table 47287 - StringIndexOutOfBoundsException in CharacterRun.replaceText() 46817 - Regression: Text from some table cells missing diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java index f0664b3b03..38fba59fd7 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java @@ -691,6 +691,53 @@ public final class TestProblems extends HWPFTestCase { } } + /** + * [RESOLVED FIXED] Bug 48065 - Problems with save output of HWPF (losing + * formatting) + */ + public void test48065() + { + HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile( "Bug48065.doc" ); + HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack( doc1 ); + + Range expected = doc1.getRange(); + Range actual = doc2.getRange(); + + assertEquals( + expected.text().replace( "\r", "\n" ).replaceAll( "\n\n", "\n" ), + actual.text().replace( "\r", "\n" ).replaceAll( "\n\n", "\n" ) ); + + assertEquals( expected.numParagraphs(), actual.numParagraphs() ); + for ( int p = 0; p < expected.numParagraphs(); p++ ) + { + Paragraph expParagraph = expected.getParagraph( p ); + Paragraph actParagraph = actual.getParagraph( p ); + + assertEquals( expParagraph.text(), actParagraph.text() ); + assertEquals( expParagraph.isInTable(), actParagraph.isInTable() ); + assertEquals( expParagraph.isTableRowEnd(), + actParagraph.isTableRowEnd() ); + + if ( expParagraph.isInTable() && actParagraph.isInTable() ) + { + Table expTable, actTable; + try + { + expTable = expected.getTable( expParagraph ); + actTable = actual.getTable( actParagraph ); + } + catch ( Exception exc ) + { + continue; + } + + assertEquals( expTable.numRows(), actTable.numRows() ); + assertEquals( expTable.numParagraphs(), + actTable.numParagraphs() ); + } + } + } + /** * Bug 50936 - HWPF fails to read a file */ diff --git a/test-data/document/Bug48065.doc b/test-data/document/Bug48065.doc new file mode 100644 index 0000000000..8dce3dbdfb Binary files /dev/null and b/test-data/document/Bug48065.doc differ