diff options
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 |