From 7be1716674db2c4092e267646be2a6f460e7073a Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Tue, 5 Jul 2011 01:19:31 +0000 Subject: [PATCH] Test correct processing of "sprmPItap" (0x6649) and "sprmPFInTable" (0x2416) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1142867 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hwpf/sprm/TestSprms.java | 72 +++++++++++++----- test-data/document/innertable.doc | Bin 0 -> 11776 bytes 2 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 test-data/document/innertable.doc diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java b/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java index 3bd0309d8d..bc00b2ffd4 100755 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java @@ -27,35 +27,73 @@ import java.io.InputStream; import junit.framework.TestCase; import org.apache.poi.POIDataSamples; import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.usermodel.Paragraph; +import org.apache.poi.hwpf.usermodel.Range; + +public class TestSprms extends TestCase +{ + private static HWPFDocument reload( HWPFDocument hwpfDocument ) + throws IOException + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + hwpfDocument.write( baos ); + return new HWPFDocument( new ByteArrayInputStream( baos.toByteArray() ) ); + } -public class TestSprms extends TestCase { /** - * Test correct processing of "sprmPJc" by uncompressor + * Test correct processing of "sprmPItap" (0x6649) and "sprmPFInTable" + * (0x2416) */ - public void testSprmPJc() throws IOException { + public void testInnerTable() throws Exception + { InputStream resourceAsStream = POIDataSamples.getDocumentInstance() - .openResourceAsStream("Bug49820.doc"); - HWPFDocument hwpfDocument = new HWPFDocument(resourceAsStream); - assertEquals(1, hwpfDocument.getStyleSheet().getParagraphStyle(8) - .getJustification()); + .openResourceAsStream( "innertable.doc" ); + HWPFDocument hwpfDocument = new HWPFDocument( resourceAsStream ); resourceAsStream.close(); + + testInnerTable( hwpfDocument ); + hwpfDocument = reload( hwpfDocument ); + testInnerTable( hwpfDocument ); + } + + private void testInnerTable( HWPFDocument hwpfDocument ) + { + Range range = hwpfDocument.getRange(); + for ( int p = 0; p < range.numParagraphs(); p++ ) + { + Paragraph paragraph = range.getParagraph( p ); + char first = paragraph.text().toLowerCase().charAt( 0 ); + if ( '1' <= first && first < '4' ) + { + assertTrue( paragraph.isInTable() ); + assertEquals( 2, paragraph.getTableLevel() ); + } + + if ( 'a' <= first && first < 'z' ) + { + assertTrue( paragraph.isInTable() ); + assertEquals( 1, paragraph.getTableLevel() ); + } + } } /** - * Test correct processing of "sprmPJc" by compressor and uncompressor + * Test correct processing of "sprmPJc" by uncompressor */ - public void testSprmPJcResave() throws IOException { + public void testSprmPJc() throws IOException + { InputStream resourceAsStream = POIDataSamples.getDocumentInstance() - .openResourceAsStream("Bug49820.doc"); - HWPFDocument hwpfDocument = new HWPFDocument(resourceAsStream); + .openResourceAsStream( "Bug49820.doc" ); + HWPFDocument hwpfDocument = new HWPFDocument( resourceAsStream ); resourceAsStream.close(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - hwpfDocument.write(baos); - hwpfDocument = new HWPFDocument( - new ByteArrayInputStream(baos.toByteArray())); + assertEquals( 1, hwpfDocument.getStyleSheet().getParagraphStyle( 8 ) + .getJustification() ); + + hwpfDocument = reload( hwpfDocument ); + + assertEquals( 1, hwpfDocument.getStyleSheet().getParagraphStyle( 8 ) + .getJustification() ); - assertEquals(1, hwpfDocument.getStyleSheet().getParagraphStyle(8) - .getJustification()); } } diff --git a/test-data/document/innertable.doc b/test-data/document/innertable.doc new file mode 100644 index 0000000000000000000000000000000000000000..e437a5fd162ecc42a0326575d7232121421bdcce GIT binary patch literal 11776 zcmeHNTWnNC82)GX>~^=5UY1hYa_Lf*OAtzL3tK7BZc8akq2-cbB5GRNrYP+~FAgLlxt^K*{kO8)SHG$LQ_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