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

(-)source/testlib/uno/ChartUtil.java (-9 / +76 lines)
Lines 31-41 Link Here
31
31
32
	/**
32
	/**
33
	 * Retrieve Chart document as model of the OLE Shape(use to create chart)
33
	 * Retrieve Chart document as model of the OLE Shape(use to create chart)
34
	 * 
34
	 * @param xShape
35
	 * @param xShape
35
	 * @return
36
	 * @return
36
	 * @throws Exception
37
	 * @throws Exception
37
	 */
38
	 */
38
	public static XChartDocument retrieveChartDocument(XShape xShape)throws Exception{
39
	public static XChartDocument retrieveChartDocument(XShape xShape)
40
			throws Exception {
39
		XChartDocument aChartDoc = null;
41
		XChartDocument aChartDoc = null;
40
		final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
42
		final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
41
		// make the OLE shape a chart
43
		// make the OLE shape a chart
Lines 48-64 Link Here
48
				XChartDocument.class, aShapeProp.getPropertyValue("Model"));
50
				XChartDocument.class, aShapeProp.getPropertyValue("Model"));
49
		return aChartDoc;
51
		return aChartDoc;
50
	}
52
	}
51
	
53
52
	/**
54
	/**
55
	 * retrieve chart2 document as model of the OLE shape
56
	 * 
57
	 * @param xShape
58
	 * @return
59
	 * @throws Exception
60
	 */
61
	public static com.sun.star.chart2.XChartDocument retrieveChart2Document(
62
			XShape xShape) throws Exception {
63
		com.sun.star.chart2.XChartDocument aChartDoc = null;
64
		final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
65
		// make the OLE shape a chart
66
		XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
67
				XPropertySet.class, xShape);
68
		// set the class id for charts
69
		aShapeProp.setPropertyValue("CLSID", msChartClassID);
70
		// retrieve the chart document as model of the OLE shape
71
		aChartDoc = (com.sun.star.chart2.XChartDocument) UnoRuntime
72
				.queryInterface(com.sun.star.chart2.XChartDocument.class,
73
						aShapeProp.getPropertyValue("Model"));
74
		return aChartDoc;
75
	}
76
77
	/**
53
	 * Create Chart in ChartDocument.
78
	 * Create Chart in ChartDocument.
79
	 * 
54
	 * @param aChartDoc
80
	 * @param aChartDoc
55
	 * @param ChartType
81
	 * @param ChartType
56
	 * @return
82
	 * @return
57
	 * @throws Exception
83
	 * @throws Exception
58
	 */
84
	 */
59
	public static XDiagram createChart(XChartDocument aChartDoc, String ChartType)
85
	public static XDiagram createChart(XChartDocument aChartDoc,
60
			throws Exception {
86
			String ChartType) throws Exception {
61
	
87
62
		// let aChartDoc be a valid XChartDocument
88
		// let aChartDoc be a valid XChartDocument
63
		// get the factory that can create diagrams
89
		// get the factory that can create diagrams
64
		XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime
90
		XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime
Lines 67-81 Link Here
67
				XDiagram.class, aFact.createInstance(ChartType));
93
				XDiagram.class, aFact.createInstance(ChartType));
68
		return aDiagram;
94
		return aDiagram;
69
	}
95
	}
70
	
96
71
	
72
	/**
97
	/**
98
	 * Create Chart2 in ChartDocument.
99
	 * 
100
	 * @param aChartDoc
101
	 * @param ChartType
102
	 * @return
103
	 * @throws Exception
104
	 */
105
	public static com.sun.star.chart2.XDiagram createChart2(
106
			com.sun.star.chart2.XChartDocument aChartDoc, String ChartType)
107
			throws Exception {
108
109
		// let aChartDoc be a valid XChartDocument
110
		// get the factory that can create diagrams
111
		XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime
112
				.queryInterface(XMultiServiceFactory.class, aChartDoc);
113
		com.sun.star.chart2.XDiagram aDiagram = (com.sun.star.chart2.XDiagram) UnoRuntime
114
				.queryInterface(com.sun.star.chart2.XDiagram.class,
115
						aFact.createInstance(ChartType));
116
		return aDiagram;
117
	}
118
119
	/**
73
	 * Get Chart Doc from a Shape
120
	 * Get Chart Doc from a Shape
121
	 * 
74
	 * @param xShape
122
	 * @param xShape
75
	 * @return
123
	 * @return
76
	 * @throws Exception
124
	 * @throws Exception
77
	 */
125
	 */
