diff options
author | Nick Burch <nick@apache.org> | 2008-01-08 11:59:26 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2008-01-08 11:59:26 +0000 |
commit | f52c41539d3055c46ff61daa91067e66c8b9dd55 (patch) | |
tree | a569c7f2e200b4b2cd283c84e16b5a9dd90c4da4 /src/testcases | |
parent | 7b8ac5e4c63cfaf3bd004789974fa53934c73b82 (diff) | |
download | poi-f52c41539d3055c46ff61daa91067e66c8b9dd55.tar.gz poi-f52c41539d3055c46ff61daa91067e66c8b9dd55.zip |
Patch from Ugo to get and set the sheet hidden flag (bug #43937)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@609942 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java | 67 |
1 files changed, 43 insertions, 24 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java index 9628ab23e4..038b6cce55 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java @@ -19,12 +19,11 @@ package org.apache.poi.hssf.usermodel; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import org.apache.poi.poifs.filesystem.POIFSFileSystem; import junit.framework.TestCase; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; + /** * Tests for how HSSFWorkbook behaves with XLS files * with a WORKBOOK directory entry (instead of the more @@ -34,11 +33,21 @@ public class TestSheetHiding extends TestCase { private String dirPath; private String xlsHidden = "TwoSheetsOneHidden.xls"; private String xlsShown = "TwoSheetsNoneHidden.xls"; + private HSSFWorkbook wbH; + private HSSFWorkbook wbU; protected void setUp() throws Exception { super.setUp(); - - dirPath = System.getProperty("HSSF.testdata.path"); + + dirPath = System.getProperty("HSSF.testdata.path"); + FileInputStream isH = new FileInputStream(dirPath + "/" + xlsHidden); + POIFSFileSystem fsH = new POIFSFileSystem(isH); + + FileInputStream isU = new FileInputStream(dirPath + "/" + xlsShown); + POIFSFileSystem fsU = new POIFSFileSystem(isU); + + wbH = new HSSFWorkbook(fsH); + wbU = new HSSFWorkbook(fsU); } /** @@ -47,36 +56,27 @@ public class TestSheetHiding extends TestCase { * the hidden flags are */ public void testTextSheets() throws Exception { - FileInputStream isH = new FileInputStream(dirPath + "/" + xlsHidden); - POIFSFileSystem fsH = new POIFSFileSystem(isH); - - FileInputStream isU = new FileInputStream(dirPath + "/" + xlsShown); - POIFSFileSystem fsU = new POIFSFileSystem(isU); - - HSSFWorkbook wbH = new HSSFWorkbook(fsH); - HSSFWorkbook wbU = new HSSFWorkbook(fsU); - // Both should have two sheets assertEquals(2, wbH.sheets.size()); assertEquals(2, wbU.sheets.size()); - + // All sheets should have one row assertEquals(0, wbH.getSheetAt(0).getLastRowNum()); assertEquals(0, wbH.getSheetAt(1).getLastRowNum()); assertEquals(0, wbU.getSheetAt(0).getLastRowNum()); assertEquals(0, wbU.getSheetAt(1).getLastRowNum()); - + // All rows should have one column assertEquals(1, wbH.getSheetAt(0).getRow(0).getLastCellNum()); assertEquals(1, wbH.getSheetAt(1).getRow(0).getLastCellNum()); assertEquals(1, wbU.getSheetAt(0).getRow(0).getLastCellNum()); assertEquals(1, wbU.getSheetAt(1).getRow(0).getLastCellNum()); - + // Text should be sheet based - assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell((short)0).getStringCellValue()); - assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell((short)0).getStringCellValue()); - assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell((short)0).getStringCellValue()); - assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell((short)0).getStringCellValue()); + assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell((short)0).getRichStringCellValue().getString()); + assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell((short)0).getRichStringCellValue().getString()); + assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell((short)0).getRichStringCellValue().getString()); + assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell((short)0).getRichStringCellValue().getString()); } /** @@ -84,7 +84,10 @@ public class TestSheetHiding extends TestCase { * as expected */ public void testHideUnHideFlags() throws Exception { - // TODO + assertTrue(wbH.isSheetHidden(0)); + assertFalse(wbH.isSheetHidden(1)); + assertFalse(wbU.isSheetHidden(0)); + assertFalse(wbU.isSheetHidden(1)); } /** @@ -92,7 +95,15 @@ public class TestSheetHiding extends TestCase { * one hidden */ public void testHide() throws Exception { - // TODO + wbU.setSheetHidden(0, true); + assertTrue(wbU.isSheetHidden(0)); + assertFalse(wbU.isSheetHidden(1)); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + wbU.write(out); + out.close(); + HSSFWorkbook wb2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); + assertTrue(wb2.isSheetHidden(0)); + assertFalse(wb2.isSheetHidden(1)); } /** @@ -100,6 +111,14 @@ public class TestSheetHiding extends TestCase { * none hidden */ public void testUnHide() throws Exception { - // TODO + wbH.setSheetHidden(0, false); + assertFalse(wbH.isSheetHidden(0)); + assertFalse(wbH.isSheetHidden(1)); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + wbH.write(out); + out.close(); + HSSFWorkbook wb2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); + assertFalse(wb2.isSheetHidden(0)); + assertFalse(wb2.isSheetHidden(1)); } } |