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

(-)testuno/source/testcase/uno/sc/cell/CellProtected.java (+178 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
23
package testcase.uno.sc.cell;
24
25
import static org.junit.Assert.assertEquals;
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
import testlib.uno.TestUtil;
42
import testlib.uno.CellInfo;
43
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.XCell;
48
import com.sun.star.util.CellProtection;
49
50
51
/**
52
 *  Check the cell protection setting can be applied and saved
53
 * 
54
 */
55
@RunWith(value = Parameterized.class)
56
public class CellProtected {
57
58
	private Boolean[] expected;
59
	private String inputType;
60
	private CellProtection inputProtectProps;
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
		Boolean[][] list = {
71
				{true, false, false, false}, //lock cell
72
				{false, true, false, false}, //hide formula
73
				{false, false, true, false}, //hide cell
74
				{false, false, false, true}, //hide cell from print
75
				
76
				{true, true, true, false}		
77
		};
78
79
		return Arrays.asList(new Object[][] {
80
			{list[0], "CellProtection", list[0], "ods"}, 
81
			{list[1], "CellProtection", list[1], "ods"},
82
			{list[4], "CellProtection", list[2], "ods"},
83
			{list[3], "CellProtection", list[3], "ods"}
84
		});
85
	}
86
	
87
	public CellProtected(Boolean[] expected, String inputType, Boolean[] inputData, String fileType) {
88
		
89
		CellProtection protection = new CellProtection();
90
		
91
		protection.IsLocked = inputData[0];
92
		protection.IsFormulaHidden = inputData[1];
93
		protection.IsHidden = inputData[2];
94
		protection.IsPrintHidden = inputData[3];
95
		
96
		this.expected = expected;
97
		this.inputType = inputType;
98
		this.inputProtectProps = protection;
99
		this.fileType = fileType;
100
	}
101
	
102
	
103
	@Before
104
	public void setUp() throws Exception {
105
		scComponent = unoApp.newDocument("scalc");
106
		scDocument = SCUtil.getSCDocument(scComponent);
107
	}
108
109
	@After
110
	public void tearDown() throws Exception {
111
		unoApp.closeDocument(scComponent);
112
		
113
	}
114
	
115
	@BeforeClass
116
	public static void setUpConnection() throws Exception {
117
		unoApp.start();
118
	}
119
120
	@AfterClass
121
	public static void tearDownConnection() throws InterruptedException, Exception {
122
		unoApp.close();
123
		SCUtil.clearTempDir();	
124
	}
125
	
126
	/**
127
	 * Check the cell protection settings
128
	 * 1. Create a spreadsheet file.
129
	 * 2. Input number, text, formula into many cell.
130
	 * 3. Set cell protection properties. (Clock, HiddenFormula, Hidden Cell, Hidden Cell from Printing)
131
	 * 4. Save file as ODF/MSBinary format.
132
	 * 5. Close and reopen file.  -> Check the cell protection setting.
133
	 * @throws Exception
134
	 */
135
	@Test
136
	public void testCellProtected() throws Exception {
137
		String fileName = "testCellProtected";
138
		
139
		int cellNum = 5;
140
		XCell[] cells = new XCell[cellNum];
141
		CellProtection[] results = new CellProtection[cellNum];
142
		CellInfo cInfo = TestUtil.randCell(10, 10);
143
		
144
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
145
		
146
		for (int i = 0; i < cellNum; i++) {
147
			cells[i] = sheet.getCellByPosition(cInfo.getCol() + i, cInfo.getRow());
148
		}
149
		
150
		cells[0].setValue(2134359.343223);
151
		SCUtil. setTextToCell(cells[1], inputType);
152
		cells[2].setFormula("=Average(A1:A10)");
153
		cells[3].setValue(-0.0003424);
154
155
		for (int i = 0; i < cellNum; i++) {
156
			SCUtil.setCellProperties(cells[i], inputType, inputProtectProps);
157
		}
158
		
159
		SCUtil.saveFileAs(scComponent, fileName, fileType);
160
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
161
		sheet = SCUtil.getCurrentSheet(scDocument);
162
		
163
		for (int i = 0; i < cellNum; i++) {
164
			cells[i] = sheet.getCellByPosition(cInfo.getCol() + i, cInfo.getRow());
165
			results[i] = (CellProtection) SCUtil.getCellProperties(cells[i], inputType);
166
		}
167
		
168
		SCUtil.closeFile(scDocument);
169
		
170
		for (int i = 0; i < cellNum; i++) {
171
			assertEquals("Incorrect cell protection (IsLocked) value got in ." + fileType + " file.", expected[0], results[i].IsLocked);
172
			assertEquals("Incorrect cell protection(IsFormulaHidden) value got in ." + fileType + " file.", expected[1], results[i].IsFormulaHidden);
173
			assertEquals("Incorrect cell protection(IsHidden) value got in ." + fileType + " file.", expected[2], results[i].IsHidden);
174
			assertEquals("Incorrect cell protection(IsPrintHidden) value got in ." + fileType + " file.", expected[3], results[i].IsPrintHidden);
175
		}	
176
	}	
177
178
}
(-)testuno/source/testcase/uno/sc/chart/ChartLegend.java (+235 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.Point;
44
import com.sun.star.awt.Rectangle;
45
import com.sun.star.chart.XChartDocument;
46
import com.sun.star.drawing.XShape;
47
import com.sun.star.lang.XComponent;
48
import com.sun.star.sheet.XSpreadsheet;
49
import com.sun.star.sheet.XSpreadsheetDocument;
50
import com.sun.star.table.CellRangeAddress;
51
52
/**
53
 *  Check the chart legend and the position can be applied and saved
54
 * 
55
 */
56
@RunWith(value = Parameterized.class)
57
public class ChartLegend {
58
59
	private String inputType;
60
	private double[][] numberData;
61
	private int[] offset;
62
	private String fileType;
63
	
64
	private static final UnoApp unoApp = new UnoApp();
65
	
66
	XComponent scComponent = null;
67
	XSpreadsheetDocument scDocument = null;
68
	
69
	@Parameters
70
	public static Collection<Object[]> data() throws Exception {
71
		int[][] offsetList = {
72
				{-50, -2000},
73
				{-1000, 3000},
74
				{-4000, -1000}
75
		};
76
		
77
		double[][] numberData1 = {
78
				{1, 2, 3, 4},
79
				{2, 4.3, 5, 8},
80
				{4, 2, 3, 1},
81
				{1, -1, 0, 3}
82
		};
83
		return Arrays.asList(new Object[][] {
84
			{"com.sun.star.chart.BarDiagram", numberData1, offsetList[0], "ods"},
85
			{"com.sun.star.chart.BubbleDiagram", numberData1, offsetList[1], "ods"},
86
			{"com.sun.star.chart.NetDiagram", numberData1, offsetList[2], "ods"},
87
			{"com.sun.star.chart.BarDiagram", numberData1, offsetList[0], "xls"},
88
			{"com.sun.star.chart.BubbleDiagram", numberData1, offsetList[1], "xls"},
89
			{"com.sun.star.chart.NetDiagram", numberData1, offsetList[2], "xls"}
90
		});
91
	}
92
	
93
	public ChartLegend(String inputType, double[][] numberData, int[] offset, String fileType) {
94
		this.inputType = inputType;
95
		this.numberData = numberData;
96
		this.offset = offset;
97
		this.fileType = fileType;
98
	}
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
	 * Check remove the legend of chart
126
	 * 1. Create a spreadsheet file.
127
	 * 2. Input number in a cell range.
128
	 * 3. Use the data to create a chart, set the chart type.
129
	 * 4. Remove the legend.
130
	 * 5. Save file as ODF/MSBinary format.
131
	 * 6. Close and reopen file.  -> Check the legend status.
132
	 * @throws Exception
133
	 */
134
	@Test
135
	public void testDisableLegend() throws Exception {
136
		String fileName = "testDisableLegend";
137
		String chartName = "testChart";
138
		String cellRangeName = "A1:D4";
139
		Boolean result = true;		
140
141
		if (fileType.equalsIgnoreCase("xls")) {
142
			chartName = "Object 1";			
143
		}
144
		
145
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
146
		
147
		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
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
154
		SCUtil.setChartType(xChartDocument, inputType);
155
		result = (Boolean) SCUtil.getProperties(xChartDocument, "HasLegend");
156
		if (result) {
157
			SCUtil.setProperties(xChartDocument, "HasLegend", false);
158
		}
159
		
160
		SCUtil.saveFileAs(scComponent, fileName, fileType);
161
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
162
		sheet = SCUtil.getCurrentSheet(scDocument);
163
		
164
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
165
		result = (Boolean) SCUtil.getProperties(xChartDocument, "HasLegend");
166
167
		SCUtil.closeFile(scDocument);
168
		
169
		assertFalse("Chart legend has not been disabled in " + fileType + " file.", result);
170
171
	}
172
	
173
	/**
174
	 * Check change the position of legend in chart
175
	 * 1. Create a spreadsheet file.
176
	 * 2. Input number in a cell range.
177
	 * 3. Use the data to create a chart, set the chart type.
178
	 * 4. Change the position of legend in chart.
179
	 * 5. Save file as ODF/MSBinary format.
180
	 * 6. Close and reopen file.  -> Check the legend position.
181
	 * @throws Exception
182
	 */
183
	@Test
184
	public void testLegendPosition() throws Exception {
185
		String fileName = "testDisableLegend";
186
		String chartName = "testChart";
187
		String cellRangeName = "A1:D4";
188
		Boolean result = true;
189
		int delta = 4;//Save as .xls file, the legend position may change a little, set acceptable range.
190
191
		if (fileType.equalsIgnoreCase("xls")) {
192
			chartName = "Object 1";			
193
		}
194
		
195
		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
196
		
197
		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
198
		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
199
		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
200
		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
201
		XChartDocument xChartDocument = null; 		
202
		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
203
204
		SCUtil.setChartType(xChartDocument, inputType);
205
		
206
		XShape legend = xChartDocument.getLegend();
207
		Point aPoint = legend.getPosition();
208
		aPoint = new Point(aPoint.X + offset[0], aPoint.Y + offset[1]);
209
		legend.setPosition(aPoint);
210
		
211
		SCUtil.saveFileAs(scComponent, fileName, fileType);
212
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
213
		sheet = SCUtil.getCurrentSheet(scDocument);
214
		
215
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
216
		result = (Boolean) SCUtil.getProperties(xChartDocument, "HasLegend");
217
		legend = xChartDocument.getLegend();
218
		Point resultPoint = legend.getPosition();
219
220
		SCUtil.closeFile(scDocument);
221
		
222
		assertTrue("Chart legend has not been enabled in ." + fileType + " file.", result);
223
		
224
		if (fileType.equalsIgnoreCase("xls")) {
225
			assertEquals("Incorrect chart legend position X got in ." + fileType + " file.", aPoint.X, resultPoint.X, delta);
226
			assertEquals("Incorrect chart legend position X got in ." + fileType + " file.", aPoint.Y, resultPoint.Y, delta);
227
		}
228
		else {
229
			assertEquals("Incorrect chart legend position X got in ." + fileType + " file.", aPoint.X, resultPoint.X);
230
			assertEquals("Incorrect chart legend position X got in ." + fileType + " file.", aPoint.Y, resultPoint.Y);
231
		}
232
		
233
	}
234
235
}
(-)testuno/source/testcase/uno/sc/chart/ChartType.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
import com.sun.star.awt.Rectangle;
41
import com.sun.star.chart.XChartDocument;
42
import com.sun.star.lang.XComponent;
43
import com.sun.star.sheet.XSpreadsheet;
44
import com.sun.star.sheet.XSpreadsheetDocument;
45
import com.sun.star.table.CellRangeAddress;
46
47
/**
48
 *  Check the chart type setting can be applied and saved
49
 * 
50
 */
51
@RunWith(value = Parameterized.class)
52
public class ChartType {
53
54
	private String expected;
55
	private String inputType;
56
	private double[][] numberData;
57
	private String fileType;
58
	
59
	private static final UnoApp unoApp = new UnoApp();
60
	
61
	XComponent scComponent = null;
62
	XSpreadsheetDocument scDocument = null;
63
	
64
	@Parameters
65
	public static Collection<Object[]> data() throws Exception {
66
		double[][] numberData1 = {
67
				{1, 2, 3, 4},
68
				{2, 4.3, 5, 8},
69
				{4, 2, 3, 1},
70
				{1, -1, 0, 3}
71
		};
72
		double[][] numberData2 = {
73
				{22, 12, 15},
74
				{20, 11, 20},
75
				{40, 37, 38},
76
				{3.01, 2.2, 2.2}
77
		};
78
79
		return Arrays.asList(new Object[][] {
80
			{"com.sun.star.chart.BarDiagram", "com.sun.star.chart.BarDiagram", numberData1, "ods"},
81
			{"com.sun.star.chart.AreaDiagram", "com.sun.star.chart.AreaDiagram", numberData1, "ods"},
82
			{"com.sun.star.chart.LineDiagram", "com.sun.star.chart.LineDiagram", numberData1, "ods"},
83
			{"com.sun.star.chart.PieDiagram", "com.sun.star.chart.PieDiagram", numberData1, "ods"},
84
			{"com.sun.star.chart.DonutDiagram", "com.sun.star.chart.DonutDiagram", numberData1, "ods"},
85
			{"com.sun.star.chart.NetDiagram", "com.sun.star.chart.NetDiagram", numberData1, "ods"},
86
			{"com.sun.star.chart.XYDiagram", "com.sun.star.chart.XYDiagram", numberData1, "ods"},
87
			{"com.sun.star.chart.StockDiagram", "com.sun.star.chart.StockDiagram", numberData2, "ods"},
88
			{"com.sun.star.chart.BubbleDiagram", "com.sun.star.chart.BubbleDiagram", numberData1, "ods"},
89
			
90
			{"com.sun.star.chart.BarDiagram", "com.sun.star.chart.BarDiagram", numberData1, "xls"},
91
			{"com.sun.star.chart.AreaDiagram", "com.sun.star.chart.AreaDiagram", numberData1, "xls"},
92
			{"com.sun.star.chart.LineDiagram", "com.sun.star.chart.LineDiagram", numberData1, "xls"},
93
			{"com.sun.star.chart.PieDiagram", "com.sun.star.chart.PieDiagram", numberData1, "xls"},
94
			{"com.sun.star.chart.DonutDiagram", "com.sun.star.chart.DonutDiagram", numberData1, "xls"},
95
			{"com.sun.star.chart.NetDiagram", "com.sun.star.chart.NetDiagram", numberData1, "xls"},
96
			{"com.sun.star.chart.XYDiagram", "com.sun.star.chart.XYDiagram", numberData1, "xls"},
97
			{"com.sun.star.chart.StockDiagram", "com.sun.star.chart.StockDiagram", numberData2, "xls"},
98
			{"com.sun.star.chart.BubbleDiagram", "com.sun.star.chart.BubbleDiagram", numberData1, "xls"}		
99
		});
100
	}
101
	
102
	public ChartType(String expected, String inputType, double[][] numberData, String fileType) {
103
		this.expected = expected;
104
		this.inputType = inputType;
105
		this.numberData = numberData;
106
		this.fileType = fileType;
107
	}
108
	
109
	
110
	@Before
111
	public void setUp() throws Exception {
112
		scComponent = unoApp.newDocument("scalc");
113
		scDocument = SCUtil.getSCDocument(scComponent);
114
	}
115
116
	@After
117
	public void tearDown() throws Exception {
118
		unoApp.closeDocument(scComponent);
119
		
120
	}
121
	
122
	@BeforeClass
123
	public static void setUpConnection() throws Exception {
124
		unoApp.start();
125
	}
126
127
	@AfterClass
128
	public static void tearDownConnection() throws InterruptedException, Exception {
129
		unoApp.close();
130
		SCUtil.clearTempDir();	
131
	}
132
	
133
	/**
134
	 * Check the basic types of chart
135
	 * 1. Create a spreadsheet file.
136
	 * 2. Input number in a cell range.
137
	 * 3. Use the data to create a chart, change the chart type.
138
	 * 4. Save file as ODF/MSBinary format.
139
	 * 5. Close and reopen file.  -> Check the chart type setting.
140
	 * @throws Exception
141
	 */
142
	@Test
143
	public void testCreateChart() throws Exception {
144
		String fileName = "testCreateChart";
145
		String chartName = "testChart";
146
		String cellRangeName = "A1:D4";
147
		String result = null;		
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
165
		SCUtil.setChartType(xChartDocument, inputType);
166
		
167
		SCUtil.saveFileAs(scComponent, fileName, fileType);
168
		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
169
		sheet = SCUtil.getCurrentSheet(scDocument);
170
		
171
		xChartDocument = SCUtil.getChartByName(sheet, chartName);
172
		result = xChartDocument.getDiagram().getDiagramType();
173
		
174
		SCUtil.closeFile(scDocument);
175
		
176
		assertEquals("Incorrect chart type string got in ." + fileType + " file.", expected, result);
177
178
	}
179
180
}
(-)testuno/source/testlib/uno/SCUtil.java (-12 / +188 lines)
Lines 28-48 Link Here
28
import org.openoffice.test.common.Testspace;
28
import org.openoffice.test.common.Testspace;
29
import org.openoffice.test.uno.UnoApp;
29
import org.openoffice.test.uno.UnoApp;
30
30
31
import com.sun.star.awt.Rectangle;
31
import com.sun.star.beans.PropertyValue;
32
import com.sun.star.beans.PropertyValue;
32
import com.sun.star.beans.XPropertySet;
33
import com.sun.star.beans.XPropertySet;
34
import com.sun.star.chart.XChartDocument;
35
import com.sun.star.chart.XDiagram;
33
import com.sun.star.container.XIndexAccess;
36
import com.sun.star.container.XIndexAccess;
37
import com.sun.star.container.XNameAccess;
34
import com.sun.star.container.XNamed;
38
import com.sun.star.container.XNamed;
39
import com.sun.star.document.XEmbeddedObjectSupplier;
35
import com.sun.star.frame.XController;
40
import com.sun.star.frame.XController;
36
import com.sun.star.frame.XModel;
41
import com.sun.star.frame.XModel;
37
import com.sun.star.frame.XStorable;
42
import com.sun.star.frame.XStorable;
38
import com.sun.star.lang.XComponent;
43
import com.sun.star.lang.XComponent;
44
import com.sun.star.lang.XMultiServiceFactory;
45
import com.sun.star.sheet.XCellRangeAddressable;
39
import com.sun.star.sheet.XSpreadsheet;
46
import com.sun.star.sheet.XSpreadsheet;
40
import com.sun.star.sheet.XSpreadsheetDocument;
47
import com.sun.star.sheet.XSpreadsheetDocument;
41
import com.sun.star.sheet.XSpreadsheetView;
48
import com.sun.star.sheet.XSpreadsheetView;
42
import com.sun.star.sheet.XSpreadsheets;
49
import com.sun.star.sheet.XSpreadsheets;
50
import com.sun.star.table.CellRangeAddress;
43
import com.sun.star.table.XCell;
51
import com.sun.star.table.XCell;
44
import com.sun.star.table.XCellRange;
52
import com.sun.star.table.XCellRange;
45
import com.sun.star.table.XColumnRowRange;
53
import com.sun.star.table.XColumnRowRange;
54
import com.sun.star.table.XTableChart;
55
import com.sun.star.table.XTableCharts;
56
import com.sun.star.table.XTableChartsSupplier;
46
import com.sun.star.table.XTableColumns;
57
import com.sun.star.table.XTableColumns;
47
import com.sun.star.table.XTableRows;
58
import com.sun.star.table.XTableRows;
48
import com.sun.star.text.XText;
59
import com.sun.star.text.XText;
Lines 288-293 Link Here
288
	 * @param values
299
	 * @param values
289
	 * @throws Exception
300
	 * @throws Exception
290
	 */
301
	 */
302
	@Deprecated
291
	public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row,  double[][] values) throws Exception {
303
	public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row,  double[][] values) throws Exception {
292
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
304
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
293
		XCell xCell = null;
305
		XCell xCell = null;
Lines 299-304 Link Here
299
		}
