xref: /AOO41X/test/testuno/source/fvt/uno/sc/chart/ChartYErrorBar.java (revision eba4d44a33e5be0b2528d5a9a6f0dcbf65adaa0d)
1*eba4d44aSLiu Zhe /**************************************************************
2*eba4d44aSLiu Zhe  *
3*eba4d44aSLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4*eba4d44aSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5*eba4d44aSLiu Zhe  * distributed with this work for additional information
6*eba4d44aSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7*eba4d44aSLiu Zhe  * to you under the Apache License, Version 2.0 (the
8*eba4d44aSLiu Zhe  * "License"); you may not use this file except in compliance
9*eba4d44aSLiu Zhe  * with the License.  You may obtain a copy of the License at
10*eba4d44aSLiu Zhe  *
11*eba4d44aSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12*eba4d44aSLiu Zhe  *
13*eba4d44aSLiu Zhe  * Unless required by applicable law or agreed to in writing,
14*eba4d44aSLiu Zhe  * software distributed under the License is distributed on an
15*eba4d44aSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*eba4d44aSLiu Zhe  * KIND, either express or implied.  See the License for the
17*eba4d44aSLiu Zhe  * specific language governing permissions and limitations
18*eba4d44aSLiu Zhe  * under the License.
19*eba4d44aSLiu Zhe  *
20*eba4d44aSLiu Zhe  *************************************************************/
21*eba4d44aSLiu Zhe 
22*eba4d44aSLiu Zhe package fvt.uno.sc.chart;
23*eba4d44aSLiu Zhe 
24*eba4d44aSLiu Zhe import static org.junit.Assert.assertEquals;
25*eba4d44aSLiu Zhe 
26*eba4d44aSLiu Zhe import java.util.Arrays;
27*eba4d44aSLiu Zhe import java.util.Collection;
28*eba4d44aSLiu Zhe 
29*eba4d44aSLiu Zhe import org.junit.After;
30*eba4d44aSLiu Zhe import org.junit.AfterClass;
31*eba4d44aSLiu Zhe import org.junit.Before;
32*eba4d44aSLiu Zhe import org.junit.BeforeClass;
33*eba4d44aSLiu Zhe import org.junit.Test;
34*eba4d44aSLiu Zhe import org.junit.runner.RunWith;
35*eba4d44aSLiu Zhe import org.junit.runners.Parameterized;
36*eba4d44aSLiu Zhe import org.junit.runners.Parameterized.Parameters;
37*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
38*eba4d44aSLiu Zhe 
39*eba4d44aSLiu Zhe import testlib.uno.SCUtil;
40*eba4d44aSLiu Zhe 
41*eba4d44aSLiu Zhe import com.sun.star.awt.Rectangle;
42*eba4d44aSLiu Zhe import com.sun.star.chart.ChartErrorCategory;
43*eba4d44aSLiu Zhe import com.sun.star.chart.ChartErrorIndicatorType;
44*eba4d44aSLiu Zhe import com.sun.star.chart.XChartDocument;
45*eba4d44aSLiu Zhe import com.sun.star.chart.XDiagram;
46*eba4d44aSLiu Zhe import com.sun.star.lang.XComponent;
47*eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheet;
48*eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
49*eba4d44aSLiu Zhe import com.sun.star.table.CellRangeAddress;
50*eba4d44aSLiu Zhe 
51*eba4d44aSLiu Zhe /**
52*eba4d44aSLiu Zhe  *  Check Y error bar in chart can be applied and saved
53*eba4d44aSLiu Zhe  *
54*eba4d44aSLiu Zhe  */
55*eba4d44aSLiu Zhe @RunWith(value = Parameterized.class)
56*eba4d44aSLiu Zhe public class ChartYErrorBar {
57*eba4d44aSLiu Zhe 
58*eba4d44aSLiu Zhe 	private ChartErrorCategory expCategory;
59*eba4d44aSLiu Zhe 	private ChartErrorIndicatorType expIndicator;
60*eba4d44aSLiu Zhe 	private ChartErrorCategory inputCategory;
61*eba4d44aSLiu Zhe 	private ChartErrorIndicatorType inputIndicator;
62*eba4d44aSLiu Zhe 	private String inputType;
63*eba4d44aSLiu Zhe 	private double[][] numberData;
64*eba4d44aSLiu Zhe 	private String fileType;
65*eba4d44aSLiu Zhe 
66*eba4d44aSLiu Zhe 	private static final UnoApp unoApp = new UnoApp();
67*eba4d44aSLiu Zhe 
68*eba4d44aSLiu Zhe 	XComponent scComponent = null;
69*eba4d44aSLiu Zhe 	XSpreadsheetDocument scDocument = null;
70*eba4d44aSLiu Zhe 
71*eba4d44aSLiu Zhe 	@Parameters
data()72*eba4d44aSLiu Zhe 	public static Collection<Object[]> data() throws Exception {
73*eba4d44aSLiu Zhe 		double[][] numberData1 = {
74*eba4d44aSLiu Zhe 				{10, 20, 30, 40},
75*eba4d44aSLiu Zhe 				{20, 40.3, 50, 80},
76*eba4d44aSLiu Zhe 				{40, 20, 30, 10},
77*eba4d44aSLiu Zhe 				{10, -10, 0, -30}
78*eba4d44aSLiu Zhe 		};
79*eba4d44aSLiu Zhe 
80*eba4d44aSLiu Zhe 		return Arrays.asList(new Object[][] {
81*eba4d44aSLiu Zhe 			{ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, "com.sun.star.chart.BarDiagram", numberData1, "ods"},
82*eba4d44aSLiu Zhe 			{ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.LineDiagram", numberData1, "ods"},
83*eba4d44aSLiu Zhe 			{ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.AreaDiagram", numberData1, "ods"},
84*eba4d44aSLiu Zhe 			{ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, "com.sun.star.chart.BarDiagram", numberData1, "ods"},
85*eba4d44aSLiu Zhe 			{ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.LineDiagram", numberData1, "ods"},
86*eba4d44aSLiu Zhe 			{ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.AreaDiagram", numberData1, "ods"},
87*eba4d44aSLiu Zhe 
88*eba4d44aSLiu Zhe 			{ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, "com.sun.star.chart.BarDiagram", numberData1, "xls"},
89*eba4d44aSLiu Zhe //			{ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.LineDiagram", numberData1, "xls"},
90*eba4d44aSLiu Zhe 			{ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.AreaDiagram", numberData1, "xls"},
91*eba4d44aSLiu Zhe 			{ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, "com.sun.star.chart.BarDiagram", numberData1, "xls"},
92*eba4d44aSLiu Zhe //			{ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.AreaDiagram", numberData1, "xls"},
93*eba4d44aSLiu Zhe 			{ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.LineDiagram", numberData1, "xls"}
94*eba4d44aSLiu Zhe 
95*eba4d44aSLiu Zhe 		});
96*eba4d44aSLiu Zhe 	}
97*eba4d44aSLiu Zhe 
ChartYErrorBar(ChartErrorCategory expCategory, ChartErrorIndicatorType expIndicator, ChartErrorCategory inputCategory, ChartErrorIndicatorType inputIndicator, String inputType, double[][] numberData, String fileType)98*eba4d44aSLiu Zhe 	public ChartYErrorBar(ChartErrorCategory expCategory, ChartErrorIndicatorType expIndicator, ChartErrorCategory inputCategory, ChartErrorIndicatorType inputIndicator, String inputType, double[][] numberData, String fileType) {
99*eba4d44aSLiu Zhe 		this.expCategory = expCategory;
100*eba4d44aSLiu Zhe 		this.expIndicator = expIndicator;
101*eba4d44aSLiu Zhe 		this.inputCategory = inputCategory;
102*eba4d44aSLiu Zhe 		this.inputIndicator = inputIndicator;
103*eba4d44aSLiu Zhe 		this.inputType = inputType;
104*eba4d44aSLiu Zhe 		this.numberData = numberData;
105*eba4d44aSLiu Zhe 		this.fileType = fileType;
106*eba4d44aSLiu Zhe 	}
107*eba4d44aSLiu Zhe 
108*eba4d44aSLiu Zhe 	@Before
setUp()109*eba4d44aSLiu Zhe 	public void setUp() throws Exception {
110*eba4d44aSLiu Zhe 		scComponent = unoApp.newDocument("scalc");
111*eba4d44aSLiu Zhe 		scDocument = SCUtil.getSCDocument(scComponent);
112*eba4d44aSLiu Zhe 	}
113*eba4d44aSLiu Zhe 
114*eba4d44aSLiu Zhe 	@After
tearDown()115*eba4d44aSLiu Zhe 	public void tearDown() throws Exception {
116*eba4d44aSLiu Zhe 		unoApp.closeDocument(scComponent);
117*eba4d44aSLiu Zhe 
118*eba4d44aSLiu Zhe 	}
119*eba4d44aSLiu Zhe 
120*eba4d44aSLiu Zhe 	@BeforeClass
setUpConnection()121*eba4d44aSLiu Zhe 	public static void setUpConnection() throws Exception {
122*eba4d44aSLiu Zhe 		unoApp.start();
123*eba4d44aSLiu Zhe 	}
124*eba4d44aSLiu Zhe 
125*eba4d44aSLiu Zhe 	@AfterClass
tearDownConnection()126*eba4d44aSLiu Zhe 	public static void tearDownConnection() throws InterruptedException, Exception {
127*eba4d44aSLiu Zhe 		unoApp.close();
128*eba4d44aSLiu Zhe 		SCUtil.clearTempDir();
129*eba4d44aSLiu Zhe 	}
130*eba4d44aSLiu Zhe 
131*eba4d44aSLiu Zhe 	/**
132*eba4d44aSLiu Zhe 	 * Enable different types of Y error bar in chart.
133*eba4d44aSLiu Zhe 	 * 1. Create a spreadsheet file.
134*eba4d44aSLiu Zhe 	 * 2. Input number in a cell range and create a chart.
135*eba4d44aSLiu Zhe 	 * 3. Enable Y error bar in chart.
136*eba4d44aSLiu Zhe 	 * 4. Save file as ODF/MSBinary format.
137*eba4d44aSLiu Zhe 	 * 5. Close and reopen file.  -> Check the Y error bar setting.
138*eba4d44aSLiu Zhe 	 * @throws Exception
139*eba4d44aSLiu Zhe 	 */
140*eba4d44aSLiu Zhe 	@Test
testCreateYErrorBar()141*eba4d44aSLiu Zhe 	public void testCreateYErrorBar() throws Exception {
142*eba4d44aSLiu Zhe 		String fileName = "testCreateYErrorBar";
143*eba4d44aSLiu Zhe 		String chartName = "testChart";
144*eba4d44aSLiu Zhe 		String cellRangeName = "A1:D4";
145*eba4d44aSLiu Zhe 		ChartErrorCategory result1 = null;
146*eba4d44aSLiu Zhe 		ChartErrorIndicatorType result2 = null;
147*eba4d44aSLiu Zhe 
148*eba4d44aSLiu Zhe 		if (inputType.equals("com.sun.star.chart.StockDiagram")) {
149*eba4d44aSLiu Zhe 			cellRangeName = "A1:C4";
150*eba4d44aSLiu Zhe 		}
151*eba4d44aSLiu Zhe 		if (fileType.equalsIgnoreCase("xls")) {
152*eba4d44aSLiu Zhe 			chartName = "Object 1";
153*eba4d44aSLiu Zhe 		}
154*eba4d44aSLiu Zhe 
155*eba4d44aSLiu Zhe 		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
156*eba4d44aSLiu Zhe 
157*eba4d44aSLiu Zhe 		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
158*eba4d44aSLiu Zhe 
159*eba4d44aSLiu Zhe 		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
160*eba4d44aSLiu Zhe 		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
161*eba4d44aSLiu Zhe 		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
162*eba4d44aSLiu Zhe 		XChartDocument xChartDocument = null;
163*eba4d44aSLiu Zhe 		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
164*eba4d44aSLiu Zhe 		SCUtil.setChartType(xChartDocument, inputType);
165*eba4d44aSLiu Zhe 		XDiagram xDiagram = xChartDocument.getDiagram();
166*eba4d44aSLiu Zhe 
167*eba4d44aSLiu Zhe 		SCUtil.setProperties(xDiagram, "ErrorCategory", inputCategory);
168*eba4d44aSLiu Zhe 		SCUtil.setProperties(xDiagram, "ErrorIndicator", inputIndicator);
169*eba4d44aSLiu Zhe 
170*eba4d44aSLiu Zhe 		SCUtil.saveFileAs(scComponent, fileName, fileType);
171*eba4d44aSLiu Zhe 		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
172*eba4d44aSLiu Zhe 		sheet = SCUtil.getCurrentSheet(scDocument);
173*eba4d44aSLiu Zhe 
174*eba4d44aSLiu Zhe 		xChartDocument = SCUtil.getChartByName(sheet, chartName);
175*eba4d44aSLiu Zhe 		xDiagram = xChartDocument.getDiagram();
176*eba4d44aSLiu Zhe 		result1 = (ChartErrorCategory) SCUtil.getProperties(xDiagram, "ErrorCategory");
177*eba4d44aSLiu Zhe 		result2 = (ChartErrorIndicatorType) SCUtil.getProperties(xDiagram, "ErrorIndicator");
178*eba4d44aSLiu Zhe 
179*eba4d44aSLiu Zhe 		SCUtil.closeFile(scDocument);
180*eba4d44aSLiu Zhe 
181*eba4d44aSLiu Zhe 		assertEquals("Incorrect chart Y error bar category got in ." + fileType + " file.", expCategory, result1);
182*eba4d44aSLiu Zhe 		assertEquals("Incorrect chart Y error bar indicator got in ." + fileType + " file.", expIndicator, result2);
183*eba4d44aSLiu Zhe 
184*eba4d44aSLiu Zhe 	}
185*eba4d44aSLiu Zhe 
186*eba4d44aSLiu Zhe }