--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.hwpf.usermodel;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.poi.hwpf.HWPFDocument;\r
+import org.apache.poi.hwpf.HWPFTestDataSamples;\r
+\r
+/**\r
+ * Bug 47563 - Exception when working with table \r
+ */\r
+public class TestBug47563 extends TestCase {\r
+\r
+ public void test() throws Exception {\r
+ test(1, 5);\r
+ test(1, 6);\r
+ test(5, 1);\r
+ test(6, 1);\r
+ test(2, 2);\r
+ test(3, 2);\r
+ test(2, 3);\r
+ test(3, 3);\r
+ }\r
+\r
+ private void test(int rows, int columns) throws Exception {\r
+ // POI apparently can't create a document from scratch,\r
+ // so we need an existing empty dummy document\r
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile("empty.doc");\r
+\r
+ Range range = doc.getRange();\r
+ range.sanityCheck();\r
+\r
+ Table table = range.insertTableBefore((short) columns, rows);\r
+ table.sanityCheck();\r
+\r
+ for (int rowIdx = 0; rowIdx < table.numRows(); rowIdx++) {\r
+ TableRow row = table.getRow(rowIdx);\r
+ row.sanityCheck();\r
+\r
+ System.out.println("row " + rowIdx);\r
+ for (int colIdx = 0; colIdx < row.numCells(); colIdx++) {\r
+ TableCell cell = row.getCell(colIdx);\r
+ cell.sanityCheck();\r
+\r
+ System.out.println("column " + colIdx + ", num paragraphs "\r
+ + cell.numParagraphs());\r
+\r
+ Paragraph par = cell.getParagraph(0);\r
+ par.sanityCheck();\r
+\r
+ par.insertBefore("" + (rowIdx * row.numCells() + colIdx));\r
+ par.sanityCheck();\r
+\r
+ row.sanityCheck();\r
+ table.sanityCheck();\r
+ range.sanityCheck();\r
+\r
+ }\r
+ }\r
+\r
+ String text = range.text();\r
+ int mustBeAfter = 0;\r
+ for (int i = 0; i < rows * columns; i++) {\r
+ int next = text.indexOf(Integer.toString(i), mustBeAfter);\r
+ assertFalse(next == -1);\r
+ mustBeAfter = next;\r
+ }\r
+ }\r
+\r
+\r
+}\r
+ "Please resolve the issue in Bugzilla and remove fail() from the test" );
}
- private static void test47563_insertTable( int rows, int columns )
- {
- // POI apparently can't create a document from scratch,
- // so we need an existing empty dummy document
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "empty.doc" );
-
- Range range = doc.getRange();
- Table table = range.insertTableBefore( (short) columns, rows );
- table.sanityCheck();
- range.sanityCheck();
-
- for ( int rowIdx = 0; rowIdx < table.numRows(); rowIdx++ )
- {
- TableRow row = table.getRow( rowIdx );
- row.sanityCheck();
- for ( int colIdx = 0; colIdx < row.numCells(); colIdx++ )
- {
- TableCell cell = row.getCell( colIdx );
- cell.sanityCheck();
-
- Paragraph par = cell.getParagraph( 0 );
- par.sanityCheck();
-
- par.insertBefore( "" + ( rowIdx * row.numCells() + colIdx ) );
-
- par.sanityCheck();
- cell.sanityCheck();
- row.sanityCheck();
- table.sanityCheck();
- range.sanityCheck();
- }
- }
-
- String text = range.text();
- int mustBeAfter = 0;
- for ( int i = 0; i < rows * columns; i++ )
- {
- int next = text.indexOf( Integer.toString( i ), mustBeAfter );
- assertFalse( next == -1 );
- mustBeAfter = next;
- }
- }
-
/**
* Bug 33519 - HWPF fails to read a file
*/
assertFalse( docText.contains( "1-15" ) );
}
- /**
- * [RESOLVED FIXED] Bug 47563 - Exception when working with table
- */
- public void test47563()
- {
- test47563_insertTable( 1, 5 );
- test47563_insertTable( 1, 6 );
- test47563_insertTable( 5, 1 );
- test47563_insertTable( 6, 1 );
- test47563_insertTable( 2, 2 );
- test47563_insertTable( 3, 2 );
- test47563_insertTable( 2, 3 );
- test47563_insertTable( 3, 3 );
- }
-
/**
* [RESOLVED FIXED] Bug 47731 - Word Extractor considers text copied from
* some website as an embedded object