311
		}
300
	}
312
	}
301
	
313
	
314
	public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, double[][] values) throws Exception {
315
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, start_col + values[0].length - 1, start_row + values.length - 1);
316
		XCell xCell = null;
317
		for (int i = 0; i < values.length; i++ ) {
318
			for(int j = 0; j < values[0].length; j++) {
319
				xCell = xCellRange.getCellByPosition(j, i);
320
				xCell.setValue(values[i][j]);
321
			}
322
		}
323
	}
324
	
302
	/**
325
	/**
303
	 * Set text into a cell range
326
	 * Set text into a cell range
304
	 * @param xSpreadsheet
327
	 * @param xSpreadsheet
Lines 309-314 Link Here
309
	 * @param texts
332
	 * @param texts
310
	 * @throws Exception
333
	 * @throws Exception
311
	 */
334
	 */
335
	@Deprecated  
312
	public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row,  String[][] texts) throws Exception {
336
	public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row,  String[][] texts) throws Exception {
313
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
337
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
314
		XCell xCell = null;
338
		XCell xCell = null;
Lines 322-327 Link Here
322
		}
346
		}
323
	}
347
	}
324
	
348
	
349
	public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, String[][] texts) throws Exception {
350
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, start_col + texts[0].length - 1, start_row + texts.length - 1);
351
		XCell xCell = null;
