aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2009-02-24 08:38:16 +0000
committerYegor Kozlov <yegor@apache.org>2009-02-24 08:38:16 +0000
commit2ef665caf691d9b5514c1d474061332ccdddac10 (patch)
treedf4cf1705e54e7555b7109f4cb610aff798c7ca5 /src/testcases
parent2c52226d5f6cd687116bf4bbc2dce23f166e2f41 (diff)
downloadpoi-2ef665caf691d9b5514c1d474061332ccdddac10.tar.gz
poi-2ef665caf691d9b5514c1d474061332ccdddac10.zip
added setDisplayZeros / isDisplayZeros and getMergedRegion(int) to common interface org.apache.poi.ss.usermodel.Sheet; more progress on testing common xssf-hssf interfaces
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@747307 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java50
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java6
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java23
-rwxr-xr-xsrc/testcases/org/apache/poi/ss/ITestDataProvider.java47
-rwxr-xr-xsrc/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java45
5 files changed, 123 insertions, 48 deletions
diff --git a/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java b/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java
new file mode 100755
index 0000000000..2311cc0b39
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java
@@ -0,0 +1,50 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf;
+
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.ITestDataProvider;
+import org.apache.poi.ss.usermodel.Workbook;
+
+/**
+ * @author Yegor Kozlov
+ */
+public final class HSSFITestDataProvider implements ITestDataProvider {
+
+ public HSSFWorkbook openSampleWorkbook(String sampleFileName) {
+ return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
+ }
+
+ public HSSFWorkbook writeOutAndReadBack(Workbook original) {
+ if(!(original instanceof HSSFWorkbook)) {
+ throw new IllegalArgumentException("Expected an instance of HSSFWorkbook");
+ }
+
+ return HSSFTestDataSamples.writeOutAndReadBack((HSSFWorkbook)original);
+ }
+
+ public HSSFWorkbook createWorkbook(){
+ return new HSSFWorkbook();
+ }
+
+ private HSSFITestDataProvider(){}
+ private static HSSFITestDataProvider inst = new HSSFITestDataProvider();
+ public static HSSFITestDataProvider getInstance(){
+ return inst;
+ }
+} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
index c119daa283..446034ebfe 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
@@ -538,16 +538,15 @@ public final class TestHSSFSheet extends TestCase {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
- wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
- sheet = wb.getSheetAt(0);
-
assertEquals(sheet.isDisplayGridlines(), true);
assertEquals(sheet.isDisplayRowColHeadings(), true);
assertEquals(sheet.isDisplayFormulas(), false);
+ assertEquals(sheet.isDisplayZeros(), true);
sheet.setDisplayGridlines(false);
sheet.setDisplayRowColHeadings(false);
sheet.setDisplayFormulas(true);
+ sheet.setDisplayZeros(false);
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
sheet = wb.getSheetAt(0);
@@ -555,6 +554,7 @@ public final class TestHSSFSheet extends TestCase {
assertEquals(sheet.isDisplayGridlines(), false);
assertEquals(sheet.isDisplayRowColHeadings(), false);
assertEquals(sheet.isDisplayFormulas(), true);
+ assertEquals(sheet.isDisplayZeros(), false);
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java
index 962a565503..84e0aebdd2 100755
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java
@@ -17,8 +17,7 @@
package org.apache.poi.hssf.usermodel;
-import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
/**
@@ -30,23 +29,11 @@ import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
*/
public final class TestSheetShiftRows extends BaseTestSheetShiftRows {
- @Override
- protected Workbook openSampleWorkbook(String sampleFileName) {
- return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
- }
- @Override
- protected Workbook writeOutAndReadBack(Workbook wb) {
- if (wb instanceof HSSFWorkbook) {
- return HSSFTestDataSamples.writeOutAndReadBack((HSSFWorkbook) wb);
- }
- throw new IllegalArgumentException("bad workbook type (" + wb.getClass().getName() + ")");
- }
-
- @Override
- protected Workbook createWorkbook() {
- return new HSSFWorkbook();
- }
+ @Override
+ protected HSSFITestDataProvider getTestDataProvider(){
+ return HSSFITestDataProvider.getInstance();
+ }
public void testShiftRows() {
baseTestShiftRows("SimpleMultiCell.xls");
diff --git a/src/testcases/org/apache/poi/ss/ITestDataProvider.java b/src/testcases/org/apache/poi/ss/ITestDataProvider.java
new file mode 100755
index 0000000000..f3ca3b256f
--- /dev/null
+++ b/src/testcases/org/apache/poi/ss/ITestDataProvider.java
@@ -0,0 +1,47 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.ss;
+
+import org.apache.poi.ss.usermodel.Workbook;
+
+/**
+ * Incapsulates a provider of test data for common HSSF / XSSF tests.
+ */
+public interface ITestDataProvider {
+ /**
+ * Override to provide HSSF / XSSF specific way for re-serialising a workbook
+ *
+ * @param wb the workbook to re-serialize
+ * @return the re-serialized workbook
+ */
+ Workbook writeOutAndReadBack(Workbook wb);
+
+ /**
+ * Override to provide way of loading HSSF / XSSF sample workbooks
+ *
+ * @param sampleFileName the file name to load
+ * @return an instance of Workbook loaded from the supplied file name
+ */
+ Workbook openSampleWorkbook(String sampleFileName);
+
+ /**
+ * Override to provide way of creating HSSF / XSSF workbooks
+ * @return an instance of Workbook
+ */
+ Workbook createWorkbook();
+
+}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java
index 7b83cbbd53..a9305d8cae 100755
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java
@@ -18,6 +18,7 @@
package org.apache.poi.ss.usermodel;
import junit.framework.TestCase;
+import org.apache.poi.ss.ITestDataProvider;
/**
* Tests row shifting capabilities.
@@ -26,19 +27,11 @@ import junit.framework.TestCase;
* @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp)
*/
public abstract class BaseTestSheetShiftRows extends TestCase {
+
/**
- * Override to provide HSSF / XSSF specific way for re-serialising a workbook
- */
- protected abstract Workbook writeOutAndReadBack(Workbook wb);
- /**
- * Override to provide way of loading HSSF / XSSF sample workbooks
- * @param sampleFileName without the ".xls" or ".xlsx" suffix
- */
- protected abstract Workbook openSampleWorkbook(String sampleFileName);
- /**
- * Override to provide way of creating HSSF / XSSF workbooks
+ * @return an object that provides test data in HSSF / XSSF specific way
*/
- protected abstract Workbook createWorkbook();
+ protected abstract ITestDataProvider getTestDataProvider();
/**
* Tests the shiftRows function. Does three different shifts.
@@ -46,17 +39,17 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
* check. This ensures that if some changes code that breaks
* writing or what not, they realize it.
*
- * @author Shawn Laubach (slaubach at apache dot org)
+ * @param sampleName the sample file to test against
*/
public final void baseTestShiftRows(String sampleName){
// Read initial file in
- Workbook wb = openSampleWorkbook(sampleName);
+ Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
Sheet s = wb.getSheetAt( 0 );
// Shift the second row down 1 and write to temp file
s.shiftRows( 1, 1, 1 );
- wb = writeOutAndReadBack(wb);
+ wb = getTestDataProvider().writeOutAndReadBack(wb);
// Read from temp file and check the number of cells in each
// row (in original file each row was unique)
@@ -71,7 +64,7 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
// Shift rows 1-3 down 3 in the current one. This tests when
// 1 row is blank. Write to a another temp file
s.shiftRows( 0, 2, 3 );
- wb = writeOutAndReadBack(wb);
+ wb = getTestDataProvider().writeOutAndReadBack(wb);
// Read and ensure things are where they should be
s = wb.getSheetAt(0);
@@ -83,12 +76,12 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
assertEquals(s.getRow(5).getPhysicalNumberOfCells(), 2);
// Read the first file again
- wb = openSampleWorkbook(sampleName);
+ wb = getTestDataProvider().openSampleWorkbook(sampleName);
s = wb.getSheetAt( 0 );
// Shift rows 3 and 4 up and write to temp file
s.shiftRows( 2, 3, -2 );
- wb = writeOutAndReadBack(wb);
+ wb = getTestDataProvider().writeOutAndReadBack(wb);
s = wb.getSheetAt( 0 );
assertEquals(s.getRow(0).getPhysicalNumberOfCells(), 3);
assertEquals(s.getRow(1).getPhysicalNumberOfCells(), 4);
@@ -103,11 +96,9 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
/**
* Tests when rows are null.
- *
- * @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp)
*/
public final void baseTestShiftRow() {
- Workbook b = createWorkbook();
+ Workbook b = getTestDataProvider().createWorkbook();
Sheet s = b.createSheet();
s.createRow(0).createCell(0).setCellValue("TEST1");
s.createRow(3).createCell(0).setCellValue("TEST2");
@@ -116,11 +107,9 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
/**
* Tests when shifting the first row.
- *
- * @author Toshiaki Kamoshida (kamoshida.toshiaki at future dot co dot jp)
*/
public final void baseTestShiftRow0() {
- Workbook b = createWorkbook();
+ Workbook b = getTestDataProvider().createWorkbook();
Sheet s = b.createSheet();
s.createRow(0).createCell(0).setCellValue("TEST1");
s.createRow(3).createCell(0).setCellValue("TEST2");
@@ -132,7 +121,7 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
*
*/
public final void baseTestShiftRowBreaks() {
- Workbook b = createWorkbook();
+ Workbook b = getTestDataProvider().createWorkbook();
Sheet s = b.createSheet();
Row row = s.createRow(4);
row.createCell(0).setCellValue("test");
@@ -144,7 +133,7 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
public final void baseTestShiftWithComments(String sampleName) {
- Workbook wb = openSampleWorkbook(sampleName);
+ Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
Sheet sheet = wb.getSheet("Sheet1");
assertEquals(3, sheet.getLastRowNum());
@@ -182,7 +171,7 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
// Write out and read back in again
// Ensure that the changes were persisted
- wb = writeOutAndReadBack(wb);
+ wb = getTestDataProvider().writeOutAndReadBack(wb);
sheet = wb.getSheet("Sheet1");
assertEquals(4, sheet.getLastRowNum());
@@ -203,9 +192,11 @@ public abstract class BaseTestSheetShiftRows extends TestCase {
/**
* See bug #34023
+ *
+ * @param sampleName the sample file to test against
*/
public void baseTestShiftWithFormulas(String sampleName) {
- Workbook wb = openSampleWorkbook(sampleName);
+ Workbook wb = getTestDataProvider().openSampleWorkbook(sampleName);
Sheet sheet = wb.getSheet("Sheet1");
assertEquals(20, sheet.getLastRowNum());