78
	public static XChartDocument getChartDocument(XShape xShape)throws Exception{
126
	public static XChartDocument getChartDocument(XShape xShape)
127
			throws Exception {
79
		XChartDocument aChartDoc = null;
128
		XChartDocument aChartDoc = null;
80
		XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
129
		XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
81
				XPropertySet.class, xShape);
130
				XPropertySet.class, xShape);
Lines 83-88 Link Here
83
		aChartDoc = (XChartDocument) UnoRuntime.queryInterface(
132
		aChartDoc = (XChartDocument) UnoRuntime.queryInterface(
84
				XChartDocument.class, aShapeProp.getPropertyValue("Model"));
133
				XChartDocument.class, aShapeProp.getPropertyValue("Model"));
85
		return aChartDoc;
134
		return aChartDoc;
86
		
135
87
	}
136
	}
137
	/**
138
	 * Get Chart2 Doc from a Shape
139
	 * 
140
	 * @param xShape
141
	 * @return
142
	 * @throws Exception
143
	 */
144
	public static com.sun.star.chart2.XChartDocument getChart2Document(XShape xShape)
145
			throws Exception {
146
		com.sun.star.chart2.XChartDocument aChartDoc = null;
147
		XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
148
				XPropertySet.class, xShape);
149
		// retrieve the chart document as model of the OLE shape
150
		aChartDoc = (com.sun.star.chart2.XChartDocument) UnoRuntime.queryInterface(
151
				com.sun.star.chart2.XChartDocument.class, aShapeProp.getPropertyValue("Model"));
152
		return aChartDoc;
153
154
	}
88
}
155
}
(-)source/testcase/uno/sd/chart/ChartData.java (+253 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
package testcase.uno.sd.chart;
22
23
import static org.junit.Assert.assertEquals;
24
25
import org.junit.After;
26
import org.junit.Before;
27
import org.junit.Test;
28
import org.openoffice.test.common.FileUtil;
29
import org.openoffice.test.common.Testspace;
30
import org.openoffice.test.uno.UnoApp;
31
32
import testlib.uno.ChartUtil;
33
import testlib.uno.PageUtil;
34
import testlib.uno.ShapeUtil;
35
import testlib.uno.TestUtil;
36
37
import com.sun.star.awt.FontRelief;
38
import com.sun.star.awt.FontUnderline;
39
import com.sun.star.awt.FontWeight;
40
import com.sun.star.awt.Gradient;
41
import com.sun.star.awt.GradientStyle;
42
import com.sun.star.awt.Point;
43
import com.sun.star.awt.Size;
44
import com.sun.star.beans.PropertyValue;
45
import com.sun.star.beans.XPropertySet;
46
import com.sun.star.chart.ChartDataCaption;
47
import com.sun.star.chart.ChartLegendPosition;
48
import com.sun.star.chart.XAxis;
49
import com.sun.star.chart.XAxisYSupplier;
50
import com.sun.star.chart.XChartData;
51
import com.sun.star.chart.XChartDataArray;
52
import com.sun.star.chart.XChartDocument;
53
import com.sun.star.chart.XDiagram;
54
import com.sun.star.chart2.data.XDataSource;
55
import com.sun.star.chart2.data.XLabeledDataSequence;
56
import com.sun.star.drawing.DashStyle;
57
import com.sun.star.drawing.FillStyle;
58
import com.sun.star.drawing.LineDash;
59
import com.sun.star.drawing.LineStyle;
60
import com.sun.star.drawing.XDrawPage;
61
import com.sun.star.drawing.XDrawPages;
62
import com.sun.star.drawing.XDrawPagesSupplier;
63
import com.sun.star.drawing.XShape;
64
import com.sun.star.drawing.XShapes;
65
import com.sun.star.frame.XStorable;
66
import com.sun.star.lang.XComponent;
67
import com.sun.star.presentation.XPresentation;
68
import com.sun.star.presentation.XPresentationSupplier;
69
import com.sun.star.uno.AnyConverter;
70
import com.sun.star.uno.UnoRuntime;
71
import com.sun.star.util.XCloseable;
72
import com.sun.star.util.XModifiable;
73
74
public class ChartData {
75
	UnoApp unoApp = new UnoApp();
76
	XPresentationSupplier sdDocument = null;
77
	XPresentation pre = null;
78
	XComponent precomp = null;
79
	XComponent impressDocument = null;
80
	XComponent reLoadFile = null;
81
	XDrawPagesSupplier drawsupplier = null;
82
	XDrawPages drawpages = null;
83
	XShapes xShapes = null;
84
	XDrawPage xpage = null;
85
	String filePath = null;
86
	XChartDocument xChartDoc = null;
87
	com.sun.star.chart2.XChartDocument xChart2Doc = null;
88
89
	@Before
90
	public void setUp() throws Exception {
91
		unoApp.start();
92
		createDocumentAndSlide();
93
	}
94
95
	@After
96
	public void tearDown() throws Exception {
97
		unoApp.closeDocument(impressDocument);
98
		unoApp.closeDocument(reLoadFile);
99
		unoApp.close();
100
		 if (filePath != null)
101
		 FileUtil.deleteFile(filePath);
102
	}
103
104
	/**
105
	 * create a new presentation document and insert a new slide.
106
	 * 
107
	 * @throws Exception
108
	 */
109
	public void createDocumentAndSlide() throws Exception {
110
		impressDocument = (XComponent) UnoRuntime.queryInterface(
111
				XComponent.class, unoApp.newDocument("simpress"));
112
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
113
				XDrawPagesSupplier.class, impressDocument);
114
		drawpages = drawsupplier.getDrawPages();
115
		drawpages.insertNewByIndex(1);
116
		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
117
	}
118
119
	/**
120
	 * Insert default Column Chart to slide.
121
	 * 
122
	 * @return
123
	 * @throws Exception
124
	 */
125
	public XChartDocument insertDefaultChart() throws Exception {
126
		Point po = new Point(1000, 1000);
127
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
128
		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
129
				15000, 9271), "com.sun.star.drawing.OLE2Shape");