352
		XText xText = null;
353
		for (int i = 0; i < texts.length; i++ ) {
354
			for(int j = 0; j < texts[0].length; j++) {
355
				xCell = xCellRange.getCellByPosition(j, i);
356
				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
357
				xText.setString(texts[i][j]);
358
			}
359
		}
360
	}
361
	
325
	/**
362
	/**
326
	 * Get number content from a cell range
363
	 * Get number content from a cell range
327
	 * @param xSpreadsheet
364
	 * @param xSpreadsheet
Lines 423-428 Link Here
423
	}
460
	}
424
	
461
	
425
	/**
462
	/**
463
	 * Set specific property's value for an object
464
	 * @param obj
465
	 * @param propName
466
	 * @param value
467
	 * @throws Exception
468
	 */
469
	public static void setProperties(Object obj, String propName, Object value) throws Exception {
470
		XPropertySet xPropertySet = 
471
				(XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, obj);
472
		xPropertySet.setPropertyValue(propName, value);
473
	}
474
	
475
	/**
476
	 * Get specific property's value of an object
477
	 * @param obj
478
	 * @param propName
479
	 * @return
480
	 * @throws Exception
481
	 */
482
	public static Object getProperties(Object obj, String propName) throws Exception {
483
		XPropertySet xPropertySet = 
484
				(XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, obj);
485
		Object value = xPropertySet.getPropertyValue(propName);
486
		
487
		return value;
488
	}	
