mirror of https://github.com/apache/poi.git
Clean-up in BaseTestSheetShiftRows and subclasses.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@893909 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f52ca0eba5
commit
136e09be84
|
@ -18,46 +18,22 @@
|
||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
|
import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
|
||||||
import org.apache.poi.ss.ITestDataProvider;
|
|
||||||
import org.apache.poi.xssf.XSSFITestDataProvider;
|
import org.apache.poi.xssf.XSSFITestDataProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public final class TestSheetShiftRows extends BaseTestSheetShiftRows {
|
public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
|
||||||
|
|
||||||
@Override
|
public TestXSSFSheetShiftRows(){
|
||||||
protected ITestDataProvider getTestDataProvider(){
|
super(XSSFITestDataProvider.instance);
|
||||||
return XSSFITestDataProvider.getInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShiftRows() {
|
public void testShiftRowBreaks() { // disabled test from superclass
|
||||||
baseTestShiftRows("SimpleMultiCell.xlsx");
|
// TODO - support shifting of page breaks
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShiftRow() {
|
public void testShiftWithComments() { // disabled test from superclass
|
||||||
baseTestShiftRow();
|
// TODO - support shifting of comments.
|
||||||
}
|
|
||||||
|
|
||||||
public void testShiftNames() {
|
|
||||||
baseTestShiftWithNames();
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO support shifting of page breaks
|
|
||||||
public void $testShiftRowBreaks() {
|
|
||||||
baseTestShiftRowBreaks();
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO support shifting of comments.
|
|
||||||
public void $testShiftWithComments() {
|
|
||||||
baseTestShiftWithComments("comments.xlsx");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testShiftWithFormulas() {
|
|
||||||
baseTestShiftWithFormulas("ForShifting.xlsx");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testShiftWithMergedRegions() {
|
|
||||||
baseTestShiftWithMergedRegions();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -66,7 +66,7 @@ public class AllUserModelTests {
|
||||||
result.addTestSuite(TestReadWriteChart.class);
|
result.addTestSuite(TestReadWriteChart.class);
|
||||||
result.addTestSuite(TestSanityChecker.class);
|
result.addTestSuite(TestSanityChecker.class);
|
||||||
result.addTestSuite(TestSheetHiding.class);
|
result.addTestSuite(TestSheetHiding.class);
|
||||||
result.addTestSuite(TestSheetShiftRows.class);
|
result.addTestSuite(TestHSSFSheetShiftRows.class);
|
||||||
if (false) { // deliberately avoiding this one
|
if (false) { // deliberately avoiding this one
|
||||||
result.addTestSuite(TestUnfixedBugs.class);
|
result.addTestSuite(TestUnfixedBugs.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,45 +21,11 @@ import org.apache.poi.hssf.HSSFITestDataProvider;
|
||||||
import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
|
import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests row shifting capabilities.
|
* @author Yegor Kozlov
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author Shawn Laubach (slaubach at apache dot com)
|
|
||||||
* @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp)
|
|
||||||
*/
|
*/
|
||||||
public final class TestSheetShiftRows extends BaseTestSheetShiftRows {
|
public final class TestHSSFSheetShiftRows extends BaseTestSheetShiftRows {
|
||||||
|
|
||||||
|
public TestHSSFSheetShiftRows() {
|
||||||
@Override
|
super(HSSFITestDataProvider.instance);
|
||||||
protected HSSFITestDataProvider getTestDataProvider(){
|
|
||||||
return HSSFITestDataProvider.getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testShiftRows() {
|
|
||||||
baseTestShiftRows("SimpleMultiCell.xls");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testShiftRow() {
|
|
||||||
baseTestShiftRow();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testShiftNames() {
|
|
||||||
baseTestShiftWithNames();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testShiftRowBreaks() {
|
|
||||||
baseTestShiftRowBreaks();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testShiftWithComments() {
|
|
||||||
baseTestShiftWithComments("comments.xls");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testShiftWithFormulas() {
|
|
||||||
baseTestShiftWithFormulas("ForShifting.xls");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testShiftWithMergedRegions() {
|
|
||||||
baseTestShiftWithMergedRegions();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.poi.ss.usermodel;
|
package org.apache.poi.ss.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.ss.ITestDataProvider;
|
import org.apache.poi.ss.ITestDataProvider;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
|
||||||
|
@ -27,12 +28,13 @@ import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
* @author Shawn Laubach (slaubach at apache dot com)
|
* @author Shawn Laubach (slaubach at apache dot com)
|
||||||
* @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp)
|
* @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp)
|
||||||
*/
|
*/
|
||||||
public abstract class BaseTestSheetShiftRows extends TestCase {
|
public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
|
|
||||||
/**
|
private final ITestDataProvider _testDataProvider;
|
||||||
* @return an object that provides test data in HSSF / XSSF specific way
|
|
||||||
*/
|
protected BaseTestSheetShiftRows(ITestDataProvider testDataProvider) {
|
||||||
protected abstract ITestDataProvider getTestDataProvider();
|
_testDataProvider = testDataProvider;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the shiftRows function. Does three different shifts.
|
* Tests the shiftRows function. Does three different shifts.
|
||||||
|
@ -42,15 +44,16 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
*
|
*
|
||||||
* @param sampleName the sample file to test against
|
* @param sampleName the sample file to test against
|
||||||
*/
|
*/
|
||||||
public final void baseTestShiftRows(String sampleName){
|
public final void testShiftRows(){
|
||||||
// Read initial file in
|
// Read initial file in
|
||||||
Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
String sampleName = "SimpleMultiCell." + _testDataProvider.getStandardFileNameExtension();
|
||||||
|
Workbook wb = _testDataProvider.openSampleWorkbook(sampleName);
|
||||||
Sheet s = wb.getSheetAt( 0 );
|
Sheet s = wb.getSheetAt( 0 );
|
||||||
|
|
||||||
// Shift the second row down 1 and write to temp file
|
// Shift the second row down 1 and write to temp file
|
||||||
s.shiftRows( 1, 1, 1 );
|
s.shiftRows( 1, 1, 1 );
|
||||||
|
|
||||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
wb = _testDataProvider.writeOutAndReadBack(wb);
|
||||||
|
|
||||||
// Read from temp file and check the number of cells in each
|
// Read from temp file and check the number of cells in each
|
||||||
// row (in original file each row was unique)
|
// row (in original file each row was unique)
|
||||||
|
@ -65,7 +68,7 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
// Shift rows 1-3 down 3 in the current one. This tests when
|
// Shift rows 1-3 down 3 in the current one. This tests when
|
||||||
// 1 row is blank. Write to a another temp file
|
// 1 row is blank. Write to a another temp file
|
||||||
s.shiftRows( 0, 2, 3 );
|
s.shiftRows( 0, 2, 3 );
|
||||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
wb = _testDataProvider.writeOutAndReadBack(wb);
|
||||||
|
|
||||||
// Read and ensure things are where they should be
|
// Read and ensure things are where they should be
|
||||||
s = wb.getSheetAt(0);
|
s = wb.getSheetAt(0);
|
||||||
|
@ -77,12 +80,12 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
assertEquals(s.getRow(5).getPhysicalNumberOfCells(), 2);
|
assertEquals(s.getRow(5).getPhysicalNumberOfCells(), 2);
|
||||||
|
|
||||||
// Read the first file again
|
// Read the first file again
|
||||||
wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
wb = _testDataProvider.openSampleWorkbook(sampleName);
|
||||||
s = wb.getSheetAt( 0 );
|
s = wb.getSheetAt( 0 );
|
||||||
|
|
||||||
// Shift rows 3 and 4 up and write to temp file
|
// Shift rows 3 and 4 up and write to temp file
|
||||||
s.shiftRows( 2, 3, -2 );
|
s.shiftRows( 2, 3, -2 );
|
||||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
wb = _testDataProvider.writeOutAndReadBack(wb);
|
||||||
s = wb.getSheetAt( 0 );
|
s = wb.getSheetAt( 0 );
|
||||||
assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 3);
|
assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 3);
|
||||||
assertEquals(s.getRow(1).getPhysicalNumberOfCells(), 4);
|
assertEquals(s.getRow(1).getPhysicalNumberOfCells(), 4);
|
||||||
|
@ -98,8 +101,8 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Tests when rows are null.
|
* Tests when rows are null.
|
||||||
*/
|
*/
|
||||||
public final void baseTestShiftRow() {
|
public final void testShiftRow() {
|
||||||
Workbook b = getTestDataProvider().createWorkbook();
|
Workbook b = _testDataProvider.createWorkbook();
|
||||||
Sheet s = b.createSheet();
|
Sheet s = b.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");
|
||||||
|
@ -109,8 +112,8 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Tests when shifting the first row.
|
* Tests when shifting the first row.
|
||||||
*/
|
*/
|
||||||
public final void baseTestActiveCell() {
|
public final void testActiveCell() {
|
||||||
Workbook b = getTestDataProvider().createWorkbook();
|
Workbook b = _testDataProvider.createWorkbook();
|
||||||
Sheet s = b.createSheet();
|
Sheet s = b.createSheet();
|
||||||
|
|
||||||
s.createRow(0).createCell(0).setCellValue("TEST1");
|
s.createRow(0).createCell(0).setCellValue("TEST1");
|
||||||
|
@ -120,10 +123,9 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When shifting rows, the page breaks should go with it
|
* When shifting rows, the page breaks should go with it
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final void baseTestShiftRowBreaks() {
|
public void testShiftRowBreaks() { // TODO - enable XSSF test
|
||||||
Workbook b = getTestDataProvider().createWorkbook();
|
Workbook b = _testDataProvider.createWorkbook();
|
||||||
Sheet s = b.createSheet();
|
Sheet s = b.createSheet();
|
||||||
Row row = s.createRow(4);
|
Row row = s.createRow(4);
|
||||||
row.createCell(0).setCellValue("test");
|
row.createCell(0).setCellValue("test");
|
||||||
|
@ -133,9 +135,9 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
assertTrue("Row number 6 should have a pagebreak", s.isRowBroken(6));
|
assertTrue("Row number 6 should have a pagebreak", s.isRowBroken(6));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testShiftWithComments() { // TODO - enable XSSF test
|
||||||
|
|
||||||
public final void baseTestShiftWithComments(String sampleName) {
|
Workbook wb = _testDataProvider.openSampleWorkbook("comments." + _testDataProvider.getStandardFileNameExtension());
|
||||||
Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
|
||||||
|
|
||||||
Sheet sheet = wb.getSheet("Sheet1");
|
Sheet sheet = wb.getSheet("Sheet1");
|
||||||
assertEquals(3, sheet.getLastRowNum());
|
assertEquals(3, sheet.getLastRowNum());
|
||||||
|
@ -173,7 +175,7 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
|
|
||||||
// Write out and read back in again
|
// Write out and read back in again
|
||||||
// Ensure that the changes were persisted
|
// Ensure that the changes were persisted
|
||||||
wb = getTestDataProvider().writeOutAndReadBack(wb);
|
wb = _testDataProvider.writeOutAndReadBack(wb);
|
||||||
sheet = wb.getSheet("Sheet1");
|
sheet = wb.getSheet("Sheet1");
|
||||||
assertEquals(4, sheet.getLastRowNum());
|
assertEquals(4, sheet.getLastRowNum());
|
||||||
|
|
||||||
|
@ -192,8 +194,8 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
assertEquals(comment4,comment4_shifted);
|
assertEquals(comment4,comment4_shifted);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void baseTestShiftWithNames() {
|
public final void testShiftWithNames() {
|
||||||
Workbook wb = getTestDataProvider().createWorkbook();
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
Sheet sheet1 = wb.createSheet("Sheet1");
|
Sheet sheet1 = wb.createSheet("Sheet1");
|
||||||
wb.createSheet("Sheet2");
|
wb.createSheet("Sheet2");
|
||||||
Row row = sheet1.createRow(0);
|
Row row = sheet1.createRow(0);
|
||||||
|
@ -234,8 +236,8 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
assertEquals("A1", name4.getRefersToFormula());
|
assertEquals("A1", name4.getRefersToFormula());
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void baseTestShiftWithMergedRegions() {
|
public final void testShiftWithMergedRegions() {
|
||||||
Workbook wb = getTestDataProvider().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);
|
||||||
|
@ -252,11 +254,9 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See bug #34023
|
* See bug #34023
|
||||||
*
|
|
||||||
* @param sampleName the sample file to test against
|
|
||||||
*/
|
*/
|
||||||
public void baseTestShiftWithFormulas(String sampleName) {
|
public final void testShiftWithFormulas() {
|
||||||
Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
|
Workbook wb = _testDataProvider.openSampleWorkbook("ForShifting." + _testDataProvider.getStandardFileNameExtension());
|
||||||
|
|
||||||
Sheet sheet = wb.getSheet("Sheet1");
|
Sheet sheet = wb.getSheet("Sheet1");
|
||||||
assertEquals(20, sheet.getLastRowNum());
|
assertEquals(20, sheet.getLastRowNum());
|
||||||
|
|
Loading…
Reference in New Issue