You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by am...@apache.org on 2005/07/13 15:11:48 UTC

cvs commit: jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel TestNamedRange.java

amol        2005/07/13 06:11:48

  Modified:    src/testcases/org/apache/poi/hssf/usermodel
                        TestNamedRange.java
  Log:
  added failing tests for singleCell NamedRange creation (testNamedCell_1 & testNamedCell_2).
  
  Revision  Changes    Path
  1.12      +76 -0     jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java
  
  Index: TestNamedRange.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TestNamedRange.java	1 Jan 2005 07:06:45 -0000	1.11
  +++ TestNamedRange.java	13 Jul 2005 13:11:48 -0000	1.12
  @@ -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 @@
    * @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 @@
       	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<iSize; i++) {
  +            CellReference cref = crefs[i];
  +            assertNotNull(cref);
  +            HSSFSheet s = wb.getSheet(cref.getSheetName());
  +            HSSFRow r = sheet.getRow(cref.getRow());
  +            HSSFCell c = r.getCell(cref.getCol());
  +            String contents = c.getStringCellValue();
  +            assertEquals("Contents of cell retrieved by its named reference", contents, cellValue);
  +        }
  +    }
  +
  +    /**
  +     * Verifies correct functioning for "single cell named range" (aka "named cell")
  +     */
  +    public void testNamedCell_2() {
           
  +        // setup for this testcase
  +        String sname = "TestSheet", cname = "TestName", cvalue = "TestVal";
  +        HSSFWorkbook wb = new HSSFWorkbook();
  +        HSSFSheet sheet = wb.createSheet(sname);
  +        sheet.createRow(0).createCell((short) 0).setCellValue(cvalue);
  +         
  +        // create named range for a single cell using cellreference
  +        HSSFName namedCell = wb.createName();
  +        namedCell.setNameName(cname);
  +        String reference = sname+"!A1";
  +        namedCell.setReference(reference);
  +        
  +        // retrieve the newly created named range
  +        int namedCellIdx = wb.getNameIndex(cname);
  +        HSSFName aNamedCell = wb.getNameAt(namedCellIdx);
  +        assertNotNull(aNamedCell);
  +        
  +        // retrieve the cell at the named range and test its contents
  +        CellReference cref = new CellReference(aNamedCell.getReference());
  +        assertNotNull(cref);
  +        HSSFSheet s = wb.getSheet(cref.getSheetName());
  +        HSSFRow r = sheet.getRow(cref.getRow());
  +        HSSFCell c = r.getCell(cref.getCol());
  +        String contents = c.getStringCellValue();
  +        assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
  +    }
  +
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/