489
	
490
	/**
426
	 * Set value of specific property from a cell
491
	 * Set value of specific property from a cell
427
	 * @param xCell
492
	 * @param xCell
428
	 * @param propName
493
	 * @param propName
Lines 431-438 Link Here
431
	 */
496
	 */
432
	public static void setCellProperties(XCell xCell, String propName, Object value) throws Exception {
497
	public static void setCellProperties(XCell xCell, String propName, Object value) throws Exception {
433
		
498
		
434
		XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xCell);
499
		setProperties(xCell, propName, value);
435
		xPropertySet.setPropertyValue(propName, value);
436
	}
500
	}
437
501
438
	/**
502
	/**
Lines 443-452 Link Here
443
	 * @throws Exception
507
	 * @throws Exception
444
	 */
508
	 */
445
	public static Object getCellProperties(XCell xCell, String propName) throws Exception {
509
	public static Object getCellProperties(XCell xCell, String propName) throws Exception {
446
		XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xCell);
510
			return getProperties(xCell, propName);
447
		Object value = xPropertySet.getPropertyValue(propName);
448
		
449
		return value;
450
	}
511
	}
451
	
512
	
452
	/**
513
	/**
Lines 483-500 Link Here
483
	}
544
	}
484
	
545
	
485
	/**
546
	/**
486
	 * Save file after open file.
547
	 * Save file after open file. 
487
	 * 
488
	 * @param xSpreadsheetDocument
548
	 * @param xSpreadsheetDocument
489
	 * @throws Exception
549
	 * @throws Exception
490
	 */
