FileDocCategorySizeDatePackage
TestHSSFRow.javaAPI DocApache Poi 3.0.14414Mon Jan 01 12:39:46 GMT 2007org.apache.poi.hssf.usermodel

TestHSSFRow

public class TestHSSFRow extends TestCase
Test HSSFRow is okay.
author
Glen Stampoultzis (glens at apache.org)

Fields Summary
Constructors Summary
public TestHSSFRow(String s)

        super(s);
    
Methods Summary
public voidtestLastAndFirstColumns()

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();
        HSSFRow row = sheet.createRow((short) 0);
        assertEquals(-1, row.getFirstCellNum());
        assertEquals(-1, row.getLastCellNum());

        row.createCell((short) 2);
        assertEquals(2, row.getFirstCellNum());
        assertEquals(2, row.getLastCellNum());

        row.createCell((short) 1);
        assertEquals(1, row.getFirstCellNum());
        assertEquals(2, row.getLastCellNum());

    
public voidtestRemoveCell()

        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);
        assertEquals(1, row.getLastCellNum());
        assertEquals(1, row.getFirstCellNum());
        row.createCell((short) 3);
        assertEquals(3, row.getLastCellNum());
        assertEquals(1, row.getFirstCellNum());
        row.removeCell(row.getCell((short) 3));
        assertEquals(1, row.getLastCellNum());
        assertEquals(1, row.getFirstCellNum());
        row.removeCell(row.getCell((short) 1));
        assertEquals(-1, row.getLastCellNum());
        assertEquals(-1, row.getFirstCellNum());

        // check the row record actually writes it out as 0's
        byte[] data = new byte[100];
        row.getRowRecord().serialize(0, data);
        assertEquals(0, data[6]);
        assertEquals(0, data[8]);

        File file = TempFile.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());


    
public voidtestRowBounds()

      HSSFWorkbook workbook = new HSSFWorkbook();
      HSSFSheet sheet = workbook.createSheet();
      //Test low row bound
      HSSFRow row = sheet.createRow( (short) 0);
      //Test low row bound exception      
      boolean caughtException = false;
      try {
        row = sheet.createRow(-1);        
      } catch (IndexOutOfBoundsException ex) {
        caughtException = true;
      }      
      assertTrue(caughtException);
      //Test high row bound      
      row = sheet.createRow(65535);     
      //Test high row bound exception           
      caughtException = false;
      try {
        row = sheet.createRow(65536);        
      } catch (IndexOutOfBoundsException ex) {
        caughtException = true;
      }      
      assertTrue(caughtException);