130
		xShapes.add(xShape);
131
		xChartDoc = ChartUtil.retrieveChartDocument(xShape);
132
		return xChartDoc;
133
	}
134
135
	/**
136
	 * test data series 
137
	 * @throws Exception
138
	 */
139
	@Test
140
	public void testDataSeries() throws Exception {
141
		XShape xShape = null;
142
		insertDefaultChart();
143
		// get the second data series.
144
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
145
				XPropertySet.class, xChartDoc.getDiagram()
146
						.getDataRowProperties(1));
147
		aDiaProp.setPropertyValue("FillStyle", FillStyle.SOLID);
148
		aDiaProp.setPropertyValue("FillColor", 0xffff00);
149
		// --------------------------
150
		xShape = saveAndLoadShape(1, 0);
151
		xChartDoc = ChartUtil.getChartDocument(xShape);
152
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
153
				xChartDoc.getDiagram().getDataRowProperties(1));
154
		assertEquals("the second DataSeries fill color isn't yellow", 0xffff00,
155
				aDiaProp.getPropertyValue("FillColor"));
156
157
	}
158
	/**
159
	 * test data point
160
	 * @throws Exception
161
	 */
162
	@Test
163
	public void testDataPoint() throws Exception {
164
		XShape xShape = null;
165
		insertDefaultChart();
166
		// set data label to the fourth points, the second series.
167
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
168
				XPropertySet.class, xChartDoc.getDiagram()
169
						.getDataPointProperties(3, 1));
170
		aDiaProp.setPropertyValue("FillStyle", FillStyle.SOLID);
171
		aDiaProp.setPropertyValue("FillColor", 0xffff00);
172
		// --------------------------
173
		xShape = saveAndLoadShape(1, 0);
174
		xChartDoc = ChartUtil.getChartDocument(xShape);
175
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
176
				xChartDoc.getDiagram().getDataPointProperties(3, 1));
177
178
		assertEquals(
179
				"the fourth point of the second series's fill color isn't yellow",
180
				0xffff00, aDiaProp.getPropertyValue("FillColor"));
181
182
	}
183
	/**
184
	 * test data of chart, update it with chart
185
	 * @throws Exception
186
	 */
187
	@Test
188
	public void testDataTable() throws Exception {
189
		XShape xShape = null;
190
		insertDefaultChart();
191
		// get data object from chart
192
		XChartDataArray array = (XChartDataArray) UnoRuntime.queryInterface(
193
				XChartDataArray.class, xChartDoc.getData());
194
195
		// set new chart data
196
		double[][] data = new double[][] { { 2, 2 }, { 2, 2 }, { 2, 2 } };
197
		array.setData(data);
198
		// update chart with data
199
		xChartDoc.attachData(xChartDoc.getData());
200
		// --------------------------
201
		xShape = saveAndLoadShape(1, 0);
202
		xChartDoc = ChartUtil.getChartDocument(xShape);
203
		array = (XChartDataArray) UnoRuntime.queryInterface(
204
				XChartDataArray.class, xChartDoc.getData());
205
		data = array.getData();
206
		assertEquals(2, data[0][0], 0.0);
207
208
	}
