From 9fd60311fd98de4e151162d5e6485cf8a8c42da3 Mon Sep 17 00:00:00 2001 From: "Amol S. Deshmukh" Date: Wed, 13 Jul 2005 13:11:48 +0000 Subject: [PATCH] added failing tests for singleCell NamedRange creation (testNamedCell_1 & testNamedCell_2). git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353747 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/usermodel/TestNamedRange.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java b/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java index 568222b199..841d042da4 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java @@ -19,6 +19,9 @@ package org.apache.poi.hssf.usermodel; import junit.framework.TestCase; + +import org.apache.poi.hssf.util.AreaReference; +import org.apache.poi.hssf.util.CellReference; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.TempFile; @@ -33,6 +36,7 @@ import java.io.IOException; * @author ROMANL * @author Andrew C. Oliver (acoliver at apache dot org) * @author Danny Mui (danny at muibros.com) + * @author Amol S. Deshmukh < amol at ap ache dot org > */ public class TestNamedRange extends TestCase { @@ -507,6 +511,78 @@ public class TestNamedRange workbook.removePrintArea(0); assertNull("PrintArea was not removed", workbook.getPrintArea(0)); } + + /** + * Verifies correct functioning for "single cell named range" (aka "named cell") + */ + public void testNamedCell_1() { + + // setup for this testcase + String sheetName = "Test Named Cell"; + String cellName = "A name for a named cell"; + String cellValue = "TEST Value"; + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet(sheetName); + sheet.createRow(0).createCell((short) 0).setCellValue(cellValue); + + // create named range for a single cell using areareference + HSSFName namedCell = wb.createName(); + namedCell.setNameName(cellName); + String reference = sheetName+"!A1:A1"; + namedCell.setReference(reference); + + // retrieve the newly created named range + int namedCellIdx = wb.getNameIndex(cellName); + HSSFName aNamedCell = wb.getNameAt(namedCellIdx); + assertNotNull(aNamedCell); + + // retrieve the cell at the named range and test its contents + AreaReference aref = new AreaReference(aNamedCell.getReference()); + CellReference[] crefs = aref.getCells(); + assertNotNull(crefs); + assertEquals("Should be exactly 1 cell in the named cell :'" +cellName+"'", 1, crefs.length); + for (int i=0, iSize=crefs.length; i