glens       02/04/27 22:22:19

  Modified:    src/java/org/apache/poi/hssf/usermodel HSSFRow.java
               src/testcases/org/apache/poi/hssf/usermodel TestHSSFRow.java
  Log:
  Merge from 1.5 branch
  
  Revision  Changes    Path
  1.10      +14 -8     jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
  
  Index: HSSFRow.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- HSSFRow.java      24 Apr 2002 14:35:12 -0000      1.9
  +++ HSSFRow.java      28 Apr 2002 05:22:19 -0000      1.10
  @@ -126,8 +126,8 @@
           this.sheet = sheet;
           row = new RowRecord();
           row.setHeight((short) 0xff);
  -        row.setLastCol((short)-1);
  -        row.setFirstCol((short)-1);
  +        row.setLastCol((short) -1);
  +        row.setFirstCol((short) -1);
   
           // row.setRowNumber(rowNum);
           setRowNum(rowNum);
  @@ -213,11 +213,11 @@
   
           if (cell.getCellNum() == row.getLastCol())
           {
  -            row.setLastCol( findLastCell(row.getLastCol()) );
  +            row.setLastCol(findLastCell(row.getLastCol()));
           }
           if (cell.getCellNum() == row.getFirstCol())
           {
  -            row.setFirstCol( findFirstCell(row.getFirstCol()) );
  +            row.setFirstCol(findFirstCell(row.getFirstCol()));
           }
       }
   
  @@ -270,11 +270,11 @@
       {
           if (row.getFirstCol() == -1)
           {
  -            row.setFirstCol( cell.getCellNum() );
  +            row.setFirstCol(cell.getCellNum());
           }
           if (row.getLastCol() == -1)
           {
  -            row.setLastCol( cell.getCellNum() );
  +            row.setLastCol(cell.getCellNum());
           }
           cells.put(new Integer(cell.getCellNum()), cell);
   
  @@ -318,7 +318,10 @@
   
       public short getFirstCellNum()
       {
  -        return row.getFirstCol();
  +        if (getPhysicalNumberOfCells() == 0)
  +            return -1;
  +        else
  +            return row.getFirstCol();
       }
   
       /**
  @@ -328,7 +331,10 @@
   
       public short getLastCellNum()
       {
  -        return row.getLastCol();
  +        if (getPhysicalNumberOfCells() == 0)
  +            return -1;
  +        else
  +            return row.getLastCol();
       }
   
   
  
  
  
  1.5       +22 -11    
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
  
  Index: TestHSSFRow.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestHSSFRow.java  24 Apr 2002 14:35:12 -0000      1.4
  +++ TestHSSFRow.java  28 Apr 2002 05:22:19 -0000      1.5
  @@ -55,7 +55,10 @@
   package org.apache.poi.hssf.usermodel;
   
   import junit.framework.TestCase;
  -import org.apache.poi.hssf.record.RowRecord;
  +
  +import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.FileOutputStream;
   
   /**
    * Test HSSFRow is okay.
  @@ -87,31 +90,26 @@
           assertEquals(1, row.getFirstCellNum());
           assertEquals(2, row.getLastCellNum());
   
  -        RowRecord rowRecord = new RowRecord();
  -        rowRecord.setFirstCol((short) 2);
  -        rowRecord.setLastCol((short) 5);
  -        row = new HSSFRow(workbook.getWorkbook(), sheet.getSheet(), rowRecord);
  -        assertEquals(2, row.getFirstCellNum());
  -        assertEquals(5, row.getLastCellNum());
       }
   
       public void testRemoveCell()
  +            throws Exception
       {
           HSSFWorkbook workbook = new HSSFWorkbook();
           HSSFSheet sheet = workbook.createSheet();
           HSSFRow row = sheet.createRow((short) 0);
           assertEquals(-1, row.getLastCellNum());
           assertEquals(-1, row.getFirstCellNum());
  -        row.createCell((short)1);
  +        row.createCell((short) 1);
           assertEquals(1, row.getLastCellNum());
           assertEquals(1, row.getFirstCellNum());
  -        row.createCell((short)3);
  +        row.createCell((short) 3);
           assertEquals(3, row.getLastCellNum());
           assertEquals(1, row.getFirstCellNum());
  -        row.removeCell(row.getCell((short)3));
  +        row.removeCell(row.getCell((short) 3));
           assertEquals(1, row.getLastCellNum());
           assertEquals(1, row.getFirstCellNum());
  -        row.removeCell(row.getCell((short)1));
  +        row.removeCell(row.getCell((short) 1));
           assertEquals(-1, row.getLastCellNum());
           assertEquals(-1, row.getFirstCellNum());
   
  @@ -120,6 +118,19 @@
           row.getRowRecord().serialize(0, data);
           assertEquals(0, data[6]);
           assertEquals(0, data[8]);
  +
  +        File file = File.createTempFile("XXX", "XLS");
  +        FileOutputStream stream = new FileOutputStream(file);
  +        workbook.write(stream);
  +        stream.close();
  +        FileInputStream inputStream = new FileInputStream(file);
  +        workbook = new HSSFWorkbook(inputStream);
  +        sheet = workbook.getSheetAt(0);
  +        stream.close();
  +        file.delete();
  +        assertEquals(-1, sheet.getRow((short) 0).getLastCellNum());
  +        assertEquals(-1, sheet.getRow((short) 0).getFirstCellNum());
  +
   
       }
   }
  
  
  


Reply via email to