209
210
	/**
211
	 * Save presentation and reLoad the presentation and shape in it.
212
	 * 
213
	 * @param po
214
	 * @param shapeType
215
	 * @return
216
	 * @throws Exception
217
	 */
218
	public XShape saveAndLoadShape(int pageIndex, int shapeIndex)
219
			throws Exception {
220
		reLoadFile = saveAsAndReloadDoc(impressDocument, "impress8", "odp");
221
		xShapes = ShapeUtil.getShapes(reLoadFile, pageIndex);
222
		return (XShape) UnoRuntime.queryInterface(XShape.class,
223
				xShapes.getByIndex(shapeIndex));
224
	}
225
226
	/**
227
	 * save and reload Presentation document.
228
	 * 
229
	 * @param presentationDocument
230
	 * @param sFilter
231
	 * @param sExtension
232
	 * @return
233
	 * @throws Exception
234
	 */
235
	private XComponent saveAsAndReloadDoc(XComponent presentationDocument,
236
			String sFilter, String sExtension) throws Exception {
237
		filePath = Testspace.getPath("tmp/chartdata." + sExtension);
238
		PropertyValue[] aStoreProperties = new PropertyValue[2];
239
		aStoreProperties[0] = new PropertyValue();
240
		aStoreProperties[1] = new PropertyValue();
241
		aStoreProperties[0].Name = "Override";
242
		aStoreProperties[0].Value = true;
243
		aStoreProperties[1].Name = "FilterName";
244
		aStoreProperties[1].Value = sFilter;
245
		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
246
				XStorable.class, presentationDocument);
247
		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
248
249
		return UnoRuntime.queryInterface(XComponent.class,
250
				unoApp.loadDocument(filePath));
251
	}
252
253
}
(-)source/testcase/uno/sd/chart/ChartProperties.java (+529 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
package testcase.uno.sd.chart;
22
23
import static org.junit.Assert.assertEquals;
24
25
import org.junit.After;
26
import org.junit.Before;
27
import org.junit.Test;
28
import org.openoffice.test.common.FileUtil;
29
import org.openoffice.test.common.Testspace;
30
import org.openoffice.test.uno.UnoApp;
31
32
import testlib.uno.ChartUtil;
33
import testlib.uno.PageUtil;
34
import testlib.uno.ShapeUtil;
35
import testlib.uno.TestUtil;
36
37
import com.sun.star.awt.FontRelief;
38
import com.sun.star.awt.FontUnderline;
39
import com.sun.star.awt.FontWeight;
40
import com.sun.star.awt.Point;
41
import com.sun.star.awt.Size;
42
import com.sun.star.beans.PropertyValue;
43
import com.sun.star.beans.XPropertySet;
44
import com.sun.star.chart.ChartDataCaption;
45
import com.sun.star.chart.ChartLegendPosition;
46
import com.sun.star.chart.XAxisYSupplier;
47
import com.sun.star.chart.XChartDocument;
48
import com.sun.star.chart.XDiagram;
49
import com.sun.star.drawing.FillStyle;
50
import com.sun.star.drawing.LineStyle;
51
import com.sun.star.drawing.XDrawPage;
52
import com.sun.star.drawing.XDrawPages;
53
import com.sun.star.drawing.XDrawPagesSupplier;
54
import com.sun.star.drawing.XShape;
55
import com.sun.star.drawing.XShapes;
56
import com.sun.star.frame.XStorable;
57
import com.sun.star.lang.XComponent;
58
import com.sun.star.presentation.XPresentation;
59
import com.sun.star.presentation.XPresentationSupplier;
60
import com.sun.star.uno.UnoRuntime;
61
import com.sun.star.util.XCloseable;
62
import com.sun.star.util.XModifiable;
63
64
public class ChartProperties {
65
	UnoApp unoApp = new UnoApp();
66
	XPresentationSupplier sdDocument = null;
67
	XPresentation pre = null;
68
	XComponent precomp = null;
69
	XComponent impressDocument = null;
70
	XComponent reLoadFile = null;
71
	XDrawPagesSupplier drawsupplier = null;
72
	XDrawPages drawpages = null;
73
	XShapes xShapes = null;
74
	XDrawPage xpage = null;
75
	String filePath = null;
76
	XChartDocument xChartDoc = null;
77
	com.sun.star.chart2.XChartDocument xChart2Doc = null;
78
79
	@Before
80
	public void setUp() throws Exception {
81
		unoApp.start();
82
		createDocumentAndSlide();
83
	}
84
85
	@After
86
	public void tearDown() throws Exception {
87
		unoApp.closeDocument(impressDocument);
88
		unoApp.closeDocument(reLoadFile);
89
		unoApp.close();
90
		 if (filePath != null)
91
		 FileUtil.deleteFile(filePath);
92
	}
93
94
	/**
95
	 * create a new presentation document and insert a new slide.
96
	 * 
97
	 * @throws Exception
98
	 */
99
	public void createDocumentAndSlide() throws Exception {
100
		impressDocument = (XComponent) UnoRuntime.queryInterface(
101
				XComponent.class, unoApp.newDocument("simpress"));
102
		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
103
				XDrawPagesSupplier.class, impressDocument);
104
		drawpages = drawsupplier.getDrawPages();
105
		drawpages.insertNewByIndex(1);
106
		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
107
	}
108
109
	/**
110
	 * Insert default Column Chart to slide.
111
	 * 
112
	 * @return
113
	 * @throws Exception
114
	 */
115
	public XChartDocument insertDefaultChart() throws Exception {
116
		Point po = new Point(1000, 1000);
117
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
118
		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
119
				15000, 9271), "com.sun.star.drawing.OLE2Shape");