550
	 */
491
	public static void save(XSpreadsheetDocument xSpreadsheetDocument)
551
	public static void save(XSpreadsheetDocument xSpreadsheetDocument)
492
			throws Exception {
552
			throws Exception {
493
494
		XStorable scStorable = (XStorable) UnoRuntime.queryInterface(
553
		XStorable scStorable = (XStorable) UnoRuntime.queryInterface(
495
				XStorable.class, xSpreadsheetDocument);
554
				XStorable.class, xSpreadsheetDocument);
496
		scStorable.store();
555
		scStorable.store();
497
498
	}
556
	}
499
557
500
	
558
	
Lines 527-534 Link Here
527
	
585
	
528
	/**
586
	/**
529
	 * open file in Spreadsheet.
587
	 * open file in Spreadsheet.
530
	 * @param unoApp
588
	 * @param app  
531
	 * @param filtpath   File path with the extension name. (e.g. "testcase/uno/sc/data/sample.xls")
589
	 * @param filePath   File path with the extension name. (e.g. "testcase/uno/sc/data/sample.xls")
532
	 * @return
590
	 * @return
533
	 * @throws Exception
591
	 * @throws Exception
534
	 */
592
	 */
Lines 551-555 Link Here
551
		filterName.put("xlt", "MS Excel 97 Vorlage/Template");
