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