120
		xShapes.add(xShape);
121
		xChartDoc = ChartUtil.retrieveChartDocument(xShape);
122
		return xChartDoc;
123
	}
124
125
	/**
126
	 * Insert default Column Chart2 to slide.
127
	 * 
128
	 * @return
129
	 * @throws Exception
130
	 */
131
	public com.sun.star.chart2.XChartDocument insertDefaultChart2()
132
			throws Exception {
133
		Point po = new Point(1000, 1000);
134
		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
135
		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
136
				15000, 9271), "com.sun.star.drawing.OLE2Shape");
137
		xShapes.add(xShape);
138
		xChart2Doc = ChartUtil.retrieveChart2Document(xShape);
139
		return xChart2Doc;
140
	}
141
142
	// --------------Chart Area----------------------
143
	/**
144
	 * test Chart Area properties about Border Line
145
	 * 
146
	 * @throws Exception
147
	 */
148
	@Test
149
	public void testAreaBordersProperties() throws Exception {
150
		XShape xShape = null;
151
		insertDefaultChart();
152
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
153
				XPropertySet.class, xChartDoc.getArea());
154
		aDiaProp.setPropertyValue("LineStyle", LineStyle.DASH);
155
		aDiaProp.setPropertyValue("LineColor", 0x00ff00);
156
157
		// --------------------------
158
		xShape = saveAndLoadShape(1, 0);
159
		xChartDoc = ChartUtil.getChartDocument(xShape);
160
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
161
				xChartDoc.getArea());
162
		// ----------------------------
163
		assertEquals("Not Dash Line Style", LineStyle.DASH,
164
				aDiaProp.getPropertyValue("LineStyle"));
165
		assertEquals("Not Yellow Line", 0x00ff00,
166
				aDiaProp.getPropertyValue("LineColor"));
167
168
	}
169
170
	/**
171
	 * test Area Properties about Gradient Fill
172
	 * @throws Exception
173
	 */
174
	@Test
175
	public void testAreaFillProperties() throws Exception {
176
		XShape xShape = null;
177
		insertDefaultChart();
178
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
179
				XPropertySet.class, xChartDoc.getArea());
180
		aDiaProp.setPropertyValue("FillStyle", FillStyle.GRADIENT);
181
		aDiaProp.setPropertyValue("FillGradientName", "Radial red/yellow");
182
		// --------------------------
183
		xShape = saveAndLoadShape(1, 0);
184
		xChartDoc = ChartUtil.getChartDocument(xShape);
185
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
186
				xChartDoc.getArea());
187
		// ----------------------------
188
		assertEquals("Not Gradient Fill Style", FillStyle.GRADIENT,
189
				aDiaProp.getPropertyValue("FillStyle"));
190
		assertEquals("Not Radial red/yellow Gradient", "Radial red/yellow",
191
				aDiaProp.getPropertyValue("FillGradientName"));
192
193
	}
194
195
	/**
196
	 * test Area properties about Transparency
197
	 * @throws Exception
198
	 */
199
	@Test
200
	public void testAreaTransparencyProperties() throws Exception {
201
		XShape xShape = null;
202
		insertDefaultChart();
203
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
204
				XPropertySet.class, xChartDoc.getArea());
205
		aDiaProp.setPropertyValue("FillStyle", FillStyle.SOLID);
206
		aDiaProp.setPropertyValue("FillColor", 0xffff00);
