diff options
author | Alain Béarez <abearez@apache.org> | 2021-02-16 23:39:19 +0000 |
---|---|---|
committer | Alain Béarez <abearez@apache.org> | 2021-02-16 23:39:19 +0000 |
commit | bcf413f68a64024ca7c4cd8efadc718576ddaf4f (patch) | |
tree | f1bc5ae65fffcc7ed35149b40abc0b6c472aa266 /src/ooxml/testcases/org/apache/poi/xssf | |
parent | 0df893124a48144b8e02fc71cf2b06af9ea339a9 (diff) | |
download | poi-bcf413f68a64024ca7c4cd8efadc718576ddaf4f.tar.gz poi-bcf413f68a64024ca7c4cd8efadc718576ddaf4f.zip |
[bug-63902] reference cloned sheet in cloned chart data series
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886605 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases/org/apache/poi/xssf')
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/TestXSSFCloneSheet.java | 33 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java | 26 |
2 files changed, 45 insertions, 14 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/TestXSSFCloneSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/TestXSSFCloneSheet.java index 2858429389..b3c2896fd8 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/TestXSSFCloneSheet.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/TestXSSFCloneSheet.java @@ -18,14 +18,16 @@ package org.apache.poi.xssf; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.fail; import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.ss.usermodel.BaseTestCloneSheet; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xddf.usermodel.chart.XDDFDataSource; +import org.apache.poi.xssf.usermodel.XSSFDrawing; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.junit.jupiter.api.BeforeEach; @@ -87,4 +89,33 @@ class TestXSSFCloneSheet extends BaseTestCloneSheet { assertNotNull(source_sh); } } + + @Test + void testBug63902() throws IOException { + try (XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("chartTitle_withTitle.xlsx")) { + XSSFSheet sheet = workbook.getSheetAt(0); + XSSFDrawing drawing = sheet.getDrawingPatriarch(); + assertEquals(1, drawing.getCharts().size()); + + XSSFSheet sheet2 = workbook.cloneSheet(0, "Sheet 2"); + XSSFDrawing drawing2 = sheet2.getDrawingPatriarch(); + assertEquals(1, drawing2.getCharts().size()); + assertEquals("Sheet 2", sheet2.getSheetName()); + + XDDFDataSource<?> data = drawing.getCharts().get(0).getChartSeries().get(0).getSeries(0).getCategoryData(); + XDDFDataSource<?> data2 = drawing2.getCharts().get(0).getChartSeries().get(0).getSeries(0).getCategoryData(); + assertNotEquals(data.getFormula(), data2.getFormula()); + assertEquals(sheet.getSheetName(), data.getFormula().substring(0, data.getFormula().indexOf('!'))); + assertEquals("'Sheet 2'", data2.getFormula().substring(0, data2.getFormula().indexOf('!'))); + assertEquals( + data.getFormula().substring(data.getFormula().indexOf('!')), + data2.getFormula().substring(data2.getFormula().indexOf('!')) + ); + + Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(workbook, "poi_cloned_sheet_with_chart"); + assertNotNull(wbBack); + wbBack.close(); + } + } + } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java index e000ed3dc9..c072013404 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java @@ -914,19 +914,19 @@ class TestXSSFDrawing { } @Test - void testBug63901() { - XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("chartTitle_withTitle.xlsx"); - XSSFSheet sheet = workbook.getSheet("Sheet1"); - XSSFDrawing drawing = sheet.createDrawingPatriarch(); - assert(drawing.getCharts().size() > 0); - - XSSFWorkbook workbook2 = new XSSFWorkbook(); - XSSFSheet sheet2 = workbook2.createSheet(); - XSSFDrawing drawing2 = sheet2.createDrawingPatriarch(); - - drawing.getCharts().forEach(drawing2::importChart); - - assertEquals(drawing.getCharts().size(), drawing2.getCharts().size()); + void testBug63901() throws IOException { + try (XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("chartTitle_withTitle.xlsx")) { + XSSFSheet sheet = workbook.getSheetAt(0); + XSSFDrawing drawing = sheet.getDrawingPatriarch(); + assertEquals(1, drawing.getCharts().size()); + + XSSFWorkbook workbook2 = new XSSFWorkbook(); + XSSFSheet sheet2 = workbook2.createSheet(); + XSSFDrawing drawing2 = sheet2.createDrawingPatriarch(); + + drawing.getCharts().forEach(drawing2::importChart); + assertEquals(1, drawing2.getCharts().size()); + } } private static void checkRewrite(XSSFWorkbook wb) throws IOException { |