ASF Bugzilla – Attachment 36582 Details for
Bug 63153
Removing a data series from a scatter chart corrupts the workbook
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Revised JUnit test case to verify bug fix for 63153
file_63153.txt (text/plain), 6.87 KB, created by
David Gauntt
on 2019-05-11 13:19:01 UTC
(
hide
)
Description:
Revised JUnit test case to verify bug fix for 63153
Filename:
MIME Type:
Creator:
David Gauntt
Created:
2019-05-11 13:19:01 UTC
Size:
6.87 KB
patch
obsolete
>package org.apache.poi.ss.unfixedBugs; > >import static org.junit.Assert.assertEquals; >import static org.junit.Assert.assertTrue; > >import java.awt.Desktop; >import java.io.File; >import java.io.FileOutputStream; >import java.io.IOException; >import java.io.OutputStream; >import java.util.ArrayList; >import java.util.List; >import java.util.Locale; > >import org.apache.poi.ss.SpreadsheetVersion; >import org.apache.poi.ss.usermodel.CellStyle; >import org.apache.poi.ss.util.AreaReference; >import org.apache.poi.ss.util.CellReference; >import org.apache.poi.xddf.usermodel.chart.AxisPosition; >import org.apache.poi.xddf.usermodel.chart.ChartTypes; >import org.apache.poi.xddf.usermodel.chart.XDDFChart; >import org.apache.poi.xddf.usermodel.chart.XDDFChartData.Series; >import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory; >import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource; >import org.apache.poi.xddf.usermodel.chart.XDDFScatterChartData; >import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis; >import org.apache.poi.xssf.usermodel.XSSFCell; >import org.apache.poi.xssf.usermodel.XSSFClientAnchor; >import org.apache.poi.xssf.usermodel.XSSFDrawing; >import org.apache.poi.xssf.usermodel.XSSFName; >import org.apache.poi.xssf.usermodel.XSSFRow; >import org.apache.poi.xssf.usermodel.XSSFSheet; >import org.apache.poi.xssf.usermodel.XSSFTable; >import org.apache.poi.xssf.usermodel.XSSFTableColumn; >import org.apache.poi.xssf.usermodel.XSSFWorkbook; >import org.junit.After; >import org.junit.Before; >import org.junit.Test; > >/** > * Test case for bug 63153 > */ >public class TestXDDFChartRemoveSeries { > final File resultDir=new File("build/custom-reports-test"); > String fileName=null; > XSSFWorkbook workbook=null; > XSSFSheet sheet=null; > XDDFScatterChartData m_chartData = null; > XDDFChart m_chart=null; > final int NUM_SERIES=3; > final Double dX[] = new Double[5]; > final Double dY[][]=new Double[NUM_SERIES][]; > final XDDFNumericalDataSource<Double> xData; > final List<XDDFNumericalDataSource<Double>> yData=new ArrayList<XDDFNumericalDataSource<Double>>(); > > public TestXDDFChartRemoveSeries() { > resultDir.mkdirs(); > > // Initialize data data sources > > for(int n=0;n<NUM_SERIES;++n) { > dY[n]=new Double[5]; > } > for (int n = 0; n < 5; ++n) { > dX[n] = 0.5*n; > dY[0][n] = (double)n; > dY[1][n] = (double) (n * n); > dY[2][n]=Math.sqrt(n); > } > > xData = XDDFDataSourcesFactory.fromArray(dX, null); > for(int n=0;n<3;++n) { > yData.add(XDDFDataSourcesFactory.fromArray(dY[n], null)); > } > } > > /** > * This creates a workbook with one worksheet, which contains a single scatter chart. > */ > @Before > public void setup() { > final boolean bDebug=false; > workbook = new XSSFWorkbook(); > sheet = workbook.createSheet(); > > final XSSFDrawing xssfDrawing = sheet.createDrawingPatriarch(); > final XSSFClientAnchor anchor = xssfDrawing.createAnchor(0, 0, 0, 0, 1, 5, 20, 20); > if(bDebug) > return; > m_chart = xssfDrawing.createChart(anchor); > final XDDFValueAxis bottomAxis = m_chart.createValueAxis(AxisPosition.BOTTOM); > final XDDFValueAxis leftAxis = m_chart.createValueAxis(AxisPosition.LEFT); > > // Create the chartdata > > m_chartData = (XDDFScatterChartData) m_chart.createData(ChartTypes.SCATTER, bottomAxis, > leftAxis); > > // Add all but the last series > for(int n=0;n<NUM_SERIES-1;++n) > m_chartData.addSeries(xData, yData.get(n)); > } > > > /** > * This method writes the workbook to resultDir/fileName. > */ > @After > public void cleanup() { > final String procName="TestXSSFTableRemoveColumn.cleanup"; > if (workbook == null) { > System.out.println(String.format(Locale.ROOT,"%s: workbook==null",procName)); > return; > } > > if(fileName==null) { > System.out.println(String.format(Locale.ROOT, "%s: fileName==null",procName)); > return; > } > > > // Finish up > m_chart.plot(m_chartData); > final int nSheet = workbook.getSheetIndex(sheet); > workbook.setSelectedTab(nSheet); > workbook.setActiveSheet(nSheet); > workbook.setFirstVisibleTab(nSheet); > > > > final File file=new File(resultDir,fileName); > try (OutputStream fileOut = new FileOutputStream(file)) { > workbook.write(fileOut); > System.out.println(String.format(Locale.ROOT, "%s: test file written to %s",procName,file.getAbsolutePath())); > } catch (Exception e) { > System.err.println(e.getMessage()); > } finally { > try { > workbook.close(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > } > } > > /** > * Remove the first series by calling m_chartData.getSeries().remove(0). > * <p> > * This will corrupt the workbook. > */ > @Test > public void testRemoveSeries0() { > final String procName="testRemoveSeries0"; > fileName=procName+".xlsx"; > > m_chartData.addSeries(xData,yData.get(NUM_SERIES-1)); > m_chartData.getSeries().remove(0); > } > > /** > * Add the last series, and then remove it by calling getSeries().remove. > * <p> > * This will corrupt the workbook. > */ > @Test > public void testRemoveLastSeries() { > final String procName="testRemoveLastSeries"; > fileName=procName+".xlsx"; > > m_chartData.addSeries(xData,yData.get(NUM_SERIES-1)); > m_chartData.getSeries().remove(1); > } > > /** > * Remove the first series by calling m_chartData.removeSeries(0). > * <p> > * This will not corrupt the workbook. > */ > @Test > public void testBugFixRemoveSeries0() { > final String procName="testBugFixRemoveSeries0"; > fileName=procName+".xlsx"; > > m_chartData.addSeries(xData,yData.get(NUM_SERIES-1)); > m_chartData.removeSeries(0); > } > > /** > * Add the last series, and then remove it by calling removeSeries. > * <p> > * This will not corrupt the workbook. > */ > @Test > public void testBugFixRemoveLastSeries() { > final String procName="testBugFixRemoveLastSeries"; > fileName=procName+".xlsx"; > > m_chartData.addSeries(xData,yData.get(NUM_SERIES-1)); > m_chartData.removeSeries(NUM_SERIES-1); > } > > /** > * Do not remove any series from the chart. > */ > @Test > public void testDontRemoveSeries() { > final String procName="testDontRemoveSeries"; > fileName=procName+".xlsx"; > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 63153
:
36579
|
36580
|
36581
| 36582