609
		filterName.put("xlt", "MS Excel 97 Vorlage/Template");
552
		filterName.put("csv", "Text - txt - csv (StarCalc)");
610
		filterName.put("csv", "Text - txt - csv (StarCalc)");
553
	}
611
	}
612
	
613
	
614
	/***************************************************************
615
	 *      Chart Utility method - using chart interface           *
616
	****************************************************************/
554
617
618
	/**
619
	 * Get a CellRangeAddress by cell range reference name
620
	 * @param xSpreadsheet
621
	 * @param rangeName    a cell range reference name(e.g. "A1:B2")
622
	 * @return
623
	 */
624
	public static CellRangeAddress getChartDataRangeByName(XSpreadsheet xSpreadsheet, String rangeName) {
625
		XCellRange cellRange = xSpreadsheet.getCellRangeByName(rangeName);
626
		XCellRangeAddressable xCellRangeAddressable = 
627
			(XCellRangeAddressable) UnoRuntime.queryInterface(XCellRangeAddressable.class, cellRange);
628
	
629
		CellRangeAddress cellRangeAddress = xCellRangeAddressable.getRangeAddress();
630
		return cellRangeAddress;
631
	}
632
	
633
	/**
634
	 * Create a spreadsheet chart with data in a specific cell range.
635
	 * @param xSpreadsheet
636
	 * @param rec   a rectangle shape object
637
	 * @param dataRangeAddress   the CellRangeAddress array of chart data source
638
	 * @param chartName
639
	 * @return
640
	 * @throws Exception
641
	 */
