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