207
		aDiaProp.setPropertyValue("FillTransparence", 50);
208
		// --------------------------
209
		xShape = saveAndLoadShape(1, 0);
210
		xChartDoc = ChartUtil.getChartDocument(xShape);
211
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
212
				xChartDoc.getArea());
213
		// ----------------------------
214
		assertEquals("Area Fill Transparency is not 50%", new Short("50"),
215
				aDiaProp.getPropertyValue("FillTransparence"));
216
217
	}
218
219
	// ------------Chart Legend-------------------
220
	/**
221
	 * test Legend Border Line Properties
222
	 * @throws Exception
223
	 */
224
	@Test
225
	public void testLegendBorderProperties() throws Exception {
226
		XShape xShape = null;
227
		insertDefaultChart();
228
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
229
				XPropertySet.class, xChartDoc.getLegend());
230
		aDiaProp.setPropertyValue("LineStyle", LineStyle.DASH);
231
		aDiaProp.setPropertyValue("LineColor", 0x00ff00);
232
		// --------------------------
233
		xShape = saveAndLoadShape(1, 0);
234
		xChartDoc = ChartUtil.getChartDocument(xShape);
235
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
236
				xChartDoc.getLegend());
237
		// ----------------------------
238
		assertEquals("Not Dash Line Style", LineStyle.DASH,
239
				aDiaProp.getPropertyValue("LineStyle"));
240
		assertEquals("Not Yellow Line", 0x00ff00,
241
				aDiaProp.getPropertyValue("LineColor"));
242
243
	}
244
245
	/**
246
	 * test Legend Fill and transparence properties
247
	 * @throws Exception
248
	 */
249
	@Test
250
	public void testLegendFillAndTransparence() throws Exception {
251
		XShape xShape = null;
252
		insertDefaultChart();
253
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
254
				XPropertySet.class, xChartDoc.getLegend());
255
		aDiaProp.setPropertyValue("FillStyle", FillStyle.SOLID);
256
		aDiaProp.setPropertyValue("FillColor", 0xffff00);
257
		aDiaProp.setPropertyValue("FillTransparence", 50);
258
		// --------------------------
259
		xShape = saveAndLoadShape(1, 0);
260
		xChartDoc = ChartUtil.getChartDocument(xShape);
261
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
262
				xChartDoc.getLegend());
263
		// ----------------------------
264
265
		assertEquals("Area Fill Transparency is not 50%", new Short("50"),
266
				aDiaProp.getPropertyValue("FillTransparence"));
267
268
	}
269
	
270
	/**
271
	 * test Legend Char Font
272
	 * @throws Exception
273
	 */
274
	@Test
275
	public void testLegendCharFont() throws Exception {
276
		XShape xShape = null;
277
		insertDefaultChart();
278
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
279
				XPropertySet.class, xChartDoc.getLegend());
280
		aDiaProp.setPropertyValue("CharFontName", "Arial");
281
		aDiaProp.setPropertyValue("CharWeight", FontWeight.BOLD);
282
		// --------------------------
283
		xShape = saveAndLoadShape(1, 0);
284
		xChartDoc = ChartUtil.getChartDocument(xShape);
285
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
286
				xChartDoc.getLegend());
287
		// ----------------------------
288
		assertEquals("Legend font name is not Arial", "Arial",
289
				aDiaProp.getPropertyValue("CharFontName"));
290
		assertEquals("Legend font weight is not BOLD", FontWeight.BOLD,
291
				aDiaProp.getPropertyValue("CharWeight"));
292
293
	}
294
295
	/**
296
	 * test Legend Char Font Effects
297
	 * @throws Exception
298
	 */
299
	@Test
300
	public void testLegendCharFontEffects() throws Exception {
301
		XShape xShape = null;
302
		insertDefaultChart();
303
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
304
				XPropertySet.class, xChartDoc.getLegend());
305
		aDiaProp.setPropertyValue("CharColor", 0xffff00);
306
		aDiaProp.setPropertyValue("CharUnderline", FontUnderline.DOUBLE);
307
		aDiaProp.setPropertyValue("CharUnderlineColor", 0xffff00);
308
		aDiaProp.setPropertyValue("CharRelief", FontRelief.ENGRAVED);
309
310
		// --------------------------
311
		xShape = saveAndLoadShape(1, 0);
312
		xChartDoc = ChartUtil.getChartDocument(xShape);
313
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
314
				xChartDoc.getLegend());
315
		// ----------------------------
316
		assertEquals("Legend font color is not yellow", 0xffff00,
317
				aDiaProp.getPropertyValue("CharColor"));
