15e5a8699SLiu Zhe /************************************************************** 25e5a8699SLiu Zhe * 35e5a8699SLiu Zhe * Licensed to the Apache Software Foundation (ASF) under one 45e5a8699SLiu Zhe * or more contributor license agreements. See the NOTICE file 55e5a8699SLiu Zhe * distributed with this work for additional information 65e5a8699SLiu Zhe * regarding copyright ownership. The ASF licenses this file 75e5a8699SLiu Zhe * to you under the Apache License, Version 2.0 (the 85e5a8699SLiu Zhe * "License"); you may not use this file except in compliance 95e5a8699SLiu Zhe * with the License. You may obtain a copy of the License at 105e5a8699SLiu Zhe * 115e5a8699SLiu Zhe * http://www.apache.org/licenses/LICENSE-2.0 125e5a8699SLiu Zhe * 135e5a8699SLiu Zhe * Unless required by applicable law or agreed to in writing, 145e5a8699SLiu Zhe * software distributed under the License is distributed on an 155e5a8699SLiu Zhe * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 165e5a8699SLiu Zhe * KIND, either express or implied. See the License for the 175e5a8699SLiu Zhe * specific language governing permissions and limitations 185e5a8699SLiu Zhe * under the License. 195e5a8699SLiu Zhe * 205e5a8699SLiu Zhe *************************************************************/ 215e5a8699SLiu Zhe 22*eba4d44aSLiu Zhe package fvt.uno.sc.chart; 235e5a8699SLiu Zhe 245e5a8699SLiu Zhe import static org.junit.Assert.assertEquals; 255e5a8699SLiu Zhe 265e5a8699SLiu Zhe import java.util.Arrays; 275e5a8699SLiu Zhe import java.util.Collection; 285e5a8699SLiu Zhe 295e5a8699SLiu Zhe import org.junit.After; 305e5a8699SLiu Zhe import org.junit.AfterClass; 315e5a8699SLiu Zhe import org.junit.Before; 325e5a8699SLiu Zhe import org.junit.BeforeClass; 335e5a8699SLiu Zhe import org.junit.Test; 345e5a8699SLiu Zhe import org.junit.runner.RunWith; 355e5a8699SLiu Zhe import org.junit.runners.Parameterized; 365e5a8699SLiu Zhe import org.junit.runners.Parameterized.Parameters; 375e5a8699SLiu Zhe import org.openoffice.test.uno.UnoApp; 385e5a8699SLiu Zhe 395e5a8699SLiu Zhe import testlib.uno.SCUtil; 405e5a8699SLiu Zhe 415e5a8699SLiu Zhe import com.sun.star.awt.Rectangle; 425e5a8699SLiu Zhe import com.sun.star.chart.XChartDocument; 435e5a8699SLiu Zhe import com.sun.star.lang.XComponent; 445e5a8699SLiu Zhe import com.sun.star.sheet.XSpreadsheet; 455e5a8699SLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument; 465e5a8699SLiu Zhe import com.sun.star.table.CellRangeAddress; 475e5a8699SLiu Zhe 485e5a8699SLiu Zhe /** 495e5a8699SLiu Zhe * Check different types of chart data labels can be applied and saved 505e5a8699SLiu Zhe * 515e5a8699SLiu Zhe */ 525e5a8699SLiu Zhe @RunWith(value = Parameterized.class) 535e5a8699SLiu Zhe public class ChartDataLabel { 545e5a8699SLiu Zhe 555e5a8699SLiu Zhe private int labelType; 565e5a8699SLiu Zhe private String inputType; 575e5a8699SLiu Zhe private double[][] numberData; 585e5a8699SLiu Zhe private String fileType; 595e5a8699SLiu Zhe 605e5a8699SLiu Zhe private static final UnoApp unoApp = new UnoApp(); 615e5a8699SLiu Zhe 625e5a8699SLiu Zhe XComponent scComponent = null; 635e5a8699SLiu Zhe XSpreadsheetDocument scDocument = null; 645e5a8699SLiu Zhe 655e5a8699SLiu Zhe @Parameters data()665e5a8699SLiu Zhe public static Collection<Object[]> data() throws Exception { 675e5a8699SLiu Zhe double[][] numberData1 = { 685e5a8699SLiu Zhe {1, 2, 3, 4}, 695e5a8699SLiu Zhe {2, 4.3, 5, 8}, 705e5a8699SLiu Zhe {4, 2, 3, 1}, 715e5a8699SLiu Zhe {1, -1, 0, -3} 725e5a8699SLiu Zhe }; 735e5a8699SLiu Zhe 745e5a8699SLiu Zhe return Arrays.asList(new Object[][] { 755e5a8699SLiu Zhe {0, "com.sun.star.chart.XYDiagram", numberData1, "ods"}, // no label 765e5a8699SLiu Zhe {1, "com.sun.star.chart.PieDiagram", numberData1, "ods"}, // show number 775e5a8699SLiu Zhe {2, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // show percentage 785e5a8699SLiu Zhe {4, "com.sun.star.chart.LineDiagram", numberData1, "ods"}, // show category name 795e5a8699SLiu Zhe {16, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // check legend symbol (won't shown on UI) 805e5a8699SLiu Zhe {3, "com.sun.star.chart.DonutDiagram", numberData1, "ods"}, // show number & percentage 815e5a8699SLiu Zhe {5, "com.sun.star.chart.BubbleDiagram", numberData1, "ods"}, // show number & category name 825e5a8699SLiu Zhe {6, "com.sun.star.chart.NetDiagram", numberData1, "ods"}, // show percentage & category name 835e5a8699SLiu Zhe {7, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // show number & percentage & category name 845e5a8699SLiu Zhe {17, "com.sun.star.chart.LineDiagram", numberData1, "ods"}, // show number & legend symbol 855e5a8699SLiu Zhe {18, "com.sun.star.chart.XYDiagram", numberData1, "ods"}, // show percentage & legend symbol 865e5a8699SLiu Zhe {19, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // show number & percentage & legend symbol 875e5a8699SLiu Zhe {20, "com.sun.star.chart.NetDiagram", numberData1, "ods"}, // show category name & legend symbol 885e5a8699SLiu Zhe {21, "com.sun.star.chart.AreaDiagram", numberData1, "ods"}, // show number & Category name & legend symbol 895e5a8699SLiu Zhe {22, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // show percentage & Category name & legend symbol 905e5a8699SLiu Zhe {23, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // show number & percentage & & Category name & legend symbol 915e5a8699SLiu Zhe {0, "com.sun.star.chart.BarDiagram", numberData1, "xls"}, 925e5a8699SLiu Zhe {1, "com.sun.star.chart.PieDiagram", numberData1, "xls"}, 935e5a8699SLiu Zhe {4, "com.sun.star.chart.LineDiagram", numberData1, "xls"}, 945e5a8699SLiu Zhe {5, "com.sun.star.chart.BarDiagram", numberData1, "xls"}, 955e5a8699SLiu Zhe {17, "com.sun.star.chart.BarDiagram", numberData1, "xls"}, 965e5a8699SLiu Zhe {20, "com.sun.star.chart.BubbleDiagram", numberData1, "xls"}, 975e5a8699SLiu Zhe {21, "com.sun.star.chart.BarDiagram", numberData1, "xls"} 985e5a8699SLiu Zhe }); 995e5a8699SLiu Zhe } 1005e5a8699SLiu Zhe ChartDataLabel(int labelType, String inputType, double[][] numberData, String fileType)1015e5a8699SLiu Zhe public ChartDataLabel(int labelType, String inputType, double[][] numberData, String fileType) { 1025e5a8699SLiu Zhe this.labelType = labelType; 1035e5a8699SLiu Zhe this.inputType = inputType; 1045e5a8699SLiu Zhe this.numberData = numberData; 1055e5a8699SLiu Zhe this.fileType = fileType; 1065e5a8699SLiu Zhe } 1075e5a8699SLiu Zhe 1085e5a8699SLiu Zhe 1095e5a8699SLiu Zhe @Before setUp()1105e5a8699SLiu Zhe public void setUp() throws Exception { 1115e5a8699SLiu Zhe scComponent = unoApp.newDocument("scalc"); 1125e5a8699SLiu Zhe scDocument = SCUtil.getSCDocument(scComponent); 1135e5a8699SLiu Zhe } 1145e5a8699SLiu Zhe 1155e5a8699SLiu Zhe @After tearDown()1165e5a8699SLiu Zhe public void tearDown() throws Exception { 1175e5a8699SLiu Zhe unoApp.closeDocument(scComponent); 1185e5a8699SLiu Zhe 1195e5a8699SLiu Zhe } 1205e5a8699SLiu Zhe 1215e5a8699SLiu Zhe @BeforeClass setUpConnection()1225e5a8699SLiu Zhe public static void setUpConnection() throws Exception { 1235e5a8699SLiu Zhe unoApp.start(); 1245e5a8699SLiu Zhe } 1255e5a8699SLiu Zhe 1265e5a8699SLiu Zhe @AfterClass tearDownConnection()1275e5a8699SLiu Zhe public static void tearDownConnection() throws InterruptedException, Exception { 1285e5a8699SLiu Zhe unoApp.close(); 1295e5a8699SLiu Zhe SCUtil.clearTempDir(); 1305e5a8699SLiu Zhe } 1315e5a8699SLiu Zhe 1325e5a8699SLiu Zhe /** 1335e5a8699SLiu Zhe * Enable different types of data labels in chart. 1345e5a8699SLiu Zhe * 1. Create a spreadsheet file. 1355e5a8699SLiu Zhe * 2. Input number in a cell range and create a chart. 1365e5a8699SLiu Zhe * 3. Enable different types of data labels for all data series in chart. 1375e5a8699SLiu Zhe * 4. Save file as ODF/MSBinary format. 1385e5a8699SLiu Zhe * 5. Close and reopen file. -> Check the chart data label setting. 1395e5a8699SLiu Zhe * @throws Exception 1405e5a8699SLiu Zhe */ 1415e5a8699SLiu Zhe @Test testCreateDataLabel()1425e5a8699SLiu Zhe public void testCreateDataLabel() throws Exception { 1435e5a8699SLiu Zhe String fileName = "testCreateDataLabel"; 1445e5a8699SLiu Zhe String chartName = "testChart"; 1455e5a8699SLiu Zhe String cellRangeName = "A1:D4"; 1465e5a8699SLiu Zhe int result = 0; 1475e5a8699SLiu Zhe 1485e5a8699SLiu Zhe if (inputType.equals("com.sun.star.chart.StockDiagram")) { 1495e5a8699SLiu Zhe cellRangeName = "A1:C4"; 1505e5a8699SLiu Zhe } 1515e5a8699SLiu Zhe if (fileType.equalsIgnoreCase("xls")) { 1525e5a8699SLiu Zhe chartName = "Object 1"; 1535e5a8699SLiu Zhe } 1545e5a8699SLiu Zhe 1555e5a8699SLiu Zhe XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument); 1565e5a8699SLiu Zhe 1575e5a8699SLiu Zhe SCUtil.setValueToCellRange(sheet, 0, 0, numberData); 1585e5a8699SLiu Zhe 1595e5a8699SLiu Zhe CellRangeAddress[] cellAddress = new CellRangeAddress[1]; 1605e5a8699SLiu Zhe cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName); 1615e5a8699SLiu Zhe Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500); 1625e5a8699SLiu Zhe XChartDocument xChartDocument = null; 1635e5a8699SLiu Zhe xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName); 1645e5a8699SLiu Zhe SCUtil.setChartType(xChartDocument, inputType); 1655e5a8699SLiu Zhe 1665e5a8699SLiu Zhe SCUtil.setProperties(xChartDocument.getDiagram(), "DataCaption", labelType); 1675e5a8699SLiu Zhe 1685e5a8699SLiu Zhe SCUtil.saveFileAs(scComponent, fileName, fileType); 1695e5a8699SLiu Zhe scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType); 1705e5a8699SLiu Zhe sheet = SCUtil.getCurrentSheet(scDocument); 1715e5a8699SLiu Zhe 1725e5a8699SLiu Zhe xChartDocument = SCUtil.getChartByName(sheet, chartName); 1735e5a8699SLiu Zhe result = ((Integer) SCUtil.getProperties(xChartDocument.getDiagram(), "DataCaption")).intValue(); 1745e5a8699SLiu Zhe SCUtil.closeFile(scDocument); 1755e5a8699SLiu Zhe 1765e5a8699SLiu Zhe assertEquals("Incorrect chart data label types got in ." + fileType + " file.", labelType, result, 0); 1775e5a8699SLiu Zhe 1785e5a8699SLiu Zhe } 1795e5a8699SLiu Zhe 1805e5a8699SLiu Zhe }