]> source.dussan.org Git - poi.git/commitdiff
Test correct processing of "sprmPItap" (0x6649) and "sprmPFInTable" (0x2416)
authorSergey Vladimirov <sergey@apache.org>
Tue, 5 Jul 2011 01:19:31 +0000 (01:19 +0000)
committerSergey Vladimirov <sergey@apache.org>
Tue, 5 Jul 2011 01:19:31 +0000 (01:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1142867 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/testcases/org/apache/poi/hwpf/sprm/TestSprms.java
test-data/document/innertable.doc [new file with mode: 0644]

index 3bd0309d8d6f12d187a634f65ffcac7cfb0db588..bc00b2ffd47c1692e5132cce3bdee76a115b5aa2 100755 (executable)
@@ -27,35 +27,73 @@ import java.io.InputStream;
 import junit.framework.TestCase;\r
 import org.apache.poi.POIDataSamples;\r
 import org.apache.poi.hwpf.HWPFDocument;\r
+import org.apache.poi.hwpf.usermodel.Paragraph;\r
+import org.apache.poi.hwpf.usermodel.Range;\r
+\r
+public class TestSprms extends TestCase\r
+{\r
+    private static HWPFDocument reload( HWPFDocument hwpfDocument )\r
+            throws IOException\r
+    {\r
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
+        hwpfDocument.write( baos );\r
+        return new HWPFDocument( new ByteArrayInputStream( baos.toByteArray() ) );\r
+    }\r
 \r
-public class TestSprms extends TestCase {\r
     /**\r
-     * Test correct processing of "sprmPJc" by uncompressor\r
+     * Test correct processing of "sprmPItap" (0x6649) and "sprmPFInTable"\r
+     * (0x2416)\r
      */\r
-    public void testSprmPJc() throws IOException {\r
+    public void testInnerTable() throws Exception\r
+    {\r
         InputStream resourceAsStream = POIDataSamples.getDocumentInstance()\r
-                .openResourceAsStream("Bug49820.doc");\r
-        HWPFDocument hwpfDocument = new HWPFDocument(resourceAsStream);\r
-        assertEquals(1, hwpfDocument.getStyleSheet().getParagraphStyle(8)\r
-                .getJustification());\r
+                .openResourceAsStream( "innertable.doc" );\r
+        HWPFDocument hwpfDocument = new HWPFDocument( resourceAsStream );\r
         resourceAsStream.close();\r
+\r
+        testInnerTable( hwpfDocument );\r
+        hwpfDocument = reload( hwpfDocument );\r
+        testInnerTable( hwpfDocument );\r
+    }\r
+\r
+    private void testInnerTable( HWPFDocument hwpfDocument )\r
+    {\r
+        Range range = hwpfDocument.getRange();\r
+        for ( int p = 0; p < range.numParagraphs(); p++ )\r
+        {\r
+            Paragraph paragraph = range.getParagraph( p );\r
+            char first = paragraph.text().toLowerCase().charAt( 0 );\r
+            if ( '1' <= first && first < '4' )\r
+            {\r
+                assertTrue( paragraph.isInTable() );\r
+                assertEquals( 2, paragraph.getTableLevel() );\r
+            }\r
+\r
+            if ( 'a' <= first && first < 'z' )\r
+            {\r
+                assertTrue( paragraph.isInTable() );\r
+                assertEquals( 1, paragraph.getTableLevel() );\r
+            }\r
+        }\r
     }\r
 \r
     /**\r
-     * Test correct processing of "sprmPJc" by compressor and uncompressor\r
+     * Test correct processing of "sprmPJc" by uncompressor\r
      */\r
-    public void testSprmPJcResave() throws IOException {\r
+    public void testSprmPJc() throws IOException\r
+    {\r
         InputStream resourceAsStream = POIDataSamples.getDocumentInstance()\r
-                .openResourceAsStream("Bug49820.doc");\r
-        HWPFDocument hwpfDocument = new HWPFDocument(resourceAsStream);\r
+                .openResourceAsStream( "Bug49820.doc" );\r
+        HWPFDocument hwpfDocument = new HWPFDocument( resourceAsStream );\r
         resourceAsStream.close();\r
 \r
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
-        hwpfDocument.write(baos);\r
-        hwpfDocument = new HWPFDocument(\r
-                new ByteArrayInputStream(baos.toByteArray()));\r
+        assertEquals( 1, hwpfDocument.getStyleSheet().getParagraphStyle( 8 )\r
+                .getJustification() );\r
+\r
+        hwpfDocument = reload( hwpfDocument );\r
+\r
+        assertEquals( 1, hwpfDocument.getStyleSheet().getParagraphStyle( 8 )\r
+                .getJustification() );\r
 \r
-        assertEquals(1, hwpfDocument.getStyleSheet().getParagraphStyle(8)\r
-                .getJustification());\r
     }\r
 }\r
diff --git a/test-data/document/innertable.doc b/test-data/document/innertable.doc
new file mode 100644 (file)
index 0000000..e437a5f
Binary files /dev/null and b/test-data/document/innertable.doc differ