mirror of https://github.com/apache/poi.git
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:
parent
fb90b50dbf
commit
f06e06ef12
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue