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.ChartErrorCategory;
435e5a8699SLiu Zhe import com.sun.star.chart.ChartErrorIndicatorType;
445e5a8699SLiu Zhe import com.sun.star.chart.XChartDocument;
455e5a8699SLiu Zhe import com.sun.star.chart.XDiagram;
465e5a8699SLiu Zhe import com.sun.star.lang.XComponent;
475e5a8699SLiu Zhe import com.sun.star.sheet.XSpreadsheet;
485e5a8699SLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
495e5a8699SLiu Zhe import com.sun.star.table.CellRangeAddress;
505e5a8699SLiu Zhe 
515e5a8699SLiu Zhe /**
525e5a8699SLiu Zhe  *  Check Y error bar in chart can be applied and saved
535e5a8699SLiu Zhe  *
545e5a8699SLiu Zhe  */
555e5a8699SLiu Zhe @RunWith(value = Parameterized.class)
565e5a8699SLiu Zhe public class ChartYErrorBar {
575e5a8699SLiu Zhe 
585e5a8699SLiu Zhe 	private ChartErrorCategory expCategory;
595e5a8699SLiu Zhe 	private ChartErrorIndicatorType expIndicator;
605e5a8699SLiu Zhe 	private ChartErrorCategory inputCategory;
615e5a8699SLiu Zhe 	private ChartErrorIndicatorType inputIndicator;
625e5a8699SLiu Zhe 	private String inputType;
635e5a8699SLiu Zhe 	private double[][] numberData;
645e5a8699SLiu Zhe 	private String fileType;
655e5a8699SLiu Zhe 
665e5a8699SLiu Zhe 	private static final UnoApp unoApp = new UnoApp();
675e5a8699SLiu Zhe 
685e5a8699SLiu Zhe 	XComponent scComponent = null;
695e5a8699SLiu Zhe 	XSpreadsheetDocument scDocument = null;
705e5a8699SLiu Zhe 
715e5a8699SLiu Zhe 	@Parameters
data()725e5a8699SLiu Zhe 	public static Collection<Object[]> data() throws Exception {
735e5a8699SLiu Zhe 		double[][] numberData1 = {
745e5a8699SLiu Zhe 				{10, 20, 30, 40},
755e5a8699SLiu Zhe 				{20, 40.3, 50, 80},
765e5a8699SLiu Zhe 				{40, 20, 30, 10},
775e5a8699SLiu Zhe 				{10, -10, 0, -30}
785e5a8699SLiu Zhe 		};
795e5a8699SLiu Zhe 
805e5a8699SLiu Zhe 		return Arrays.asList(new Object[][] {
815e5a8699SLiu Zhe 			{ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, "com.sun.star.chart.BarDiagram", numberData1, "ods"},
825e5a8699SLiu Zhe 			{ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.LineDiagram", numberData1, "ods"},
835e5a8699SLiu Zhe 			{ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.AreaDiagram", numberData1, "ods"},
845e5a8699SLiu Zhe 			{ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, "com.sun.star.chart.BarDiagram", numberData1, "ods"},
855e5a8699SLiu Zhe 			{ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.LineDiagram", numberData1, "ods"},
865e5a8699SLiu Zhe 			{ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.AreaDiagram", numberData1, "ods"},
875e5a8699SLiu Zhe 
885e5a8699SLiu Zhe 			{ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, "com.sun.star.chart.BarDiagram", numberData1, "xls"},
895e5a8699SLiu Zhe //			{ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.LineDiagram", numberData1, "xls"},
905e5a8699SLiu Zhe 			{ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.AreaDiagram", numberData1, "xls"},
915e5a8699SLiu Zhe 			{ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, "com.sun.star.chart.BarDiagram", numberData1, "xls"},
925e5a8699SLiu Zhe //			{ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.AreaDiagram", numberData1, "xls"},
935e5a8699SLiu Zhe 			{ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.LineDiagram", numberData1, "xls"}
945e5a8699SLiu Zhe 
955e5a8699SLiu Zhe 		});
965e5a8699SLiu Zhe 	}
975e5a8699SLiu Zhe 
ChartYErrorBar(ChartErrorCategory expCategory, ChartErrorIndicatorType expIndicator, ChartErrorCategory inputCategory, ChartErrorIndicatorType inputIndicator, String inputType, double[][] numberData, String fileType)985e5a8699SLiu Zhe 	public ChartYErrorBar(ChartErrorCategory expCategory, ChartErrorIndicatorType expIndicator, ChartErrorCategory inputCategory, ChartErrorIndicatorType inputIndicator, String inputType, double[][] numberData, String fileType) {
995e5a8699SLiu Zhe 		this.expCategory = expCategory;
1005e5a8699SLiu Zhe 		this.expIndicator = expIndicator;
1015e5a8699SLiu Zhe 		this.inputCategory = inputCategory;
1025e5a8699SLiu Zhe 		this.inputIndicator = inputIndicator;
1035e5a8699SLiu Zhe 		this.inputType = inputType;
1045e5a8699SLiu Zhe 		this.numberData = numberData;
1055e5a8699SLiu Zhe 		this.fileType = fileType;
1065e5a8699SLiu Zhe 	}
1075e5a8699SLiu Zhe 
1085e5a8699SLiu Zhe 	@Before
setUp()1095e5a8699SLiu Zhe 	public void setUp() throws Exception {
1105e5a8699SLiu Zhe 		scComponent = unoApp.newDocument("scalc");
1115e5a8699SLiu Zhe 		scDocument = SCUtil.getSCDocument(scComponent);
1125e5a8699SLiu Zhe 	}
1135e5a8699SLiu Zhe 
1145e5a8699SLiu Zhe 	@After
tearDown()1155e5a8699SLiu Zhe 	public void tearDown() throws Exception {
1165e5a8699SLiu Zhe 		unoApp.closeDocument(scComponent);
1175e5a8699SLiu Zhe 
1185e5a8699SLiu Zhe 	}
1195e5a8699SLiu Zhe 
1205e5a8699SLiu Zhe 	@BeforeClass
setUpConnection()1215e5a8699SLiu Zhe 	public static void setUpConnection() throws Exception {
1225e5a8699SLiu Zhe 		unoApp.start();
1235e5a8699SLiu Zhe 	}
1245e5a8699SLiu Zhe 
1255e5a8699SLiu Zhe 	@AfterClass
tearDownConnection()1265e5a8699SLiu Zhe 	public static void tearDownConnection() throws InterruptedException, Exception {
1275e5a8699SLiu Zhe 		unoApp.close();
1285e5a8699SLiu Zhe 		SCUtil.clearTempDir();
1295e5a8699SLiu Zhe 	}
1305e5a8699SLiu Zhe 
1315e5a8699SLiu Zhe 	/**
1325e5a8699SLiu Zhe 	 * Enable different types of Y error bar in chart.
1335e5a8699SLiu Zhe 	 * 1. Create a spreadsheet file.
1345e5a8699SLiu Zhe 	 * 2. Input number in a cell range and create a chart.
1355e5a8699SLiu Zhe 	 * 3. Enable Y error bar in chart.
1365e5a8699SLiu Zhe 	 * 4. Save file as ODF/MSBinary format.
1375e5a8699SLiu Zhe 	 * 5. Close and reopen file.  -> Check the Y error bar setting.
1385e5a8699SLiu Zhe 	 * @throws Exception
1395e5a8699SLiu Zhe 	 */
1405e5a8699SLiu Zhe 	@Test
testCreateYErrorBar()1415e5a8699SLiu Zhe 	public void testCreateYErrorBar() throws Exception {
1425e5a8699SLiu Zhe 		String fileName = "testCreateYErrorBar";
1435e5a8699SLiu Zhe 		String chartName = "testChart";
1445e5a8699SLiu Zhe 		String cellRangeName = "A1:D4";
1455e5a8699SLiu Zhe 		ChartErrorCategory result1 = null;
1465e5a8699SLiu Zhe 		ChartErrorIndicatorType result2 = null;
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 		XDiagram xDiagram = xChartDocument.getDiagram();
1665e5a8699SLiu Zhe 
1675e5a8699SLiu Zhe 		SCUtil.setProperties(xDiagram, "ErrorCategory", inputCategory);
1685e5a8699SLiu Zhe 		SCUtil.setProperties(xDiagram, "ErrorIndicator", inputIndicator);
1695e5a8699SLiu Zhe 
1705e5a8699SLiu Zhe 		SCUtil.saveFileAs(scComponent, fileName, fileType);
1715e5a8699SLiu Zhe 		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
1725e5a8699SLiu Zhe 		sheet = SCUtil.getCurrentSheet(scDocument);
1735e5a8699SLiu Zhe 
1745e5a8699SLiu Zhe 		xChartDocument = SCUtil.getChartByName(sheet, chartName);
1755e5a8699SLiu Zhe 		xDiagram = xChartDocument.getDiagram();
1765e5a8699SLiu Zhe 		result1 = (ChartErrorCategory) SCUtil.getProperties(xDiagram, "ErrorCategory");
1775e5a8699SLiu Zhe 		result2 = (ChartErrorIndicatorType) SCUtil.getProperties(xDiagram, "ErrorIndicator");
1785e5a8699SLiu Zhe 
1795e5a8699SLiu Zhe 		SCUtil.closeFile(scDocument);
1805e5a8699SLiu Zhe 
1815e5a8699SLiu Zhe 		assertEquals("Incorrect chart Y error bar category got in ." + fileType + " file.", expCategory, result1);
1825e5a8699SLiu Zhe 		assertEquals("Incorrect chart Y error bar indicator got in ." + fileType + " file.", expIndicator, result2);
1835e5a8699SLiu Zhe 
1845e5a8699SLiu Zhe 	}
1855e5a8699SLiu Zhe 
1865e5a8699SLiu Zhe }