1*7fb388b8SZhu Shan /************************************************************** 2*7fb388b8SZhu Shan * 3*7fb388b8SZhu Shan * Licensed to the Apache Software Foundation (ASF) under one 4*7fb388b8SZhu Shan * or more contributor license agreements. See the NOTICE file 5*7fb388b8SZhu Shan * distributed with this work for additional information 6*7fb388b8SZhu Shan * regarding copyright ownership. The ASF licenses this file 7*7fb388b8SZhu Shan * to you under the Apache License, Version 2.0 (the 8*7fb388b8SZhu Shan * "License"); you may not use this file except in compliance 9*7fb388b8SZhu Shan * with the License. You may obtain a copy of the License at 10*7fb388b8SZhu Shan * 11*7fb388b8SZhu Shan * http://www.apache.org/licenses/LICENSE-2.0 12*7fb388b8SZhu Shan * 13*7fb388b8SZhu Shan * Unless required by applicable law or agreed to in writing, 14*7fb388b8SZhu Shan * software distributed under the License is distributed on an 15*7fb388b8SZhu Shan * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*7fb388b8SZhu Shan * KIND, either express or implied. See the License for the 17*7fb388b8SZhu Shan * specific language governing permissions and limitations 18*7fb388b8SZhu Shan * under the License. 19*7fb388b8SZhu Shan * 20*7fb388b8SZhu Shan *************************************************************/ 21*7fb388b8SZhu Shan 22*7fb388b8SZhu Shan package fvt.uno.sc.chart; 23*7fb388b8SZhu Shan 24*7fb388b8SZhu Shan import static org.junit.Assert.assertArrayEquals; 25*7fb388b8SZhu Shan 26*7fb388b8SZhu Shan import java.util.Arrays; 27*7fb388b8SZhu Shan import java.util.Collection; 28*7fb388b8SZhu Shan 29*7fb388b8SZhu Shan import org.junit.After; 30*7fb388b8SZhu Shan import org.junit.AfterClass; 31*7fb388b8SZhu Shan import org.junit.Before; 32*7fb388b8SZhu Shan import org.junit.BeforeClass; 33*7fb388b8SZhu Shan import org.junit.Test; 34*7fb388b8SZhu Shan import org.junit.runner.RunWith; 35*7fb388b8SZhu Shan import org.junit.runners.Parameterized; 36*7fb388b8SZhu Shan import org.junit.runners.Parameterized.Parameters; 37*7fb388b8SZhu Shan import org.openoffice.test.uno.UnoApp; 38*7fb388b8SZhu Shan 39*7fb388b8SZhu Shan import testlib.uno.SCUtil; 40*7fb388b8SZhu Shan 41*7fb388b8SZhu Shan import com.sun.star.awt.Rectangle; 42*7fb388b8SZhu Shan import com.sun.star.chart.XChartDocument; 43*7fb388b8SZhu Shan import com.sun.star.chart.XDiagram; 44*7fb388b8SZhu Shan import com.sun.star.lang.XComponent; 45*7fb388b8SZhu Shan import com.sun.star.sheet.XSpreadsheet; 46*7fb388b8SZhu Shan import com.sun.star.sheet.XSpreadsheetDocument; 47*7fb388b8SZhu Shan import com.sun.star.table.CellRangeAddress; 48*7fb388b8SZhu Shan 49*7fb388b8SZhu Shan /** 50*7fb388b8SZhu Shan * Check Axis in chart can be applied and saved 51*7fb388b8SZhu Shan * 52*7fb388b8SZhu Shan */ 53*7fb388b8SZhu Shan @RunWith(value = Parameterized.class) 54*7fb388b8SZhu Shan public class ChartAxis { 55*7fb388b8SZhu Shan 56*7fb388b8SZhu Shan private Boolean[] axes; 57*7fb388b8SZhu Shan private Boolean[] secondaryAxes; 58*7fb388b8SZhu Shan private String inputType; 59*7fb388b8SZhu Shan private double[][] numberData; 60*7fb388b8SZhu Shan private String fileType; 61*7fb388b8SZhu Shan 62*7fb388b8SZhu Shan private static final UnoApp unoApp = new UnoApp(); 63*7fb388b8SZhu Shan 64*7fb388b8SZhu Shan XComponent scComponent = null; 65*7fb388b8SZhu Shan XSpreadsheetDocument scDocument = null; 66*7fb388b8SZhu Shan 67*7fb388b8SZhu Shan @Parameters data()68*7fb388b8SZhu Shan public static Collection<Object[]> data() throws Exception { 69*7fb388b8SZhu Shan double[][] numberData1 = { 70*7fb388b8SZhu Shan {10, 20, 30, 40}, 71*7fb388b8SZhu Shan {20, 40.3, 50, 80}, 72*7fb388b8SZhu Shan {40, 20, 30, 10}, 73*7fb388b8SZhu Shan {10, -10, 0, -30} 74*7fb388b8SZhu Shan }; 75*7fb388b8SZhu Shan Boolean[][] axesList = { 76*7fb388b8SZhu Shan {false, false, false}, //[0] no Axis 77*7fb388b8SZhu Shan {true, false, false}, // [1] X 78*7fb388b8SZhu Shan {false, true, false}, // [2] Y 79*7fb388b8SZhu Shan {true, true, false}, // [3] X & Y 80*7fb388b8SZhu Shan {true, true, true}, // [4] X & Y & Z 81*7fb388b8SZhu Shan {false, false, true}, // [5] Z 82*7fb388b8SZhu Shan {false, true, true}, // [6] Y & Z 83*7fb388b8SZhu Shan {true, false, true} // [7] X & Z 84*7fb388b8SZhu Shan }; 85*7fb388b8SZhu Shan 86*7fb388b8SZhu Shan return Arrays.asList(new Object[][] { 87*7fb388b8SZhu Shan // {axesList[0], null, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, //Bug #121046 88*7fb388b8SZhu Shan // {axesList[2], axesList[3], "com.sun.star.chart.BarDiagram", numberData1, "ods"}, //Bug #121046 89*7fb388b8SZhu Shan {null, axesList[4], "com.sun.star.chart.BarDiagram", numberData1, "ods"}, 90*7fb388b8SZhu Shan // {axesList[6], axesList[7], "com.sun.star.chart.BarDiagram", numberData1, "ods"}, //Bug #121046 91*7fb388b8SZhu Shan {axesList[1], axesList[5], "com.sun.star.chart.AreaDiagram", numberData1, "ods"}, 92*7fb388b8SZhu Shan {axesList[4], axesList[4], "com.sun.star.chart.LineDiagram", numberData1, "ods"}, 93*7fb388b8SZhu Shan 94*7fb388b8SZhu Shan // {axesList[0], axesList[0], "com.sun.star.chart.BarDiagram", numberData1, "xls"}, //Bug #121043 95*7fb388b8SZhu Shan // {axesList[2], axesList[3], "com.sun.star.chart.BarDiagram", numberData1, "xls"}, //Bug #121043 96*7fb388b8SZhu Shan {null, axesList[4], "com.sun.star.chart.BarDiagram", numberData1, "xls"}, 97*7fb388b8SZhu Shan {axesList[6], axesList[7], "com.sun.star.chart.BarDiagram", numberData1, "xls"}, 98*7fb388b8SZhu Shan {axesList[1], axesList[5], "com.sun.star.chart.AreaDiagram", numberData1, "xls"}, 99*7fb388b8SZhu Shan {axesList[4], axesList[4], "com.sun.star.chart.LineDiagram", numberData1, "xls"} 100*7fb388b8SZhu Shan 101*7fb388b8SZhu Shan }); 102*7fb388b8SZhu Shan } 103*7fb388b8SZhu Shan ChartAxis(Boolean[] axes, Boolean[] secondaryAxes, String inputType, double[][] numberData, String fileType)104*7fb388b8SZhu Shan public ChartAxis(Boolean[] axes, Boolean[] secondaryAxes, String inputType, double[][] numberData, String fileType) { 105*7fb388b8SZhu Shan this.axes = axes; 106*7fb388b8SZhu Shan this.secondaryAxes = secondaryAxes; 107*7fb388b8SZhu Shan this.inputType = inputType; 108*7fb388b8SZhu Shan this.numberData = numberData; 109*7fb388b8SZhu Shan this.fileType = fileType; 110*7fb388b8SZhu Shan } 111*7fb388b8SZhu Shan 112*7fb388b8SZhu Shan @Before setUp()113*7fb388b8SZhu Shan public void setUp() throws Exception { 114*7fb388b8SZhu Shan scComponent = unoApp.newDocument("scalc"); 115*7fb388b8SZhu Shan scDocument = SCUtil.getSCDocument(scComponent); 116*7fb388b8SZhu Shan } 117*7fb388b8SZhu Shan 118*7fb388b8SZhu Shan @After tearDown()119*7fb388b8SZhu Shan public void tearDown() throws Exception { 120*7fb388b8SZhu Shan unoApp.closeDocument(scComponent); 121*7fb388b8SZhu Shan 122*7fb388b8SZhu Shan } 123*7fb388b8SZhu Shan 124*7fb388b8SZhu Shan @BeforeClass setUpConnection()125*7fb388b8SZhu Shan public static void setUpConnection() throws Exception { 126*7fb388b8SZhu Shan unoApp.start(); 127*7fb388b8SZhu Shan } 128*7fb388b8SZhu Shan 129*7fb388b8SZhu Shan @AfterClass tearDownConnection()130*7fb388b8SZhu Shan public static void tearDownConnection() throws InterruptedException, Exception { 131*7fb388b8SZhu Shan unoApp.close(); 132*7fb388b8SZhu Shan SCUtil.clearTempDir(); 133*7fb388b8SZhu Shan } 134*7fb388b8SZhu Shan 135*7fb388b8SZhu Shan /** 136*7fb388b8SZhu Shan * Enable different types of axes in chart. 137*7fb388b8SZhu Shan * 1. Create a spreadsheet file. 138*7fb388b8SZhu Shan * 2. Input number in a cell range and create a 2D chart. 139*7fb388b8SZhu Shan * 3. Enable X/Y axis/secondaryAxis in chart. 140*7fb388b8SZhu Shan * 4. Save file as ODF/MSBinary format. 141*7fb388b8SZhu Shan * 5. Close and reopen file. -> Check the axes setting. 142*7fb388b8SZhu Shan * @throws Exception 143*7fb388b8SZhu Shan */ 144*7fb388b8SZhu Shan @Test testCreateXYAxes()145*7fb388b8SZhu Shan public void testCreateXYAxes() throws Exception { 146*7fb388b8SZhu Shan String fileName = "testCreateXYAxes"; 147*7fb388b8SZhu Shan String chartName = "testChart"; 148*7fb388b8SZhu Shan String cellRangeName = "A1:D4"; 149*7fb388b8SZhu Shan Boolean[][] expected = { 150*7fb388b8SZhu Shan {true, true, false}, 151*7fb388b8SZhu Shan {false, false, false} 152*7fb388b8SZhu Shan }; 153*7fb388b8SZhu Shan Boolean[][] results = { 154*7fb388b8SZhu Shan {false, false, false}, 155*7fb388b8SZhu Shan {false, false, false} 156*7fb388b8SZhu Shan }; 157*7fb388b8SZhu Shan 158*7fb388b8SZhu Shan if (inputType.equals("com.sun.star.chart.StockDiagram")) { 159*7fb388b8SZhu Shan cellRangeName = "A1:C4"; 160*7fb388b8SZhu Shan } 161*7fb388b8SZhu Shan if (fileType.equalsIgnoreCase("xls")) { 162*7fb388b8SZhu Shan chartName = "Object 1"; 163*7fb388b8SZhu Shan } 164*7fb388b8SZhu Shan 165*7fb388b8SZhu Shan XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument); 166*7fb388b8SZhu Shan 167*7fb388b8SZhu Shan SCUtil.setValueToCellRange(sheet, 0, 0, numberData); 168*7fb388b8SZhu Shan 169*7fb388b8SZhu Shan CellRangeAddress[] cellAddress = new CellRangeAddress[1]; 170*7fb388b8SZhu Shan cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName); 171*7fb388b8SZhu Shan Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500); 172*7fb388b8SZhu Shan XChartDocument xChartDocument = null; 173*7fb388b8SZhu Shan xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName); 174*7fb388b8SZhu Shan SCUtil.setChartType(xChartDocument, inputType); 175*7fb388b8SZhu Shan XDiagram xDiagram = xChartDocument.getDiagram(); 176*7fb388b8SZhu Shan 177*7fb388b8SZhu Shan if (axes != null) { 178*7fb388b8SZhu Shan SCUtil.setProperties(xDiagram, "HasXAxis", axes[0]); 179*7fb388b8SZhu Shan SCUtil.setProperties(xDiagram, "HasYAxis", axes[1]); 180*7fb388b8SZhu Shan expected[0][0] = axes[0]; 181*7fb388b8SZhu Shan expected[0][1] = axes[1]; 182*7fb388b8SZhu Shan } 183*7fb388b8SZhu Shan if (secondaryAxes != null) { 184*7fb388b8SZhu Shan SCUtil.setProperties(xDiagram, "HasSecondaryXAxis", secondaryAxes[0]); 185*7fb388b8SZhu Shan SCUtil.setProperties(xDiagram, "HasSecondaryYAxis", secondaryAxes[1]); 186*7fb388b8SZhu Shan expected[1][0] = secondaryAxes[0]; 187*7fb388b8SZhu Shan expected[1][1] = secondaryAxes[1]; 188*7fb388b8SZhu Shan } 189*7fb388b8SZhu Shan 190*7fb388b8SZhu Shan //Excel does not has secondary X axis, the value depends on the secondary Y axis setting 191*7fb388b8SZhu Shan if (fileType.equalsIgnoreCase("xls")) { 192*7fb388b8SZhu Shan expected[1][0] = false; 193*7fb388b8SZhu Shan if (expected[1][1]) { 194*7fb388b8SZhu Shan expected[1][0] = true; 195*7fb388b8SZhu Shan SCUtil.setProperties(xDiagram.getDataRowProperties(1), "Axis", 4); 196*7fb388b8SZhu Shan } 197*7fb388b8SZhu Shan } 198*7fb388b8SZhu Shan 199*7fb388b8SZhu Shan SCUtil.saveFileAs(scComponent, fileName, fileType); 200*7fb388b8SZhu Shan scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType); 201*7fb388b8SZhu Shan sheet = SCUtil.getCurrentSheet(scDocument); 202*7fb388b8SZhu Shan 203*7fb388b8SZhu Shan xChartDocument = SCUtil.getChartByName(sheet, chartName); 204*7fb388b8SZhu Shan xDiagram = xChartDocument.getDiagram(); 205*7fb388b8SZhu Shan results[0][0] = (Boolean) SCUtil.getProperties(xDiagram, "HasXAxis"); 206*7fb388b8SZhu Shan results[0][1] = (Boolean) SCUtil.getProperties(xDiagram, "HasYAxis"); 207*7fb388b8SZhu Shan results[1][0] = (Boolean) SCUtil.getProperties(xDiagram, "HasSecondaryXAxis"); 208*7fb388b8SZhu Shan results[1][1] = (Boolean) SCUtil.getProperties(xDiagram, "HasSecondaryYAxis"); 209*7fb388b8SZhu Shan 210*7fb388b8SZhu Shan SCUtil.closeFile(scDocument); 211*7fb388b8SZhu Shan 212*7fb388b8SZhu Shan assertArrayEquals("Incorrect chart grids got in ." + fileType + " file.", expected, results); 213*7fb388b8SZhu Shan 214*7fb388b8SZhu Shan } 215*7fb388b8SZhu Shan 216*7fb388b8SZhu Shan /** 217*7fb388b8SZhu Shan * Enable different types of axes in 3D chart. 218*7fb388b8SZhu Shan * 1. Create a spreadsheet file. 219*7fb388b8SZhu Shan * 2. Input number in a cell range and create a 2D chart. 220*7fb388b8SZhu Shan * 3. Enable X/Y/Z axis in chart. 221*7fb388b8SZhu Shan * 4. Save file as ODF/MSBinary format. 222*7fb388b8SZhu Shan * 5. Close and reopen file. -> Check the axes setting. 223*7fb388b8SZhu Shan * @throws Exception 224*7fb388b8SZhu Shan */ 225*7fb388b8SZhu Shan @Test testCreateXYZAxes()226*7fb388b8SZhu Shan public void testCreateXYZAxes() throws Exception { 227*7fb388b8SZhu Shan String fileName = "testCreateXYZAxes"; 228*7fb388b8SZhu Shan String chartName = "testChart"; 229*7fb388b8SZhu Shan String cellRangeName = "A1:D4"; 230*7fb388b8SZhu Shan Boolean[][] expected = { 231*7fb388b8SZhu Shan {true, true, true}, 232*7fb388b8SZhu Shan {false, false, false} 233*7fb388b8SZhu Shan }; 234*7fb388b8SZhu Shan Boolean[][] results = { 235*7fb388b8SZhu Shan {false, false, false}, 236*7fb388b8SZhu Shan {false, false, false} 237*7fb388b8SZhu Shan }; 238*7fb388b8SZhu Shan 239*7fb388b8SZhu Shan if (inputType.equals("com.sun.star.chart.StockDiagram")) { 240*7fb388b8SZhu Shan cellRangeName = "A1:C4"; 241*7fb388b8SZhu Shan } 242*7fb388b8SZhu Shan if (fileType.equalsIgnoreCase("xls")) { 243*7fb388b8SZhu Shan chartName = "Object 1"; 244*7fb388b8SZhu Shan } 245*7fb388b8SZhu Shan 246*7fb388b8SZhu Shan XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument); 247*7fb388b8SZhu Shan 248*7fb388b8SZhu Shan SCUtil.setValueToCellRange(sheet, 0, 0, numberData); 249*7fb388b8SZhu Shan 250*7fb388b8SZhu Shan CellRangeAddress[] cellAddress = new CellRangeAddress[1]; 251*7fb388b8SZhu Shan cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName); 252*7fb388b8SZhu Shan Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500); 253*7fb388b8SZhu Shan XChartDocument xChartDocument = null; 254*7fb388b8SZhu Shan xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName); 255*7fb388b8SZhu Shan SCUtil.setChartType(xChartDocument, inputType); 256*7fb388b8SZhu Shan SCUtil.setProperties(xChartDocument.getDiagram(), "Dim3D", true); 257*7fb388b8SZhu Shan XDiagram xDiagram = xChartDocument.getDiagram(); 258*7fb388b8SZhu Shan 259*7fb388b8SZhu Shan if (axes != null) { 260*7fb388b8SZhu Shan SCUtil.setProperties(xDiagram, "HasXAxis", axes[0]); 261*7fb388b8SZhu Shan SCUtil.setProperties(xDiagram, "HasYAxis", axes[1]); 262*7fb388b8SZhu Shan SCUtil.setProperties(xDiagram, "HasZAxis", axes[2]); 263*7fb388b8SZhu Shan expected[0][0] = axes[0]; 264*7fb388b8SZhu Shan expected[0][1] = axes[1]; 265*7fb388b8SZhu Shan expected[0][2] = axes[2]; 266*7fb388b8SZhu Shan } 267*7fb388b8SZhu Shan 268*7fb388b8SZhu Shan 269*7fb388b8SZhu Shan SCUtil.saveFileAs(scComponent, fileName, fileType); 270*7fb388b8SZhu Shan scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType); 271*7fb388b8SZhu Shan sheet = SCUtil.getCurrentSheet(scDocument); 272*7fb388b8SZhu Shan 273*7fb388b8SZhu Shan xChartDocument = SCUtil.getChartByName(sheet, chartName); 274*7fb388b8SZhu Shan xDiagram = xChartDocument.getDiagram(); 275*7fb388b8SZhu Shan results[0][0] = (Boolean) SCUtil.getProperties(xDiagram, "HasXAxis"); 276*7fb388b8SZhu Shan results[0][1] = (Boolean) SCUtil.getProperties(xDiagram, "HasYAxis"); 277*7fb388b8SZhu Shan results[0][2] = (Boolean) SCUtil.getProperties(xDiagram, "HasZAxis"); 278*7fb388b8SZhu Shan 279*7fb388b8SZhu Shan SCUtil.closeFile(scDocument); 280*7fb388b8SZhu Shan 281*7fb388b8SZhu Shan assertArrayEquals("Incorrect chart Axes got in ." + fileType + " file.", expected, results); 282*7fb388b8SZhu Shan 283*7fb388b8SZhu Shan } 284*7fb388b8SZhu Shan 285*7fb388b8SZhu Shan }