diff options
author | Nick Burch <nick@apache.org> | 2008-01-09 23:21:35 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2008-01-09 23:21:35 +0000 |
commit | 7ad30758812963137fe648cb07eacabcddbaec56 (patch) | |
tree | 4d367ef4706707c3d9f0791ea9d8776dc48c5e8b /src/testcases/org/apache/poi/hssf/usermodel | |
parent | fbbd6523bad9a8d63050fbb87343e09c9c0127ed (diff) | |
download | poi-7ad30758812963137fe648cb07eacabcddbaec56.tar.gz poi-7ad30758812963137fe648cb07eacabcddbaec56.zip |
Make a start on processing shapes on a sheet out of a record. For now, doesn't actually manage to do this, but has much of the infrastructure that'll be needed. Includes ability to get an existing HSSFPatriarch for a sheet, if there are the required records, and for the HSSFPatriarch to be in a position to be given the shapes that make it up (but this isn't done yet)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@610608 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java | 24 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java | 67 |
2 files changed, 91 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java index 5f9ef53c89..f0deb68e0c 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java @@ -407,6 +407,30 @@ public class TestHSSFSheet assertEquals(0, r6.getOutlineLevel()); } + public void testGetDrawings() throws Exception { + String filename = System.getProperty("HSSF.testdata.path"); + HSSFWorkbook wb1c = new HSSFWorkbook( + new FileInputStream(new File(filename,"WithChart.xls")) + ); + HSSFWorkbook wb2c = new HSSFWorkbook( + new FileInputStream(new File(filename,"WithTwoCharts.xls")) + ); + + // 1 chart sheet -> data on 1st, chart on 2nd + assertNotNull(wb1c.getSheetAt(0).getDrawingPatriarch()); + assertNotNull(wb1c.getSheetAt(1).getDrawingPatriarch()); + assertFalse(wb1c.getSheetAt(0).getDrawingPatriarch().containsChart()); + assertTrue(wb1c.getSheetAt(1).getDrawingPatriarch().containsChart()); + + // 2 chart sheet -> data on 1st, chart on 2nd+3rd + assertNotNull(wb2c.getSheetAt(0).getDrawingPatriarch()); + assertNotNull(wb2c.getSheetAt(1).getDrawingPatriarch()); + assertNotNull(wb2c.getSheetAt(2).getDrawingPatriarch()); + assertFalse(wb2c.getSheetAt(0).getDrawingPatriarch().containsChart()); + assertTrue(wb2c.getSheetAt(1).getDrawingPatriarch().containsChart()); + assertTrue(wb2c.getSheetAt(2).getDrawingPatriarch().containsChart()); + } + /** * Test that the ProtectRecord is included when creating or cloning a sheet */ diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index 6d5afca114..40a577240e 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -16,6 +16,8 @@ */ package org.apache.poi.hssf.usermodel; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -129,4 +131,69 @@ public class TestHSSFWorkbook extends TestCase b.cloneSheet(0); assertEquals(2, b.getNumberOfSheets()); } + + public void testReadWriteWithCharts() throws Exception { + HSSFWorkbook b; + HSSFSheet s; + + // Single chart, two sheets + b = new HSSFWorkbook( + new FileInputStream(new File(filename,"44010-SingleChart.xls")) + ); + assertEquals(2, b.getNumberOfSheets()); + s = b.getSheetAt(1); + assertEquals(0, s.getFirstRowNum()); + assertEquals(0, s.getLastRowNum()); + + // Has chart on 1st sheet?? + // FIXME + assertNotNull(b.getSheetAt(0).getDrawingPatriarch()); + assertNull(b.getSheetAt(1).getDrawingPatriarch()); + assertFalse(b.getSheetAt(0).getDrawingPatriarch().containsChart()); + + b = writeRead(b); + assertEquals(2, b.getNumberOfSheets()); + s = b.getSheetAt(1); + assertEquals(0, s.getFirstRowNum()); + assertEquals(0, s.getLastRowNum()); + + + // Two charts, three sheets + b = new HSSFWorkbook( + new FileInputStream(new File(filename,"44010-TwoCharts.xls")) + ); + assertEquals(3, b.getNumberOfSheets()); + + s = b.getSheetAt(1); + assertEquals(0, s.getFirstRowNum()); + assertEquals(0, s.getLastRowNum()); + s = b.getSheetAt(2); + assertEquals(0, s.getFirstRowNum()); + assertEquals(0, s.getLastRowNum()); + + // Has chart on 1st sheet?? + // FIXME + assertNotNull(b.getSheetAt(0).getDrawingPatriarch()); + assertNull(b.getSheetAt(1).getDrawingPatriarch()); + assertNull(b.getSheetAt(2).getDrawingPatriarch()); + assertFalse(b.getSheetAt(0).getDrawingPatriarch().containsChart()); + + b = writeRead(b); + assertEquals(3, b.getNumberOfSheets()); + + s = b.getSheetAt(1); + assertEquals(0, s.getFirstRowNum()); + assertEquals(0, s.getLastRowNum()); + s = b.getSheetAt(2); + assertEquals(0, s.getFirstRowNum()); + assertEquals(0, s.getLastRowNum()); + } + + private HSSFWorkbook writeRead(HSSFWorkbook b) throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + b.write(baos); + return new HSSFWorkbook( + new ByteArrayInputStream(baos.toByteArray()) + ); + } }
\ No newline at end of file |