642
	public static XChartDocument createChart(XSpreadsheet xSpreadsheet, Rectangle rec, CellRangeAddress[] dataRangeAddress, String chartName) throws Exception {
643
		XChartDocument xChartDocument = null;
644
		XTableChartsSupplier xTChartSupplier = 
645
				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
646
		XTableCharts xTableCharts = xTChartSupplier.getCharts();
647
		XNameAccess xNameAccess = 
648
				(XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xTableCharts);
649
		if (xNameAccess != null && !xNameAccess.hasByName(chartName)) {
650
			
651
			xTableCharts.addNewByName(chartName, rec, dataRangeAddress, true, false);
652
			XTableChart xTableChart = (XTableChart) UnoRuntime.queryInterface(
653
					XTableChart.class, xNameAccess.getByName(chartName));
654
			XEmbeddedObjectSupplier xEmbeddedObjectSupplier = (XEmbeddedObjectSupplier) UnoRuntime.queryInterface(
655
					XEmbeddedObjectSupplier.class, xTableChart);
656
			xChartDocument = (XChartDocument) UnoRuntime.queryInterface(
657
					XChartDocument.class, xEmbeddedObjectSupplier.getEmbeddedObject());
658
		}
659
		
660
		return xChartDocument;
661
	}
662
	
663
	/**
664
	 * Get XChartDocument object via the chart name.
665
	 * @param xSpreadsheet
666
	 * @param chartName
667
	 * @return
668
	 * @throws Exception
669
	 */
