Add testcase which tries to reproduce Bug 48495, but seems to be fixed

now.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1516981 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2013-08-23 18:56:11 +00:00
parent fb90b50dbf
commit f06e06ef12
4 changed files with 47 additions and 13 deletions

View 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.Font;
import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.RichTextString; 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.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples; 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("hello world", workbook.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
assertEquals(2048, workbook.getSheetAt(0).getColumnWidth(0)); // <-works 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");
}
} }

View File

@ -965,17 +965,4 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
HSSFWorkbook read = HSSFTestDataSamples.writeOutAndReadBack(wb); HSSFWorkbook read = HSSFTestDataSamples.writeOutAndReadBack(wb);
assertSheetOrder(read, "Invoice", "Deferred", "Received", "Digest"); 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());
}
}
} }

View File

@ -604,4 +604,17 @@ public abstract class BaseTestWorkbook extends TestCase {
assertEquals(cellB.getStringCellValue(), evaluator.evaluate(cellA).getStringValue()); 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());
}
}
} }

Binary file not shown.