View | Details | Raw Unified | Return to issue 120973
Collapse All | Expand All

(-)testuno/source/testcase/uno/sc/chart/ChartDataLabel.java (+180 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
package testcase.uno.sc.chart;
23
24
import static org.junit.Assert.assertEquals;
25
26
import java.util.Arrays;
27
import java.util.Collection;
28
29
import org.junit.After;
30
import org.junit.AfterClass;
31
import org.junit.Before;
32
import org.junit.BeforeClass;
33
import org.junit.Test;
34
import org.junit.runner.RunWith;
35
import org.junit.runners.Parameterized;
36
import org.junit.runners.Parameterized.Parameters;
37
import org.openoffice.test.uno.UnoApp;
38
39
import testlib.uno.SCUtil;
40
41
import com.sun.star.awt.Rectangle;
42
import com.sun.star.chart.XChartDocument;
43
import com.sun.star.lang.XComponent;
44
import com.sun.star.sheet.XSpreadsheet;
45
import com.sun.star.sheet.XSpreadsheetDocument;
46
import com.sun.star.table.CellRangeAddress;
47
48
/**
49
 *  Check different types of chart data labels can be applied and saved
50
 * 
51
 */
52
@RunWith(value = Parameterized.class)
53
public class ChartDataLabel {
54
55
	private int labelType;
56
	private String inputType;
57
	private double[][] numberData;	
58
	private String fileType;
59
	
60
	private static final UnoApp unoApp = new UnoApp();
61
	
62
	XComponent scComponent = null;
63
	XSpreadsheetDocument scDocument = null;
64
	
65
	@Parameters
66
	public static Collection<Object[]> data() throws Exception {
67
		double[][] numberData1 = {
68
				{1, 2, 3, 4},
69
				{2, 4.3, 5, 8},
70
				{4, 2, 3, 1},
71
				{1, -1, 0, -3}
72
		};
73
74
		return Arrays.asList(new Object[][] {
75
			{0, "com.sun.star.chart.XYDiagram", numberData1, "ods"}, // no label
76
			{1, "com.sun.star.chart.PieDiagram", numberData1, "ods"}, // show number
77
			{2, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // show percentage
78
			{4, "com.sun.star.chart.LineDiagram", numberData1, "ods"}, // show category name
79
			{16, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // check legend symbol (won't shown on UI)
80
			{3, "com.sun.star.chart.DonutDiagram", numberData1, "ods"}, // show number & percentage
81
			{5, "com.sun.star.chart.BubbleDiagram", numberData1, "ods"}, // show number & category name
82
			{6, "com.sun.star.chart.NetDiagram", numberData1, "ods"}, // show percentage & category name
83
			{7, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // show number & percentage & category name
84
			{17, "com.sun.star.chart.LineDiagram", numberData1, "ods"}, // show number & legend symbol
85
			{18, "com.sun.star.chart.XYDiagram", numberData1, "ods"}, // show percentage & legend symbol
86
			{19, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // show number & percentage & legend symbol
87
			{20, "com.sun.star.chart.NetDiagram", numberData1, "ods"}, // show category name & legend symbol
88
			{21, "com.sun.star.chart.AreaDiagram", numberData1, "ods"}, // show number & Category name & legend symbol
89
			{22, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // show percentage & Category name & legend symbol
90
			{23, "com.sun.star.chart.BarDiagram", numberData1, "ods"}, // show number & percentage & & Category name & legend symbol
91
			{0, "com.sun.star.chart.BarDiagram", numberData1, "xls"}, 
92
			{1, "com.sun.star.chart.PieDiagram", numberData1, "xls"}, 
93
			{4, "com.sun.star.chart.LineDiagram", numberData1, "xls"},
94
			{5, "com.sun.star.chart.BarDiagram", numberData1, "xls"},
95
			{17, "com.sun.star.chart.BarDiagram", numberData1, "xls"},
96
			{20, "com.sun.star.chart.BubbleDiagram", numberData1, "xls"},
97
			{21, "com.sun.star.chart.BarDiagram", numberData1, "xls"}
98
		});
99
	}
100
	
101
	public ChartDataLabel(int labelType, String inputType, double[][] numberData, String fileType) {
102
		this.labelType = labelType;
103
		this.inputType = inputType;
104
		this.numberData = numberData;
105
		this.fileType = fileType;
106
	}
107
	
108
	
109
	@Before
110
	public void setUp() throws Exception {
111
		scComponent = unoApp.newDocument("scalc");
112
		scDocument = SCUtil.getSCDocument(scComponent);
113
	}
114
115
	@After
116
	public void tearDown() throws Exception {
117
		unoApp.closeDocument(scComponent);
118
		
119
	}
120
	
121
	@BeforeClass
122
	public static void setUpConnection() throws Exception {
123
		unoApp.start();
124
	}
125
126
	@AfterClass
127
	public static void tearDownConnection() throws InterruptedException, Exception {
128
		unoApp.close();
129
		SCUtil.clearTempDir();	
130
	}
131
	
132
	/**
133
	 * Enable different types of data labels in chart.
134
	 * 1. Create a spreadsheet file.
135
	 * 2. Input number in a cell range and create a chart.
136
	 * 3. Enable different types of data labels for all data series in chart.
137
	 * 4. Save file as ODF/MSBinary format.
138
	 * 5. Close and reopen file.  -> Check the chart data label setting.
139
	 * @throws Exception
140
	 */
141
	@Test
142
	public void testCreateDataLabel() throws Exception {
143
		String fileName = "testCreateDataLabel";
144
		String chartName = "testChart";
145
		String cellRangeName = "A1:D4";
146
		int result = 0;	
147
		
148
		if (inputType.equals("com.sun.star.chart.StockDiagram")) {
149
			cellRangeName = "A1:C4";
150
		}	
151
		if (fileType.equalsIgnoreCase("xls")) {
152
			chartName = "Object 1";			
153
		}
154
		
155
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
156
		
157
		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
158
159
		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
160
		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
161
		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
162
		XChartDocument xChartDocument = null; 		
163
		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
164
		SCUtil.setChartType(xChartDocument, inputType);
165
		
166
		SCUtil.setProperties(xChartDocument.getDiagram(), "DataCaption", labelType);
167
168
		SCUtil.saveFileAs(scComponent, fileName, fileType);
169
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
170
		sheet = SCUtil.getCurrentSheet(scDocument);
171
		
172
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
173
		result = ((Integer) SCUtil.getProperties(xChartDocument.getDiagram(), "DataCaption")).intValue();
174
		SCUtil.closeFile(scDocument);
175
		
176
		assertEquals("Incorrect chart data label types got in ." + fileType + " file.", labelType, result, 0);
177
178
	}
179
	
180
}
(-)testuno/source/testcase/uno/sc/chart/ChartGrid.java (+286 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
package testcase.uno.sc.chart;
23
24
import static org.junit.Assert.assertArrayEquals;
25
26
import java.util.Arrays;
27
import java.util.Collection;
28
29
import org.junit.After;
30
import org.junit.AfterClass;
31
import org.junit.Before;
32
import org.junit.BeforeClass;
33
import org.junit.Test;
34
import org.junit.runner.RunWith;
35
import org.junit.runners.Parameterized;
36
import org.junit.runners.Parameterized.Parameters;
37
import org.openoffice.test.uno.UnoApp;
38
39
import testlib.uno.SCUtil;
40
41
import com.sun.star.awt.Rectangle;
42
import com.sun.star.chart.XChartDocument;
43
import com.sun.star.chart.XDiagram;
44
import com.sun.star.lang.XComponent;
45
import com.sun.star.sheet.XSpreadsheet;
46
import com.sun.star.sheet.XSpreadsheetDocument;
47
import com.sun.star.table.CellRangeAddress;
48
49
/**
50
 *  Check Grids in chart can be applied and saved
51
 * 
52
 */
53
@RunWith(value = Parameterized.class)
54
public class ChartGrid {
55
56
	private Boolean[] majorGrids;
57
	private Boolean[] minorGrids;
58
	private String inputType;
59
	private double[][] numberData;	
60
	private String fileType;
61
	
62
	private static final UnoApp unoApp = new UnoApp();
63
	
64
	XComponent scComponent = null;
65
	XSpreadsheetDocument scDocument = null;
66
	
67
	@Parameters
68
	public static Collection<Object[]> data() throws Exception {
69
		double[][] numberData1 = {
70
				{10, 20, 30, 40},
71
				{20, 40.3, 50, 80},
72
				{40, 20, 30, 10},
73
				{10, -10, 0, -30}
74
		};
75
		Boolean[][] gridsList = {
76
				{false, false, false}, //[0] no grid
77
				{true, false, false}, // [1] X 
78
				{false, true, false}, // [2] Y
79
				{true, true, false}, // [3] X & Y
80
				{true, true, true}, // [4] X & Y & Z
81
				{false, false, true}, // [5] Z
82
				{false, true, true}, // [6] Y & Z
83
				{true, false, true} // [7] X & Z
84
		};
85
86
		return Arrays.asList(new Object[][] {
87
			{gridsList[0], null, "com.sun.star.chart.BarDiagram", numberData1, "ods"},
88
			{gridsList[2], gridsList[3], "com.sun.star.chart.BarDiagram", numberData1, "ods"},
89
			{gridsList[2], gridsList[4], "com.sun.star.chart.BarDiagram", numberData1, "ods"},
90
			{gridsList[6], gridsList[7], "com.sun.star.chart.BarDiagram", numberData1, "ods"},
91
			{gridsList[1], gridsList[5], "com.sun.star.chart.BarDiagram", numberData1, "ods"},
92
			{gridsList[4], gridsList[4], "com.sun.star.chart.BarDiagram", numberData1, "ods"},
93
			
94
			{gridsList[0], null, "com.sun.star.chart.BarDiagram", numberData1, "xls"},
95
			{gridsList[2], gridsList[3], "com.sun.star.chart.BarDiagram", numberData1, "xls"}
96
//			{null, gridsList[4], "com.sun.star.chart.BarDiagram", numberData1, "xls"},
97
//			{gridsList[6], gridsList[7], "com.sun.star.chart.BarDiagram", numberData1, "xls"},
98
//			{gridsList[1], gridsList[5], "com.sun.star.chart.BarDiagram", numberData1, "xls"},
99
//			{gridsList[4], gridsList[4], "com.sun.star.chart.BarDiagram", numberData1, "xls"}
100
		
101
		});
102
	}
103
	
104
	public ChartGrid(Boolean[] majorGrids, Boolean[] minorGrids, String inputType, double[][] numberData, String fileType) {
105
		this.majorGrids = majorGrids;
106
		this.minorGrids = minorGrids;
107
		this.inputType = inputType;
108
		this.numberData = numberData;
109
		this.fileType = fileType;
110
	}
111
		
112
	@Before
113
	public void setUp() throws Exception {
114
		scComponent = unoApp.newDocument("scalc");
115
		scDocument = SCUtil.getSCDocument(scComponent);
116
	}
117
118
	@After
119
	public void tearDown() throws Exception {
120
		unoApp.closeDocument(scComponent);
121
		
122
	}
123
	
124
	@BeforeClass
125
	public static void setUpConnection() throws Exception {
126
		unoApp.start();
127
	}
128
129
	@AfterClass
130
	public static void tearDownConnection() throws InterruptedException, Exception {
131
		unoApp.close();
132
		SCUtil.clearTempDir();	
133
	}
134
	
135
	/**
136
	 * Enable different types of grids in chart.
137
	 * 1. Create a spreadsheet file.
138
	 * 2. Input number in a cell range and create a 2D chart.
139
	 * 3. Enable grids of X/Y axis in chart.
140
	 * 4. Save file as ODF/MSBinary format.
141
	 * 5. Close and reopen file.  -> Check the grid setting.
142
	 * @throws Exception
143
	 */
144
	@Test
145
	public void testCreateXYGrid() throws Exception {
146
		String fileName = "testCreateXYGrid";
147
		String chartName = "testChart";
148
		String cellRangeName = "A1:D4";
149
		Boolean[][] expected = {
150
				{false, true, false},
151
				{false, false, false}
152
		};
153
		Boolean[][] results = {
154
				{false, false, false},
155
				{false, false, false}
156
		};	
157
		
158
		if (inputType.equals("com.sun.star.chart.StockDiagram")) {
159
			cellRangeName = "A1:C4";
160
		}	
161
		if (fileType.equalsIgnoreCase("xls")) {
162
			chartName = "Object 1";			
163
		}
164
		
165
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
166
		
167
		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
168
169
		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
170
		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
171
		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
172
		XChartDocument xChartDocument = null; 		
173
		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
174
		SCUtil.setChartType(xChartDocument, inputType);
175
		XDiagram xDiagram = xChartDocument.getDiagram(); 
176
		
177
		if (majorGrids != null) {
178
			SCUtil.setProperties(xDiagram, "HasXAxisGrid", majorGrids[0]);
179
			SCUtil.setProperties(xDiagram, "HasYAxisGrid", majorGrids[1]);
180
			expected[0][0] = majorGrids[0];
181
			expected[0][1] = majorGrids[1];
182
		}
183
		if (minorGrids != null) {
184
			SCUtil.setProperties(xDiagram, "HasXAxisHelpGrid", minorGrids[0]);
185
			SCUtil.setProperties(xDiagram, "HasYAxisHelpGrid", minorGrids[1]);
186
			expected[1][0] = minorGrids[0];
187
			expected[1][1] = minorGrids[1];
188
		}
189
		
190
		SCUtil.saveFileAs(scComponent, fileName, fileType);
191
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
192
		sheet = SCUtil.getCurrentSheet(scDocument);
193
		
194
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
195
		xDiagram = xChartDocument.getDiagram(); 
196
		results[0][0] = (Boolean) SCUtil.getProperties(xDiagram, "HasXAxisGrid");
197
		results[0][1] = (Boolean) SCUtil.getProperties(xDiagram, "HasYAxisGrid");
198
		results[1][0] = (Boolean) SCUtil.getProperties(xDiagram, "HasXAxisHelpGrid");
199
		results[1][1] = (Boolean) SCUtil.getProperties(xDiagram, "HasYAxisHelpGrid");
200
		
201
		SCUtil.closeFile(scDocument);
202
		
203
		assertArrayEquals("Incorrect chart grids got in ." + fileType + " file.", expected, results);
204
205
	}
206
	
207
	/** 
208
	 * Enable different types of grids in chart.
209
	 * 1. Create a spreadsheet file.
210
	 * 2. Input number in a cell range and create a 3D chart.
211
	 * 3. Enable grids of X/Y/Z axes in chart.
212
	 * 4. Save file as ODF/MSBinary format.
213
	 * 5. Close and reopen file.  -> Check the grid setting.
214
	 * @throws Exception
215
	 */
216
	@Test
217
	public void testCreateXYZGrid() throws Exception {
218
		String fileName = "testCreateXYZGrid";
219
		String chartName = "testChart";
220
		String cellRangeName = "A1:D4";
221
		Boolean[][] expected = {
222
				{false, true, false},
223
				{false, false, false}
224
		};
225
		Boolean[][] results = {
226
				{false, false, false},
227
				{false, false, false}
228
		};	
229
		
230
		if (inputType.equals("com.sun.star.chart.StockDiagram")) {
231
			cellRangeName = "A1:C4";
232
		}	
233
		if (fileType.equalsIgnoreCase("xls")) {
234
			chartName = "Object 1";			
235
		}
236
		
237
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
238
		
239
		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
240
241
		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
242
		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
243
		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
244
		XChartDocument xChartDocument = null; 		
245
		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
246
		SCUtil.setChartType(xChartDocument, inputType);
247
		SCUtil.setProperties(xChartDocument.getDiagram(), "Dim3D", true);
248
		XDiagram xDiagram = xChartDocument.getDiagram();
249
		
250
		if (majorGrids != null) {
251
			SCUtil.setProperties(xDiagram, "HasXAxisGrid", majorGrids[0]);
252
			SCUtil.setProperties(xDiagram, "HasYAxisGrid", majorGrids[1]);
253
			SCUtil.setProperties(xDiagram, "HasZAxisGrid", majorGrids[2]);
254
			expected[0][0] = majorGrids[0];
255
			expected[0][1] = majorGrids[1];
256
			expected[0][2] = majorGrids[2];
257
		}
258
		if (minorGrids != null) {
259
			SCUtil.setProperties(xDiagram, "HasXAxisHelpGrid", minorGrids[0]);
260
			SCUtil.setProperties(xDiagram, "HasYAxisHelpGrid", minorGrids[1]);
261
			SCUtil.setProperties(xDiagram, "HasZAxisHelpGrid", minorGrids[2]);
262
			expected[1][0] = minorGrids[0];
263
			expected[1][1] = minorGrids[1];
264
			expected[1][2] = minorGrids[2];
265
		}
266
267
		SCUtil.saveFileAs(scComponent, fileName, fileType);
268
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
269
		sheet = SCUtil.getCurrentSheet(scDocument);
270
		
271
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
272
		xDiagram = xChartDocument.getDiagram(); 
273
		results[0][0] = (Boolean) SCUtil.getProperties(xDiagram, "HasXAxisGrid");
274
		results[0][1] = (Boolean) SCUtil.getProperties(xDiagram, "HasYAxisGrid");
275
		results[0][2] = (Boolean) SCUtil.getProperties(xDiagram, "HasZAxisGrid");
276
		results[1][0] = (Boolean) SCUtil.getProperties(xDiagram, "HasXAxisHelpGrid");
277
		results[1][1] = (Boolean) SCUtil.getProperties(xDiagram, "HasYAxisHelpGrid");
278
		results[1][2] = (Boolean) SCUtil.getProperties(xDiagram, "HasZAxisHelpGrid");
279
280
		SCUtil.closeFile(scDocument);
281
		
282
		assertArrayEquals("Incorrect chart grids got in ." + fileType + " file.", expected, results);
283
284
	}
285
	
286
}
(-)testuno/source/testcase/uno/sc/chart/ChartMeanValueLine.java (+177 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
package testcase.uno.sc.chart;
23
24
import static org.junit.Assert.assertFalse;
25
import static org.junit.Assert.assertTrue;
26
27
import java.util.Arrays;
28
import java.util.Collection;
29
30
import org.junit.After;
31
import org.junit.AfterClass;
32
import org.junit.Before;
33
import org.junit.BeforeClass;
34
import org.junit.Test;
35
import org.junit.runner.RunWith;
36
import org.junit.runners.Parameterized;
37
import org.junit.runners.Parameterized.Parameters;
38
import org.openoffice.test.uno.UnoApp;
39
40
import testlib.uno.SCUtil;
41
42
import com.sun.star.awt.Rectangle;
43
import com.sun.star.chart.XChartDocument;
44
import com.sun.star.chart.XDiagram;
45
import com.sun.star.lang.XComponent;
46
import com.sun.star.sheet.XSpreadsheet;
47
import com.sun.star.sheet.XSpreadsheetDocument;
48
import com.sun.star.table.CellRangeAddress;
49
50
/**
51
 *  Check mean value line in chart can be applied and saved
52
 * 
53
 */
54
@RunWith(value = Parameterized.class)
55
public class ChartMeanValueLine {
56
57
	private Boolean expected;
58
	private Boolean meanValueLine;
59
	private String inputType;
60
	private double[][] numberData;	
61
	private String fileType;
62
	
63
	private static final UnoApp unoApp = new UnoApp();
64
	
65
	XComponent scComponent = null;
66
	XSpreadsheetDocument scDocument = null;
67
	
68
	@Parameters
69
	public static Collection<Object[]> data() throws Exception {
70
		double[][] numberData1 = {
71
				{10, 20, 30, 40},
72
				{20, 40.3, 50, 80},
73
				{40, 20, 30, 10},
74
				{10, -10, 0, -30}
75
		};
76
77
		return Arrays.asList(new Object[][] {
78
			{true, true, "com.sun.star.chart.BarDiagram", numberData1, "ods"},
79
			{true, true, "com.sun.star.chart.LineDiagram", numberData1, "ods"},
80
			{true, true, "com.sun.star.chart.AreaDiagram", numberData1, "ods"},
81
			{true, true, "com.sun.star.chart.XYDiagram", numberData1, "ods"},
82
			
83
			{false, true, "com.sun.star.chart.BarDiagram", numberData1, "xls"}, //Excel does not support this property, save as .xls, the setting will be lost.
84
			{false, true, "com.sun.star.chart.LineDiagram", numberData1, "xls"},
85
			{false, true, "com.sun.star.chart.AreaDiagram", numberData1, "xls"},
86
			{false, true, "com.sun.star.chart.XYDiagram", numberData1, "xls"}		
87
		});
88
	}
89
	
90
	public ChartMeanValueLine(Boolean expected, Boolean meanValueLine, String inputType, double[][] numberData, String fileType) {
91
		this.expected = expected;
92
		this.meanValueLine = meanValueLine;
93
		this.inputType = inputType;
94
		this.numberData = numberData;
95
		this.fileType = fileType;
96
	}
97
		
98
	@Before
99
	public void setUp() throws Exception {
100
		scComponent = unoApp.newDocument("scalc");
101
		scDocument = SCUtil.getSCDocument(scComponent);
102
	}
103
104
	@After
105
	public void tearDown() throws Exception {
106
		unoApp.closeDocument(scComponent);
107
		
108
	}
109
	
110
	@BeforeClass
111
	public static void setUpConnection() throws Exception {
112
		unoApp.start();
113
	}
114
115
	@AfterClass
116
	public static void tearDownConnection() throws InterruptedException, Exception {
117
		unoApp.close();
118
		SCUtil.clearTempDir();	
119
	}
120
	
121
	/**
122
	 * Enable different types of mean value line in chart.
123
	 * 1. Create a spreadsheet file.
124
	 * 2. Input number in a cell range and create a 2D chart.
125
	 * 3. Enable mean value line in chart.
126
	 * 4. Save file as ODF/MSBinary format.
127
	 * 5. Close and reopen file.  -> Check the mean value line setting.
128
	 * @throws Exception
129
	 */
130
	@Test
131
	public void testCreateTrendline() throws Exception {
132
		String fileName = "testCreateMeanValueline";
133
		String chartName = "testChart";
134
		String cellRangeName = "A1:D4";
135
		Boolean result = null;
136
		
137
		if (inputType.equals("com.sun.star.chart.StockDiagram")) {
138
			cellRangeName = "A1:C4";
139
		}	
140
		if (fileType.equalsIgnoreCase("xls")) {
141
			chartName = "Object 1";			
142
		}
143
		
144
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
145
		
146
		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
147
148
		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
149
		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
150
		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
151
		XChartDocument xChartDocument = null; 		
152
		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
153
		SCUtil.setChartType(xChartDocument, inputType);
154
		XDiagram xDiagram = xChartDocument.getDiagram(); 
155
		
156
		SCUtil.setProperties(xDiagram, "MeanValue", meanValueLine);
157
		
158
		SCUtil.saveFileAs(scComponent, fileName, fileType);
159
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
160
		sheet = SCUtil.getCurrentSheet(scDocument);
161
		
162
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
163
		xDiagram = xChartDocument.getDiagram(); 
164
		result = (Boolean) SCUtil.getProperties(xDiagram, "MeanValue");
165
166
		SCUtil.closeFile(scDocument);
167
		
168
		if (expected) {
169
			assertTrue("Incorrect chart trendline got in ." + fileType + " file.", result);
170
		}
171
		else {
172
			assertFalse("Incorrect chart trendline got in ." + fileType + " file.", result);
173
		}
174
		
175
	}
176
	
177
}
(-)testuno/source/testcase/uno/sc/chart/ChartTitle.java (+305 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
package testcase.uno.sc.chart;
23
24
import static org.junit.Assert.assertEquals;
25
import static org.junit.Assert.assertFalse;
26
import static org.junit.Assert.assertTrue;
27
28
import java.util.Arrays;
29
import java.util.Collection;
30
31
import org.junit.After;
32
import org.junit.AfterClass;
33
import org.junit.Before;
34
import org.junit.BeforeClass;
35
import org.junit.Test;
36
import org.junit.runner.RunWith;
37
import org.junit.runners.Parameterized;
38
import org.junit.runners.Parameterized.Parameters;
39
import org.openoffice.test.uno.UnoApp;
40
41
import testlib.uno.SCUtil;
42
43
import com.sun.star.awt.Rectangle;
44
import com.sun.star.chart.XChartDocument;
45
import com.sun.star.drawing.XShape;
46
import com.sun.star.lang.XComponent;
47
import com.sun.star.sheet.XSpreadsheet;
48
import com.sun.star.sheet.XSpreadsheetDocument;
49
import com.sun.star.table.CellRangeAddress;
50
51
/**
52
 *  Check the chart title/subtitle can be created, modified and saved
53
 * 
54
 */
55
@RunWith(value = Parameterized.class)
56
public class ChartTitle {
57
58
	private String[] titles;
59
	private String inputType;
60
	private double[][] numberData;
61
	private String fileType;
62
	
63
	private static final UnoApp unoApp = new UnoApp();
64
	
65
	XComponent scComponent = null;
66
	XSpreadsheetDocument scDocument = null;
67
	
68
	@Parameters
69
	public static Collection<Object[]> data() throws Exception {
70
		double[][] numberData1 = {
71
				{1, 2, 3, 4},
72
				{2, 4.3, 5, 8},
73
				{4, 2, 3, 1},
74
				{1, -1, 0, -3}
75
		};
76
		String[][] titles = {
77
				{"MyMainTitle", "MySubTitle"},
78
				{"A Main Title With Space", "   Sub Title "},
79
				{"  ", "      "}			
80
		};
81
82
		return Arrays.asList(new Object[][] {
83
			{titles[0], "com.sun.star.chart.BarDiagram", numberData1, "ods"},
84
			{titles[1], "com.sun.star.chart.NetDiagram", numberData1, "ods"},
85
			{titles[2], "com.sun.star.chart.AreaDiagram", numberData1, "ods"},
86
			{titles[0], "com.sun.star.chart.PieDiagram", numberData1, "xls"},
87
			{titles[1], "com.sun.star.chart.NetDiagram", numberData1, "xls"},
88
			{titles[2], "com.sun.star.chart.XYDiagram", numberData1, "xls"}
89
		});
90
	}
91
	
92
	public ChartTitle(String[] titles, String inputType, double[][] numberData, String fileType) {
93
		this.titles = titles;
94
		this.inputType = inputType;
95
		this.numberData = numberData;
96
		this.fileType = fileType;
97
	}
98
	
99
	
100
	@Before
101
	public void setUp() throws Exception {
102
		scComponent = unoApp.newDocument("scalc");
103
		scDocument = SCUtil.getSCDocument(scComponent);
104
	}
105
106
	@After
107
	public void tearDown() throws Exception {
108
		unoApp.closeDocument(scComponent);
109
		
110
	}
111
	
112
	@BeforeClass
113
	public static void setUpConnection() throws Exception {
114
		unoApp.start();
115
	}
116
117
	@AfterClass
118
	public static void tearDownConnection() throws InterruptedException, Exception {
119
		unoApp.close();
120
		SCUtil.clearTempDir();	
121
	}
122
	
123
	/**
124
	 * Create main title in chart.
125
	 * 1. Create a spreadsheet file.
126
	 * 2. Input number in a cell range and create a chart.
127
	 * 3. Create main title in chart.
128
	 * 4. Save file as ODF/MSBinary format.
129
	 * 5. Close and reopen file.  -> Check the chart main title.
130
	 * @throws Exception
131
	 */
132
	@Test
133
	public void testCreateMainTitle() throws Exception {
134
		String fileName = "testCreateMainTitle";
135
		String chartName = "testChart";
136
		String cellRangeName = "A1:D4";
137
		Boolean result = null;	
138
		String resultTitle = null;
139
		String defaultTitle = null;
140
		
141
		if (inputType.equals("com.sun.star.chart.StockDiagram")) {
142
			cellRangeName = "A1:C4";
143
		}	
144
		if (fileType.equalsIgnoreCase("xls")) {
145
			chartName = "Object 1";			
146
		}
147
		
148
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
149
		
150
		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
151
152
		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
153
		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
154
		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
155
		XChartDocument xChartDocument = null; 		
156
		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
157
		SCUtil.setChartType(xChartDocument, inputType);
158
		
159
		result = (Boolean) SCUtil.getProperties(xChartDocument, "HasMainTitle");
160
		if (!result) {
161
			SCUtil.setProperties(xChartDocument, "HasMainTitle", true);
162
		}
163
		XShape aTitle = xChartDocument.getTitle();
164
		defaultTitle = (String) SCUtil.getProperties(aTitle, "String");
165
		
166
		SCUtil.saveFileAs(scComponent, fileName, fileType);
167
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
168
		sheet = SCUtil.getCurrentSheet(scDocument);
169
		
170
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
171
		result = (Boolean) SCUtil.getProperties(xChartDocument, "HasMainTitle");
172
		resultTitle = (String) SCUtil.getProperties(xChartDocument.getTitle(), "String");		
173
		SCUtil.closeFile(scDocument);
174
		
175
		assertTrue("Chart title has not be created in ." + fileType + " file.", result);
176
		assertEquals("Incorrect chart title got in ." + fileType + " file.", defaultTitle, resultTitle);
177
178
	}
179
	
180
	/**
181
	 * Create sub title in chart.
182
	 * 1. Create a spreadsheet file.
183
	 * 2. Input number in a cell range and create a chart.
184
	 * 3. Create subtitle in chart.
185
	 * 4. Save file as ODF/MSBinary format.
186
	 * 5. Close and reopen file.  -> Check the chart main title.
187
	 * @throws Exception
188
	 */
189
	@Test
190
	public void testCreateSubTitle() throws Exception {
191
		String fileName = "testCreateSubTitle";
192
		String chartName = "testChart";
193
		String cellRangeName = "A1:D4";
194
		Boolean result = null;	
195
		String resultTitle = null;
196
		String defaultTitle = null;
197
		
198
		if (inputType.equals("com.sun.star.chart.StockDiagram")) {
199
			cellRangeName = "A1:C4";
200
		}	
201
		if (fileType.equalsIgnoreCase("xls")) {
202
			chartName = "Object 1";			
203
		}
204
		
205
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
206
		
207
		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
208
209
		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
210
		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
211
		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
212
		XChartDocument xChartDocument = null; 		
213
		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
214
		SCUtil.setChartType(xChartDocument, inputType);
215
		result = (Boolean) SCUtil.getProperties(xChartDocument, "HasSubTitle");
216
		if (!result) {
217
			SCUtil.setProperties(xChartDocument, "HasSubTitle", true);
218
		}
219
		XShape aSubTitle = xChartDocument.getSubTitle();
220
		defaultTitle = (String) SCUtil.getProperties(aSubTitle, "String");
221
		
222
		SCUtil.saveFileAs(scComponent, fileName, fileType);
223
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
224
		sheet = SCUtil.getCurrentSheet(scDocument);
225
		
226
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
227
		result = (Boolean) SCUtil.getProperties(xChartDocument, "HasSubTitle");
228
		resultTitle = (String) SCUtil.getProperties(xChartDocument.getSubTitle(), "String");		
229
		SCUtil.closeFile(scDocument);
230
		
231
		
232
		if (fileType.equalsIgnoreCase("xls")) {
233
			assertFalse("Chart subtitle should not be saved in ." + fileType + " file.", result);
234
		}
235
		else {
236
			assertTrue("Chart subtitle has not be created in ." + fileType + " file.", result);
237
			assertEquals("Incorrect chart subtitle got in ." + fileType + " file.", defaultTitle, resultTitle);
238
		}	
239
240
	}
241
	
242
	/**
243
	 * Create titles in chart and change title string.
244
	 * 1. Create a spreadsheet file.
245
	 * 2. Input number in a cell range and create a chart.
246
	 * 3. Create main title and subtitle in chart, input customized string in title box.
247
	 * 4. Save file as ODF/MSBinary format.
248
	 * 5. Close and reopen file.  -> Check the chart titles.
249
	 * @throws Exception
250
	 */
251
	@Test
252
	public void testInputTitles() throws Exception {
253
		String fileName = "testInputTitles";
254
		String chartName = "testChart";
255
		String cellRangeName = "A1:D4";
256
		Boolean[] result = new Boolean[2];	
257
		String[] resultTitle = new String[2];
258
		
259
		if (inputType.equals("com.sun.star.chart.StockDiagram")) {
260
			cellRangeName = "A1:C4";
261
		}	
262
		if (fileType.equalsIgnoreCase("xls")) {
263
			chartName = "Object 1";			
264
		}
265
		
266
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
267
		
268
		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
269
270
		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
271
		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
272
		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
273
		XChartDocument xChartDocument = null; 		
274
		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
275
		SCUtil.setChartType(xChartDocument, inputType);
276
		SCUtil.setProperties(xChartDocument, "HasMainTitle", true);
277
		SCUtil.setProperties(xChartDocument, "HasSubTitle", true);
278
		
279
		SCUtil.setProperties(xChartDocument.getTitle(), "String", titles[0]);
280
		SCUtil.setProperties(xChartDocument.getSubTitle(), "String", titles[1]);
281
		
282
		SCUtil.saveFileAs(scComponent, fileName, fileType);
283
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
284
		sheet = SCUtil.getCurrentSheet(scDocument);
285
		
286
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
287
		result[0] = (Boolean) SCUtil.getProperties(xChartDocument, "HasMainTitle");
288
		result[1] = (Boolean) SCUtil.getProperties(xChartDocument, "HasSubTitle");
289
		resultTitle[0] = (String) SCUtil.getProperties(xChartDocument.getTitle(), "String");	
290
		resultTitle[1] = (String) SCUtil.getProperties(xChartDocument.getSubTitle(), "String");		
291
		SCUtil.closeFile(scDocument);
292
		
293
		assertTrue("Chart main title has not be created in ." + fileType + " file.", result[0]);
294
		assertEquals("Incorrect chart title got in ." + fileType + " file.", titles[0], resultTitle[0]);
295
		if (fileType.equalsIgnoreCase("xls")) {
296
			assertFalse("Chart subtitle should not be saved in ." + fileType + " file.", result[1]);
297
		}
298
		else {
299
			assertTrue("Chart subtitle has not be created in ." + fileType + " file.", result[1]);
300
			assertEquals("Incorrect chart subtitle got in ." + fileType + " file.", titles[1], resultTitle[1]);
301
		}	
302
303
	}
304
	
305
}
(-)testuno/source/testcase/uno/sc/chart/ChartTrendline.java (+175 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
package testcase.uno.sc.chart;
23
24
import static org.junit.Assert.assertEquals;
25
26
import java.util.Arrays;
27
import java.util.Collection;
28
29
import org.junit.After;
30
import org.junit.AfterClass;
31
import org.junit.Before;
32
import org.junit.BeforeClass;
33
import org.junit.Test;
34
import org.junit.runner.RunWith;
35
import org.junit.runners.Parameterized;
36
import org.junit.runners.Parameterized.Parameters;
37
import org.openoffice.test.uno.UnoApp;
38
39
import testlib.uno.SCUtil;
40
41
import com.sun.star.awt.Rectangle;
42
import com.sun.star.chart.ChartRegressionCurveType;
43
import com.sun.star.chart.XChartDocument;
44
import com.sun.star.chart.XDiagram;
45
import com.sun.star.lang.XComponent;
46
import com.sun.star.sheet.XSpreadsheet;
47
import com.sun.star.sheet.XSpreadsheetDocument;
48
import com.sun.star.table.CellRangeAddress;
49
50
/**
51
 *  Check trend line in chart can be applied and saved
52
 * 
53
 */
54
@RunWith(value = Parameterized.class)
55
public class ChartTrendline {
56
57
	private ChartRegressionCurveType expected;
58
	private ChartRegressionCurveType trendlineType;
59
	private String inputType;
60
	private double[][] numberData;	
61
	private String fileType;
62
	
63
	private static final UnoApp unoApp = new UnoApp();
64
	
65
	XComponent scComponent = null;
66
	XSpreadsheetDocument scDocument = null;
67
	
68
	@Parameters
69
	public static Collection<Object[]> data() throws Exception {
70
		double[][] numberData1 = {
71
				{10, 20, 30, 40},
72
				{20, 40.3, 50, 80},
73
				{40, 20, 30, 10},
74
				{10, -10, 0, -30}
75
		};
76
77
		return Arrays.asList(new Object[][] {
78
			{ChartRegressionCurveType.NONE, ChartRegressionCurveType.NONE, "com.sun.star.chart.LineDiagram", numberData1, "ods"},
79
			{ChartRegressionCurveType.LINEAR, ChartRegressionCurveType.LINEAR, "com.sun.star.chart.LineDiagram", numberData1, "ods"},
80
			{ChartRegressionCurveType.LOGARITHM, ChartRegressionCurveType.LOGARITHM, "com.sun.star.chart.AreaDiagram", numberData1, "ods"},
81
			{ChartRegressionCurveType.EXPONENTIAL, ChartRegressionCurveType.EXPONENTIAL, "com.sun.star.chart.XYDiagram", numberData1, "ods"},
82
			{ChartRegressionCurveType.POWER, ChartRegressionCurveType.POWER, "com.sun.star.chart.BarDiagram", numberData1, "ods"},
83
			
84
			{ChartRegressionCurveType.NONE, ChartRegressionCurveType.NONE, "com.sun.star.chart.BarDiagram", numberData1, "xls"},
85
			{ChartRegressionCurveType.LINEAR, ChartRegressionCurveType.LINEAR, "com.sun.star.chart.XYDiagram", numberData1, "xls"},
86
			{ChartRegressionCurveType.LOGARITHM, ChartRegressionCurveType.LOGARITHM, "com.sun.star.chart.LineDiagram", numberData1, "xls"},
87
			{ChartRegressionCurveType.EXPONENTIAL, ChartRegressionCurveType.EXPONENTIAL, "com.sun.star.chart.AreaDiagram", numberData1, "xls"},
88
			{ChartRegressionCurveType.POWER, ChartRegressionCurveType.POWER, "com.sun.star.chart.BarDiagram", numberData1, "xls"}
89
		
90
		});
91
	}
92
	
93
	public ChartTrendline(ChartRegressionCurveType expected, ChartRegressionCurveType trendlineType, String inputType, double[][] numberData, String fileType) {
94
		this.expected = expected;
95
		this.trendlineType = trendlineType;
96
		this.inputType = inputType;
97
		this.numberData = numberData;
98
		this.fileType = fileType;
99
	}
100
		
101
	@Before
102
	public void setUp() throws Exception {
103
		scComponent = unoApp.newDocument("scalc");
104
		scDocument = SCUtil.getSCDocument(scComponent);
105
	}
106
107
	@After
108
	public void tearDown() throws Exception {
109
		unoApp.closeDocument(scComponent);
110
		
111
	}
112
	
113
	@BeforeClass
114
	public static void setUpConnection() throws Exception {
115
		unoApp.start();
116
	}
117
118
	@AfterClass
119
	public static void tearDownConnection() throws InterruptedException, Exception {
120
		unoApp.close();
121
		SCUtil.clearTempDir();	
122
	}
123
	
124
	/**
125
	 * Enable different types of trend line in chart.
126
	 * 1. Create a spreadsheet file.
127
	 * 2. Input number in a cell range and create a 2D chart.
128
	 * 3. Enable trend line in chart.
129
	 * 4. Save file as ODF/MSBinary format.
130
	 * 5. Close and reopen file.  -> Check the trend line setting.
131
	 * @throws Exception
132
	 */
133
	@Test
134
	public void testCreateTrendline() throws Exception {
135
		String fileName = "testCreateTrendline";
136
		String chartName = "testChart";
137
		String cellRangeName = "A1:D4";
138
		ChartRegressionCurveType result = null;
139
		
140
		if (inputType.equals("com.sun.star.chart.StockDiagram")) {
141
			cellRangeName = "A1:C4";
142
		}	
143
		if (fileType.equalsIgnoreCase("xls")) {
144
			chartName = "Object 1";			
145
		}
146
		
147
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
148
		
149
		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
150
151
		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
152
		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
153
		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
154
		XChartDocument xChartDocument = null; 		
155
		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
156
		SCUtil.setChartType(xChartDocument, inputType);
157
		XDiagram xDiagram = xChartDocument.getDiagram(); 
158
		
159
		SCUtil.setProperties(xDiagram, "RegressionCurves", trendlineType);
160
		
161
		SCUtil.saveFileAs(scComponent, fileName, fileType);
162
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
163
		sheet = SCUtil.getCurrentSheet(scDocument);
164
		
165
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
166
		xDiagram = xChartDocument.getDiagram(); 
167
		result = (ChartRegressionCurveType) SCUtil.getProperties(xDiagram, "RegressionCurves");
168
169
		SCUtil.closeFile(scDocument);
170
		
171
		assertEquals("Incorrect chart trendline got in ." + fileType + " file.", expected, result);
172
173
	}
174
	
175
}
(-)testuno/source/testcase/uno/sc/chart/ChartYErrorBar.java (+186 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
package testcase.uno.sc.chart;
23
24
import static org.junit.Assert.assertEquals;
25
26
import java.util.Arrays;
27
import java.util.Collection;
28
29
import org.junit.After;
30
import org.junit.AfterClass;
31
import org.junit.Before;
32
import org.junit.BeforeClass;
33
import org.junit.Test;
34
import org.junit.runner.RunWith;
35
import org.junit.runners.Parameterized;
36
import org.junit.runners.Parameterized.Parameters;
37
import org.openoffice.test.uno.UnoApp;
38
39
import testlib.uno.SCUtil;
40
41
import com.sun.star.awt.Rectangle;
42
import com.sun.star.chart.ChartErrorCategory;
43
import com.sun.star.chart.ChartErrorIndicatorType;
44
import com.sun.star.chart.XChartDocument;
45
import com.sun.star.chart.XDiagram;
46
import com.sun.star.lang.XComponent;
47
import com.sun.star.sheet.XSpreadsheet;
48
import com.sun.star.sheet.XSpreadsheetDocument;
49
import com.sun.star.table.CellRangeAddress;
50
51
/**
52
 *  Check Y error bar in chart can be applied and saved
53
 * 
54
 */
55
@RunWith(value = Parameterized.class)
56
public class ChartYErrorBar {
57
58
	private ChartErrorCategory expCategory;
59
	private ChartErrorIndicatorType expIndicator;
60
	private ChartErrorCategory inputCategory;
61
	private ChartErrorIndicatorType inputIndicator;
62
	private String inputType;
63
	private double[][] numberData;	
64
	private String fileType;
65
	
66
	private static final UnoApp unoApp = new UnoApp();
67
	
68
	XComponent scComponent = null;
69
	XSpreadsheetDocument scDocument = null;
70
	
71
	@Parameters
72
	public static Collection<Object[]> data() throws Exception {
73
		double[][] numberData1 = {
74
				{10, 20, 30, 40},
75
				{20, 40.3, 50, 80},
76
				{40, 20, 30, 10},
77
				{10, -10, 0, -30}
78
		};
79
80
		return Arrays.asList(new Object[][] {
81
			{ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, "com.sun.star.chart.BarDiagram", numberData1, "ods"},
82
			{ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.LineDiagram", numberData1, "ods"},
83
			{ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.AreaDiagram", numberData1, "ods"},
84
			{ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, "com.sun.star.chart.BarDiagram", numberData1, "ods"},
85
			{ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.LineDiagram", numberData1, "ods"},
86
			{ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.AreaDiagram", numberData1, "ods"},
87
			
88
			{ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, ChartErrorCategory.NONE, ChartErrorIndicatorType.NONE, "com.sun.star.chart.BarDiagram", numberData1, "xls"},
89
//			{ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.VARIANCE, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.LineDiagram", numberData1, "xls"},
90
			{ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, ChartErrorCategory.STANDARD_DEVIATION, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.AreaDiagram", numberData1, "xls"},
91
			{ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, ChartErrorCategory.PERCENT, ChartErrorIndicatorType.LOWER, "com.sun.star.chart.BarDiagram", numberData1, "xls"},
92
//			{ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, ChartErrorCategory.ERROR_MARGIN, ChartErrorIndicatorType.TOP_AND_BOTTOM, "com.sun.star.chart.AreaDiagram", numberData1, "xls"},
93
			{ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, ChartErrorCategory.CONSTANT_VALUE, ChartErrorIndicatorType.UPPER, "com.sun.star.chart.LineDiagram", numberData1, "xls"}
94
		
95
		});
96
	}
97
	
98
	public ChartYErrorBar(ChartErrorCategory expCategory, ChartErrorIndicatorType expIndicator, ChartErrorCategory inputCategory, ChartErrorIndicatorType inputIndicator, String inputType, double[][] numberData, String fileType) {
99
		this.expCategory = expCategory;
100
		this.expIndicator = expIndicator;
101
		this.inputCategory = inputCategory;
102
		this.inputIndicator = inputIndicator;
103
		this.inputType = inputType;
104
		this.numberData = numberData;
105
		this.fileType = fileType;
106
	}
107
		
108
	@Before
109
	public void setUp() throws Exception {
110
		scComponent = unoApp.newDocument("scalc");
111
		scDocument = SCUtil.getSCDocument(scComponent);
112
	}
113
114
	@After
115
	public void tearDown() throws Exception {
116
		unoApp.closeDocument(scComponent);
117
		
118
	}
119
	
120
	@BeforeClass
121
	public static void setUpConnection() throws Exception {
122
		unoApp.start();
123
	}
124
125
	@AfterClass
126
	public static void tearDownConnection() throws InterruptedException, Exception {
127
		unoApp.close();
128
		SCUtil.clearTempDir();	
129
	}
130
	
131
	/**
132
	 * Enable different types of Y error bar in chart.
133
	 * 1. Create a spreadsheet file.
134
	 * 2. Input number in a cell range and create a chart.
135
	 * 3. Enable Y error bar in chart.
136
	 * 4. Save file as ODF/MSBinary format.
137
	 * 5. Close and reopen file.  -> Check the Y error bar setting.
138
	 * @throws Exception
139
	 */
140
	@Test
141
	public void testCreateYErrorBar() throws Exception {
142
		String fileName = "testCreateYErrorBar";
143
		String chartName = "testChart";
144
		String cellRangeName = "A1:D4";
145
		ChartErrorCategory result1 = null;
146
		ChartErrorIndicatorType result2 = null;
147
		
148
		if (inputType.equals("com.sun.star.chart.StockDiagram")) {
149
			cellRangeName = "A1:C4";
150
		}	
151
		if (fileType.equalsIgnoreCase("xls")) {
152
			chartName = "Object 1";			
153
		}
154
		
155
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
156
		
157
		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
158
159
		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
160
		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
161
		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
162
		XChartDocument xChartDocument = null; 		
163
		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
164
		SCUtil.setChartType(xChartDocument, inputType);
165
		XDiagram xDiagram = xChartDocument.getDiagram(); 
166
		
167
		SCUtil.setProperties(xDiagram, "ErrorCategory", inputCategory);
168
		SCUtil.setProperties(xDiagram, "ErrorIndicator", inputIndicator);
169
		
170
		SCUtil.saveFileAs(scComponent, fileName, fileType);
171
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
172
		sheet = SCUtil.getCurrentSheet(scDocument);
173
		
174
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
175
		xDiagram = xChartDocument.getDiagram(); 
176
		result1 = (ChartErrorCategory) SCUtil.getProperties(xDiagram, "ErrorCategory");
177
		result2 = (ChartErrorIndicatorType) SCUtil.getProperties(xDiagram, "ErrorIndicator");
178
		
179
		SCUtil.closeFile(scDocument);
180
		
181
		assertEquals("Incorrect chart Y error bar category got in ." + fileType + " file.", expCategory, result1);
182
		assertEquals("Incorrect chart Y error bar indicator got in ." + fileType + " file.", expIndicator, result2);
183
184
	}
185
	
186
}
(-)testuno/source/testlib/uno/SCUtil.java (-2 / +17 lines)
Lines 640-645 Link Here
640
	 * @throws Exception
640
	 * @throws Exception
641
	 */
641
	 */
642
	public static XChartDocument createChart(XSpreadsheet xSpreadsheet, Rectangle rec, CellRangeAddress[] dataRangeAddress, String chartName) throws Exception {
642
	public static XChartDocument createChart(XSpreadsheet xSpreadsheet, Rectangle rec, CellRangeAddress[] dataRangeAddress, String chartName) throws Exception {
643
		
644
		return createChart(xSpreadsheet, rec, dataRangeAddress, chartName, true, false);
645
	}
646
	
647
	/**
648
	 * Create a spreadsheet chart with data in a specific cell range with column/row label enable/not.
649
	 * @param xSpreadsheet
650
	 * @param rec    a rectangle shape object
651
	 * @param dataRangeAddress    the CellRangeAddress array of chart data source
652
	 * @param chartName
653
	 * @param hasColumnLabel  
654
	 * @param hasRowLabel
655
	 * @return
656
	 * @throws Exception
657
	 */
658
	public static XChartDocument createChart(XSpreadsheet xSpreadsheet, Rectangle rec, CellRangeAddress[] dataRangeAddress, String chartName, Boolean hasColumnLabel, Boolean hasRowLabel) throws Exception {
643
		XChartDocument xChartDocument = null;
659
		XChartDocument xChartDocument = null;
644
		XTableChartsSupplier xTChartSupplier = 
660
		XTableChartsSupplier xTChartSupplier = 
645
				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
661
				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
Lines 648-654 Link Here
648
				(XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xTableCharts);
664
				(XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xTableCharts);
649
		if (xNameAccess != null && !xNameAccess.hasByName(chartName)) {
665
		if (xNameAccess != null && !xNameAccess.hasByName(chartName)) {
650
			
666
			
651
			xTableCharts.addNewByName(chartName, rec, dataRangeAddress, true, false);
667
			xTableCharts.addNewByName(chartName, rec, dataRangeAddress, hasColumnLabel, hasRowLabel);
652
			XTableChart xTableChart = (XTableChart) UnoRuntime.queryInterface(
668
			XTableChart xTableChart = (XTableChart) UnoRuntime.queryInterface(
653
					XTableChart.class, xNameAccess.getByName(chartName));
669
					XTableChart.class, xNameAccess.getByName(chartName));
654
			XEmbeddedObjectSupplier xEmbeddedObjectSupplier = (XEmbeddedObjectSupplier) UnoRuntime.queryInterface(
670
			XEmbeddedObjectSupplier xEmbeddedObjectSupplier = (XEmbeddedObjectSupplier) UnoRuntime.queryInterface(
Lines 718-724 Link Here
718
	 * @throws Exception
734
	 * @throws Exception
719
	 */
735
	 */
720
	public static String[] getChartNameList(XSpreadsheet xSpreadsheet) throws Exception {
736
	public static String[] getChartNameList(XSpreadsheet xSpreadsheet) throws Exception {
721
		XChartDocument xChartDocument = null;
722
		XTableChartsSupplier xTChartSupplier = 
737
		XTableChartsSupplier xTChartSupplier = 
723
				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
738
				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
724
		XTableCharts xTableCharts = xTChartSupplier.getCharts();
739
		XTableCharts xTableCharts = xTChartSupplier.getCharts();

Return to issue 120973