diff options
author | Yegor Kozlov <yegor@apache.org> | 2009-04-06 15:06:23 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2009-04-06 15:06:23 +0000 |
commit | 7873f0d8cf6a0bb787712ad4ef5bb7a922c4dc2f (patch) | |
tree | 1c4dfe7568d25eecba964b64b25de3a0ceb9491e /src/testcases | |
parent | 246e83e1b7f8a7caa869ded7d52f8233fe64be60 (diff) | |
download | poi-7873f0d8cf6a0bb787712ad4ef5bb7a922c4dc2f.tar.gz poi-7873f0d8cf6a0bb787712ad4ef5bb7a922c4dc2f.zip |
consolidate limits specific to Excel version(Excel97, Excel2007) in SpreadsheetVersion enum, allow merged regions with columns greater than 255 or rows bigger than 65536 in XSSF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@762372 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
6 files changed, 57 insertions, 6 deletions
diff --git a/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java b/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java index a86bd099ee..926ed3d382 100755 --- a/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java +++ b/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java @@ -19,6 +19,7 @@ package org.apache.poi.hssf; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider;
+import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Workbook;
/**
@@ -46,6 +47,10 @@ public final class HSSFITestDataProvider implements ITestDataProvider { return HSSFTestDataSamples.getTestDataFileContent(fileName);
}
+ public SpreadsheetVersion getSpreadsheetVersion(){
+ return SpreadsheetVersion.EXCEL2007;
+ }
+
private HSSFITestDataProvider(){}
private static HSSFITestDataProvider inst = new HSSFITestDataProvider();
public static HSSFITestDataProvider getInstance(){
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java index 1b63f9f233..3c5a0911c4 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java @@ -25,6 +25,7 @@ import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.record.BlankRecord; import org.apache.poi.hssf.record.RowRecord; import org.apache.poi.ss.usermodel.BaseTestRow; +import org.apache.poi.ss.SpreadsheetVersion; /** * Test HSSFRow is okay. @@ -39,11 +40,11 @@ public final class TestHSSFRow extends BaseTestRow { } public void testRowBounds() { - baseTestRowBounds(RowRecord.MAX_ROW_NUMBER); + baseTestRowBounds(SpreadsheetVersion.EXCEL97.getLastRowIndex()); } public void testCellBounds() { - baseTestCellBounds(HSSFCell.LAST_COLUMN_NUMBER); + baseTestCellBounds(SpreadsheetVersion.EXCEL97.getLastColumnIndex()); } public void testLastAndFirstColumns_bug46654() { diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java index 65f2f76891..af53957820 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java @@ -17,21 +17,17 @@ package org.apache.poi.hssf.usermodel; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import junit.framework.AssertionFailedError; -import junit.framework.TestCase; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.model.Sheet; import org.apache.poi.hssf.model.DrawingManager2; import org.apache.poi.hssf.record.*; -import org.apache.poi.ss.util.Region; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.usermodel.BaseTestSheet; import org.apache.poi.ddf.EscherDgRecord; diff --git a/src/testcases/org/apache/poi/ss/ITestDataProvider.java b/src/testcases/org/apache/poi/ss/ITestDataProvider.java index 983147691b..db31b8f39b 100755 --- a/src/testcases/org/apache/poi/ss/ITestDataProvider.java +++ b/src/testcases/org/apache/poi/ss/ITestDataProvider.java @@ -50,4 +50,6 @@ public interface ITestDataProvider { * @return an open <tt>InputStream</tt> for the specified sample file
*/
byte[] getTestDataFileContent(String fileName);
+
+ SpreadsheetVersion getSpreadsheetVersion();
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java index c119ce05fc..9c51656dd4 100755 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java @@ -19,6 +19,7 @@ package org.apache.poi.ss.usermodel; import junit.framework.TestCase; import org.apache.poi.ss.ITestDataProvider; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.util.CellRangeAddress; import java.util.Iterator; @@ -196,6 +197,46 @@ public abstract class BaseTestSheet extends TestCase { } /** + * Test adding merged regions. If the region's bounds are outside of the allowed range + * then an IllegalArgumentException should be thrown + * + */ + public void testAddMerged() { + Workbook wb = getTestDataProvider().createWorkbook(); + Sheet sheet = wb.createSheet(); + assertEquals(0, sheet.getNumMergedRegions()); + SpreadsheetVersion ssVersion = getTestDataProvider().getSpreadsheetVersion(); + + CellRangeAddress region = new CellRangeAddress(0, 1, 0, 1); + sheet.addMergedRegion(region); + assertEquals(1, sheet.getNumMergedRegions()); + + try { + region = new CellRangeAddress(-1, -1, -1, -1); + sheet.addMergedRegion(region); + fail("Expected exception"); + } catch (IllegalArgumentException e){ + ; + } + try { + region = new CellRangeAddress(0, 0, 0, ssVersion.getLastColumnIndex() + 1); + sheet.addMergedRegion(region); + fail("Expected exception"); + } catch (IllegalArgumentException e){ + ; + } + try { + region = new CellRangeAddress(0, ssVersion.getLastRowIndex() + 1, 0, 1); + sheet.addMergedRegion(region); + fail("Expected exception"); + } catch (IllegalArgumentException e){ + ; + } + assertEquals(1, sheet.getNumMergedRegions()); + + } + + /** * When removing one merged region, it would break * */ diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java index 1a556dc0ed..ca1f174b4f 100755 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java @@ -108,6 +108,12 @@ public abstract class BaseTestWorkbook extends TestCase { assertEquals("sheet3", workbook.getSheetName(0));
workbook.removeSheetAt(0);
assertEquals(0, workbook.getNumberOfSheets());
+
+ //re-create the sheets
+ workbook.createSheet("sheet1");
+ workbook.createSheet("sheet2");
+ workbook.createSheet("sheet3");
+ assertEquals(3, workbook.getNumberOfSheets());
}
public void testDefaultValues() {
|