170af8983SLiu Zhe /**************************************************************
270af8983SLiu Zhe  *
370af8983SLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
470af8983SLiu Zhe  * or more contributor license agreements.  See the NOTICE file
570af8983SLiu Zhe  * distributed with this work for additional information
670af8983SLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
770af8983SLiu Zhe  * to you under the Apache License, Version 2.0 (the
870af8983SLiu Zhe  * "License"); you may not use this file except in compliance
970af8983SLiu Zhe  * with the License.  You may obtain a copy of the License at
1070af8983SLiu Zhe  *
1170af8983SLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
1270af8983SLiu Zhe  *
1370af8983SLiu Zhe  * Unless required by applicable law or agreed to in writing,
1470af8983SLiu Zhe  * software distributed under the License is distributed on an
1570af8983SLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1670af8983SLiu Zhe  * KIND, either express or implied.  See the License for the
1770af8983SLiu Zhe  * specific language governing permissions and limitations
1870af8983SLiu Zhe  * under the License.
1970af8983SLiu Zhe  *
2070af8983SLiu Zhe  *************************************************************/
21*eba4d44aSLiu Zhe package fvt.uno.sd.chart;
2270af8983SLiu Zhe 
2370af8983SLiu Zhe import static org.junit.Assert.assertEquals;
2470af8983SLiu Zhe 
2570af8983SLiu Zhe import org.junit.After;
2670af8983SLiu Zhe import org.junit.Before;
2770af8983SLiu Zhe import org.junit.Test;
2870af8983SLiu Zhe import org.openoffice.test.common.FileUtil;
2970af8983SLiu Zhe import org.openoffice.test.common.Testspace;
3070af8983SLiu Zhe import org.openoffice.test.uno.UnoApp;
3170af8983SLiu Zhe 
3270af8983SLiu Zhe import testlib.uno.ChartUtil;
3370af8983SLiu Zhe import testlib.uno.PageUtil;
3470af8983SLiu Zhe import testlib.uno.ShapeUtil;
3570af8983SLiu Zhe import testlib.uno.TestUtil;
3670af8983SLiu Zhe 
3770af8983SLiu Zhe import com.sun.star.awt.FontRelief;
3870af8983SLiu Zhe import com.sun.star.awt.FontUnderline;
3970af8983SLiu Zhe import com.sun.star.awt.FontWeight;
4070af8983SLiu Zhe import com.sun.star.awt.Point;
4170af8983SLiu Zhe import com.sun.star.awt.Size;
4270af8983SLiu Zhe import com.sun.star.beans.PropertyValue;
4370af8983SLiu Zhe import com.sun.star.beans.XPropertySet;
4470af8983SLiu Zhe import com.sun.star.chart.ChartDataCaption;
4570af8983SLiu Zhe import com.sun.star.chart.ChartLegendPosition;
4670af8983SLiu Zhe import com.sun.star.chart.XAxisYSupplier;
4770af8983SLiu Zhe import com.sun.star.chart.XChartDocument;
4870af8983SLiu Zhe import com.sun.star.chart.XDiagram;
4970af8983SLiu Zhe import com.sun.star.drawing.FillStyle;
5070af8983SLiu Zhe import com.sun.star.drawing.LineStyle;
5170af8983SLiu Zhe import com.sun.star.drawing.XDrawPage;
5270af8983SLiu Zhe import com.sun.star.drawing.XDrawPages;
5370af8983SLiu Zhe import com.sun.star.drawing.XDrawPagesSupplier;
5470af8983SLiu Zhe import com.sun.star.drawing.XShape;
5570af8983SLiu Zhe import com.sun.star.drawing.XShapes;
5670af8983SLiu Zhe import com.sun.star.frame.XStorable;
5770af8983SLiu Zhe import com.sun.star.lang.XComponent;
5870af8983SLiu Zhe import com.sun.star.presentation.XPresentation;
5970af8983SLiu Zhe import com.sun.star.presentation.XPresentationSupplier;
6070af8983SLiu Zhe import com.sun.star.uno.UnoRuntime;
6170af8983SLiu Zhe import com.sun.star.util.XCloseable;
6270af8983SLiu Zhe import com.sun.star.util.XModifiable;
6370af8983SLiu Zhe 
6470af8983SLiu Zhe public class ChartProperties {
6570af8983SLiu Zhe 	UnoApp unoApp = new UnoApp();
6670af8983SLiu Zhe 	XPresentationSupplier sdDocument = null;
6770af8983SLiu Zhe 	XPresentation pre = null;
6870af8983SLiu Zhe 	XComponent precomp = null;
6970af8983SLiu Zhe 	XComponent impressDocument = null;
7070af8983SLiu Zhe 	XComponent reLoadFile = null;
7170af8983SLiu Zhe 	XDrawPagesSupplier drawsupplier = null;
7270af8983SLiu Zhe 	XDrawPages drawpages = null;
7370af8983SLiu Zhe 	XShapes xShapes = null;
7470af8983SLiu Zhe 	XDrawPage xpage = null;
7570af8983SLiu Zhe 	String filePath = null;
7670af8983SLiu Zhe 	XChartDocument xChartDoc = null;
7770af8983SLiu Zhe 	com.sun.star.chart2.XChartDocument xChart2Doc = null;
7870af8983SLiu Zhe 
7970af8983SLiu Zhe 	@Before
setUp()8070af8983SLiu Zhe 	public void setUp() throws Exception {
8170af8983SLiu Zhe 		unoApp.start();
8270af8983SLiu Zhe 		createDocumentAndSlide();
8370af8983SLiu Zhe 	}
8470af8983SLiu Zhe 
8570af8983SLiu Zhe 	@After
tearDown()8670af8983SLiu Zhe 	public void tearDown() throws Exception {
8770af8983SLiu Zhe 		unoApp.closeDocument(impressDocument);
8870af8983SLiu Zhe 		unoApp.closeDocument(reLoadFile);
8970af8983SLiu Zhe 		unoApp.close();
9070af8983SLiu Zhe 		 if (filePath != null)
9170af8983SLiu Zhe 		 FileUtil.deleteFile(filePath);
9270af8983SLiu Zhe 	}
9370af8983SLiu Zhe 
9470af8983SLiu Zhe 	/**
9570af8983SLiu Zhe 	 * create a new presentation document and insert a new slide.
9670af8983SLiu Zhe 	 *
9770af8983SLiu Zhe 	 * @throws Exception
9870af8983SLiu Zhe 	 */
createDocumentAndSlide()9970af8983SLiu Zhe 	public void createDocumentAndSlide() throws Exception {
10070af8983SLiu Zhe 		impressDocument = (XComponent) UnoRuntime.queryInterface(
10170af8983SLiu Zhe 				XComponent.class, unoApp.newDocument("simpress"));
10270af8983SLiu Zhe 		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
10370af8983SLiu Zhe 				XDrawPagesSupplier.class, impressDocument);
10470af8983SLiu Zhe 		drawpages = drawsupplier.getDrawPages();
10570af8983SLiu Zhe 		drawpages.insertNewByIndex(1);
10670af8983SLiu Zhe 		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
10770af8983SLiu Zhe 	}
10870af8983SLiu Zhe 
10970af8983SLiu Zhe 	/**
11070af8983SLiu Zhe 	 * Insert default Column Chart to slide.
11170af8983SLiu Zhe 	 *
11270af8983SLiu Zhe 	 * @return
11370af8983SLiu Zhe 	 * @throws Exception
11470af8983SLiu Zhe 	 */
insertDefaultChart()11570af8983SLiu Zhe 	public XChartDocument insertDefaultChart() throws Exception {
11670af8983SLiu Zhe 		Point po = new Point(1000, 1000);
11770af8983SLiu Zhe 		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
11870af8983SLiu Zhe 		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
11970af8983SLiu Zhe 				15000, 9271), "com.sun.star.drawing.OLE2Shape");
12070af8983SLiu Zhe 		xShapes.add(xShape);
12170af8983SLiu Zhe 		xChartDoc = ChartUtil.retrieveChartDocument(xShape);
12270af8983SLiu Zhe 		return xChartDoc;
12370af8983SLiu Zhe 	}
12470af8983SLiu Zhe 
12570af8983SLiu Zhe 	/**
12670af8983SLiu Zhe 	 * Insert default Column Chart2 to slide.
12770af8983SLiu Zhe 	 *
12870af8983SLiu Zhe 	 * @return
12970af8983SLiu Zhe 	 * @throws Exception
13070af8983SLiu Zhe 	 */
insertDefaultChart2()13170af8983SLiu Zhe 	public com.sun.star.chart2.XChartDocument insertDefaultChart2()
13270af8983SLiu Zhe 			throws Exception {
13370af8983SLiu Zhe 		Point po = new Point(1000, 1000);
13470af8983SLiu Zhe 		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
13570af8983SLiu Zhe 		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
13670af8983SLiu Zhe 				15000, 9271), "com.sun.star.drawing.OLE2Shape");
13770af8983SLiu Zhe 		xShapes.add(xShape);
13870af8983SLiu Zhe 		xChart2Doc = ChartUtil.retrieveChart2Document(xShape);
13970af8983SLiu Zhe 		return xChart2Doc;
14070af8983SLiu Zhe 	}
14170af8983SLiu Zhe 
14270af8983SLiu Zhe 	// --------------Chart Area----------------------
14370af8983SLiu Zhe 	/**
14470af8983SLiu Zhe 	 * test Chart Area properties about Border Line
14570af8983SLiu Zhe 	 *
14670af8983SLiu Zhe 	 * @throws Exception
14770af8983SLiu Zhe 	 */
14870af8983SLiu Zhe 	@Test
testAreaBordersProperties()14970af8983SLiu Zhe 	public void testAreaBordersProperties() throws Exception {
15070af8983SLiu Zhe 		XShape xShape = null;
15170af8983SLiu Zhe 		insertDefaultChart();
15270af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
15370af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getArea());
15470af8983SLiu Zhe 		aDiaProp.setPropertyValue("LineStyle", LineStyle.DASH);
15570af8983SLiu Zhe 		aDiaProp.setPropertyValue("LineColor", 0x00ff00);
15670af8983SLiu Zhe 
15770af8983SLiu Zhe 		// --------------------------
15870af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
15970af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
16070af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
16170af8983SLiu Zhe 				xChartDoc.getArea());
16270af8983SLiu Zhe 		// ----------------------------
16370af8983SLiu Zhe 		assertEquals("Not Dash Line Style", LineStyle.DASH,
16470af8983SLiu Zhe 				aDiaProp.getPropertyValue("LineStyle"));
16570af8983SLiu Zhe 		assertEquals("Not Yellow Line", 0x00ff00,
16670af8983SLiu Zhe 				aDiaProp.getPropertyValue("LineColor"));
16770af8983SLiu Zhe 
16870af8983SLiu Zhe 	}
16970af8983SLiu Zhe 
17070af8983SLiu Zhe 	/**
17170af8983SLiu Zhe 	 * test Area Properties about Gradient Fill
17270af8983SLiu Zhe 	 * @throws Exception
17370af8983SLiu Zhe 	 */
17470af8983SLiu Zhe 	@Test
testAreaFillProperties()17570af8983SLiu Zhe 	public void testAreaFillProperties() throws Exception {
17670af8983SLiu Zhe 		XShape xShape = null;
17770af8983SLiu Zhe 		insertDefaultChart();
17870af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
17970af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getArea());
18070af8983SLiu Zhe 		aDiaProp.setPropertyValue("FillStyle", FillStyle.GRADIENT);
18170af8983SLiu Zhe 		aDiaProp.setPropertyValue("FillGradientName", "Radial red/yellow");
18270af8983SLiu Zhe 		// --------------------------
18370af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
18470af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
18570af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
18670af8983SLiu Zhe 				xChartDoc.getArea());
18770af8983SLiu Zhe 		// ----------------------------
18870af8983SLiu Zhe 		assertEquals("Not Gradient Fill Style", FillStyle.GRADIENT,
18970af8983SLiu Zhe 				aDiaProp.getPropertyValue("FillStyle"));
19070af8983SLiu Zhe 		assertEquals("Not Radial red/yellow Gradient", "Radial red/yellow",
19170af8983SLiu Zhe 				aDiaProp.getPropertyValue("FillGradientName"));
19270af8983SLiu Zhe 
19370af8983SLiu Zhe 	}
19470af8983SLiu Zhe 
19570af8983SLiu Zhe 	/**
19670af8983SLiu Zhe 	 * test Area properties about Transparency
19770af8983SLiu Zhe 	 * @throws Exception
19870af8983SLiu Zhe 	 */
19970af8983SLiu Zhe 	@Test
testAreaTransparencyProperties()20070af8983SLiu Zhe 	public void testAreaTransparencyProperties() throws Exception {
20170af8983SLiu Zhe 		XShape xShape = null;
20270af8983SLiu Zhe 		insertDefaultChart();
20370af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
20470af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getArea());
20570af8983SLiu Zhe 		aDiaProp.setPropertyValue("FillStyle", FillStyle.SOLID);
20670af8983SLiu Zhe 		aDiaProp.setPropertyValue("FillColor", 0xffff00);
20770af8983SLiu Zhe 		aDiaProp.setPropertyValue("FillTransparence", 50);
20870af8983SLiu Zhe 		// --------------------------
20970af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
21070af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
21170af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
21270af8983SLiu Zhe 				xChartDoc.getArea());
21370af8983SLiu Zhe 		// ----------------------------
21470af8983SLiu Zhe 		assertEquals("Area Fill Transparency is not 50%", new Short("50"),
21570af8983SLiu Zhe 				aDiaProp.getPropertyValue("FillTransparence"));
21670af8983SLiu Zhe 
21770af8983SLiu Zhe 	}
21870af8983SLiu Zhe 
21970af8983SLiu Zhe 	// ------------Chart Legend-------------------
22070af8983SLiu Zhe 	/**
22170af8983SLiu Zhe 	 * test Legend Border Line Properties
22270af8983SLiu Zhe 	 * @throws Exception
22370af8983SLiu Zhe 	 */
22470af8983SLiu Zhe 	@Test
testLegendBorderProperties()22570af8983SLiu Zhe 	public void testLegendBorderProperties() throws Exception {
22670af8983SLiu Zhe 		XShape xShape = null;
22770af8983SLiu Zhe 		insertDefaultChart();
22870af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
22970af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getLegend());
23070af8983SLiu Zhe 		aDiaProp.setPropertyValue("LineStyle", LineStyle.DASH);
23170af8983SLiu Zhe 		aDiaProp.setPropertyValue("LineColor", 0x00ff00);
23270af8983SLiu Zhe 		// --------------------------
23370af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
23470af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
23570af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
23670af8983SLiu Zhe 				xChartDoc.getLegend());
23770af8983SLiu Zhe 		// ----------------------------
23870af8983SLiu Zhe 		assertEquals("Not Dash Line Style", LineStyle.DASH,
23970af8983SLiu Zhe 				aDiaProp.getPropertyValue("LineStyle"));
24070af8983SLiu Zhe 		assertEquals("Not Yellow Line", 0x00ff00,
24170af8983SLiu Zhe 				aDiaProp.getPropertyValue("LineColor"));
24270af8983SLiu Zhe 
24370af8983SLiu Zhe 	}
24470af8983SLiu Zhe 
24570af8983SLiu Zhe 	/**
24670af8983SLiu Zhe 	 * test Legend Fill and transparence properties
24770af8983SLiu Zhe 	 * @throws Exception
24870af8983SLiu Zhe 	 */
24970af8983SLiu Zhe 	@Test
testLegendFillAndTransparence()25070af8983SLiu Zhe 	public void testLegendFillAndTransparence() throws Exception {
25170af8983SLiu Zhe 		XShape xShape = null;
25270af8983SLiu Zhe 		insertDefaultChart();
25370af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
25470af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getLegend());
25570af8983SLiu Zhe 		aDiaProp.setPropertyValue("FillStyle", FillStyle.SOLID);
25670af8983SLiu Zhe 		aDiaProp.setPropertyValue("FillColor", 0xffff00);
25770af8983SLiu Zhe 		aDiaProp.setPropertyValue("FillTransparence", 50);
25870af8983SLiu Zhe 		// --------------------------
25970af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
26070af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
26170af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
26270af8983SLiu Zhe 				xChartDoc.getLegend());
26370af8983SLiu Zhe 		// ----------------------------
26470af8983SLiu Zhe 
26570af8983SLiu Zhe 		assertEquals("Area Fill Transparency is not 50%", new Short("50"),
26670af8983SLiu Zhe 				aDiaProp.getPropertyValue("FillTransparence"));
26770af8983SLiu Zhe 
26870af8983SLiu Zhe 	}
26970af8983SLiu Zhe 
27070af8983SLiu Zhe 	/**
27170af8983SLiu Zhe 	 * test Legend Char Font
27270af8983SLiu Zhe 	 * @throws Exception
27370af8983SLiu Zhe 	 */
27470af8983SLiu Zhe 	@Test
testLegendCharFont()27570af8983SLiu Zhe 	public void testLegendCharFont() throws Exception {
27670af8983SLiu Zhe 		XShape xShape = null;
27770af8983SLiu Zhe 		insertDefaultChart();
27870af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
27970af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getLegend());
28070af8983SLiu Zhe 		aDiaProp.setPropertyValue("CharFontName", "Arial");
28170af8983SLiu Zhe 		aDiaProp.setPropertyValue("CharWeight", FontWeight.BOLD);
28270af8983SLiu Zhe 		// --------------------------
28370af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
28470af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
28570af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
28670af8983SLiu Zhe 				xChartDoc.getLegend());
28770af8983SLiu Zhe 		// ----------------------------
28870af8983SLiu Zhe 		assertEquals("Legend font name is not Arial", "Arial",
28970af8983SLiu Zhe 				aDiaProp.getPropertyValue("CharFontName"));
29070af8983SLiu Zhe 		assertEquals("Legend font weight is not BOLD", FontWeight.BOLD,
29170af8983SLiu Zhe 				aDiaProp.getPropertyValue("CharWeight"));
29270af8983SLiu Zhe 
29370af8983SLiu Zhe 	}
29470af8983SLiu Zhe 
29570af8983SLiu Zhe 	/**
29670af8983SLiu Zhe 	 * test Legend Char Font Effects
29770af8983SLiu Zhe 	 * @throws Exception
29870af8983SLiu Zhe 	 */
29970af8983SLiu Zhe 	@Test
testLegendCharFontEffects()30070af8983SLiu Zhe 	public void testLegendCharFontEffects() throws Exception {
30170af8983SLiu Zhe 		XShape xShape = null;
30270af8983SLiu Zhe 		insertDefaultChart();
30370af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
30470af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getLegend());
30570af8983SLiu Zhe 		aDiaProp.setPropertyValue("CharColor", 0xffff00);
30670af8983SLiu Zhe 		aDiaProp.setPropertyValue("CharUnderline", FontUnderline.DOUBLE);
30770af8983SLiu Zhe 		aDiaProp.setPropertyValue("CharUnderlineColor", 0xffff00);
30870af8983SLiu Zhe 		aDiaProp.setPropertyValue("CharRelief", FontRelief.ENGRAVED);
30970af8983SLiu Zhe 
31070af8983SLiu Zhe 		// --------------------------
31170af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
31270af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
31370af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
31470af8983SLiu Zhe 				xChartDoc.getLegend());
31570af8983SLiu Zhe 		// ----------------------------
31670af8983SLiu Zhe 		assertEquals("Legend font color is not yellow", 0xffff00,
31770af8983SLiu Zhe 				aDiaProp.getPropertyValue("CharColor"));
31870af8983SLiu Zhe 		assertEquals("Legend font underline is not DOUBLE",
31970af8983SLiu Zhe 				FontUnderline.DOUBLE,
32070af8983SLiu Zhe 				aDiaProp.getPropertyValue("CharUnderline"));
32170af8983SLiu Zhe 		assertEquals("Legend font underline color is not yellow", 0xffff00,
32270af8983SLiu Zhe 				aDiaProp.getPropertyValue("CharUnderlineColor"));
32370af8983SLiu Zhe 		assertEquals("Legend font relief is not engraved", FontRelief.ENGRAVED,
32470af8983SLiu Zhe 				aDiaProp.getPropertyValue("CharRelief"));
32570af8983SLiu Zhe 
32670af8983SLiu Zhe 	}
32770af8983SLiu Zhe 
32870af8983SLiu Zhe 	/**
32970af8983SLiu Zhe 	 * test Legend Position in Chart
33070af8983SLiu Zhe 	 * @throws Exception
33170af8983SLiu Zhe 	 */
33270af8983SLiu Zhe 	@Test
testLegendposition()33370af8983SLiu Zhe 	public void testLegendposition() throws Exception {
33470af8983SLiu Zhe 		XShape xShape = null;
33570af8983SLiu Zhe 		insertDefaultChart();
33670af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
33770af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getLegend());
33870af8983SLiu Zhe 		aDiaProp.setPropertyValue("Alignment", ChartLegendPosition.LEFT);
33970af8983SLiu Zhe 
34070af8983SLiu Zhe 		// --------------------------
34170af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
34270af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
34370af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
34470af8983SLiu Zhe 				xChartDoc.getLegend());
34570af8983SLiu Zhe 		// ----------------------------
34670af8983SLiu Zhe 		assertEquals("Legend position is not left", ChartLegendPosition.LEFT,
34770af8983SLiu Zhe 				aDiaProp.getPropertyValue("Alignment"));
34870af8983SLiu Zhe 
34970af8983SLiu Zhe 	}
35070af8983SLiu Zhe 
35170af8983SLiu Zhe 	// --------------Chart Title---------------
35270af8983SLiu Zhe 	/**
35370af8983SLiu Zhe 	 * test Addition and Modification of Title and subTitle
35470af8983SLiu Zhe 	 * @throws Exception
35570af8983SLiu Zhe 	 */
35670af8983SLiu Zhe 	@Test
testTitleAndSubTitle()35770af8983SLiu Zhe 	public void testTitleAndSubTitle() throws Exception {
35870af8983SLiu Zhe 		XShape xShape = null;
35970af8983SLiu Zhe 		insertDefaultChart();
36070af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
36170af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getTitle());
36270af8983SLiu Zhe 		aDiaProp.setPropertyValue("String", "TestTitle");
36370af8983SLiu Zhe 		XPropertySet aDiaProp2 = (XPropertySet) UnoRuntime.queryInterface(
36470af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getSubTitle());
36570af8983SLiu Zhe 		aDiaProp2.setPropertyValue("String", "TestSubTitle");
36670af8983SLiu Zhe 		// save and load shape
36770af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
36870af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
36970af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
37070af8983SLiu Zhe 				xChartDoc.getTitle());
37170af8983SLiu Zhe 		aDiaProp2 = (XPropertySet) UnoRuntime.queryInterface(
37270af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getSubTitle());
37370af8983SLiu Zhe 		assertEquals("Chart title is wrong", "TestTitle",
37470af8983SLiu Zhe 				aDiaProp.getPropertyValue("String"));
37570af8983SLiu Zhe 		assertEquals("Chart sub title is wrong", "TestSubTitle",
37670af8983SLiu Zhe 				aDiaProp2.getPropertyValue("String"));
37770af8983SLiu Zhe 		// modify title and subtitle
37870af8983SLiu Zhe 		aDiaProp.setPropertyValue("String", "AnotherTestTitle");
37970af8983SLiu Zhe 		aDiaProp2.setPropertyValue("String", "AnotherTestSubTitle");
38070af8983SLiu Zhe 
38170af8983SLiu Zhe 		// close document and save modification.
38270af8983SLiu Zhe 		XModifiable modified = (XModifiable) UnoRuntime.queryInterface(
38370af8983SLiu Zhe 				XModifiable.class, impressDocument);
38470af8983SLiu Zhe 		XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
38570af8983SLiu Zhe 				XCloseable.class, impressDocument);
38670af8983SLiu Zhe 		if (modified != null)
38770af8983SLiu Zhe 			modified.setModified(true);
38870af8983SLiu Zhe 		closer.close(true);
38970af8983SLiu Zhe 
39070af8983SLiu Zhe 		// load and get Chart
3914c280f34SLinyi Li 		impressDocument = (XComponent) UnoRuntime.queryInterface(XComponent.class,
39270af8983SLiu Zhe 				unoApp.loadDocument(filePath));
39370af8983SLiu Zhe 		xShapes = ShapeUtil.getShapes(reLoadFile, 1);
39470af8983SLiu Zhe 		xShape = (XShape) UnoRuntime.queryInterface(XShape.class,
39570af8983SLiu Zhe 				xShapes.getByIndex(0));
39670af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
39770af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
39870af8983SLiu Zhe 				xChartDoc.getTitle());
39970af8983SLiu Zhe 		aDiaProp2 = (XPropertySet) UnoRuntime.queryInterface(
40070af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getSubTitle());
40170af8983SLiu Zhe 		assertEquals("Chart title is wrong", "AnotherTestTitle",
40270af8983SLiu Zhe 				aDiaProp.getPropertyValue("String"));
40370af8983SLiu Zhe 		assertEquals("Chart sub title is wrong", "AnotherTestSubTitle",
40470af8983SLiu Zhe 				aDiaProp2.getPropertyValue("String"));
40570af8983SLiu Zhe 	}
40670af8983SLiu Zhe 
40770af8983SLiu Zhe 	/**
40870af8983SLiu Zhe 	 * test Data label and show it as value
40970af8983SLiu Zhe 	 * @throws Exception
41070af8983SLiu Zhe 	 */
41170af8983SLiu Zhe 	@Test
testDataLabel()41270af8983SLiu Zhe 	public void testDataLabel() throws Exception {
41370af8983SLiu Zhe 		XShape xShape = null;
41470af8983SLiu Zhe 		insertDefaultChart();
41570af8983SLiu Zhe 		// set data label to the fourth points, the second series.
41670af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
41770af8983SLiu Zhe 				XPropertySet.class, xChartDoc.getDiagram()
41870af8983SLiu Zhe 						.getDataPointProperties(3, 1));
41970af8983SLiu Zhe 		aDiaProp.setPropertyValue("DataCaption", ChartDataCaption.VALUE);
42070af8983SLiu Zhe 
42170af8983SLiu Zhe 		// --------------------------
42270af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
42370af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
42470af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
42570af8983SLiu Zhe 				xChartDoc.getDiagram().getDataPointProperties(3, 1));
42670af8983SLiu Zhe 
42770af8983SLiu Zhe 		assertEquals(
42870af8983SLiu Zhe 				"Data label of fourth points, the second series not show as value",
42970af8983SLiu Zhe 				ChartDataCaption.VALUE,
43070af8983SLiu Zhe 				aDiaProp.getPropertyValue("DataCaption"));
43170af8983SLiu Zhe 
43270af8983SLiu Zhe 	}
43370af8983SLiu Zhe 
43470af8983SLiu Zhe 	/**
43570af8983SLiu Zhe 	 * test GridLine of Y Axis.
43670af8983SLiu Zhe 	 * @throws Exception
43770af8983SLiu Zhe 	 */
43870af8983SLiu Zhe 	@Test
testGridLine()43970af8983SLiu Zhe 	public void testGridLine() throws Exception {
44070af8983SLiu Zhe 		XShape xShape = null;
44170af8983SLiu Zhe 		insertDefaultChart();
44270af8983SLiu Zhe 		XDiagram xdiagram = xChartDoc.getDiagram();
44370af8983SLiu Zhe 		// get Y axis
44470af8983SLiu Zhe 		XAxisYSupplier aYAxisSupplier = (XAxisYSupplier) UnoRuntime
44570af8983SLiu Zhe 				.queryInterface(XAxisYSupplier.class, xdiagram);
44670af8983SLiu Zhe 		// get Y axis's gridline
44770af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
44870af8983SLiu Zhe 				XPropertySet.class, aYAxisSupplier.getYMainGrid());
44970af8983SLiu Zhe 		aDiaProp.setPropertyValue("LineColor", 0xffff00);
45070af8983SLiu Zhe 
45170af8983SLiu Zhe 		// --------------------------
45270af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
45370af8983SLiu Zhe 		xChartDoc = ChartUtil.getChartDocument(xShape);
45470af8983SLiu Zhe 		xdiagram = xChartDoc.getDiagram();
45570af8983SLiu Zhe 		aYAxisSupplier = (XAxisYSupplier) UnoRuntime.queryInterface(
45670af8983SLiu Zhe 				XAxisYSupplier.class, xdiagram);
45770af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
45870af8983SLiu Zhe 				aYAxisSupplier.getYMainGrid());
45970af8983SLiu Zhe 		assertEquals("the Y grid line color is not yellow", 0xffff00,
46070af8983SLiu Zhe 				aDiaProp.getPropertyValue("LineColor"));
46170af8983SLiu Zhe 	}
46270af8983SLiu Zhe 
46370af8983SLiu Zhe 	/**
46470af8983SLiu Zhe 	 * test Wall Fill properties
46570af8983SLiu Zhe 	 * @throws Exception
46670af8983SLiu Zhe 	 */
46770af8983SLiu Zhe 	@Test
testWall()46870af8983SLiu Zhe 	public void testWall() throws Exception {
46970af8983SLiu Zhe 		XShape xShape = null;
47070af8983SLiu Zhe 		insertDefaultChart2();
47170af8983SLiu Zhe 		com.sun.star.chart2.XDiagram xDiagram2 = xChart2Doc.getFirstDiagram();
47270af8983SLiu Zhe 		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
47370af8983SLiu Zhe 				XPropertySet.class, xDiagram2.getWall());
47470af8983SLiu Zhe 		aDiaProp.setPropertyValue("FillStyle", FillStyle.SOLID);
47570af8983SLiu Zhe 		aDiaProp.setPropertyValue("FillColor", 0xffff00);
47670af8983SLiu Zhe 		// --------------------------
47770af8983SLiu Zhe 		xShape = saveAndLoadShape(1, 0);
47870af8983SLiu Zhe 		xChart2Doc = ChartUtil.getChart2Document(xShape);
47970af8983SLiu Zhe 		xDiagram2 = xChart2Doc.getFirstDiagram();
48070af8983SLiu Zhe 		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
48170af8983SLiu Zhe 				xDiagram2.getWall());
48270af8983SLiu Zhe 		assertEquals("the Chart wall is not yellow", 0xffff00,
48370af8983SLiu Zhe 				aDiaProp.getPropertyValue("FillColor"));
48470af8983SLiu Zhe 	}
48570af8983SLiu Zhe 
48670af8983SLiu Zhe 	/**
48770af8983SLiu Zhe 	 * Save presentation and reLoad the presentation and shape in it.
48870af8983SLiu Zhe 	 *
48970af8983SLiu Zhe 	 * @param po
49070af8983SLiu Zhe 	 * @param shapeType
49170af8983SLiu Zhe 	 * @return
49270af8983SLiu Zhe 	 * @throws Exception
49370af8983SLiu Zhe 	 */
saveAndLoadShape(int pageIndex, int shapeIndex)49470af8983SLiu Zhe 	public XShape saveAndLoadShape(int pageIndex, int shapeIndex)
49570af8983SLiu Zhe 			throws Exception {
49670af8983SLiu Zhe 		reLoadFile = saveAsAndReloadDoc(impressDocument, "impress8", "odp");
49770af8983SLiu Zhe 		xShapes = ShapeUtil.getShapes(reLoadFile, pageIndex);
49870af8983SLiu Zhe 		return (XShape) UnoRuntime.queryInterface(XShape.class,
49970af8983SLiu Zhe 				xShapes.getByIndex(shapeIndex));
50070af8983SLiu Zhe 	}
50170af8983SLiu Zhe 
50270af8983SLiu Zhe 	/**
50370af8983SLiu Zhe 	 * save and reload Presentation document.
50470af8983SLiu Zhe 	 *
50570af8983SLiu Zhe 	 * @param presentationDocument
50670af8983SLiu Zhe 	 * @param sFilter
50770af8983SLiu Zhe 	 * @param sExtension
50870af8983SLiu Zhe 	 * @return
50970af8983SLiu Zhe 	 * @throws Exception
51070af8983SLiu Zhe 	 */
saveAsAndReloadDoc(XComponent presentationDocument, String sFilter, String sExtension)51170af8983SLiu Zhe 	private XComponent saveAsAndReloadDoc(XComponent presentationDocument,
51270af8983SLiu Zhe 			String sFilter, String sExtension) throws Exception {
51370af8983SLiu Zhe 		filePath = Testspace.getPath("tmp/chartproperties." + sExtension);
51470af8983SLiu Zhe 		PropertyValue[] aStoreProperties = new PropertyValue[2];
51570af8983SLiu Zhe 		aStoreProperties[0] = new PropertyValue();
51670af8983SLiu Zhe 		aStoreProperties[1] = new PropertyValue();
51770af8983SLiu Zhe 		aStoreProperties[0].Name = "Override";
51870af8983SLiu Zhe 		aStoreProperties[0].Value = true;
51970af8983SLiu Zhe 		aStoreProperties[1].Name = "FilterName";
52070af8983SLiu Zhe 		aStoreProperties[1].Value = sFilter;
52170af8983SLiu Zhe 		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
52270af8983SLiu Zhe 				XStorable.class, presentationDocument);
52370af8983SLiu Zhe 		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
52470af8983SLiu Zhe 
5254c280f34SLinyi Li 		return (XComponent) UnoRuntime.queryInterface(XComponent.class,
52670af8983SLiu Zhe 				unoApp.loadDocument(filePath));
52770af8983SLiu Zhe 	}
52870af8983SLiu Zhe 
52970af8983SLiu Zhe }
530