670
	public static XChartDocument getChartByName(XSpreadsheet xSpreadsheet, String chartName) throws Exception {
671
		XChartDocument xChartDocument = null;
672
		XTableChartsSupplier xTChartSupplier = 
673
				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
674
		XTableCharts xTableCharts = xTChartSupplier.getCharts();
675
		XNameAccess xNameAccess = 
676
				(XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xTableCharts);
677
		
678
		if (xNameAccess != null && xNameAccess.hasByName(chartName)) {
679
			XTableChart xTableChart = (XTableChart) UnoRuntime.queryInterface(
680
					XTableChart.class, xNameAccess.getByName(chartName));
681
			XEmbeddedObjectSupplier xEmbeddedObjectSupplier = (XEmbeddedObjectSupplier) UnoRuntime.queryInterface(
682
					XEmbeddedObjectSupplier.class, xTableChart);
683
			xChartDocument = (XChartDocument) UnoRuntime.queryInterface(
684
					XChartDocument.class, xEmbeddedObjectSupplier.getEmbeddedObject());
685
		}
686
		
687
		return xChartDocument;
688
	}
689
	
690
	/**
691
	 * Set specific basic type to chart
692
	 * @param xChartDocument
693
	 * @param chartType
694
	 * @throws Exception
695
	 */
696
	public static void setChartType(XChartDocument xChartDocument, String chartType) throws Exception {
697
		XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
698
			XMultiServiceFactory.class, xChartDocument);
699
		XDiagram xDiagram = (XDiagram) UnoRuntime.queryInterface(
700
			XDiagram.class, xMultiServiceFactory.createInstance(chartType));
701
		xChartDocument.setDiagram(xDiagram);
702
	}
703
	
704
	/**
705
	 * Get the type string of a chart
706
	 * @param xChartDocument
707
	 * @return
708
	 * @throws Exception
709
	 */
710
	public static String getChartType(XChartDocument xChartDocument) throws Exception {
711
		return xChartDocument.getDiagram().getDiagramType();
712
	}
713
	
714
	/**
715
	 * Get the names of charts in specific sheet
716
	 * @param xSpreadsheet
717
	 * @return
718
	 * @throws Exception
719
	 */
720
	public static String[] getChartNameList(XSpreadsheet xSpreadsheet) throws Exception {
721
		XChartDocument xChartDocument = null;
722
		XTableChartsSupplier xTChartSupplier = 
723
				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
724
		XTableCharts xTableCharts = xTChartSupplier.getCharts();
725
		String[] chartNames = xTableCharts.getElementNames();
726
		return chartNames;
727
	}
728
	
729
730
555
}
731
}

Return to issue 120844