318
		assertEquals("Legend font underline is not DOUBLE",
319
				FontUnderline.DOUBLE,
320
				aDiaProp.getPropertyValue("CharUnderline"));
321
		assertEquals("Legend font underline color is not yellow", 0xffff00,
322
				aDiaProp.getPropertyValue("CharUnderlineColor"));
323
		assertEquals("Legend font relief is not engraved", FontRelief.ENGRAVED,
324
				aDiaProp.getPropertyValue("CharRelief"));
325
326
	}
327
328
	/**
329
	 * test Legend Position in Chart
330
	 * @throws Exception
331
	 */
332
	@Test
333
	public void testLegendposition() throws Exception {
334
		XShape xShape = null;
335
		insertDefaultChart();
336
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
337
				XPropertySet.class, xChartDoc.getLegend());
338
		aDiaProp.setPropertyValue("Alignment", ChartLegendPosition.LEFT);
339
340
		// --------------------------
341
		xShape = saveAndLoadShape(1, 0);
342
		xChartDoc = ChartUtil.getChartDocument(xShape);
343
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
344
				xChartDoc.getLegend());
345
		// ----------------------------
346
		assertEquals("Legend position is not left", ChartLegendPosition.LEFT,
347
				aDiaProp.getPropertyValue("Alignment"));
348
349
	}
350
351
	// --------------Chart Title---------------
352
	/**
353
	 * test Addition and Modification of Title and subTitle
354
	 * @throws Exception
355
	 */
356
	@Test
357
	public void testTitleAndSubTitle() throws Exception {
358
		XShape xShape = null;
359
		insertDefaultChart();
360
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
361
				XPropertySet.class, xChartDoc.getTitle());
362
		aDiaProp.setPropertyValue("String", "TestTitle");
363
		XPropertySet aDiaProp2 = (XPropertySet) UnoRuntime.queryInterface(
364
				XPropertySet.class, xChartDoc.getSubTitle());
365
		aDiaProp2.setPropertyValue("String", "TestSubTitle");
366
		// save and load shape
367
		xShape = saveAndLoadShape(1, 0);
368
		xChartDoc = ChartUtil.getChartDocument(xShape);
369
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
370
				xChartDoc.getTitle());
371
		aDiaProp2 = (XPropertySet) UnoRuntime.queryInterface(
372
				XPropertySet.class, xChartDoc.getSubTitle());
373
		assertEquals("Chart title is wrong", "TestTitle",
374
				aDiaProp.getPropertyValue("String"));
375
		assertEquals("Chart sub title is wrong", "TestSubTitle",
376
				aDiaProp2.getPropertyValue("String"));
377
		// modify title and subtitle
378
		aDiaProp.setPropertyValue("String", "AnotherTestTitle");
379
		aDiaProp2.setPropertyValue("String", "AnotherTestSubTitle");
380
381
		// close document and save modification.
382
		XModifiable modified = (XModifiable) UnoRuntime.queryInterface(
383
				XModifiable.class, impressDocument);
384
		XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
385
				XCloseable.class, impressDocument);
386
		if (modified != null)
387
			modified.setModified(true);
388
		closer.close(true);
389
390
		// load and get Chart
391
		impressDocument = UnoRuntime.queryInterface(XComponent.class,
392
				unoApp.loadDocument(filePath));
393
		xShapes = ShapeUtil.getShapes(reLoadFile, 1);
394
		xShape = (XShape) UnoRuntime.queryInterface(XShape.class,
395
				xShapes.getByIndex(0));
396
		xChartDoc = ChartUtil.getChartDocument(xShape);
397
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
398
				xChartDoc.getTitle());
399
		aDiaProp2 = (XPropertySet) UnoRuntime.queryInterface(
400
				XPropertySet.class, xChartDoc.getSubTitle());
401
		assertEquals("Chart title is wrong", "AnotherTestTitle",
402
				aDiaProp.getPropertyValue("String"));
403
		assertEquals("Chart sub title is wrong", "AnotherTestSubTitle",
404
				aDiaProp2.getPropertyValue("String"));
405
	}
406
407
	/**
408
	 * test Data label and show it as value
409
	 * @throws Exception
410
	 */
411
	@Test
412
	public void testDataLabel() throws Exception {
413
		XShape xShape = null;
414
		insertDefaultChart();
415
		// set data label to the fourth points, the second series.
416
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
417
				XPropertySet.class, xChartDoc.getDiagram()
418
						.getDataPointProperties(3, 1));
419
		aDiaProp.setPropertyValue("DataCaption", ChartDataCaption.VALUE);
