]> source.dussan.org Git - poi.git/commitdiff
Add testcase which tries to reproduce Bug 48495, but seems to be fixed
authorDominik Stadler <centic@apache.org>
Fri, 23 Aug 2013 18:56:11 +0000 (18:56 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 23 Aug 2013 18:56:11 +0000 (18:56 +0000)
now.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1516981 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
test-data/spreadsheet/48495.xlsx [new file with mode: 0644]

index 96eaef5719ccd250e7dd57d2b5dedc8123de33f2..ec6ab237450fd6b33c111a83d28814a480380b8f 100644 (file)
@@ -37,7 +37,9 @@ import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Font;
 import org.apache.poi.ss.usermodel.IndexedColors;
 import org.apache.poi.ss.usermodel.RichTextString;
+import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.util.TempFile;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
@@ -494,4 +496,36 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
                assertEquals("hello world", workbook.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
                assertEquals(2048, workbook.getSheetAt(0).getColumnWidth(0)); // <-works
        }
+
+
+       public void testBug48495() {
+               try {
+                       Workbook wb = XSSFTestDataSamples.openSampleWorkbook("48495.xlsx");
+                       
+                       assertSheetOrder(wb, "Sheet1");
+                       
+                       Sheet sheet = wb.getSheetAt(0);
+                       sheet.shiftRows(2, sheet.getLastRowNum(), 1, true, false);
+                       Row newRow = sheet.getRow(2);
+                       if (newRow == null) newRow = sheet.createRow(2);
+                       newRow.createCell(0).setCellValue(" Another Header");
+                       wb.cloneSheet(0);
+
+                       assertSheetOrder(wb, "Sheet1", "Sheet1 (2)");
+
+                       //                  FileOutputStream fileOut = new FileOutputStream("/tmp/bug48495.xlsx");
+//                 try {
+//                     wb.write(fileOut);
+//                 } finally {
+//                     fileOut.close();
+//                 }
+                       
+                       Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
+                       assertNotNull(read);
+                       assertSheetOrder(read, "Sheet1", "Sheet1 (2)");
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+               System.out.println("Done");
+       }
 }
index 6d49827bf67fe1d62681888e2adf3f9d4af5742b..1927727e42efe585734688d3625921dbdf565528 100644 (file)
@@ -965,17 +965,4 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
                HSSFWorkbook read = HSSFTestDataSamples.writeOutAndReadBack(wb);
                assertSheetOrder(read, "Invoice", "Deferred", "Received", "Digest");
        }
-       
-       private void assertSheetOrder(HSSFWorkbook wb, String... sheets) {
-               StringBuilder sheetNames = new StringBuilder();
-               for(int i = 0;i < wb.getNumberOfSheets();i++) {
-                       sheetNames.append(wb.getSheetAt(i).getSheetName()).append(",");
-               }
-               assertEquals("Had: " + sheetNames.toString(), 
-                               sheets.length, wb.getNumberOfSheets());
-               for(int i = 0;i < wb.getNumberOfSheets();i++) {
-                       assertEquals("Had: " + sheetNames.toString(), 
-                                       sheets[i], wb.getSheetAt(i).getSheetName());
-               }
-       }
 }
index b2357f947e1612221771f63171eb87ca3b1eb9d2..ce96c3fe177f4b4e7f650c6b84a44ef388e19ff4 100644 (file)
@@ -604,4 +604,17 @@ public abstract class BaseTestWorkbook extends TestCase {
             assertEquals(cellB.getStringCellValue(), evaluator.evaluate(cellA).getStringValue());
         }
     }
+
+       protected void assertSheetOrder(Workbook wb, String... sheets) {
+               StringBuilder sheetNames = new StringBuilder();
+               for(int i = 0;i < wb.getNumberOfSheets();i++) {
+                       sheetNames.append(wb.getSheetAt(i).getSheetName()).append(",");
+               }
+               assertEquals("Had: " + sheetNames.toString(), 
+                               sheets.length, wb.getNumberOfSheets());
+               for(int i = 0;i < wb.getNumberOfSheets();i++) {
+                       assertEquals("Had: " + sheetNames.toString(), 
+                                       sheets[i], wb.getSheetAt(i).getSheetName());
+               }
+       }
 }
diff --git a/test-data/spreadsheet/48495.xlsx b/test-data/spreadsheet/48495.xlsx
new file mode 100644 (file)
index 0000000..73bc28b
Binary files /dev/null and b/test-data/spreadsheet/48495.xlsx differ