whitespace (tabs to 4 spaces)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749264 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-06-20 04:21:26 +00:00
parent 40727700f4
commit 7929adbf80
2 changed files with 114 additions and 114 deletions

View File

@ -44,115 +44,115 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
@Override @Override
@Test @Test
public void testShiftRowBreaks() { public void testShiftRowBreaks() {
// disabled test from superclass // disabled test from superclass
// TODO - support shifting of page breaks // TODO - support shifting of page breaks
} }
@Test @Test
public void testBug54524() throws IOException { public void testBug54524() throws IOException {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("54524.xlsx"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("54524.xlsx");
XSSFSheet sheet = workbook.getSheetAt(0); XSSFSheet sheet = workbook.getSheetAt(0);
sheet.shiftRows(3, 5, -1); sheet.shiftRows(3, 5, -1);
Cell cell = CellUtil.getCell(sheet.getRow(1), 0); Cell cell = CellUtil.getCell(sheet.getRow(1), 0);
assertEquals(1.0, cell.getNumericCellValue(), 0); assertEquals(1.0, cell.getNumericCellValue(), 0);
cell = CellUtil.getCell(sheet.getRow(2), 0); cell = CellUtil.getCell(sheet.getRow(2), 0);
assertEquals("SUM(A2:A2)", cell.getCellFormula()); assertEquals("SUM(A2:A2)", cell.getCellFormula());
cell = CellUtil.getCell(sheet.getRow(3), 0); cell = CellUtil.getCell(sheet.getRow(3), 0);
assertEquals("X", cell.getStringCellValue()); assertEquals("X", cell.getStringCellValue());
workbook.close(); workbook.close();
} }
@Test @Test
public void testBug53798() throws IOException { public void testBug53798() throws IOException {
// NOTE that for HSSF (.xls) negative shifts combined with positive ones do work as expected // NOTE that for HSSF (.xls) negative shifts combined with positive ones do work as expected
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx");
Sheet testSheet = wb.getSheetAt(0); Sheet testSheet = wb.getSheetAt(0);
// 1) corrupted xlsx (unreadable data in the first row of a shifted group) already comes about // 1) corrupted xlsx (unreadable data in the first row of a shifted group) already comes about
// when shifted by less than -1 negative amount (try -2) // when shifted by less than -1 negative amount (try -2)
testSheet.shiftRows(3, 3, -2); testSheet.shiftRows(3, 3, -2);
Row newRow = null; Cell newCell = null; Row newRow = null; Cell newCell = null;
// 2) attempt to create a new row IN PLACE of a removed row by a negative shift causes corrupted // 2) attempt to create a new row IN PLACE of a removed row by a negative shift causes corrupted
// xlsx file with unreadable data in the negative shifted row. // xlsx file with unreadable data in the negative shifted row.
// NOTE it's ok to create any other row. // NOTE it's ok to create any other row.
newRow = testSheet.createRow(3); newRow = testSheet.createRow(3);
newCell = newRow.createCell(0); newCell = newRow.createCell(0);
newCell.setCellValue("new Cell in row "+newRow.getRowNum()); newCell.setCellValue("new Cell in row "+newRow.getRowNum());
// 3) once a negative shift has been made any attempt to shift another group of rows // 3) once a negative shift has been made any attempt to shift another group of rows
// (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception: // (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception:
// org.apache.xmlbeans.impl.values.XmlValueDisconnectedException. // org.apache.xmlbeans.impl.values.XmlValueDisconnectedException.
// NOTE: another negative shift on another group of rows is successful, provided no new rows in // NOTE: another negative shift on another group of rows is successful, provided no new rows in
// place of previously shifted rows were attempted to be created as explained above. // place of previously shifted rows were attempted to be created as explained above.
// -- CHANGE the shift to positive once the behaviour of the above has been tested // -- CHANGE the shift to positive once the behaviour of the above has been tested
testSheet.shiftRows(6, 7, 1); testSheet.shiftRows(6, 7, 1);
Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb); Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
wb.close(); wb.close();
assertNotNull(read); assertNotNull(read);
Sheet readSheet = read.getSheetAt(0); Sheet readSheet = read.getSheetAt(0);
verifyCellContent(readSheet, 0, "0.0"); verifyCellContent(readSheet, 0, "0.0");
verifyCellContent(readSheet, 1, "3.0"); verifyCellContent(readSheet, 1, "3.0");
verifyCellContent(readSheet, 2, "2.0"); verifyCellContent(readSheet, 2, "2.0");
verifyCellContent(readSheet, 3, "new Cell in row 3"); verifyCellContent(readSheet, 3, "new Cell in row 3");
verifyCellContent(readSheet, 4, "4.0"); verifyCellContent(readSheet, 4, "4.0");
verifyCellContent(readSheet, 5, "5.0"); verifyCellContent(readSheet, 5, "5.0");
verifyCellContent(readSheet, 6, null); verifyCellContent(readSheet, 6, null);
verifyCellContent(readSheet, 7, "6.0"); verifyCellContent(readSheet, 7, "6.0");
verifyCellContent(readSheet, 8, "7.0"); verifyCellContent(readSheet, 8, "7.0");
read.close(); read.close();
} }
private void verifyCellContent(Sheet readSheet, int row, String expect) { private void verifyCellContent(Sheet readSheet, int row, String expect) {
Row readRow = readSheet.getRow(row); Row readRow = readSheet.getRow(row);
if(expect == null) { if(expect == null) {
assertNull(readRow); assertNull(readRow);
return; return;
}
Cell readCell = readRow.getCell(0);
if(readCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
assertEquals(expect, Double.toString(readCell.getNumericCellValue()));
} else {
assertEquals(expect, readCell.getStringCellValue());
}
}
@Test
public void testBug53798a() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx");
Sheet testSheet = wb.getSheetAt(0);
testSheet.shiftRows(3, 3, -1);
for (Row r : testSheet) {
r.getRowNum();
} }
testSheet.shiftRows(6, 6, 1); Cell readCell = readRow.getCell(0);
if(readCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
assertEquals(expect, Double.toString(readCell.getNumericCellValue()));
} else {
assertEquals(expect, readCell.getStringCellValue());
}
}
Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb); @Test
wb.close(); public void testBug53798a() throws IOException {
assertNotNull(read); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx");
Sheet readSheet = read.getSheetAt(0); Sheet testSheet = wb.getSheetAt(0);
verifyCellContent(readSheet, 0, "0.0"); testSheet.shiftRows(3, 3, -1);
verifyCellContent(readSheet, 1, "1.0"); for (Row r : testSheet) {
verifyCellContent(readSheet, 2, "3.0"); r.getRowNum();
verifyCellContent(readSheet, 3, null); }
verifyCellContent(readSheet, 4, "4.0"); testSheet.shiftRows(6, 6, 1);
verifyCellContent(readSheet, 5, "5.0");
verifyCellContent(readSheet, 6, null);
verifyCellContent(readSheet, 7, "6.0");
verifyCellContent(readSheet, 8, "8.0");
read.close();
}
@Test Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
public void testBug56017() throws IOException { wb.close();
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56017.xlsx"); assertNotNull(read);
Sheet readSheet = read.getSheetAt(0);
verifyCellContent(readSheet, 0, "0.0");
verifyCellContent(readSheet, 1, "1.0");
verifyCellContent(readSheet, 2, "3.0");
verifyCellContent(readSheet, 3, null);
verifyCellContent(readSheet, 4, "4.0");
verifyCellContent(readSheet, 5, "5.0");
verifyCellContent(readSheet, 6, null);
verifyCellContent(readSheet, 7, "6.0");
verifyCellContent(readSheet, 8, "8.0");
read.close();
}
@Test
public void testBug56017() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56017.xlsx");
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
@ -189,11 +189,11 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
assertEquals("Amdocs", comment.getAuthor()); assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString()); assertEquals("Amdocs:\ntest\n", comment.getString().getString());
wbBack.close(); wbBack.close();
} }
@Test @Test
public void test57171() throws IOException { public void test57171() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
assertEquals(5, wb.getActiveSheetIndex()); assertEquals(5, wb.getActiveSheetIndex());
removeAllSheetsBut(5, wb); // 5 is the active / selected sheet removeAllSheetsBut(5, wb); // 5 is the active / selected sheet
assertEquals(0, wb.getActiveSheetIndex()); assertEquals(0, wb.getActiveSheetIndex());
@ -208,7 +208,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
wbRead.close(); wbRead.close();
} }
@Test @Test
public void test57163() throws IOException { public void test57163() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
assertEquals(5, wb.getActiveSheetIndex()); assertEquals(5, wb.getActiveSheetIndex());
@ -218,7 +218,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
wb.close(); wb.close();
} }
@Test @Test
public void testSetSheetOrderAndAdjustActiveSheet() throws IOException { public void testSetSheetOrderAndAdjustActiveSheet() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
@ -268,7 +268,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
wb.close(); wb.close();
} }
@Test @Test
public void testRemoveSheetAndAdjustActiveSheet() throws IOException { public void testRemoveSheetAndAdjustActiveSheet() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
@ -312,7 +312,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
wb.close(); wb.close();
} }
@Test @Test
public void test57165() throws IOException { public void test57165() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
assertEquals(5, wb.getActiveSheetIndex()); assertEquals(5, wb.getActiveSheetIndex());

View File

@ -123,7 +123,7 @@ public abstract class BaseTestSheetShiftRows {
@Test @Test
public final void testShiftRow() throws IOException { public final void testShiftRow() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet(); Sheet s = wb.createSheet();
s.createRow(0).createCell(0).setCellValue("TEST1"); s.createRow(0).createCell(0).setCellValue("TEST1");
s.createRow(3).createCell(0).setCellValue("TEST2"); s.createRow(3).createCell(0).setCellValue("TEST2");
s.shiftRows(0,4,1); s.shiftRows(0,4,1);
@ -136,7 +136,7 @@ public abstract class BaseTestSheetShiftRows {
@Test @Test
public final void testActiveCell() throws IOException { public final void testActiveCell() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet(); Sheet s = wb.createSheet();
s.createRow(0).createCell(0).setCellValue("TEST1"); s.createRow(0).createCell(0).setCellValue("TEST1");
s.createRow(3).createCell(0).setCellValue("TEST2"); s.createRow(3).createCell(0).setCellValue("TEST2");
@ -150,7 +150,7 @@ public abstract class BaseTestSheetShiftRows {
@Test @Test
public void testShiftRowBreaks() throws IOException { // TODO - enable XSSF test public void testShiftRowBreaks() throws IOException { // TODO - enable XSSF test
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet(); Sheet s = wb.createSheet();
Row row = s.createRow(4); Row row = s.createRow(4);
row.createCell(0).setCellValue("test"); row.createCell(0).setCellValue("test");
s.setRowBreak(4); s.setRowBreak(4);
@ -228,13 +228,13 @@ public abstract class BaseTestSheetShiftRows {
// TODO: it seems HSSFSheet does not correctly remove comments from rows that are overwritten // TODO: it seems HSSFSheet does not correctly remove comments from rows that are overwritten
// by shifting rows... // by shifting rows...
if(!(wb2 instanceof HSSFWorkbook)) { if(!(wb2 instanceof HSSFWorkbook)) {
assertEquals(2, sheet.getLastRowNum()); assertEquals(2, sheet.getLastRowNum());
// Verify comments are in the position expected // Verify comments are in the position expected
assertNull("Had: " + (sheet.getCellComment(new CellAddress(0,0)) == null ? "null" : sheet.getCellComment(new CellAddress(0,0)).getString()), assertNull("Had: " + (sheet.getCellComment(new CellAddress(0,0)) == null ? "null" : sheet.getCellComment(new CellAddress(0,0)).getString()),
sheet.getCellComment(new CellAddress(0,0))); sheet.getCellComment(new CellAddress(0,0)));
assertNotNull(sheet.getCellComment(new CellAddress(1,0))); assertNotNull(sheet.getCellComment(new CellAddress(1,0)));
assertNotNull(sheet.getCellComment(new CellAddress(2,0))); assertNotNull(sheet.getCellComment(new CellAddress(2,0)));
} }
comment1 = sheet.getCellComment(new CellAddress(1,0)).getString().getString(); comment1 = sheet.getCellComment(new CellAddress(1,0)).getString().getString();
@ -293,7 +293,7 @@ public abstract class BaseTestSheetShiftRows {
@Test @Test
public final void testShiftWithMergedRegions() throws IOException { public final void testShiftWithMergedRegions() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet(); Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0); Row row = sheet.createRow(0);
row.createCell(0).setCellValue(1.1); row.createCell(0).setCellValue(1.1);
row.createCell(1).setCellValue(2.2); row.createCell(1).setCellValue(2.2);
@ -481,7 +481,7 @@ public abstract class BaseTestSheetShiftRows {
} }
@Test @Test
public void testBug55280() throws IOException { public void testBug55280() throws IOException {
Workbook w = _testDataProvider.createWorkbook(); Workbook w = _testDataProvider.createWorkbook();
Sheet s = w.createSheet(); Sheet s = w.createSheet();
for (int row = 0; row < 5000; ++row) for (int row = 0; row < 5000; ++row)
@ -489,7 +489,7 @@ public abstract class BaseTestSheetShiftRows {
s.shiftRows(0, 4999, 1); // takes a long time... s.shiftRows(0, 4999, 1); // takes a long time...
w.close(); w.close();
} }
@Test @Test
public void test47169() throws IOException { public void test47169() throws IOException {