Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9E9D410311 for ; Sat, 15 Mar 2014 17:00:46 +0000 (UTC) Received: (qmail 62290 invoked by uid 500); 15 Mar 2014 17:00:45 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 62247 invoked by uid 500); 15 Mar 2014 17:00:44 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 62240 invoked by uid 99); 15 Mar 2014 17:00:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 15 Mar 2014 17:00:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 15 Mar 2014 17:00:43 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 13B382388A5B; Sat, 15 Mar 2014 17:00:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1577901 - /poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java Date: Sat, 15 Mar 2014 17:00:23 -0000 To: commits@poi.apache.org From: centic@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140315170023.13B382388A5B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: centic Date: Sat Mar 15 17:00:22 2014 New Revision: 1577901 URL: http://svn.apache.org/r1577901 Log: Bug 56114: Add testcase to verify that the flag is correctly stored in the XLS Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java?rev=1577901&r1=1577900&r2=1577901&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java (original) +++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java Sat Mar 15 17:00:22 2014 @@ -17,6 +17,7 @@ package org.apache.poi.hssf.usermodel; +import java.io.IOException; import java.util.Date; import java.util.GregorianCalendar; @@ -31,7 +32,11 @@ import org.apache.poi.hssf.record.Record import org.apache.poi.hssf.record.StringRecord; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.BaseTestCell; +import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.ErrorConstants; +import org.apache.poi.ss.usermodel.RichTextString; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; /** * Tests various functionality having to do with {@link HSSFCell}. For instance support for @@ -156,6 +161,54 @@ public final class TestHSSFCell extends 3, s.getActiveCellRow()); } + + public void testActiveCellBug56114() throws IOException { + Workbook wb = new HSSFWorkbook(); + Sheet sh = wb.createSheet(); + + sh.createRow(0); + sh.createRow(1); + sh.createRow(2); + sh.createRow(3); + + Cell cell = sh.getRow(1).createCell(3); + sh.getRow(3).createCell(3); + + assertEquals(0, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellRow()); + assertEquals(0, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellCol()); + + cell.setAsActiveCell(); + + assertEquals(1, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellRow()); + assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellCol()); + +// FileOutputStream fos = new FileOutputStream("/tmp/56114.xls"); +// +// wb.write(fos); +// +// fos.close(); + + wb = _testDataProvider.writeOutAndReadBack(wb); + + assertEquals(1, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellRow()); + assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellCol()); + + wb.getSheetAt(0).getRow(3).getCell(3).setAsActiveCell(); + + assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellRow()); + assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellCol()); + +// fos = new FileOutputStream("/tmp/56114a.xls"); +// +// wb.write(fos); +// +// fos.close(); + + wb = _testDataProvider.writeOutAndReadBack(wb); + + assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellRow()); + assertEquals(3, ((HSSFSheet)wb.getSheetAt(0)).getSheet().getActiveCellCol()); + } /** * Test reading hyperlinks */ @@ -326,5 +379,84 @@ public final class TestHSSFCell extends */ public void testReadNaN() { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49761.xls"); + assertNotNull(wb); + } + + public void testHSSFCell() { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet(); + HSSFRow row = sheet.createRow(0); + row.createCell(0); + HSSFCell cell = new HSSFCell(wb, sheet, 0, (short)0); + assertNotNull(cell); + } + + @SuppressWarnings("deprecation") + public void testDeprecatedMethods() { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet(); + HSSFRow row = sheet.createRow(0); + HSSFCell cell = row.createCell(0); + + // cover some deprecated methods and other smaller stuff... + assertEquals(wb.getWorkbook(), cell.getBoundWorkbook()); + cell.getCellNum(); + cell.setCellNum((short)0); + + try { + cell.getCachedFormulaResultType(); + fail("Should catch exception"); + } catch (IllegalStateException e) { + } + + try { + assertNotNull(new HSSFCell(wb, sheet, 0, (short)0, Cell.CELL_TYPE_ERROR+1 )); + fail("Should catch exception"); + } catch (RuntimeException e) { + } + + cell.removeCellComment(); + cell.removeCellComment(); + } + + public void testCellType() { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet(); + HSSFRow row = sheet.createRow(0); + HSSFCell cell = row.createCell(0); + + cell.setCellType(Cell.CELL_TYPE_BLANK); + assertNull(null, cell.getDateCellValue()); + assertFalse(cell.getBooleanCellValue()); + assertEquals("", cell.toString()); + + cell.setCellType(Cell.CELL_TYPE_STRING); + assertEquals("", cell.toString()); + cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellValue(1.2); + cell.setCellType(Cell.CELL_TYPE_NUMERIC); + assertEquals("1.2", cell.toString()); + cell.setCellType(Cell.CELL_TYPE_BOOLEAN); + assertEquals("TRUE", cell.toString()); + cell.setCellType(Cell.CELL_TYPE_BOOLEAN); + cell.setCellType(Cell.CELL_TYPE_ERROR); + assertEquals("#VALUE!", cell.toString()); + cell.setCellType(Cell.CELL_TYPE_ERROR); + cell.setCellType(Cell.CELL_TYPE_BOOLEAN); + assertEquals("FALSE", cell.toString()); + cell.setCellValue(1.2); + cell.setCellType(Cell.CELL_TYPE_NUMERIC); + assertEquals("1.2", cell.toString()); + cell.setCellType(Cell.CELL_TYPE_BOOLEAN); + cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellType(Cell.CELL_TYPE_ERROR); + cell.setCellType(Cell.CELL_TYPE_STRING); + cell.setCellValue(1.2); + cell.setCellType(Cell.CELL_TYPE_NUMERIC); + cell.setCellType(Cell.CELL_TYPE_STRING); + assertEquals("1.2", cell.toString()); + + cell.setCellValue((String)null); + cell.setCellValue((RichTextString)null); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org