diff options
author | Dominik Stadler <centic@apache.org> | 2019-01-13 17:14:05 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2019-01-13 17:14:05 +0000 |
commit | 068c820ef432a7e5e2de549e5471979ffbcf9ea3 (patch) | |
tree | 34398c3e45c038c10244fc2adafbf5178a3329fa /src/testcases/org/apache | |
parent | 88b9e48287e67db6faf0878054114886ce7c1d8b (diff) | |
download | poi-068c820ef432a7e5e2de549e5471979ffbcf9ea3.tar.gz poi-068c820ef432a7e5e2de549e5471979ffbcf9ea3.zip |
Bug 62810: AreaReference ctor looses sheet name if rows or columns swapped
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1851209 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/util/TestAreaReference.java | 20 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/ss/util/TestAreaReference.java | 32 |
2 files changed, 39 insertions, 13 deletions
diff --git a/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java b/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java index 8668b95688..4594cf5655 100644 --- a/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java +++ b/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java @@ -46,18 +46,18 @@ public final class TestAreaReference extends TestCase { AreaReference ar = new AreaReference("$A$1:$B$2", SpreadsheetVersion.EXCEL97); assertFalse("Two cells expected", ar.isSingleCell()); CellReference cf = ar.getFirstCell(); - assertTrue("row is 4",cf.getRow()==0); - assertTrue("col is 1",cf.getCol()==0); + assertEquals("row is 4", 0, cf.getRow()); + assertEquals("col is 1", 0, cf.getCol()); assertTrue("row is abs",cf.isRowAbsolute()); assertTrue("col is abs",cf.isColAbsolute()); - assertTrue("string is $A$1",cf.formatAsString().equals("$A$1")); + assertEquals("string is $A$1", "$A$1", cf.formatAsString()); cf = ar.getLastCell(); - assertTrue("row is 4",cf.getRow()==1); - assertTrue("col is 1",cf.getCol()==1); + assertEquals("row is 4", 1, cf.getRow()); + assertEquals("col is 1", 1, cf.getCol()); assertTrue("row is abs",cf.isRowAbsolute()); assertTrue("col is abs",cf.isColAbsolute()); - assertTrue("string is $B$2",cf.formatAsString().equals("$B$2")); + assertEquals("string is $B$2", "$B$2", cf.formatAsString()); CellReference[] refs = ar.getAllReferencedCells(); assertEquals(4, refs.length); @@ -225,11 +225,13 @@ public final class TestAreaReference extends TestCase { HSSFName aNamedCell = wb.getNameAt(idx); // Should have 2 references - assertEquals(ref, aNamedCell.getRefersToFormula()); + String formulaRefs = aNamedCell.getRefersToFormula(); + assertNotNull(formulaRefs); + assertEquals(ref, formulaRefs); // Check the parsing of the reference into cells - assertFalse(AreaReference.isContiguous(aNamedCell.getRefersToFormula())); - AreaReference[] arefs = AreaReference.generateContiguous(SpreadsheetVersion.EXCEL97, aNamedCell.getRefersToFormula()); + assertFalse(AreaReference.isContiguous(formulaRefs)); + AreaReference[] arefs = AreaReference.generateContiguous(SpreadsheetVersion.EXCEL97, formulaRefs); assertEquals(2, arefs.length); assertEquals(refA, arefs[0].formatAsString()); assertEquals(refB, arefs[1].formatAsString()); diff --git a/src/testcases/org/apache/poi/ss/util/TestAreaReference.java b/src/testcases/org/apache/poi/ss/util/TestAreaReference.java index d8416972c1..d15dd5f7dd 100644 --- a/src/testcases/org/apache/poi/ss/util/TestAreaReference.java +++ b/src/testcases/org/apache/poi/ss/util/TestAreaReference.java @@ -16,17 +16,24 @@ ==================================================================== */ package org.apache.poi.ss.util; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.SpreadsheetVersion; -import junit.framework.TestCase; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * Test for {@link AreaReference} handling of max rows. * * @author David North */ -public class TestAreaReference extends TestCase { - +public class TestAreaReference { + @Test public void testWholeColumn() { AreaReference oldStyle = AreaReference.getWholeColumn(SpreadsheetVersion.EXCEL97, "A", "B"); assertEquals(0, oldStyle.getFirstCell().getCol()); @@ -48,7 +55,8 @@ public class TestAreaReference extends TestCase { AreaReference newStyleNonWholeColumn = new AreaReference("A1:B23", SpreadsheetVersion.EXCEL2007); assertFalse(newStyleNonWholeColumn.isWholeColumnReference()); } - + + @Test public void testWholeRow() { AreaReference oldStyle = AreaReference.getWholeRow(SpreadsheetVersion.EXCEL97, "1", "2"); assertEquals(0, oldStyle.getFirstCell().getCol()); @@ -62,4 +70,20 @@ public class TestAreaReference extends TestCase { assertEquals(SpreadsheetVersion.EXCEL2007.getLastColumnIndex(), newStyle.getLastCell().getCol()); assertEquals(1, newStyle.getLastCell().getRow()); } + + @Test + public void test62810() { + final Workbook wb = new HSSFWorkbook(); + final Sheet sheet = wb.createSheet("Ctor test"); + final String sheetName = sheet.getSheetName(); + final CellReference topLeft = new CellReference(sheetName, 1, 1, true, true); + final CellReference bottomRight = new CellReference(sheetName, 5, 10, true, true); + final AreaReference goodAreaRef = new AreaReference(topLeft, bottomRight, SpreadsheetVersion.EXCEL2007); + final AreaReference badAreaRef = new AreaReference(bottomRight, topLeft, SpreadsheetVersion.EXCEL2007); + + assertEquals("'Ctor test'!$B$2", topLeft.formatAsString()); + assertEquals("'Ctor test'!$K$6", bottomRight.formatAsString()); + assertEquals("'Ctor test'!$B$2:$K$6", goodAreaRef.formatAsString()); + assertEquals("'Ctor test'!$B$2:$K$6", badAreaRef.formatAsString()); + } } |