420
421
		// --------------------------
422
		xShape = saveAndLoadShape(1, 0);
423
		xChartDoc = ChartUtil.getChartDocument(xShape);
424
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
425
				xChartDoc.getDiagram().getDataPointProperties(3, 1));
426
427
		assertEquals(
428
				"Data label of fourth points, the second series not show as value",
429
				ChartDataCaption.VALUE,
430
				aDiaProp.getPropertyValue("DataCaption"));
431
432
	}
433
434
	/**
435
	 * test GridLine of Y Axis.
436
	 * @throws Exception
437
	 */
438
	@Test
439
	public void testGridLine() throws Exception {
440
		XShape xShape = null;
441
		insertDefaultChart();
442
		XDiagram xdiagram = xChartDoc.getDiagram();
443
		// get Y axis
444
		XAxisYSupplier aYAxisSupplier = (XAxisYSupplier) UnoRuntime
445
				.queryInterface(XAxisYSupplier.class, xdiagram);
446
		// get Y axis's gridline
447
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
448
				XPropertySet.class, aYAxisSupplier.getYMainGrid());
449
		aDiaProp.setPropertyValue("LineColor", 0xffff00);
450
451
		// --------------------------
452
		xShape = saveAndLoadShape(1, 0);
453
		xChartDoc = ChartUtil.getChartDocument(xShape);
454
		xdiagram = xChartDoc.getDiagram();
455
		aYAxisSupplier = (XAxisYSupplier) UnoRuntime.queryInterface(
456
				XAxisYSupplier.class, xdiagram);
457
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
458
				aYAxisSupplier.getYMainGrid());
459
		assertEquals("the Y grid line color is not yellow", 0xffff00,
460
				aDiaProp.getPropertyValue("LineColor"));
461
	}
462
463
	/**
464
	 * test Wall Fill properties 
465
	 * @throws Exception
466
	 */
467
	@Test
468
	public void testWall() throws Exception {
469
		XShape xShape = null;
470
		insertDefaultChart2();
471
		com.sun.star.chart2.XDiagram xDiagram2 = xChart2Doc.getFirstDiagram();
472
		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
473
				XPropertySet.class, xDiagram2.getWall());
474
		aDiaProp.setPropertyValue("FillStyle", FillStyle.SOLID);
475
		aDiaProp.setPropertyValue("FillColor", 0xffff00);
476
		// --------------------------
477
		xShape = saveAndLoadShape(1, 0);
478
		xChart2Doc = ChartUtil.getChart2Document(xShape);
479
		xDiagram2 = xChart2Doc.getFirstDiagram();
480
		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
481
				xDiagram2.getWall());
482
		assertEquals("the Chart wall is not yellow", 0xffff00,
483
				aDiaProp.getPropertyValue("FillColor"));
484
	}
485
486
	/**
487
	 * Save presentation and reLoad the presentation and shape in it.
488
	 * 
489
	 * @param po
490
	 * @param shapeType
491
	 * @return
492
	 * @throws Exception
493
	 */
494
	public XShape saveAndLoadShape(int pageIndex, int shapeIndex)
495
			throws Exception {
496
		reLoadFile = saveAsAndReloadDoc(impressDocument, "impress8", "odp");
497
		xShapes = ShapeUtil.getShapes(reLoadFile, pageIndex);
498
		return (XShape) UnoRuntime.queryInterface(XShape.class,
499
				xShapes.getByIndex(shapeIndex));
500
	}
501
502
	/**
503
	 * save and reload Presentation document.
504
	 * 
505
	 * @param presentationDocument
506
	 * @param sFilter
507
	 * @param sExtension
508
	 * @return
509
	 * @throws Exception
510
	 */
511
	private XComponent saveAsAndReloadDoc(XComponent presentationDocument,
512
			String sFilter, String sExtension) throws Exception {
513
		filePath = Testspace.getPath("tmp/chartproperties." + sExtension);
514
		PropertyValue[] aStoreProperties = new PropertyValue[2];
515
		aStoreProperties[0] = new PropertyValue();
516
		aStoreProperties[1] = new PropertyValue();
517
		aStoreProperties[0].Name = "Override";
518
		aStoreProperties[0].Value = true;
519
		aStoreProperties[1].Name = "FilterName";
520
		aStoreProperties[1].Value = sFilter;
521
		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
522
				XStorable.class, presentationDocument);
523
		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
524
525
		return UnoRuntime.queryInterface(XComponent.class,
526
				unoApp.loadDocument(filePath));
527
	}
528
529
}

Return to issue 120794